| 1 | package Net::OAI::Base; | ||||||||||||||||||||||||||||
| 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 Carp qw ( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 17 | our $VERSION = "1.16_12"; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | Net::OAI::Base - A base class for all OAI-PMH responses | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | if ( $object->resumptionToken() ) { | ||||||||||||||||||||||||||||
| 15 | ... | ||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | if ( $object->error() ) { | ||||||||||||||||||||||||||||
| 19 | print "verb action resulted in error code:" . $object->errorCode() . | ||||||||||||||||||||||||||||
| 20 | " message:" . $object->errorString() . "\n"; | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | print "xml response can be found here: " . $obj->file() . "\n"; | ||||||||||||||||||||||||||||
| 24 | print "the response xml is " . $obj->xml(); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | Net::OAI::Base is the base class for all the OAI-PMH verb responses. It is | ||||||||||||||||||||||||||||
| 29 | used to provide similar methods to all the responses. The following | ||||||||||||||||||||||||||||
| 30 | classes inherit from Net::OAI::Base. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =over 4 | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =item * | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | Net::OAI::GetRecord | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =item * | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | Net::OAI::Identify | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =item * | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Net::OAI::ListIdentifiers | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =item * | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | Net::OAI::ListMetadataFormats | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =item * | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Net::OAI::ListRecords | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =item * | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | Net::OAI::ListSets | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =back | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head1 METHODS | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head2 responseDate() | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Returns the content of the mandatory responseDate element. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub responseDate { | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
responseDate: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | return ($self->{ responseDate }->[0] || undef) if exists $self->{ responseDate }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{'responseDate'}[0] || undef
MC/DC0%0/1
$self->{'responseDate'}[0] || undef
$self->{'responseDate'}[0]
Truth table0%0/2
A
A= $self->{'responseDate'}[0]
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | return ($self->{ error }->{ _responseDate } || undef) if exists $self->{ error }->{ _responseDate }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{'error'}{'_responseDate'} || undef
MC/DC0%0/1
$self->{'error'}{'_responseDate'} || undef
$self->{'error'}{'_responseDate'}
Truth table0%0/2
A
A= $self->{'error'}{'_responseDate'}
| |||||||||||||||||||||||||||||
| 72 | 0 | return undef; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head2 request() | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | In scalar context this method returns just the base URL (text content) | ||||||||||||||||||||||||||||
| 79 | of the mandatory OAI request element. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | $requestText = $OAI->request(); | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | In array context a hash with the delivered attributes of the OAI request | ||||||||||||||||||||||||||||
| 84 | element (mirroring the valid query parameters) is appended. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | my ($requestURI, %requestParams) = $OAI->request(); | ||||||||||||||||||||||||||||
| 87 | print STDERR "Repository URL: ", $requestURI, "\n"; | ||||||||||||||||||||||||||||
| 88 | print STDERR "verb was: ", $requestParams->{'verb'}, "\n"; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Returns C<undef> / C<()> if the OAI response could not be parsed or did not | ||||||||||||||||||||||||||||
| 91 | contain the mandatory response element. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub request { | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
request: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( wantarray () ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ( exists $self->{ requestContent } ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | return $self->{ requestContent }->[0] || "", %{$self->{ requestAttrs }->[0]}} | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'requestContent'}[0] || ''
MC/DC0%0/1
$self->{'requestContent'}[0] || ''
$self->{'requestContent'}[0]
Truth table0%0/2
A
A= $self->{'requestContent'}[0]
| |||||||||||||||||||||||||||||
| 100 | elsif ( exists $self->{ error }->{ _requestContent } ) { | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | return $self->{ error }->{ _requestContent } || "", %{$self->{ error }->{ _requestAttrs }}} | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'error'}{'_requestContent'} || ''
MC/DC0%0/1
$self->{'error'}{'_requestContent'} || ''
$self->{'error'}{'_requestContent'}
Truth table0%0/2
A
A= $self->{'error'}{'_requestContent'}
| |||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||
| 103 | 0 | return (); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ( exists $self->{ requestContent } ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | return $self->{ requestContent }->[0] || ""} | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'requestContent'}[0] || ''
MC/DC0%0/1
$self->{'requestContent'}[0] || ''
$self->{'requestContent'}[0]
Truth table0%0/2
A
A= $self->{'requestContent'}[0]
| |||||||||||||||||||||||||||||
| 109 | elsif ( exists $self->{ error }->{ _requestContent } ) { | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | return $self->{ error }->{ _requestContent } || ""} | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'error'}{'_requestContent'} || ''
MC/DC0%0/1
$self->{'error'}{'_requestContent'} || ''
$self->{'error'}{'_requestContent'}
Truth table0%0/2
A
A= $self->{'error'}{'_requestContent'}
| |||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||
| 112 | 0 | return undef; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head2 is_error() | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Returns -1 for HTTP or XML errors, 1 for OAI error respones, 0 for no errors; | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =cut | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub is_error { | ||||||||||||||||||||||||||||
| 125 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_error: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | 4 | ▶ | return undef unless exists $self->{ error }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 4 | ▶ | return 0 unless my $c = $self->{ error }->errorCode(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 4 | ▶ | return -1 if $self->{ error }->HTTPError(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 1 | ▶ | return -1 if $c =~ /^xml/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | return 1; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =head2 errorCode() | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | Returns an error code associated with the verb result. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =cut | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | sub errorCode { | ||||||||||||||||||||||||||||
| 140 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
errorCode: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 7 | ▶ | if ( $self->{ error }->errorCode() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 7 | return( $self->{ error }->errorCode() ); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 0 | return( undef ); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head2 errorString() | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | Returns an error message associated with an error code. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | sub errorString { | ||||||||||||||||||||||||||||
| 154 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
errorString: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 155 | 3 | ▶ | if ( $self->{ error }->errorCode() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 3 | return( $self->{ error }->errorString() ); | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | 0 | return( undef ); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head2 HTTPRetryAfter() | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | Returns the HTTP Retry-After header in case of HTTP level errors. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | sub HTTPRetryAfter { | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
HTTPRetryAfter: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | return undef unless $self->{ error }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | return $self->{ error }->HTTPRetryAfter(); | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =head2 HTTPError() | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | Returns the HTTP::Response object in case of HTTP level errors. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | sub HTTPError { | ||||||||||||||||||||||||||||
| 181 | 30 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
HTTPError: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 182 | 30 | return $self->{ error }->HTTPError(); | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =head2 resumptionToken() | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Returns a Net::OAI::ResumptionToken object associated with the call. If | ||||||||||||||||||||||||||||
| 189 | there was no resumption token returned in the response then you will | ||||||||||||||||||||||||||||
| 190 | be returned undef. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =cut | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | sub resumptionToken { | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
resumptionToken: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 196 | 0 | return( $self->{ token } ); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head2 xml() | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | Returns a reference to a scalar that contains the raw content of the response | ||||||||||||||||||||||||||||
| 202 | as XML. | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | sub xml { | ||||||||||||||||||||||||||||
| 207 | 0 | ▶ | my( $self, %args ) = shift; | ||||||||||||||||||||||||||
|
Subroutine
xml: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 208 | 0 | ▶ | return undef unless $self->{ file }; # not set eg. after HTTP error | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | open( XML, $self->{ file } ) or croak "unable to open file ".$self->{ file }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | ## slurp entire file into $xml | ||||||||||||||||||||||||||||
| 211 | 0 | local $/ = undef; | |||||||||||||||||||||||||||
| 212 | 0 | my $xml = <XML>; | |||||||||||||||||||||||||||
| 213 | 0 | close(XML); # prevent tempfile leak on Win32 | |||||||||||||||||||||||||||
| 214 | 0 | return( $xml ); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =head2 file() | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | Returns the path to a file that contains the complete XML response. | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =cut | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | sub file { | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 225 | 0 | return( $self->{ file } ); | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | # called by next() methods in ListRecords and ListIdentifiers | ||||||||||||||||||||||||||||
| 229 | # listAllIdentifiers and listAllRecords store a reference into $self->{harvester} | ||||||||||||||||||||||||||||
| 230 | sub handleResumptionToken { | ||||||||||||||||||||||||||||
| 231 | 0 | ▶ | my ( $self, $method ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
handleResumptionToken: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | ▶ | my $harvester = exists( $self->{ harvester } ) ? $self->{ harvester } : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 0 | ▶ | return() unless $harvester && $harvester->isa('Net::OAI::Harvester'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$harvester and $harvester->isa("Net::OAI::Harvester")
MC/DC0%0/2
$harvester and $harvester->isa("Net::OAI::Harvester")
$harvester
$harvester->isa("Net::OAI::Harvester")
Truth table0%0/3
A and B
A= $harvesterB= $harvester->isa("Net::OAI::Harvester")
| |||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 0 | my $rToken = $self->resumptionToken(); | |||||||||||||||||||||||||||
| 237 | 0 | ▶ | if ( $rToken ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | my $new = $harvester->$method( | ||||||||||||||||||||||||||||
| 239 | resumptionToken => $rToken->token(), | ||||||||||||||||||||||||||||
| 240 | metadataHandler => $self->{ metadataHandler }, | ||||||||||||||||||||||||||||
| 241 | recordHandler => $self->{ recordHandler }, | ||||||||||||||||||||||||||||
| 242 | 0 | ); | |||||||||||||||||||||||||||
| 243 | 0 | $new->{ harvester } = $harvester; | |||||||||||||||||||||||||||
| 244 | 0 | %$self = %$new; | |||||||||||||||||||||||||||
| 245 | 0 | return( $self->next() ); | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 0 | return(); | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =head1 TODO | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | Ed Summers <ehs@pobox.com> | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | =cut | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 17 | 1; | |||||||||||||||||||||||||||