line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::OAI::Base; |
2
|
|
|
|
|
|
|
|
3
|
17
|
|
|
17
|
|
102
|
use strict; |
|
17
|
|
|
|
|
45
|
|
|
17
|
|
|
|
|
454
|
|
4
|
17
|
|
|
17
|
|
84
|
use warnings; |
|
17
|
|
|
|
|
33
|
|
|
17
|
|
|
|
|
447
|
|
5
|
17
|
|
|
17
|
|
97
|
use Carp qw ( croak ); |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
15203
|
|
6
|
|
|
|
|
|
|
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
|
11
|
|
|
11
|
1
|
7964
|
my $self = shift; |
70
|
11
|
50
|
0
|
|
|
58
|
return ($self->{ responseDate }->[0] || undef) if exists $self->{ responseDate }; |
71
|
11
|
50
|
50
|
|
|
172
|
return ($self->{ error }->{ _responseDate } || undef) if exists $self->{ error }->{ _responseDate }; |
72
|
0
|
|
|
|
|
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 / 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
|
10
|
|
|
10
|
1
|
26
|
my $self = shift; |
97
|
10
|
100
|
|
|
|
45
|
if ( wantarray () ) { |
98
|
9
|
50
|
|
|
|
138
|
if ( exists $self->{ requestContent } ) { |
|
|
50
|
|
|
|
|
|
99
|
0
|
|
0
|
|
|
0
|
return $self->{ requestContent }->[0] || "", %{$self->{ requestAttrs }->[0]}} |
|
0
|
|
|
|
|
0
|
|
100
|
|
|
|
|
|
|
elsif ( exists $self->{ error }->{ _requestContent } ) { |
101
|
9
|
|
50
|
|
|
44
|
return $self->{ error }->{ _requestContent } || "", %{$self->{ error }->{ _requestAttrs }}} |
|
9
|
|
|
|
|
80
|
|
102
|
|
|
|
|
|
|
else { |
103
|
0
|
|
|
|
|
0
|
return (); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else { |
107
|
1
|
50
|
|
|
|
6
|
if ( exists $self->{ requestContent } ) { |
|
|
50
|
|
|
|
|
|
108
|
0
|
|
0
|
|
|
0
|
return $self->{ requestContent }->[0] || ""} |
109
|
|
|
|
|
|
|
elsif ( exists $self->{ error }->{ _requestContent } ) { |
110
|
1
|
|
50
|
|
|
8
|
return $self->{ error }->{ _requestContent } || ""} |
111
|
|
|
|
|
|
|
else { |
112
|
0
|
|
|
|
|
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
|
6
|
|
|
6
|
1
|
2593
|
my $self = shift; |
126
|
6
|
50
|
|
|
|
24
|
return undef unless exists $self->{ error }; |
127
|
6
|
50
|
|
|
|
34
|
return 0 unless my $c = $self->{ error }->errorCode(); |
128
|
6
|
100
|
|
|
|
28
|
return -1 if $self->{ error }->HTTPError(); |
129
|
2
|
50
|
|
|
|
21
|
return -1 if $c =~ /^xml/; |
130
|
2
|
|
|
|
|
10
|
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
|
27
|
|
|
27
|
1
|
927
|
my $self = shift; |
141
|
27
|
100
|
|
|
|
138
|
if ( $self->{ error }->errorCode() ) { |
142
|
10
|
|
|
|
|
37
|
return( $self->{ error }->errorCode() ); |
143
|
|
|
|
|
|
|
} |
144
|
17
|
|
|
|
|
102
|
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
|
15
|
|
|
15
|
1
|
36
|
my $self = shift; |
155
|
15
|
100
|
|
|
|
67
|
if ( $self->{ error }->errorCode() ) { |
156
|
4
|
|
|
|
|
21
|
return( $self->{ error }->errorString() ); |
157
|
|
|
|
|
|
|
} |
158
|
11
|
|
|
|
|
49
|
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
|
|
|
0
|
1
|
0
|
my ( $self ) = @_; |
169
|
0
|
0
|
|
|
|
0
|
return undef unless $self->{ error }; |
170
|
0
|
|
|
|
|
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
|
|
|
30
|
1
|
8437
|
my ( $self ) = @_; |
182
|
30
|
|
|
|
|
185
|
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
|
1211
|
|
|
1211
|
1
|
514887
|
my $self = shift; |
196
|
1211
|
|
|
|
|
4542
|
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
|
5
|
|
|
5
|
1
|
104
|
my( $self, %args ) = shift; |
208
|
5
|
50
|
|
|
|
22
|
return undef unless $self->{ file }; # not set eg. after HTTP error |
209
|
5
|
50
|
|
|
|
312
|
open( XML, $self->{ file } ) or croak "unable to open file ".$self->{ file }; |
210
|
|
|
|
|
|
|
## slurp entire file into $xml |
211
|
5
|
|
|
|
|
26
|
local $/ = undef; |
212
|
5
|
|
|
|
|
2642
|
my $xml = ; |
213
|
5
|
|
|
|
|
43
|
close(XML); # prevent tempfile leak on Win32 |
214
|
5
|
|
|
|
|
1217
|
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
|
56
|
|
|
56
|
1
|
127
|
my $self = shift; |
225
|
56
|
|
|
|
|
528
|
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
|
8
|
|
|
8
|
0
|
24
|
my ( $self, $method ) = @_; |
232
|
|
|
|
|
|
|
|
233
|
8
|
100
|
|
|
|
51
|
my $harvester = exists( $self->{ harvester } ) ? $self->{ harvester } : 0; |
234
|
8
|
100
|
66
|
|
|
99
|
return() unless $harvester && $harvester->isa('Net::OAI::Harvester'); |
235
|
|
|
|
|
|
|
|
236
|
2
|
|
|
|
|
10
|
my $rToken = $self->resumptionToken(); |
237
|
2
|
50
|
|
|
|
12
|
if ( $rToken ) { |
238
|
|
|
|
|
|
|
my $new = $harvester->$method( |
239
|
|
|
|
|
|
|
resumptionToken => $rToken->token(), |
240
|
|
|
|
|
|
|
metadataHandler => $self->{ metadataHandler }, |
241
|
|
|
|
|
|
|
recordHandler => $self->{ recordHandler }, |
242
|
2
|
|
|
|
|
17
|
); |
243
|
2
|
|
|
|
|
11
|
$new->{ harvester } = $harvester; |
244
|
2
|
|
|
|
|
76
|
%$self = %$new; |
245
|
2
|
|
|
|
|
18
|
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 |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=cut |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
1; |