Importer/OAI.pm

filter: Statementstmt 37.9% 117 / 308 Branchbran 13.5% 16 / 118 Conditioncond 10.2% 5 / 49 MC/DCmcdc 3.2% 1 / 31 Subroutinesub 40.3% 21 / 52 Podpod 25.0% 1 / 4 totaltotal 28.6% 161 / 562 CC 81 SCAR 40.2
CC
81
Cov
29%
__ANON__
306.0
__ANON__
56.0
oai_run
56.0
CRAP 55.6
↑ Summary Importer/OAI/Parser/marcxml.pm »
1 package Catmandu::Importer::OAI;
2  
3 4 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Catmandu::Util qw(:is);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use HTTP::OAI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Catmandu::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 our $VERSION = '0.21';
13  
14 3 with 'Catmandu::Importer';
15  
16 3 has url => (is => 'ro', required => 1);
17 3 has identifier => (is => 'ro');
18 2 ▶has metadataPrefix => (is => 'ro', default => sub { "oai_dc" });
Subroutine __ANON__: called CC=1 SCAR=0.0
19 3 has set => (is => 'ro');
20 3 has from => (is => 'ro');
21 3 has until => (is => 'ro');
22 3 has resumptionToken => (is => 'ro');
23  
24 3 has strict => (is => 'ro');
25  
26 3 has identify => (is => 'ro');
27 3 has listIdentifiers => (is => 'ro');
28 3 has listRecords => (is => 'ro');
29 3 has listSets => (is => 'ro');
30 3 has listMetadataFormats => (is => 'ro');
31 3 has getRecord => (is => 'ro');
32  
33 3 has oai => (is => 'ro', lazy => 1, builder => 1);
34 3 has dry => (is => 'ro');
35 3 has handler => (is => 'rw', lazy => 1 , builder => 1, coerce => \&_coerce_handler );
36 3 has xslt => (is => 'ro', coerce => \&_coerce_xslt );
37 2 ▶has sleep => ( is => 'ro', default => sub { 0 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
38 2 ▶has max_retries => ( is => 'ro', default => sub { 0 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
39 2 ▶has _retried => ( is => 'rw', default => sub { 0; } );
Subroutine __ANON__: called CC=1 SCAR=0.0
40 2 ▶has _xml_handlers => ( is => 'ro', default => sub { +{} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
41 3 has realm => ( is => 'ro', predicate => 1 );
42 3 has username => ( is => 'ro', predicate => 1 );
43 3 has password => ( is => 'ro', predicate => 1 );
44  
45 0 ▶sub _build_handler {
Subroutine _build_handler: not called CC=4 SCAR=30.0
46 0 my ($self) = @_;
47 0 ▶ if ($self->metadataPrefix eq 'oai_dc') {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->metadataPrefix eq 'oai_dc') { } 0 0 0
elsif ($self->metadataPrefix eq 'marcxml') { } 0 0 0
elsif ($self->metadataPrefix eq 'mods') { } 0 0 0
48 0 return 'oai_dc';
49 }
50 elsif ($self->metadataPrefix eq 'marcxml') {
51 0 return 'marcxml';
52 }
53 elsif ($self->metadataPrefix eq 'mods') {
54 0 return 'mods';
55 }
56 else {
57 0 return 'struct';
58 }
59 }
60  
61 1 ▶sub _coerce_handler {
Subroutine _coerce_handler: called CC=7 SCAR=23.7
62 1 my ($handler) = @_;
63  
64 1 ▶ return $handler if is_invocant($handler) or is_code_ref($handler);
Branch: 1 branch
BranchTrueFalseTotal
if is_invocant($handler) or is_code_ref($handler) 0 1 1
Condition33%1/3
is_invocant($handler) or is_code_ref($handler)
l!l&&r!l&&!r
001
MC/DC0%0/2
is_invocant($handler) or is_code_ref($handler)
is_invocant($handler) is_code_ref($handler)
Truth table33%1/3
A or B
A= is_invocant($handler)B= is_code_ref($handler)
ABresult
1X1
011
000
65  
66 1 ▶ if (is_string($handler) && !is_number($handler)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_string($handler) and not is_number($handler)) 1 0 1
Condition33%1/3
is_string($handler) and not is_number($handler)
!ll&&!rl&&r
001
MC/DC0%0/2
is_string($handler) and not is_number($handler)
is_string($handler) not is_number($handler)
Truth table33%1/3
A and not(B)
A= is_string($handler)B= not is_number($handler)
ABresult
0X0
100
111
67 1 ▶ my $class = $handler =~ /^\+(.+)/ ? $1
Branch: 1 branch
BranchTrueFalseTotal
$handler =~ /^\+(.+)/ ? : 0 1 1
68 : "Catmandu::Importer::OAI::Parser::$handler";
69  
70 1 my $handler;
71 1 eval {
72 1 $handler = Catmandu::Util::require_package($class)->new;
73 };
74 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 1 1
75 0 croak $@;
76 } else {
77 1 return $handler;
78 }
79 }
80  
81 0 ▶ return sub { return { _metadata => readXML($_[0]) } };
Subroutine __ANON__: not called CC=1 SCAR=6.9
82 }
83  
84 1 ▶sub _coerce_xslt {
Subroutine _coerce_xslt: called CC=2 SCAR=7.2
85 1 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { Catmandu::Util::require_package("Catmandu::XML::Transformer")->new("stylesheet", $_[0]) } } or croak($@) 0 1 1
86 1 Catmandu::Util::require_package('Catmandu::XML::Transformer')
87 ->new( stylesheet => $_[0] )
88 } or croak $@;
89 }
90  
91 1 ▶sub _build_oai {
Subroutine _build_oai: called CC=4 SCAR=18.6
92 1 my ($self) = @_;
93 1 my $agent = HTTP::OAI::Harvester->new(baseURL => $self->url, resume => 0, keep_alive => 1);
94 1 ▶ if( $self->has_username && $self->has_password ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_username and $self->has_password) 0 1 1
Condition33%1/3
$self->has_username and $self->has_password
!ll&&!rl&&r
100
MC/DC0%0/2
$self->has_username and $self->has_password
$self->has_username $self->has_password
Truth table33%1/3
A and B
A= $self->has_usernameB= $self->has_password
ABresult
0X0
100
111
95 0 my $uri = URI->new( $self->url );
96 0 ▶ my @credentials = (
Condition0%0/2
$self->realm || undef
l!l
00
MC/DC0%0/1
$self->realm || undef
$self->realm
Truth table0%0/2
A
A= $self->realm
Aresult
11
00
97 $uri->host_port,
98 $self->realm || undef,
99 $self->username,
100 $self->password
101 );
102 0 $agent->credentials( @credentials );
103 }
104 1 $agent->env_proxy;
105 1 $agent;
106 }
107  
108 0 ▶sub _xml_handler_for_node {
Subroutine _xml_handler_for_node: not called CC=5 SCAR=34.0
109 0 my ( $self, $node ) = @_;
110 0 my $ns = $node->namespaceURI();
111  
112 0 my $type;
113  
114 0 ▶ if( $ns eq "http://www.openarchives.org/OAI/2.0/oai_dc/" ){
Branch: 3 branches
BranchTrueFalseTotal
if ($ns eq 'http://www.openarchives.org/OAI/2.0/oai_dc/') { } 0 0 0
elsif ($ns eq 'http://www.loc.gov/MARC21/slim') { } 0 0 0
elsif ($ns eq 'http://www.loc.gov/mods/v3') { } 0 0 0
115  
116 0 $type = "oai_dc";
117  
118 }
119 elsif( $ns eq "http://www.loc.gov/MARC21/slim" ){
120  
121 0 $type = "marcxml";
122  
123 }
124 elsif( $ns eq "http://www.loc.gov/mods/v3" ){
125  
126 0 $type = "mods";
127  
128 }
129 else{
130  
131 0 $type = "struct";
132  
133 }
134  
135 0 ▶ $self->_xml_handlers()->{$type} ||= Catmandu::Util::require_package( "Catmandu::Importer::OAI::Parser::$type" )->new();
Condition0%0/3
$self->_xml_handlers->{$type} ||= Catmandu::Util::require_package("Catmandu::Importer::OAI::Parser::$type")->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_xml_handlers->{$type} ||= Catmandu::Util::require_package("Catmandu::Importer::OAI::Parser::$type")->new
$self->_xml_handlers->{$type} Catmandu::Util::require_package("Catmandu::Importer::OAI::Parser::$type")->new
Truth table0%0/3
A ||= B
A= $self->_xml_handlers->{$type}B= Catmandu::Util::require_package("Catmandu::Importer::OAI::Parser::$type")->new
ABresult
1X1
011
000
136 }
137  
138 0 ▶sub _map_set {
Subroutine _map_set: not called CC=1 SCAR=6.9
139 0 my ($self, $rec) = @_;
140  
141 +{
142 _id => $rec->setSpec(),
143 setSpec => $rec->setSpec(),
144 setName => $rec->setName(),
145 setDescription => [ map {
146  
147 #root: 'setDescription'
148 0 my @root = $_->dom()->childNodes();
149 #child: oai_dc, marcxml, mods..
150 0 my @children = $root[0]->childNodes();
151 0 $self->_xml_handler_for_node( $children[0] )->parse( $children[0] );
152  
153 } $rec->setDescription() ]
154 };
155 }
156  
157 0 ▶sub _map_format {
Subroutine _map_format: not called CC=1 SCAR=6.9
158 0 my ($self, $rec) = @_;
159  
160 +{
161 0 _id => $rec->metadataPrefix,
162 metadataPrefix => $rec->metadataPrefix(),
163 metadataNamespace => $rec->metadataNamespace(),
164 schema => $rec->schema()
165 };
166 }
167  
168 0 ▶sub _map_identify {
Subroutine _map_identify: not called CC=3 SCAR=24.8
169 0 my ($self, $rec) = @_;
170  
171 0 my @description;
172  
173 0 ▶ if ($rec->description) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->description) 0 0 0
174 0 for my $desc ($rec->description) {
175 0 push @description , $desc->dom->toString;
176 }
177 }
178  
179 +{
180 0 _id => $rec->baseURL,
181 baseURL => $rec->baseURL,
182 granularity => $rec->granularity,
183 deletedRecord => $rec->deletedRecord,
184 earliestDatestamp => $rec->earliestDatestamp,
185 adminEmail => $rec->adminEmail,
186 protocolVersion => $rec->protocolVersion,
187 repositoryName => $rec->repositoryName,
188 description => \@description
189 };
190 }
191  
192 0 ▶sub _map_record {
Subroutine _map_record: not called CC=5 SCAR=34.0
193 0 my ($self, $rec) = @_;
194  
195 0 my $sets = [ $rec->header->setSpec ];
196 0 my $identifier = $rec->identifier;
197 0 my $datestamp = $rec->datestamp;
198 0 ▶ my $status = $rec->status // "";
Condition0%0/2
$rec->status // ""
l!l
00
MC/DC0%0/1
$rec->status // ""
$rec->status
Truth table0%0/2
A
A= $rec->status
Aresult
11
00
199 0 ▶ my $dom = $rec->metadata ? $rec->metadata->dom->nonBlankChildNodes->[0]->nonBlankChildNodes->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$rec->metadata ? : 0 0 0
200 0 my $about = [];
201  
202 0 for ($rec->about) {
203 0 push(@$about , $_->dom->nonBlankChildNodes->[0]->nonBlankChildNodes->[0]->toString);
204 }
205  
206 0 ▶ my $values = $self->handle_record($dom) // { };
Condition0%0/2
$self->handle_record($dom) // {}
l!l
00
MC/DC0%0/1
$self->handle_record($dom) // {}
$self->handle_record($dom)
Truth table0%0/2
A
A= $self->handle_record($dom)
Aresult
11
00
207  
208 0 my $data = {
209 _id => $identifier ,
210 _identifier => $identifier ,
211 _datestamp => $datestamp ,
212 _status => $status ,
213 _setSpec => $sets ,
214 _about => $about ,
215 %$values
216 };
217  
218 0 $data;
219 }
220  
221 1 ▶sub _args {
Subroutine _args: called CC=4 SCAR=13.9
222 1 my $self = $_[0];
223  
224 1 my %args = (
225 identifier => $self->identifier,
226 metadataPrefix => $self->metadataPrefix,
227 set => $self->set ,
228 from => $self->from ,
229 until => $self->until ,
230 force => !$self->strict ,
231 );
232  
233 1 for( keys %args ) {
234 6 ▶ delete $args{$_} if !defined($args{$_}) || !length($args{$_});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{$_} and length $args{$_} 3 3 6
Condition66%2/3
defined $args{$_} and length $args{$_}
!ll&&!rl&&r
303
MC/DC50%1/2
defined $args{$_} and length $args{$_}
defined $args{$_} length $args{$_}
Truth table66%2/3
A and B
A= defined $args{$_}B= length $args{$_}
ABresult
0X0
100
111
235 }
236  
237 1 return %args;
238 }
239  
240 1 ▶sub _verb {
Subroutine _verb: called CC=7 SCAR=27.8
241 1 my $self = $_[0];
242  
243 1 ▶ if ($self->identify) {
Branch: 6 branches
BranchTrueFalseTotal
if ($self->identify) { } 0 1 1
elsif ($self->listIdentifiers) { } 0 1 1
elsif ($self->listSets) { } 0 1 1
elsif ($self->getRecord) { } 0 1 1
elsif ($self->listMetadataFormats) { } 0 1 1
elsif ($self->listRecords) { } 0 1 1
244 0 return 'Identify';
245 }
246 elsif ($self->listIdentifiers) {
247 0 return 'ListIdentifiers';
248 }
249 elsif ($self->listSets) {
250 0 return 'ListSets';
251 }
252 elsif ($self->getRecord) {
253 0 return 'GetRecord';
254 }
255 elsif ($self->listMetadataFormats) {
256 0 return 'ListMetadataFormats';
257 }
258 elsif ($self->listRecords) {
259 0 return 'ListRecords';
260 }
261 else {
262 1 return 'ListRecords';
263 }
264 }
265  
266 0 ▶sub handle_record {
Subroutine handle_record: not called CC=4 SCAR=30.0
Pod documented
267 0 my ($self, $dom) = @_;
268 0 ▶ return unless $dom;
Branch: 1 branch
BranchTrueFalseTotal
unless $dom 0 0 0
269  
270 0 ▶ $dom = $self->xslt->transform($dom) if $self->xslt;
Branch: 1 branch
BranchTrueFalseTotal
if $self->xslt 0 0 0
271 0 ▶ return blessed($self->handler)
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self->handler) ? : 0 0 0
272 ? $self->handler->parse($dom)
273 : $self->handler->($dom);
274 }
275  
276 1 ▶sub dry_run {
Subroutine dry_run: called CC=1 SCAR=0.0
Pod undocumented
277 1 my ($self) = @_;
278 1 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
279 1 state $called = 0;
280 1 ▶ return if $called;
Branch: 1 branch
BranchTrueFalseTotal
if $called 0 1 1
281 1 $called = 1;
282 # TODO: make sure that HTTP::OAI does not change this internal method
283 return +{
284 1 url => $self->oai->_buildurl(
285 $self->_args(),
286 verb => $self->_verb()
287 )
288 };
289 1 };
290 }
291  
292 0 ▶sub _retry {
Subroutine _retry: not called CC=5 SCAR=34.0
293 0 my ( $self, $sub ) = @_;
294  
295 0 $self->_retried( 0 );
296  
297 0 my $res;
298  
299 0 while ( 1 ) {
300  
301 0 $res = $sub->();
302  
303 0 ▶ if ($res->is_error && ref($res) ne 'HTTP::OAI::Response') {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_error and ref $res ne "HTTP::OAI::Response") 0 0 0
Condition0%0/3
$res->is_error and ref $res ne "HTTP::OAI::Response"
!ll&&!rl&&r
000
MC/DC0%0/2
$res->is_error and ref $res ne "HTTP::OAI::Response"
$res->is_error ref $res ne "HTTP::OAI::Response"
Truth table0%0/3
A and B
A= $res->is_errorB= ref $res ne "HTTP::OAI::Response"
ABresult
0X0
100
111
304  
305 0 my $max_retries = $self->max_retries();
306 0 my $_retried = $self->_retried();
307  
308 0 ▶ if ( $max_retries > 0 && $_retried < $max_retries ){
Branch: 1 branch
BranchTrueFalseTotal
if ($max_retries > 0 and $_retried < $max_retries) { } 0 0 0
Condition0%0/3
$max_retries > 0 and $_retried < $max_retries
!ll&&!rl&&r
000
MC/DC0%0/2
$max_retries > 0 and $_retried < $max_retries
$max_retries > 0 $_retried < $max_retries
Truth table0%0/3
A and B
A= $max_retries > 0B= $_retried < $max_retries
ABresult
0X0
100
111
309  
310 0 $_retried++;
311  
312 #exponential backoff: [0 .. 2^c [
313 0 my $n_seconds = int( 2**$_retried );
314 0 $self->log->error("failed, retrying after $n_seconds");
315 0 sleep $n_seconds;
316 0 $self->_retried( $_retried );
317 0 next;
318 }
319 else {
320 0 my $err_msg = $self->url . " : " . $res->message." (stopped after ".$self->_retried()." retries)";
321 0 $self->log->error( $err_msg );
322 0 Catmandu::Error->throw( $err_msg );
323 }
324 }
325  
326 0 last;
327 }
328  
329 0 $res;
330 }
331  
332 0 ▶sub _list_records {
Subroutine _list_records: not called CC=1 SCAR=6.9
333 0 my $self = $_[0];
334 0 my $args = $_[1];
335 0 ▶ sub {
Subroutine __ANON__: not called CC=17 SCAR=57.2
336 0 state $stack = [];
337 0 state $resumptionToken = $self->resumptionToken;
338 0 state $resumptionData = {};
339 0 state $done = 0;
340  
341 0 ▶ my $fill_stack = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
342 0 push @$stack , shift;
343 0 };
344  
345 0 ▶ if (@$stack <= 1 && $done == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack <= 1 and $done == 0) 0 0 0
Condition0%0/3
@$stack <= 1 and $done == 0
!ll&&!rl&&r
000
MC/DC0%0/2
@$stack <= 1 and $done == 0
@$stack <= 1 $done == 0
Truth table0%0/3
A and B
A= @$stack <= 1B= $done == 0
ABresult
0X0
100
111
346 0 ▶ my %args = $args ? %$args : $self->_args;
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 0 0
347  
348 # Use the resumptionToken if one found on the last run, or if it was
349 # undefined (last record)
350 0 ▶ if (defined $resumptionToken) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resumptionToken) 0 0 0
351 0 my $verb = $args{verb};
352 0 %args = (verb => $verb , resumptionToken => $resumptionToken);
353 }
354  
355 my $sub = $self->listIdentifiers() ?
356 0 ▶ sub { $self->oai->ListIdentifiers( %args , onRecord => $fill_stack ); } :
Subroutine __ANON__: not called CC=1 SCAR=6.9
357 0 ▶ sub { $self->oai->ListRecords( %args , onRecord => $fill_stack ); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->listIdentifiers ? : 0 0 0
358  
359 0 my $res = $self->_retry( $sub );
360 0 ▶ if (defined $res->resumptionToken) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res->resumptionToken) { } 0 0 0
361 0 $resumptionToken = $res->resumptionToken->resumptionToken;
362  
363 0 $resumptionData->{token} = $resumptionToken;
364 0 $resumptionData->{expirationDate} = $res->resumptionToken->expirationDate;
365 0 $resumptionData->{completeListSize} = $res->resumptionToken->completeListSize;
366 0 $resumptionData->{cursor} = $res->resumptionToken->cursor;
367 }
368 else {
369 0 $resumptionToken = undef;
370 }
371  
372 0 ▶ unless (defined $resumptionToken && length $resumptionToken) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $resumptionToken and length $resumptionToken) 0 0 0
Condition0%0/3
defined $resumptionToken and length $resumptionToken
!ll&&!rl&&r
000
MC/DC0%0/2
defined $resumptionToken and length $resumptionToken
defined $resumptionToken length $resumptionToken
Truth table0%0/3
A and B
A= defined $resumptionTokenB= length $resumptionToken
ABresult
0X0
100
111
373 0 $done = 1;
374 }
375  
376 0 ▶ if ($self->sleep) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->sleep) 0 0 0
377 0 sleep $self->sleep;
378 }
379 }
380  
381 0 ▶ if (my $rec = shift @$stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rec = shift @$stack) 0 0 0
382 0 ▶ if ($rec->isa('HTTP::OAI::Record')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->isa('HTTP::OAI::Record')) { } 0 0 0
383 0 my $rec = $self->_map_record($rec);
384  
385 0 ▶ $rec->{_resumptionToken} = $resumptionToken if defined($resumptionToken);
Branch: 1 branch
BranchTrueFalseTotal
if defined $resumptionToken 0 0 0
386 0 ▶ $rec->{_resumption} = $resumptionData if defined($resumptionData);
Branch: 1 branch
BranchTrueFalseTotal
if defined $resumptionData 0 0 0
387  
388 0 return $rec;
389 }
390 else {
391 0 ▶ my $rec = {
Condition0%0/2
$rec->status // ""
l!l
00
MC/DC0%0/1
$rec->status // ""
$rec->status
Truth table0%0/2
A
A= $rec->status
Aresult
11
00
392 _id => $rec->identifier,
393 _datestamp => $rec->datestamp,
394 _status => $rec->status // "",
395 };
396  
397 0 ▶ $rec->{_resumptionToken} = $resumptionToken if defined($resumptionToken);
Branch: 1 branch
BranchTrueFalseTotal
if defined $resumptionToken 0 0 0
398 0 ▶ $rec->{_resumption} = $resumptionData if defined($resumptionData);
Branch: 1 branch
BranchTrueFalseTotal
if defined $resumptionData 0 0 0
399  
400 0 return $rec;
401 }
402 }
403  
404 0 return undef;
405 0 };
406 }
407  
408 0 ▶sub _list_sets {
Subroutine _list_sets: not called CC=1 SCAR=6.9
409 0 my $self = $_[0];
410 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
411 0 state $stack = [];
412 0 state $done = 0;
413  
414 0 ▶ my $fill_stack = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
415 0 push @$stack , shift;
416 0 };
417  
418 0 ▶ if (@$stack <= 1 && $done == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack <= 1 and $done == 0) 0 0 0
Condition0%0/3
@$stack <= 1 and $done == 0
!ll&&!rl&&r
000
MC/DC0%0/2
@$stack <= 1 and $done == 0
@$stack <= 1 $done == 0
Truth table0%0/3
A and B
A= @$stack <= 1B= $done == 0
ABresult
0X0
100
111
419 0 ▶ my $sub = sub { $self->oai->ListSets( onRecord => $fill_stack ); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
420  
421 0 my $res = $self->_retry( $sub );
422 0 $done = 1;
423 }
424  
425 0 ▶ if (my $rec = shift @$stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rec = shift @$stack) 0 0 0
426 0 return $self->_map_set($rec);
427 }
428  
429 0 return undef;
430 0 };
431 }
432  
433 0 ▶sub _get_record {
Subroutine _get_record: not called CC=1 SCAR=6.9
434 0 my $self = $_[0];
435 0 my $args = $_[1];
436 0 ▶ sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
437 0 state $stack = [];
438 0 state $done = 0;
439  
440 0 ▶ my $fill_stack = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
441 0 push @$stack , shift;
442 0 };
443  
444 0 ▶ if (@$stack <= 1 && $done == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack <= 1 and $done == 0) 0 0 0
Condition0%0/3
@$stack <= 1 and $done == 0
!ll&&!rl&&r
000
MC/DC0%0/2
@$stack <= 1 and $done == 0
@$stack <= 1 $done == 0
Truth table0%0/3
A and B
A= @$stack <= 1B= $done == 0
ABresult
0X0
100
111
445 0 ▶ my %args = $args ? %$args : $self->_args;
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 0 0
446 0 ▶ my $sub = sub { $self->oai->GetRecord(%args , onRecord => $fill_stack) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
447 0 my $res = $self->_retry( $sub );
448 0 $done = 1;
449 }
450  
451 0 ▶ if (my $rec = shift @$stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rec = shift @$stack) 0 0 0
452 0 ▶ if ($rec->isa('HTTP::OAI::Record')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rec->isa('HTTP::OAI::Record')) { } 0 0 0
453 0 return $self->_map_record($rec);
454 }
455 else {
456 return {
457 0 ▶ _id => $rec->identifier,
Condition0%0/2
$rec->status // ""
l!l
00
MC/DC0%0/1
$rec->status // ""
$rec->status
Truth table0%0/2
A
A= $rec->status
Aresult
11
00
458 _datestamp => $rec->datestamp,
459 _status => $rec->status // "",
460 }
461 }
462 }
463  
464 0 return undef;
465 0 };
466 }
467  
468 0 ▶sub _list_metadata_formats {
Subroutine _list_metadata_formats: not called CC=1 SCAR=6.9
469 0 my $self = $_[0];
470 0 my $args = $_[1];
471 0 ▶ sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
472 0 state $stack = [];
473 0 state $done = 0;
474  
475 0 ▶ my $fill_stack = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
476 0 push @$stack , shift;
477 0 };
478  
479 0 ▶ if (@$stack <= 1 && $done == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack <= 1 and $done == 0) 0 0 0
Condition0%0/3
@$stack <= 1 and $done == 0
!ll&&!rl&&r
000
MC/DC0%0/2
@$stack <= 1 and $done == 0
@$stack <= 1 $done == 0
Truth table0%0/3
A and B
A= @$stack <= 1B= $done == 0
ABresult
0X0
100
111
480 0 ▶ my %args = $args ? %$args : $self->_args;
Branch: 1 branch
BranchTrueFalseTotal
$args ? : 0 0 0
481 0 delete $args{metadataPrefix};
482  
483 0 ▶ my $sub = sub { $self->oai->ListMetadataFormats( %args ); };
Subroutine __ANON__: not called CC=1 SCAR=6.9
484  
485 0 my $res = $self->_retry( $sub );
486  
487 0 ▶ while( my $mdf = $res->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mdf = $res->next) 0 0 0
488 0 $fill_stack->($mdf);
489 }
490  
491 0 $done = 1;
492 }
493  
494 0 ▶ if (my $rec = shift @$stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rec = shift @$stack) 0 0 0
495 0 return $self->_map_format($rec);
496 }
497  
498 0 return undef;
499 0 };
500 }
501  
502 0 ▶sub _identify {
Subroutine _identify: not called CC=1 SCAR=6.9
503 0 my $self = $_[0];
504 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
505 0 state $stack = [];
506 0 state $done = 0;
507  
508 0 ▶ my $fill_stack = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
509 0 push @$stack , shift;
510 0 };
511  
512 0 ▶ if (@$stack <= 1 && $done == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack <= 1 and $done == 0) 0 0 0
Condition0%0/3
@$stack <= 1 and $done == 0
!ll&&!rl&&r
000
MC/DC0%0/2
@$stack <= 1 and $done == 0
@$stack <= 1 $done == 0
Truth table0%0/3
A and B
A= @$stack <= 1B= $done == 0
ABresult
0X0
100
111
513 0 ▶ my $sub = sub { $self->oai->Identify( onRecord => $fill_stack) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
514 0 my $res = $self->_retry( $sub );
515  
516 0 $fill_stack->($res);
517  
518 0 $done = 1;
519 }
520  
521 0 ▶ if (my $rec = shift @$stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rec = shift @$stack) 0 0 0
522 0 return $self->_map_identify($rec);
523 }
524  
525 0 return undef;
526 0 };
527 }
528  
529 0 ▶sub oai_run {
Subroutine oai_run: not called CC=7 SCAR=40.3
Pod undocumented
530 0 my ($self) = @_;
531  
532 0 ▶ if ($self->identify) {
Branch: 6 branches
BranchTrueFalseTotal
if ($self->identify) { } 0 0 0
elsif ($self->listIdentifiers) { } 0 0 0
elsif ($self->listSets) { } 0 0 0
elsif ($self->getRecord) { } 0 0 0
elsif ($self->listMetadataFormats) { } 0 0 0
elsif ($self->listRecords) { } 0 0 0
533 0 return $self->_identify;
534 }
535 elsif ($self->listIdentifiers) {
536 0 return $self->_list_records;
537 }
538 elsif ($self->listSets) {
539 0 return $self->_list_sets
540 }
541 elsif ($self->getRecord) {
542 0 return $self->_get_record;
543 }
544 elsif ($self->listMetadataFormats) {
545 0 return $self->_list_metadata_formats;
546 }
547 elsif ($self->listRecords) {
548 0 return $self->_list_records
549 }
550 else {
551 0 return $self->_list_records
552 }
553 }
554  
555 1 ▶sub generator {
Subroutine generator: called CC=2 SCAR=7.2
Pod undocumented
556 1 my ($self) = @_;
557  
558 1 ▶ return $self->dry ? $self->dry_run : $self->oai_run;
Branch: 1 branch
BranchTrueFalseTotal
$self->dry ? : 1 0 1
559 }
560  
561 3 1;
562 __END__
↑ Summary Importer/OAI/Parser/marcxml.pm »