| 1 | package Net::OAI::Record::Header; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use base qw( XML::SAX::Base ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use Carp qw( carp ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 17 | our $VERSION = "1.16_12"; | |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | Net::OAI::Record::Header - class for record header representation | ||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | Actually this class implements a SAX filter for the | ||||||||||||||||||||||||||||||
| 19 | complete C<record> OAI-PMH element. The contents of the C<header> | ||||||||||||||||||||||||||||||
| 20 | child are collected into a header object and can be accessed by the | ||||||||||||||||||||||||||||||
| 21 | methods documented here. | ||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | Events will be traditionally forwarded only from the subelement(s) of | ||||||||||||||||||||||||||||||
| 24 | the C<metadata> child which makes it difficult to access data | ||||||||||||||||||||||||||||||
| 25 | contained in the (possibly multiple) C<about> containers which may follow | ||||||||||||||||||||||||||||||
| 26 | the C<metadata> in the C<record>. | ||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | Beginning from OAI-Harvester v1.20 a new "recordHandler" argument | ||||||||||||||||||||||||||||||
| 29 | may be given to the harvester functions C<getRecord()> and C<listRecords()>: | ||||||||||||||||||||||||||||||
| 30 | In contrast to a "metadataHandler" argument this will pass the "fwdAll" | ||||||||||||||||||||||||||||||
| 31 | argument to the constructor of this Header class and result in | ||||||||||||||||||||||||||||||
| 32 | forwarding all events in the C<record> (including C<record> itself) to | ||||||||||||||||||||||||||||||
| 33 | the handler specified, not only those from C<metadata> children. | ||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | In case of compatibility issues of Filters written for older veresions | ||||||||||||||||||||||||||||||
| 36 | you might set C<$Net::OAI::Harvester::OLDmetadataHandler = 1>, | ||||||||||||||||||||||||||||||
| 37 | in which case the metadataHandler Option behaves like a recordHandler. | ||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||
| 39 | The SAX filter implemented by this class purposefully does not generate | ||||||||||||||||||||||||||||||
| 40 | any start_document() or end_document() events. | ||||||||||||||||||||||||||||||
| 41 | Consider inserting L<Net::OAI::Record::DocumentHelper> as an additional | ||||||||||||||||||||||||||||||
| 42 | filtering stage if your handler(s) need these events, if they fail | ||||||||||||||||||||||||||||||
| 43 | class verification, or if you need a hook for capturing their result. | ||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||
| 46 | =head1 METHODS | ||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | =head2 new() | ||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | sub new { | ||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | my ( $class, %opts ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | my $self = bless \%opts, ref( $class ) || $class; | ||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||
| 55 | 1 | $self->{ status } = $self->{ identifier } = $self->{ datestamp } = ''; | |||||||||||||||||||||||||||||
| 56 | 1 | $self->{ _tagStack } = []; | |||||||||||||||||||||||||||||
| 57 | 1 | $self->{ sets } = []; | |||||||||||||||||||||||||||||
| 58 | 1 | $self->{ _insideHeader } = $self->{ _insideMetadata } = $self->{ _insideAbout } = 0; | |||||||||||||||||||||||||||||
| 59 | 1 | return( $self ); | |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | =head2 status() | ||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | Gets the optional C<status> attribute of the OAI header and returns either "deleted" or "". | ||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||
| 68 | sub status { | ||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | my ( $self, $status ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
status: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | if ( $status ) { $self->{ headerStatus } = $status; } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 71 | 2 | return( $self->{ headerStatus } ); | |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | =head2 identifier() | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | sub identifier { | ||||||||||||||||||||||||||||||
| 79 | 2 | ▶ | my ( $self, $id ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
identifier: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | if ( $id ) { $self->{ identifier } = $id; } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 81 | 2 | return( $self->{ identifier } ); | |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||
| 84 | =head2 datestamp() | ||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | sub datestamp { | ||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | my ( $self, $datestamp ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
datestamp: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | if ( $datestamp ) { $self->{ datestamp } = $datestamp; } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 91 | 2 | return( $self->{ datestamp } ); | |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | =head2 setSpecs() | ||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | =head2 sets() DEPRECATED | ||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | sub setSpecs { | ||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | my ( $self, @sets ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setSpecs: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 102 | 2 | ▶ | if ( @sets ) { $self->{ sets } = \@sets; } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 103 | 2 | return( @{ $self->{ sets } } ); | |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||
| 106 | sub sets { | ||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | return setSpecs(@_); | ||||||||||||||||||||||||||||
|
Subroutine
sets: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | ## SAX Handlers | ||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||
| 112 | sub start_prefix_mapping { | ||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my ($self, $mapping) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
start_prefix_mapping: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ( $self->get_handler() ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 115 | 0 | return $self->SUPER::start_prefix_mapping( $mapping )}; | |||||||||||||||||||||||||||||
| 116 | 0 | die "HEADER: would have to buffer @{[$mapping]}"; | |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||
| 119 | sub start_element { | ||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my ( $self, $element ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
start_element: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | unless ( $element->{ NamespaceURI } eq Net::OAI::Harvester::XMLNS_OAI ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | $self->SUPER::start_element($element) if $self->{ fwdAll } or $self->{ _insideMetadata }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"fwdAll"} or $self->{"_insideMetadata"}
MC/DC0%0/2
$self->{"fwdAll"} or $self->{"_insideMetadata"}
$self->{"fwdAll"}
$self->{"_insideMetadata"}
Truth table0%0/3
A or B
A= $self->{"fwdAll"}B= $self->{"_insideMetadata"}
| |||||||||||||||||||||||||||||||
| 123 | 0 | return; | |||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | 0 | my $tagName = $element->{ LocalName }; | |||||||||||||||||||||||||||||
| 127 | 0 | push( @{$self->{ _tagStack }}, $tagName ); | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ( $tagName eq 'record' ) { | ||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||
| 129 | 0 | $self->{ _insideHeader } = $self->{ _insideMetadata } = $self->{ _insideAbout } = 0} | |||||||||||||||||||||||||||||
| 130 | elsif ( $tagName eq 'header' ) { | ||||||||||||||||||||||||||||||
| 131 | 0 | $self->{ _insideHeader } = 1; | |||||||||||||||||||||||||||||
| 132 | $self->{ headerStatus } = ( exists $element->{ Attributes }{ '{}status' } ) | ||||||||||||||||||||||||||||||
| 133 | ? $element->{ Attributes }{ '{}status' }{ Value } | ||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | : ""; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||
| 136 | elsif ( $self->{ _insideHeader } ) { | ||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||
| 138 | elsif ( $tagName eq 'metadata' ) { | ||||||||||||||||||||||||||||||
| 139 | 0 | $self->{ _insideMetadata } = 1; | |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||
| 141 | elsif ( $tagName eq 'about' ) { | ||||||||||||||||||||||||||||||
| 142 | 0 | $self->{ _insideAbout } = 1; | |||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||
| 144 | else { | ||||||||||||||||||||||||||||||
| 145 | 0 | carp "who am I? ($tagName)"; | |||||||||||||||||||||||||||||
| 146 | 0 | return $self->SUPER::start_element($element); | |||||||||||||||||||||||||||||
| 147 | }; | ||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return $self->SUPER::start_element($element) if $self->{ fwdAll }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||
| 151 | sub end_element { | ||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | my ( $self, $element ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
end_element: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | unless ( $element->{ NamespaceURI } eq Net::OAI::Harvester::XMLNS_OAI ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | $self->SUPER::end_element($element) if $self->{ fwdAll } or $self->{ _insideMetadata }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"fwdAll"} or $self->{"_insideMetadata"}
MC/DC0%0/2
$self->{"fwdAll"} or $self->{"_insideMetadata"}
$self->{"fwdAll"}
$self->{"_insideMetadata"}
Truth table0%0/3
A or B
A= $self->{"fwdAll"}B= $self->{"_insideMetadata"}
| |||||||||||||||||||||||||||||||
| 155 | 0 | return; | |||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||
| 158 | 0 | pop( @{$self->{ _tagStack }} ); | |||||||||||||||||||||||||||||
| 159 | 0 | my $tagName = $element->{ LocalName }; | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ( $tagName eq 'header' ) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 161 | 0 | $self->{ _insideHeader } = 0; | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | (defined $self->{header}) && ($self->{header} =~ /\S/) && carp "Excess content in record header: ".$self->{ header }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"header"} and $self->{"header"} =~ /\S/
MC/DC0%0/2
defined $self->{"header"} and $self->{"header"} =~ /\S/
defined $self->{"header"}
$self->{"header"} =~ /\S/
Truth table0%0/3
A and B
A= defined $self->{"header"}B= $self->{"header"} =~ /\S/
| |||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||
| 164 | elsif ( $tagName eq 'setSpec' ) { | ||||||||||||||||||||||||||||||
| 165 | 0 | push( @{ $self->{ sets } }, $self->{ setSpec } ); | |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||
| 167 | elsif ( $self->{ _insideHeader } ) { | ||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||
| 169 | elsif ( $tagName eq 'metadata' ) { | ||||||||||||||||||||||||||||||
| 170 | 0 | $self->{ _insideMetadata } = 0; | |||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||
| 172 | elsif ( $tagName eq 'about' ) { | ||||||||||||||||||||||||||||||
| 173 | 0 | $self->{ _insideAbout } = 0; | |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||
| 175 | elsif ( $tagName eq 'record' ) { | ||||||||||||||||||||||||||||||
| 176 | 0 | delete $self->{ _insideHeader }; | |||||||||||||||||||||||||||||
| 177 | 0 | delete $self->{ _insideMetadata }; | |||||||||||||||||||||||||||||
| 178 | 0 | delete $self->{ _insideAbout }; | |||||||||||||||||||||||||||||
| 179 | 0 | delete $self->{ _tagStack }; | |||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||||
| 182 | 0 | carp "who am I? ($tagName)"; | |||||||||||||||||||||||||||||
| 183 | 0 | return $self->SUPER::end_element( $element ); | |||||||||||||||||||||||||||||
| 184 | }; | ||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | return $self->SUPER::end_element($element) if $self->{ fwdAll }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||
| 189 | sub ignorable_whitespace { | ||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my ( $self, $characters ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
ignorable_whitespace: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | return $self->SUPER::ignorable_whitespace( $characters ) if $self->{ fwdAll } or $self->{ _insideMetadata }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"fwdAll"} or $self->{"_insideMetadata"}
MC/DC0%0/2
$self->{"fwdAll"} or $self->{"_insideMetadata"}
$self->{"fwdAll"}
$self->{"_insideMetadata"}
Truth table0%0/3
A or B
A= $self->{"fwdAll"}B= $self->{"_insideMetadata"}
| |||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||
| 194 | sub characters { | ||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | my ( $self, $characters ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
characters: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | $self->{ $self->{ _tagStack }[-1] } .= $characters->{ Data } if $self->{ _insideHeader }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | return $self->SUPER::characters( $characters ) if $self->{ fwdAll } or $self->{ _insideMetadata }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"fwdAll"} or $self->{"_insideMetadata"}
MC/DC0%0/2
$self->{"fwdAll"} or $self->{"_insideMetadata"}
$self->{"fwdAll"}
$self->{"_insideMetadata"}
Truth table0%0/3
A or B
A= $self->{"fwdAll"}B= $self->{"_insideMetadata"}
| |||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||
| 200 | 17 | 1; | |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||