line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Furl::S3::Error; |
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
5
|
use Class::Accessor::Lite; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
371
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use overload q{""} => \&stringify; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Class::Accessor::Lite->mk_accessors(qw(code http_code http_status message request_id host_id)); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
|
|
|
|
|
|
my( $class, $res ) = @_; |
11
|
|
|
|
|
|
|
my $self = bless { |
12
|
|
|
|
|
|
|
http_code => $res->{code}, |
13
|
|
|
|
|
|
|
http_status => $res->{msg}, |
14
|
|
|
|
|
|
|
}, $class; |
15
|
|
|
|
|
|
|
if ( my $xml = $res->{body} ) { |
16
|
|
|
|
|
|
|
$self->_parse_xml( $xml ); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
$self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub stringify { |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
if ( $self->message ) { |
24
|
|
|
|
|
|
|
return sprintf('%s: %s', $self->code, $self->message); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
|
|
|
|
|
|
return sprintf('HTTP Error: %s %s', $self->http_code, $self->http_status); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _parse_xml { |
32
|
|
|
|
|
|
|
my( $self, $xml ) = @_; |
33
|
|
|
|
|
|
|
my $doc = XML::LibXML->new->parse_string( $xml ); |
34
|
|
|
|
|
|
|
my $code = $doc->findvalue('/Error/Code'); |
35
|
|
|
|
|
|
|
my $message = $doc->findvalue('/Error/Message'); |
36
|
|
|
|
|
|
|
my $request_id = $doc->findvalue('/Error/RequestId'); |
37
|
|
|
|
|
|
|
my $host_id = $doc->findvalue('/Error/HostId'); |
38
|
|
|
|
|
|
|
$self->code( $code ); |
39
|
|
|
|
|
|
|
$self->message( $message ); |
40
|
|
|
|
|
|
|
$self->request_id( $request_id ); |
41
|
|
|
|
|
|
|
$self->host_id( $host_id ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |