/usr/share/perl5/HTTP/OAI/Header.pm is in libhttp-oai-perl 3.27-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | package HTTP::OAI::Header;
use strict;
use warnings;
use POSIX qw/strftime/;
use vars qw(@ISA);
use HTTP::OAI::SAXHandler qw( :SAX );
@ISA = qw(HTTP::OAI::Encapsulation);
sub new {
my ($class,%args) = @_;
my $self = $class->SUPER::new(%args);
$self->identifier($args{identifier}) unless $self->identifier;
$self->datestamp($args{datestamp}) unless $self->datestamp;
$self->status($args{status}) unless $self->status;
$self->{setSpec} ||= $args{setSpec} || [];
$self;
}
sub identifier { shift->_elem('identifier',@_) }
sub now { return strftime("%Y-%m-%dT%H:%M:%SZ",gmtime()) }
sub datestamp {
my $self = shift;
return $self->_elem('datestamp') unless @_;
my $ds = shift or return $self->_elem('datestamp',undef);
if( $ds =~ /^(\d{4})(\d{2})(\d{2})$/ ) {
$ds = "$1-$2-$3";
} elsif( $ds =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/ ) {
$ds = "$1-$2-$3T$4:$5:$6Z";
}
return $self->_elem('datestamp',$ds);
}
sub status { shift->_attr('status',@_) }
sub is_deleted { my $s = shift->status(); return defined($s) && $s eq 'deleted'; }
sub setSpec {
my $self = shift;
push(@{$self->{setSpec}},@_);
@{$self->{setSpec}};
}
sub dom {
my $self = shift;
if( my $dom = shift ) {
my $driver = XML::LibXML::SAX::Parser->new(
Handler=>HTTP::OAI::SAXHandler->new(
Handler=>$self
));
$driver->generate($dom->ownerDocument);
} else {
$self->set_handler(my $builder = XML::LibXML::SAX::Builder->new());
g_start_document($self);
$self->xml_decl({'Version'=>'1.0','Encoding'=>'UTF-8'});
$self->characters({'Data'=>"\n"});
$self->generate();
$self->end_document();
return $builder->result;
}
}
sub generate {
my ($self) = @_;
return unless defined(my $handler = $self->get_handler);
if( defined($self->status) ) {
g_start_element($handler,'http://www.openarchives.org/OAI/2.0/','header',
{
"{}status"=>{
'Name'=>'status',
'LocalName'=>'status',
'Value'=>$self->status,
'Prefix'=>'',
'NamespaceURI'=>''
}
});
} else {
g_start_element($handler,'http://www.openarchives.org/OAI/2.0/','header',{});
}
g_data_element($handler,'http://www.openarchives.org/OAI/2.0/','identifier',{},$self->identifier);
g_data_element($handler,'http://www.openarchives.org/OAI/2.0/','datestamp',{},($self->datestamp || $self->now));
for($self->setSpec) {
g_data_element($handler,'http://www.openarchives.org/OAI/2.0/','setSpec',{},$_);
}
g_end_element($handler,'http://www.openarchives.org/OAI/2.0/','header');
}
sub end_element {
my ($self,$hash) = @_;
my $elem = lc($hash->{LocalName});
my $text = $hash->{Text};
if( defined $text )
{
$text =~ s/^\s+//;
$text =~ s/\s+$//;
}
if( $elem eq 'identifier' ) {
die "HTTP::OAI::Header parse error: Empty identifier\n" unless $text;
$self->identifier($text);
} elsif( $elem eq 'datestamp' ) {
warn "HTTP::OAI::Header parse warning: Empty datestamp for ".$self->identifier."\n" unless $text;
$self->datestamp($text);
} elsif( $elem eq 'setspec' ) {
$self->setSpec($text);
} elsif( $elem eq 'header' ) {
$self->status($hash->{Attributes}->{'{}status'}->{Value});
}
}
1;
__END__
=head1 NAME
HTTP::OAI::Header - Encapsulates an OAI header structure
=head1 SYNOPSIS
use HTTP::OAI::Header;
my $h = new HTTP::OAI::Header(
identifier=>'oai:myarchive.org:2233-add',
datestamp=>'2002-04-12T20:31:00Z',
);
$h->setSpec('all:novels');
=head1 METHODS
=over 4
=item $h = new HTTP::OAI::Header
This constructor method returns a new C<HTTP::OAI::Header object>.
=item $h->identifier([$identifier])
Get and optionally set the record OAI identifier.
=item $h->datestamp([$datestamp])
Get and optionally set the record datestamp (OAI 2.0+).
=item $h->status([$status])
Get and optionally set the record status (valid values are 'deleted' or undef).
=item $h->is_deleted()
Returns whether this record's status is deleted.
=item @sets = $h->setSpec([$setSpec])
Returns the list of setSpecs and optionally appends a new setSpec C<$setSpec> (OAI 2.0+).
=item $dom_fragment = $id->generate()
Act as a SAX driver (use C<< $h->set_handler() >> to specify the filter to pass events to).
=back
|