| 1 | package HTTP::OAI::Response; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | @ISA = qw( HTTP::Response HTTP::OAI::MemberMixin HTTP::OAI::SAX::Base ); | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | our $VERSION = '4.13'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | # Backwards compatibility, pass any unknown methods to content | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub DESTROY {} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | sub AUTOLOAD | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | $AUTOLOAD =~ s/^.*:://; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # don't call a $self method here, because that might call AUTOLOAD again! | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 8 | my $content = $self->{content}->[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | ▶ | return defined $content ? $content->$AUTOLOAD( @_ ) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 20 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 20 | my( $class, %self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 20 | my $handlers = delete $self{handlers}; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 20 | my $cb = delete $self{onRecord}; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 20 | ▶ | $self{responseDate} ||= POSIX::strftime("%Y-%m-%dT%H:%M:%S",gmtime).'Z'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self{"responseDate"} ||= POSIX::strftime("%Y-%m-%dT%H:%M:%S", gmtime) . 'Z'
MC/DC100%1/1
$self{"responseDate"} ||= POSIX::strftime("%Y-%m-%dT%H:%M:%S", gmtime) . 'Z'
$self{"responseDate"}
Truth table100%2/2
A
A= $self{"responseDate"}
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 20 | ▶ | $self{requestURL} ||= CGI::self_url() if defined &CGI::self_url; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self{"requestURL"} ||= CGI::self_url()
MC/DC0%0/2
$self{"requestURL"} ||= CGI::self_url()
$self{"requestURL"}
CGI::self_url()
Truth table0%0/3
A ||= B
A= $self{"requestURL"}B= CGI::self_url()
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | my $self = $class->SUPER::new( | ||||||||||||||||||||||||||||||||||||||||||
| 36 | delete($self{code}) || 200, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 20 | ▶ | delete($self{message}) || "OK", | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
delete $self{'code'} || 200
delete $self{'message'} || 'OK'
MC/DC0%0/1
delete $self{'code'} || 200
delete $self{'code'}
MC/DC0%0/1
delete $self{'message'} || 'OK'
delete $self{'message'}
Truth table50%1/2
A
A= delete $self{'code'}
Truth table50%1/2
A
A= delete $self{'message'}
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | HTTP::Headers->new( %self ) | ||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 20 | $self->{Depth} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 20 | ▶ | $self->{handlers} = $handlers || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$handlers || {}
MC/DC100%1/1
$handlers || {}
$handlers
Truth table100%2/2
A
A= $handlers
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 20 | $self->{onRecord} = $cb; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 20 | $self->{doc} = XML::LibXML::Document->new( '1.0', 'UTF-8' ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 20 | $self->{content} = []; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 20 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Back compatibility | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | ▶ | sub errors { shift->error(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errors: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | sub toDOM { shift->dom } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toDOM: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # data that belong to this class | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 38 | ▶ | sub content { shift->_multi('content',@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub doc { shift->_elem('doc',@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
doc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 12 | ▶ | sub handlers { shift->_elem('handlers',@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handlers: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | # data that belong to this class's headers | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 100 | ▶ | sub version { shift->headers->header('version',@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 96 | ▶ | sub verb { shift->headers->header('verb',@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verb: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 21 | ▶ | sub error { shift->headers->header('error',@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub xslt { shift->headers->header('xslt',@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xslt: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | sub responseDate { shift->headers->header('responseDate',@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
responseDate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | sub requestURL { shift->headers->header('requestURL',@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
requestURL: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | sub callback | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
callback: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 12 | my( $self, $item, $list ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 12 | ▶ | if( defined $self->{onRecord} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $self->{onRecord}->( $item, $self ); | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | else | ||||||||||||||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 12 | ▶ | Carp::confess( "Requires list parameter" ) if !defined $list; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 12 | $list->item( $item ); | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # error on 600 as well | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 31 | ▶ | sub is_error { my $code = shift->code; $code != 0 && $code != 200 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_error: called CC=2 SCAR=7.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 20 | ▶ | sub is_success { !shift->is_error } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_success: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | sub parse_string | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_string: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 6 | my( $self, $string ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 6 | eval { $self->SUPER::parse_string( $string ) }; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 6 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | $self->code( 600 ); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | $self->message( $@ ); | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | sub parse_file | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_file: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | my( $self, $fh ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | eval { $self->SUPER::parse_file( $fh ) }; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $self->code( 600 ); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $self->message( $@ ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | sub generate | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=9 SCAR=32.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | my( $self, $driver ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | if( $self->xslt ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $driver->processing_instruction({ | |||||||||||||||||||||||||||||||||||||||||
| 116 | 'Target' => 'xml-stylesheet', | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 'Data' => 'type=\'text/xsl\' href=\''. $self->xslt . '\'' | ||||||||||||||||||||||||||||||||||||||||||
| 118 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | ▶ | if( !defined $self->version || $self->version eq "2.0" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
not defined $self->version or $self->version eq "2.0"
MC/DC0%0/2
not defined $self->version or $self->version eq "2.0"
not defined $self->version
$self->version eq "2.0"
Truth table33%1/3
not(A) or B
A= not defined $self->versionB= $self->version eq "2.0"
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | $driver->start_element( 'OAI-PMH', | |||||||||||||||||||||||||||||||||||||||||
| 124 | 'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd', | ||||||||||||||||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | $driver->data_element( 'responseDate', $self->responseDate ); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my $url = URI->new( $self->requestURL ); | |||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | if( $self->error ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | $url->query( undef ); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | $driver->data_element( 'request', $url ); | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | for($self->error) | |||||||||||||||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | $_->generate( $driver ); | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | elsif( $self->content ) | ||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my %attr = $url->query_form; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $url->query( undef ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $driver->data_element( 'request', $url, %attr ); | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $content = ($self->content)[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $driver->start_element( $content->verb ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $content->generate_body( $driver ); | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $driver->end_element( $content->verb ); | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | $driver->end_element( 'OAI-PMH' ); | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | elsif( $self->version eq "2.0s" ) | ||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $driver->start_prefix_mapping({ | |||||||||||||||||||||||||||||||||||||||||
| 154 | Prefix => 'static', | ||||||||||||||||||||||||||||||||||||||||||
| 155 | NamespaceURI => 'http://www.openarchives.org/OAI/2.0/static-repository', | ||||||||||||||||||||||||||||||||||||||||||
| 156 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $driver->start_element( 'static:Repository', | |||||||||||||||||||||||||||||||||||||||||
| 158 | 'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd http://www.openarchives.org/OAI/2.0/static-repository http://www.openarchives.org/OAI/2.0/static-repository.xsd', | ||||||||||||||||||||||||||||||||||||||||||
| 159 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | for($self->content) | |||||||||||||||||||||||||||||||||||||||||
| 161 | { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $driver->start_element( 'static:' . $_->verb ); | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $_->generate_body( $driver ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $driver->end_element( 'static:' . $_->verb ); | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $driver->end_element( 'static:Repository' ); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | sub start_element | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 482 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_element: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 482 | my( $self, $hash ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 482 | $hash->{Depth} = ++$self->{Depth}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 482 | ▶ | if( $self->{Depth} == 1 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 18 | $self->version( $HTTP::OAI::VERSIONS{lc($hash->{NamespaceURI})} ); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 18 | ▶ | if( !defined $self->version ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | { | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | die "Unrecognised namespace for OAI response: {$hash->{NamespaceURI}}$hash->{Name}"; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | # static repositories don't contain ListIdentifiers or GetRecord, so | ||||||||||||||||||||||||||||||||||||||||||
| 184 | # instead we'll perform a complete ListRecords then extract the | ||||||||||||||||||||||||||||||||||||||||||
| 185 | # relevant data | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 17 | ▶ | if( $self->version eq "2.0s" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 9 | ▶ | if( $self->verb eq "ListIdentifiers" || $self->verb eq "GetRecord" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$self->verb eq "ListIdentifiers" or $self->verb eq "GetRecord"
MC/DC100%2/2
$self->verb eq "ListIdentifiers" or $self->verb eq "GetRecord"
$self->verb eq "ListIdentifiers"
$self->verb eq "GetRecord"
Truth table100%3/3
A or B
A= $self->verb eq "ListIdentifiers"B= $self->verb eq "GetRecord"
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | { | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | $self->{_verb} = $self->verb; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | $self->verb( "ListRecords" ); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | elsif( $self->verb eq 'ListSets' ) | ||||||||||||||||||||||||||||||||||||||||||
| 194 | { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | $self->content( HTTP::OAI::ListSets->new ); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | $self->error(HTTP::OAI::Error->new( code => 'noSetHierarchy' )); | |||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | die "done\n"; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | elsif( $self->{Depth} == 2 ) | ||||||||||||||||||||||||||||||||||||||||||
| 202 | { | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 43 | my $elem = $hash->{LocalName}; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 43 | ▶ | if( $elem eq "error" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | $self->set_handler( my $error = HTTP::OAI::Error->new ); | |||||||||||||||||||||||||||||||||||||||||
| 207 | 2 | $self->error( $error ); | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | ▶ | elsif | |||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$elem =~ /^GetRecord|Identify|ListIdentifiers|ListMetadataFormats|ListRecords|ListSets$/ and !defined($self->verb) || $elem eq $self->verb
not defined $self->verb or $elem eq $self->verb
MC/DC66%2/3
$elem =~ /^GetRecord|Identify|ListIdentifiers|ListMetadataFormats|ListRecords|ListSets$/ and !defined($self->verb) || $elem eq $self->verb
$elem =~ /^GetRecord|Identify|ListIdentifiers|ListMetadataFormats|ListRecords|ListSets$/
not defined $self->verb
$elem eq $self->verb
Truth table75%3/4
A and not(B) or C
A= $elem =~ /^GetRecord|Identify|ListIdentifiers|ListMetadataFormats|ListRecords|ListSets$/B= not defined $self->verbC= $elem eq $self->verb
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 211 | $elem =~ /^GetRecord|Identify|ListIdentifiers|ListMetadataFormats|ListRecords|ListSets$/ && | ||||||||||||||||||||||||||||||||||||||||||
| 212 | (!defined $self->verb || $elem eq $self->verb) | ||||||||||||||||||||||||||||||||||||||||||
| 213 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 214 | { | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 16 | ▶ | if( $self->version eq "2.0s" && $self->verb eq "ListRecords" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->version eq "2.0s" and $self->verb eq "ListRecords"
MC/DC100%2/2
$self->version eq "2.0s" and $self->verb eq "ListRecords"
$self->version eq "2.0s"
$self->verb eq "ListRecords"
Truth table100%3/3
A and B
A= $self->version eq "2.0s"B= $self->verb eq "ListRecords"
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 7 | my $metadataPrefix = $hash->{Attributes}{'{}metadataPrefix'}{Value}; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 7 | ▶ | if( $metadataPrefix eq $self->headers->header( 'metadataPrefix' ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | { | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 4 | $self->set_handler( my $content = "HTTP::OAI::$elem"->new ); | |||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | $self->content( [ $content ] ); | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | else | ||||||||||||||||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 9 | $self->set_handler( my $content = "HTTP::OAI::$elem"->new ); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 9 | $self->content( [ $content ] ); | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 480 | $self->SUPER::start_element( $hash, $self ); | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | sub end_element | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 473 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end_element: called CC=19 SCAR=29.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 473 | my( $self, $hash ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 473 | $hash->{Depth} = $self->{Depth}; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 473 | $self->SUPER::end_element( $hash, $self ); | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 473 | ▶ | if( $self->{Depth} == 2 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | { | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 43 | my $elem = $hash->{LocalName}; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 43 | ▶ | if( $elem eq "responseDate" || $elem eq "requestURL" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$elem eq "responseDate" or $elem eq "requestURL"
MC/DC50%1/2
$elem eq "responseDate" or $elem eq "requestURL"
$elem eq "responseDate"
$elem eq "requestURL"
Truth table66%2/3
A or B
A= $elem eq "responseDate"B= $elem eq "requestURL"
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | { | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 7 | $self->headers->header( $elem, $hash->{Text} ); | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | elsif( $elem eq "request" ) | ||||||||||||||||||||||||||||||||||||||||||
| 251 | { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 7 | $self->headers->header("request",$hash->{Text}); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 7 | my $uri = new URI($hash->{Text}); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 7 | $uri->query_form(map { ($_->{LocalName},$_->{Value}) } values %{$hash->{Attributes}}); | |||||||||||||||||||||||||||||||||||||||||
| 255 | 7 | $self->headers->header("requestURL",$uri); | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | elsif( $elem eq "error" ) | ||||||||||||||||||||||||||||||||||||||||||
| 258 | { | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | my $error = $self->get_handler; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | ▶ | if( $error->code !~ /^noRecordsMatch|noSetHierarchy$/ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | { | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | $self->code( 500 ); | |||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | $self->message( $error->code . ": " . $error->message ); | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | # extract ListIdentifiers and GetRecord from a static ListRecords | ||||||||||||||||||||||||||||||||||||||||||
| 267 | ▶ | elsif( defined($self->get_handler) && $self->version eq "2.0s" ) | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $self->get_handler and $self->version eq "2.0s"
MC/DC100%2/2
defined $self->get_handler and $self->version eq "2.0s"
defined $self->get_handler
$self->version eq "2.0s"
Truth table100%3/3
A and B
A= defined $self->get_handlerB= $self->version eq "2.0s"
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | { | ||||||||||||||||||||||||||||||||||||||||||
| 269 | # fake ListIdentifiers/GetRecord | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 7 | ▶ | if( defined(my $verb = $self->{_verb}) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | ▶ | if( $verb eq "ListIdentifiers" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | { | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | my $content = HTTP::OAI::ListIdentifiers->new; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | $content->item( map { $_->header } ($self->content)[-1]->item ); | |||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | $self->content( [ $content ] ); | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | elsif( $verb eq "GetRecord" ) | ||||||||||||||||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | my $content = HTTP::OAI::GetRecord->new; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | $content->item( [grep { $_->identifier eq $self->headers->header('identifier') } ($self->content)[-1]->item] ); | |||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | $self->content( [ $content ] ); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | ▶ | if( !defined( ($content->item)[0] ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | { | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 1 | $self->content( [] ); | |||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | $self->error(my $error = HTTP::OAI::Error->new( code => 'idDoesNotExist' )); | |||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | $self->code( 500 ); | |||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | $self->message( $error->code . ": " . $error->message ); | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 7 | die "done\n"; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 36 | $self->set_handler( undef ); | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 466 | ▶ | if( $self->{Depth} == 1 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | { | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 9 | ▶ | if( $self->version eq "2.0s" && !$self->error && !$self->content ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->version eq "2.0s" and not $self->error and not $self->content
$self->version eq "2.0s" and not $self->error
MC/DC33%1/3
$self->version eq "2.0s" and not $self->error and not $self->content
$self->version eq "2.0s"
not $self->error
not $self->content
Truth table50%2/4
A and not(B) and not(C)
A= $self->version eq "2.0s"B= not $self->errorC= not $self->content
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | { | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | $self->error(my $error = HTTP::OAI::Error->new( code => 'cannotDisseminateFormat' )); | |||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | $self->code( 500 ); | |||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | $self->message( $error->code . ": " . $error->message ); | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | # allow callers to do $r->next to check whether anything came back | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 9 | ▶ | if( !$self->content && defined(my $verb = $self->verb) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $self->content and defined(my $verb = $self->verb)
MC/DC100%2/2
not $self->content and defined(my $verb = $self->verb)
not $self->content
defined(my $verb = $self->verb)
Truth table100%3/3
not(A) and B
A= not $self->contentB= defined(my $verb = $self->verb)
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | $self->content( "HTTP::OAI::$verb"->new ); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 466 | $self->{Depth}--; | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||