blib/lib/HTTP/OAI/Harvester.pm

filter: Statementstmt 93.4% 43 / 46 Branchbran 64.2% 9 / 14 Conditioncond 60.0% 9 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 13 / 13 Podpod 75.0% 6 / 8 totaltotal 76.9% 80 / 104 CC 13 SCAR 14.5
CC
13
Cov
81%
_list
8.8
new
5.6
baseURL
2.0
CRAP 4.3
« blib/lib/HTTP/OAI/Header.pm ↑ Summary blib/lib/HTTP/OAI/ListIdentifiers.pm »
1 package HTTP::OAI::Harvester;
2  
3 11 ▶use base HTTP::OAI::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 11 our $VERSION = '4.07';
8  
9 sub new {
10 4 ▶ my ($class,%args) = @_;
Subroutine new: called CC=5 SCAR=17.2
Pod documented
11 4 my %ARGS = %args;
12 4 delete @ARGS{qw(baseURL resume repository handlers onRecord)};
13 4 my $self = $class->SUPER::new(%ARGS);
14  
15 4 $self->{doc} = XML::LibXML::Document->new( '1.0', 'UTF-8' );
16  
17 4 ▶ $self->{'resume'} = exists($args{resume}) ? $args{resume} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'resume'} ? : 0 4 4
18  
19 4 $self->agent('OAI-PERL/'.$HTTP::OAI::VERSION);
20  
21 # Record the base URL this harvester instance is associated with
22 $self->{repository} =
23 $args{repository} ||
24 4 ▶ HTTP::OAI::Identify->new(baseURL=>$args{baseURL});
Condition33%1/3
$args{'repository'} || 'HTTP::OAI::Identify'->new('baseURL', $args{'baseURL'})
l!l&&r!l&&!r
040
MC/DC0%0/2
$args{'repository'} || 'HTTP::OAI::Identify'->new('baseURL', $args{'baseURL'})
$args{'repository'} 'HTTP::OAI::Identify'->new('baseURL', $args{'baseURL'})
Truth table33%1/3
A || B
A= $args{'repository'}B= 'HTTP::OAI::Identify'->new('baseURL', $args{'baseURL'})
ABresult
1X1
011
000
25 4 ▶ Carp::croak "Requires repository or baseURL" unless $self->repository and $self->repository->baseURL;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->repository and $self->repository->baseURL 0 4 4
Condition33%1/3
$self->repository and $self->repository->baseURL
!ll&&!rl&&r
004
MC/DC0%0/2
$self->repository and $self->repository->baseURL
$self->repository $self->repository->baseURL
Truth table33%1/3
A and B
A= $self->repositoryB= $self->repository->baseURL
ABresult
0X0
100
111
26  
27 # Canonicalise
28 4 $self->baseURL($self->baseURL);
29  
30 4 return $self;
31 }
32  
33 6 ▶sub resume { shift->_elem('resume',@_) }
Subroutine resume: called CC=1 SCAR=0.0
Pod documented
34 33 ▶sub repository { shift->_elem('repository',@_) }
Subroutine repository: called CC=1 SCAR=0.0
Pod documented
35  
36 sub baseURL {
37 18 ▶ my $self = shift;
Subroutine baseURL: called CC=2 SCAR=6.9
Pod undocumented
38 18 ▶ return @_ ?
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 4 14 18
39 $self->repository->baseURL(URI->new(shift)->canonical) :
40 $self->repository->baseURL();
41 }
42 7 ▶sub version { shift->repository->protocolVersion(@_); }
Subroutine version: called CC=1 SCAR=0.0
Pod undocumented
43  
44 1 ▶sub ListIdentifiers { shift->_list( @_, verb => "ListIdentifiers" ); }
Subroutine ListIdentifiers: called CC=1 SCAR=0.0
Pod documented
45 3 ▶sub ListRecords { shift->_list( @_, verb => "ListRecords" ); }
Subroutine ListRecords: called CC=1 SCAR=0.0
Pod documented
46 1 ▶sub ListSets { shift->_list( @_, verb => "ListSets" ); }
Subroutine ListSets: called CC=1 SCAR=0.0
Pod documented
47 sub _list
48 {
49 5 ▶ my $self = shift;
Subroutine _list: called CC=7 SCAR=21.8
50  
51 5 local $self->{recursion};
52 5 my $r = $self->_oai( @_ );
53  
54 # resume the partial list?
55 # note: noRecordsMatch is a "success" but won't have a resumptionToken
56 5 ▶ RESUME: while($self->resume && $r->is_success && !$r->error && defined(my $token = $r->resumptionToken))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->resume and $r->is_success and not $r->error and defined(my $token = $r->resumptionToken)) 0 5 5
Condition77%7/9
$self->resume and $r->is_success and not $r->error and defined(my $token = $r->resumptionToken)
!ll&&!rl&&r
320
$self->resume and $r->is_success and not $r->error
!ll&&!rl&&r
212
$self->resume and $r->is_success
!ll&&!rl&&r
023
MC/DC0%0/4
$self->resume and $r->is_success and not $r->error and defined(my $token = $r->resumptionToken)
$self->resume $r->is_success not $r->error defined(my $token = $r->resumptionToken)
Truth table60%3/5
A and B and not(C) and D
A= $self->resumeB= $r->is_successC= not $r->errorD= defined(my $token = $r->resumptionToken)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
57 {
58 0 ▶ last RESUME if !$token->resumptionToken;
Branch: 1 branch
BranchTrueFalseTotal
unless $token->resumptionToken 0 0 0
59 0 local $self->{recursion};
60 $r = $self->_oai(
61 onRecord => $r->{onRecord},
62 0 handlers => $r->handlers,
63 verb => $r->verb,
64 resumptionToken => $token->resumptionToken,
65 );
66 }
67  
68 5 ▶ $self->version( $r->version ) if $r->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $r->is_success 3 2 5
69  
70 5 return $r;
71 }
72  
73 # build the methods for each OAI verb
74 11 foreach my $verb (qw( GetRecord Identify ListMetadataFormats ))
75 {
76 11 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
77 *$verb = sub {
78 5 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
79 5 local $self->{recursion};
80  
81 5 my $r = $self->_oai( @_, verb => $verb );
82  
83 5 ▶ $self->version( $r->version ) if $r->is_success;
Branch: 1 branch
BranchTrueFalseTotal
if $r->is_success 4 1 5
84  
85 5 return $r;
86 33 };
87 }
88  
89 11 1;
90  
91 __END__
« blib/lib/HTTP/OAI/Header.pm ↑ Summary blib/lib/HTTP/OAI/ListIdentifiers.pm »