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