blib/lib/Net/OAI/Error.pm

filter: Statementstmt 39.6% 25 / 63 Branchbran 25.0% 8 / 32 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.3% 7 / 12 Podpod 100% 9 / 9 totaltotal 41.3% 50 / 121 SCAR 47.8
CC
19
Cov
35%
start_element
56.0
end_element
30.0
HTTPRetryAfter
6.0
CRAP 119.5
« blib/lib/Net/OAI/ListMetadataFormats.pm ↑ Summary blib/lib/Net/OAI/ResumptionToken.pm »
1 package Net::OAI::Error;
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 Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 our @EXPORT = (
7 );
8  
9  
10 =head1 NAME
11  
12 Net::OAI::Error - OAI-PMH errors.
13  
14 =head1 SYNOPSIS
15  
16 =head1 DESCRIPTION
17  
18 Note: Actually this class implements the SAX filter which processes
19 (and forwards) all top-level OAI-PMH elements.
20  
21 Specifically the following events are not forwarded: OAI-PMH itself,
22 request, responseDate and error.
23  
24 Thus only events for the elements corresponding to the individual
25 OAI-PMH verbs are forwarded.
26  
27  
28 =head1 METHODS
29  
30 =head2 new()
31  
32 =cut
33  
34 sub new {
35 31 ▶ my ( $class, %opts ) = @_;
Subroutine new: called CC=4 SCAR=14.0
Pod documented
36 31 ▶ my $self = bless \%opts, ref( $class ) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0310
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
37 31 $self->{ tagStack } = [];
38 31 ▶ $self->{ errorCode } = '' if ! exists( $self->{ errorCode } );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"errorCode"} 1 30 31
39 31 ▶ $self->{ errorString } = '' if ! exists( $self->{ errorString } );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"errorString"} 1 30 31
40 # do not initialize $self->{ HTTPError } and $self->{ HTTPRetryAfter }
41 31 return( $self );
42 }
43  
44 =head2 errorCode()
45  
46 Returns an OAI error if one was encountered, or the empty string if no errors
47 were associated with the OAI request.
48  
49 =over 4
50  
51 =item
52  
53 badArgument
54  
55 =item
56  
57 badResumptionToken
58  
59 =item
60  
61 badVerb
62  
63 =item
64  
65 cannotDisseminateFormat
66  
67 =item
68  
69 idDoesNotExist
70  
71 =item
72  
73 noRecordsMatch
74  
75 =item
76  
77 noMetadataFormats
78  
79 =item
80  
81 noSetHierarchy
82  
83 =item
84  
85 xmlParseError
86  
87 =item
88  
89 xmlContentError
90  
91 =item
92  
93 numerical HTTP status code
94  
95 =back
96  
97 For more information about these error codes see:
98 L<http://www.openarchives.org/OAI/openarchivesprotocol.html#ErrorConditions>.
99  
100 =cut
101  
102 sub errorCode {
103 21 ▶ my ( $self, $code ) = @_;
Subroutine errorCode: called CC=2 SCAR=7.6
Pod documented
104 21 ▶ if ( $code ) { $self->{ errorCode } = $code; }
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 0 21 21
105 21 return( $self->{ errorCode } );
106 }
107  
108 =head2 errorString()
109  
110 Returns a textual description of the error that was encountered, or an empty
111 string if there was no error associated with the OAI request.
112  
113 =cut
114  
115 sub errorString {
116 3 ▶ my ( $self, $str ) = @_;
Subroutine errorString: called CC=2 SCAR=7.6
Pod documented
117 3 ▶ if ( $str ) { $self->{ errorString } = $str; }
Branch: 1 branch
BranchTrueFalseTotal
if ($str) 0 3 3
118 3 return( $self->{ errorString } );
119 }
120  
121 =head2 HTTPError()
122  
123 In case of HTTP level errors, returns the associated HTTP::Response object.
124 Otherwise C<undef>.
125  
126  
127 =cut
128  
129 sub HTTPError {
130 34 ▶ my ( $self ) = @_;
Subroutine HTTPError: called CC=2 SCAR=6.9
Pod documented
131 34 ▶ return exists $self->{ HTTPError } ? $self->{ HTTPError } : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'HTTPError'} ? : 32 2 34
132 }
133  
134  
135 =head2 HTTPRetryAfter()
136  
137 In case of HTTP level errors, returns the Retry-After header of the HTTP Response object,
138 or the empty string if no such header is persent. Otherwise C<undef>.
139  
140  
141 =cut
142  
143 sub HTTPRetryAfter {
144 0 ▶ my ( $self ) = @_;
Subroutine HTTPRetryAfter: not called CC=2 SCAR=17.9
Pod documented
145 0 ▶ return exists $self->{ HTTPRetryAfter } ? $self->{ HTTPRetryAfter } : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'HTTPRetryAfter'} ? : 0 0 0
146 }
147  
148  
149 =head1 TODO
150  
151 =head1 SEE ALSO
152  
153 =over 4
154  
155 =back
156  
157 =head1 AUTHORS
158  
159 Ed Summers <ehs@pobox.com>
160  
161 =cut
162  
163 ## internal stuff
164  
165 ## all children of Net::OAI::Base should call this to make sure
166 ## certain object properties are set
167  
168 sub start_prefix_mapping {
169 0 ▶ my ($self, $mapping) = @_;
Subroutine start_prefix_mapping: not called CC=1 SCAR=6.9
Pod documented
170 0 return $self->SUPER::start_prefix_mapping( $mapping );
171 }
172  
173 sub start_element {
174 0 ▶ my ( $self, $element ) = @_;
Subroutine start_element: not called CC=7 SCAR=40.3
Pod documented
175 0 ▶ return $self->SUPER::start_element($element) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI; # should be error?
Branch: 1 branch
BranchTrueFalseTotal
unless $element->{"NamespaceURI"} eq "http://www.openarchives.org/OAI/2.0/" 0 0 0
176  
177 0 my $tagName = $element->{ LocalName };
178 0 ▶ if ( $tagName eq 'request' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tagName eq 'request') { } 0 0 0
elsif ($tagName eq 'responseDate') { } 0 0 0
elsif ($tagName eq 'error') { } 0 0 0
179 0 Net::OAI::Harvester::debug( "caught request" );
180 0 $self->{ _requestAttrs } = {};
181 0 foreach ( values %{$element->{ Attributes }} ) {
182 0 ▶ next if $_->{ Prefix };
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"Prefix"} 0 0 0
183 0 $self->{ _requestAttrs }->{ $_->{ Name } } = $_->{ Value };
184 }
185 0 $self->{ _insideSelf } = "";
186 }
187 elsif ( $tagName eq 'responseDate' ) {
188 0 Net::OAI::Harvester::debug( "caught responseDate" );
189 0 $self->{ _insideSelf } = "";
190 }
191 elsif ( $tagName eq 'error' ) {
192 0 Net::OAI::Harvester::debug( "caught error" );
193 0 $self->{ errorCode } = $element->{ Attributes }{ '{}code' }{ Value };
194 0 $self->{ _insideSelf } = "";
195 }
196 else {
197 0 $self->SUPER::start_element( $element );
198 }
199 }
200  
201 sub end_element {
202 0 ▶ my ( $self, $element ) = @_;
Subroutine end_element: not called CC=5 SCAR=34.0
Pod documented
203 0 ▶ return $self->SUPER::end_element($element) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI; # should be error?
Branch: 1 branch
BranchTrueFalseTotal
unless $element->{"NamespaceURI"} eq "http://www.openarchives.org/OAI/2.0/" 0 0 0
204  
205 0 my $tagName = $element->{ LocalName };
206 0 ▶ if ( $tagName eq 'request' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tagName eq 'request') { } 0 0 0
elsif ($tagName eq 'responseDate') { } 0 0 0
elsif ($tagName eq 'error') { } 0 0 0
207 0 $self->{ _requestContent } = $self->{ _insideSelf };
208 0 delete $self->{ _insideSelf };
209 }
210 elsif ( $tagName eq 'responseDate' ) {
211 0 $self->{ _responseDate } = $self->{ _insideSelf };
212 0 delete $self->{ _insideSelf };
213 }
214 elsif ( $tagName eq 'error' ) {
215 0 $self->{ errorString } = $self->{ _insideSelf };
216 0 delete $self->{ _insideSelf };
217 }
218 else {
219 0 $self->SUPER::end_element( $element );
220 }
221 }
222  
223 sub characters {
224 0 ▶ my ( $self, $characters ) = @_;
Subroutine characters: not called CC=2 SCAR=17.9
Pod documented
225 0 ▶ if ( exists $self->{ _insideSelf } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'_insideSelf'}) { } 0 0 0
226 0 $self->{ _insideSelf } .= $characters->{ Data };
227 } else {
228 0 $self->SUPER::characters( $characters );
229 }
230 }
231  
232 17 1;
233  
« blib/lib/Net/OAI/ListMetadataFormats.pm ↑ Summary blib/lib/Net/OAI/ResumptionToken.pm »