blib/lib/Net/OAI/ListIdentifiers.pm

filter: Statementstmt 56.9% 33 / 58 Branchbran 0.0% 0 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 9 / 12 Podpod 100% 4 / 4 totaltotal 47.4% 47 / 99 SCAR 36.9
CC
12
Cov
42%
next
30.0
start_element
20.0
end_element
20.0
CRAP 40.1
« blib/lib/Net/OAI/Identify.pm ↑ Summary blib/lib/Net/OAI/ListSets.pm »
1 package Net::OAI::ListIdentifiers;
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 base qw( XML::SAX::Base Net::OAI::Base );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use Carp qw ( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use Net::OAI::Record::Header;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use File::Temp qw( tempfile );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 17 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 17 ▶use Storable qw( store_fd fd_retrieve );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Net::OAI::ListIdentifiers - Results of the ListIdentifiers OAI-PMH verb.
15  
16 =head1 SYNOPSIS
17  
18 =head1 DESCRIPTION
19  
20 =head1 METHODS
21  
22 This class is based on C<Net::OAI::Base> and inherits the general methods
23 expect for the following:
24  
25 =head2 new()
26  
27 =cut
28  
29 sub new {
30 4 ▶ my ( $class, %opts ) = @_;
Subroutine new: called CC=2 SCAR=7.1
Pod documented
31 4 ▶ my $self = bless \%opts, ref( $class ) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
32
33 ## open a temp file for storing identifiers
34 4 my ($fh,$filename) = tempfile(UNLINK => 1);
35 4 $self->{ headerFileHandle } = $fh;
36 4 $self->{ headerFilename } = $filename;
37 ## so we can store code refs
38 4 $Storable::Deparse = 1;
39 4 $Storable::Eval = 1;
40 4 return( $self );
41 }
42  
43 =head2 next()
44  
45 Returns the L<Net::OAI::Record::Header> object for the next OAI record in the
46 response, C<undef> if none remain. resumptionToken handling is performed
47 automagically if the original request was listAllIdentifiers().
48  
49 =cut
50  
51 sub next {
52 0 ▶ my $self = shift;
Subroutine next: not called CC=5 SCAR=34.0
Pod documented
53  
54 0 ▶ if ( ! $self->{ headerFileHandle } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"headerFileHandle"}) 0 0 0
55 $self->{ headerFileHandle } = IO::File->new( $self->{ headerFilename } )
56 0 ▶ or croak "unable to open temp file: ".$self->{ headerFilename };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"headerFileHandle"} = "IO::File"->new($self->{"headerFilename"}) or croak('unable to open temp file: ' . $self->{"headerFilename"}) 0 0 0
57 }
58  
59 0 ▶ if ( $self->{ headerFileHandle }->eof() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"headerFileHandle"}->eof) 0 0 0
60 $self->{ headerFileHandle }->close() or croak "Could not close() ".$self->{ headerFilename }
61 0 ▶ .". File system full?";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"headerFileHandle"}->close or croak('Could not close() ' . $self->{"headerFilename"} . '. File system full?') 0 0 0
62 0 return( $self->handleResumptionToken( 'listIdentifiers' ) );
63 }
64  
65 0 my $header = fd_retrieve( $self->{ headerFileHandle } );
66 0 return( $header );
67 }
68  
69 ## SAX Handlers
70  
71 sub start_element {
72 0 ▶ my ( $self, $element ) = @_;
Subroutine start_element: not called CC=4 SCAR=30.0
Pod documented
73 0 ▶ return $self->SUPER::start_element( $element ) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI;
Branch: 1 branch
BranchTrueFalseTotal
unless $element->{"NamespaceURI"} eq "http://www.openarchives.org/OAI/2.0/" 0 0 0
74  
75 0 ▶ if ( $element->{ LocalName } eq 'header' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($element->{'LocalName'} eq 'header') { } 0 0 0
elsif ($element->{'LocalName'} eq 'ListIdentifiers') { } 0 0 0
76 0 $self->{ OLD_Handler } = $self->get_handler();
77 0 $self->set_handler( Net::OAI::Record::Header->new() );
78 } elsif ( $element->{ LocalName } eq 'ListIdentifiers' ) {
79 }
80 0 $self->SUPER::start_element( $element );
81 }
82  
83 sub end_element {
84 0 ▶ my ( $self, $element ) = @_;
Subroutine end_element: not called CC=4 SCAR=30.0
Pod documented
85 0 $self->SUPER::end_element( $element );
86 0 ▶ return unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI;
Branch: 1 branch
BranchTrueFalseTotal
unless $element->{"NamespaceURI"} eq "http://www.openarchives.org/OAI/2.0/" 0 0 0
87  
88 0 ▶ if ( $element->{ LocalName } eq 'header' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($element->{'LocalName'} eq 'header') { } 0 0 0
elsif ($element->{'LocalName'} eq 'ListIdentifiers') { } 0 0 0
89 0 my $header = $self->get_handler();
90 0 Net::OAI::Harvester::debug( "committing header to object store" );
91 0 store_fd( $header, $self->{ headerFileHandle } );
92 0 $self->set_handler( $self->{ OLD_Handler } );
93 } elsif ( $element->{ LocalName } eq 'ListIdentifiers' ) {
94 0 Net::OAI::Harvester::debug( "finished reading identifiers" );
95 0 $self->{ headerFileHandle }->close();
96 0 $self->{ headerFileHandle } = undef;
97 }
98 }
99  
100 17 1;
101  
« blib/lib/Net/OAI/Identify.pm ↑ Summary blib/lib/Net/OAI/ListSets.pm »