line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Amazon::SimpleDB::Response; |
2
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
40
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1631
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Carp qw( croak ); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our %SPECIALS = ( |
9
|
|
|
|
|
|
|
'ErrorResponse' => 1, |
10
|
|
|
|
|
|
|
'ListDomainsResponse' => 1, |
11
|
|
|
|
|
|
|
'GetAttributesResponse' => 1, |
12
|
|
|
|
|
|
|
'QueryResponse' => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
|
|
|
|
|
|
my $class = shift; |
17
|
|
|
|
|
|
|
my $args = shift || {}; |
18
|
|
|
|
|
|
|
croak "No account" unless $args->{account}; |
19
|
|
|
|
|
|
|
my $r = $args->{http_response}; |
20
|
|
|
|
|
|
|
croak 'No HTTP::Response object in http_response' |
21
|
|
|
|
|
|
|
unless ref $r && $r->isa('HTTP::Response'); |
22
|
|
|
|
|
|
|
my $tree; |
23
|
|
|
|
|
|
|
eval { |
24
|
|
|
|
|
|
|
my $content = $r->content; |
25
|
|
|
|
|
|
|
$tree = |
26
|
|
|
|
|
|
|
XMLin( |
27
|
|
|
|
|
|
|
$content, |
28
|
|
|
|
|
|
|
'ForceArray' => ['Attribute', 'DomainName', 'ItemName'], |
29
|
|
|
|
|
|
|
'KeepRoot' => 1 |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
croak $@ if $@; |
33
|
|
|
|
|
|
|
my ($type) = keys %$tree; |
34
|
|
|
|
|
|
|
if ($r->is_error) { |
35
|
|
|
|
|
|
|
require Amazon::SimpleDB::ErrorResponse; |
36
|
|
|
|
|
|
|
$class = 'Amazon::SimpleDB::ErrorResponse'; |
37
|
|
|
|
|
|
|
} elsif ($SPECIALS{$type}) { |
38
|
|
|
|
|
|
|
$class = "Amazon::SimpleDB::${type}"; |
39
|
|
|
|
|
|
|
eval "use $class"; |
40
|
|
|
|
|
|
|
croak $@ if $@; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
my $self = bless {}, $class; |
43
|
|
|
|
|
|
|
$self->{'account'} = $args->{account}; |
44
|
|
|
|
|
|
|
$self->{'http_response'} = $r; |
45
|
|
|
|
|
|
|
$self->{'http_status'} = $r->code; |
46
|
|
|
|
|
|
|
$self->{'content'} = $tree; |
47
|
|
|
|
|
|
|
$self->{'response_type'} = $type; |
48
|
|
|
|
|
|
|
if ($r->is_success) { # errors are stored differently |
49
|
|
|
|
|
|
|
$self->{'request_id'} = $tree->{$type}{ResponseMetadata}{RequestId}; |
50
|
|
|
|
|
|
|
$self->{'box_usage'} = $tree->{$type}{ResponseMetadata}{BoxUsage}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub type { return $_[0]->{'response_type'} } |
56
|
|
|
|
|
|
|
sub http_response { return $_[0]->{'http_response'} } |
57
|
|
|
|
|
|
|
sub http_status { return $_[0]->{'http_status'} } |
58
|
|
|
|
|
|
|
sub content { return $_[0]->{'content'} } |
59
|
|
|
|
|
|
|
sub request_id { return $_[0]->{'request_id'} } |
60
|
|
|
|
|
|
|
sub box_usage { return $_[0]->{'box_usage'} } |
61
|
|
|
|
|
|
|
sub is_success { return $_[0]->{'http_response'}->is_success } |
62
|
|
|
|
|
|
|
sub is_error { return $_[0]->{'http_response'}->is_error } |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |