| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::OAI::Error; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 17 |  |  | 17 |  | 88 | use strict; | 
|  | 17 |  |  |  |  | 36 |  | 
|  | 17 |  |  |  |  | 474 |  | 
| 4 | 17 |  |  | 17 |  | 90 | use warnings; | 
|  | 17 |  |  |  |  | 35 |  | 
|  | 17 |  |  |  |  | 601 |  | 
| 5 | 17 |  |  | 17 |  | 90 | use base qw( XML::SAX::Base Exporter ); | 
|  | 17 |  |  |  |  | 37 |  | 
|  | 17 |  |  |  |  | 23366 |  | 
| 6 |  |  |  |  |  |  | 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 | 34 |  |  | 34 | 1 | 1306 | my ( $class, %opts ) = @_; | 
| 36 | 34 |  | 33 |  |  | 298 | my $self = bless \%opts, ref( $class ) || $class; | 
| 37 | 34 |  |  |  |  | 260 | $self->{ tagStack } = []; | 
| 38 | 34 | 100 |  |  |  | 242 | $self->{ errorCode } = '' if ! exists( $self->{ errorCode } ); | 
| 39 | 34 | 100 |  |  |  | 223 | $self->{ errorString }  = '' if ! exists( $self->{ errorString } ); | 
| 40 |  |  |  |  |  |  | # do not initialize $self->{ HTTPError } and $self->{ HTTPRetryAfter } | 
| 41 | 34 |  |  |  |  | 170 | 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. | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =cut | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | sub errorCode { | 
| 103 | 58 |  |  | 58 | 1 | 109 | my ( $self, $code ) = @_; | 
| 104 | 58 | 50 |  |  |  | 165 | if ( $code ) { $self->{ errorCode } = $code; } | 
|  | 0 |  |  |  |  | 0 |  | 
| 105 | 58 |  |  |  |  | 316 | 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 | 4 |  |  | 4 | 1 | 8 | my ( $self, $str ) = @_; | 
| 117 | 4 | 50 |  |  |  | 16 | if ( $str ) { $self->{ errorString } = $str; } | 
|  | 0 |  |  |  |  | 0 |  | 
| 118 | 4 |  |  |  |  | 33 | 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. | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =cut | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | sub HTTPError { | 
| 130 | 36 |  |  | 36 | 1 | 83 | my ( $self ) = @_; | 
| 131 | 36 | 100 |  |  |  | 204 | return exists $self->{ HTTPError } ? $self->{ HTTPError } : undef; | 
| 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. | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =cut | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | sub HTTPRetryAfter { | 
| 144 | 0 |  |  | 0 | 1 | 0 | my ( $self ) = @_; | 
| 145 | 0 | 0 |  |  |  | 0 | return exists $self->{ HTTPRetryAfter } ? $self->{ HTTPRetryAfter } : undef; | 
| 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 | 
| 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 | 4454 |  |  | 4454 | 1 | 2567402 | my ($self, $mapping) = @_; | 
| 170 | 4454 |  |  |  |  | 12137 | return $self->SUPER::start_prefix_mapping( $mapping ); | 
| 171 |  |  |  |  |  |  | } | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | sub start_element { | 
| 174 | 66912 |  |  | 66912 | 1 | 21430080 | my ( $self, $element ) = @_; | 
| 175 | 66912 | 100 |  |  |  | 246719 | return $self->SUPER::start_element($element) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI;  # should be error? | 
| 176 |  |  |  |  |  |  |  | 
| 177 | 32380 |  |  |  |  | 50213 | my $tagName = $element->{ LocalName }; | 
| 178 | 32380 | 100 |  |  |  | 106607 | if ( $tagName eq 'request' ) { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 179 | 28 |  |  |  |  | 130 | Net::OAI::Harvester::debug( "caught request" ); | 
| 180 | 28 |  |  |  |  | 89 | $self->{ _requestAttrs } = {}; | 
| 181 | 28 |  |  |  |  | 65 | foreach ( values %{$element->{ Attributes }} ) { | 
|  | 28 |  |  |  |  | 146 |  | 
| 182 | 67 | 50 |  |  |  | 201 | next if $_->{ Prefix }; | 
| 183 | 67 |  |  |  |  | 257 | $self->{ _requestAttrs }->{ $_->{ Name } } = $_->{ Value }; | 
| 184 |  |  |  |  |  |  | } | 
| 185 | 28 |  |  |  |  | 170 | $self->{ _insideSelf } = ""; | 
| 186 |  |  |  |  |  |  | } | 
| 187 |  |  |  |  |  |  | elsif ( $tagName eq 'responseDate' ) { | 
| 188 | 28 |  |  |  |  | 149 | Net::OAI::Harvester::debug( "caught responseDate" ); | 
| 189 | 28 |  |  |  |  | 138 | $self->{ _insideSelf } = ""; | 
| 190 |  |  |  |  |  |  | } | 
| 191 |  |  |  |  |  |  | elsif ( $tagName eq 'error' ) { | 
| 192 | 4 |  |  |  |  | 111 | Net::OAI::Harvester::debug( "caught error" ); | 
| 193 | 4 |  |  |  |  | 15 | $self->{ errorCode } = $element->{ Attributes }{ '{}code' }{ Value }; | 
| 194 | 4 |  |  |  |  | 18 | $self->{ _insideSelf } = ""; | 
| 195 |  |  |  |  |  |  | } | 
| 196 |  |  |  |  |  |  | else { | 
| 197 | 32320 |  |  |  |  | 83872 | $self->SUPER::start_element( $element ); | 
| 198 |  |  |  |  |  |  | } | 
| 199 |  |  |  |  |  |  | } | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | sub end_element { | 
| 202 | 66912 |  |  | 66912 | 1 | 12152124 | my ( $self, $element ) = @_; | 
| 203 | 66912 | 100 |  |  |  | 240735 | return $self->SUPER::end_element($element) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI;  # should be error? | 
| 204 |  |  |  |  |  |  |  | 
| 205 | 32380 |  |  |  |  | 48674 | my $tagName = $element->{ LocalName }; | 
| 206 | 32380 | 100 |  |  |  | 109597 | if ( $tagName eq 'request' ) { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 207 | 28 |  |  |  |  | 90 | $self->{ _requestContent } = $self->{ _insideSelf }; | 
| 208 | 28 |  |  |  |  | 106 | delete $self->{ _insideSelf }; | 
| 209 |  |  |  |  |  |  | } | 
| 210 |  |  |  |  |  |  | elsif ( $tagName eq 'responseDate' ) { | 
| 211 | 28 |  |  |  |  | 137 | $self->{ _responseDate } = $self->{ _insideSelf }; | 
| 212 | 28 |  |  |  |  | 119 | delete $self->{ _insideSelf }; | 
| 213 |  |  |  |  |  |  | } | 
| 214 |  |  |  |  |  |  | elsif ( $tagName eq 'error' ) { | 
| 215 | 4 |  |  |  |  | 52 | $self->{ errorString } = $self->{ _insideSelf }; | 
| 216 | 4 |  |  |  |  | 17 | delete $self->{ _insideSelf }; | 
| 217 |  |  |  |  |  |  | } | 
| 218 |  |  |  |  |  |  | else { | 
| 219 | 32320 |  |  |  |  | 88222 | $self->SUPER::end_element( $element ); | 
| 220 |  |  |  |  |  |  | } | 
| 221 |  |  |  |  |  |  | } | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | sub characters { | 
| 224 | 141259 |  |  | 141259 | 1 | 14405924 | my ( $self, $characters ) = @_; | 
| 225 | 141259 | 100 |  |  |  | 294600 | if ( exists $self->{ _insideSelf } ) { | 
| 226 | 60 |  |  |  |  | 270 | $self->{ _insideSelf } .= $characters->{ Data }; | 
| 227 |  |  |  |  |  |  | } else { | 
| 228 | 141199 |  |  |  |  | 353890 | $self->SUPER::characters( $characters ); | 
| 229 |  |  |  |  |  |  | } | 
| 230 |  |  |  |  |  |  | } | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | 1; | 
| 233 |  |  |  |  |  |  |  |