line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
###################################################################### |
2
|
|
|
|
|
|
|
package Net::Amazon::Response; |
3
|
|
|
|
|
|
|
###################################################################### |
4
|
8
|
|
|
8
|
|
534
|
use warnings; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
241
|
|
5
|
8
|
|
|
8
|
|
43
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
244
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
38
|
use base qw(Net::Amazon); |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
32823
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Text::Wrap qw($columns wrap); |
10
|
|
|
|
|
|
|
use XML::Simple; |
11
|
|
|
|
|
|
|
use Log::Log4perl qw(:easy get_logger); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @FORCE_ARRAY_FIELDS = qw(Author Artist Creator Director Disc |
14
|
|
|
|
|
|
|
Review EditorialReview SimilarProduct Track); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__PACKAGE__->make_accessor($_) for qw( |
17
|
|
|
|
|
|
|
status messages items xmlref total_results); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
################################################## |
20
|
|
|
|
|
|
|
sub new { |
21
|
|
|
|
|
|
|
################################################## |
22
|
|
|
|
|
|
|
my($class, %options) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $self = { |
25
|
|
|
|
|
|
|
status => "", |
26
|
|
|
|
|
|
|
messages => [], |
27
|
|
|
|
|
|
|
items => [], |
28
|
|
|
|
|
|
|
xmlref => {}, |
29
|
|
|
|
|
|
|
total_results => undef, |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
bless $self, $class; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub message { |
36
|
|
|
|
|
|
|
my($self) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return join(";",@{$self->{messages}}); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
########################################### |
42
|
|
|
|
|
|
|
sub is_success { |
43
|
|
|
|
|
|
|
########################################### |
44
|
|
|
|
|
|
|
my($self) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return $self->{status} ? 1 : ""; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
########################################### |
50
|
|
|
|
|
|
|
sub is_error { |
51
|
|
|
|
|
|
|
########################################### |
52
|
|
|
|
|
|
|
my($self) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return !$self->is_success(); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
########################################### |
58
|
|
|
|
|
|
|
sub push_item { |
59
|
|
|
|
|
|
|
########################################### |
60
|
|
|
|
|
|
|
my($self, $item) = @_; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
push @{$self->{items}}, $item; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
########################################### |
66
|
|
|
|
|
|
|
sub as_string { |
67
|
|
|
|
|
|
|
########################################### |
68
|
|
|
|
|
|
|
my($self) = @_; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return Data::Dumper::Dumper($self); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
########################################### |
74
|
|
|
|
|
|
|
sub list_as_string { |
75
|
|
|
|
|
|
|
########################################### |
76
|
|
|
|
|
|
|
my($self, @properties) = @_; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $full = ""; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Column with |
81
|
|
|
|
|
|
|
$columns = 60; |
82
|
|
|
|
|
|
|
my $bullet = 1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
foreach my $property (@properties) { |
85
|
|
|
|
|
|
|
$full .= "\n" if $full; |
86
|
|
|
|
|
|
|
my $bullet_string = sprintf("[%d]%s", |
87
|
|
|
|
|
|
|
$bullet, (" " x (3-length($bullet)))); |
88
|
|
|
|
|
|
|
$full .= wrap("", " ", $bullet_string . $property->as_string()); |
89
|
|
|
|
|
|
|
$bullet++; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
return $full; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
################################################## |
96
|
|
|
|
|
|
|
sub properties { |
97
|
|
|
|
|
|
|
################################################## |
98
|
|
|
|
|
|
|
my($self) = @_; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my @properties = (); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
if($self->is_success && ref($self->{xmlref}->{Items}) eq 'ARRAY') { |
103
|
|
|
|
|
|
|
foreach my $xmlref (@{$self->{xmlref}->{Items}}) { |
104
|
|
|
|
|
|
|
my $property = Net::Amazon::Property::factory(xmlref => $xmlref); |
105
|
|
|
|
|
|
|
push @properties, $property; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
if(wantarray) { |
110
|
|
|
|
|
|
|
return (@properties); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
if(@properties) { |
114
|
|
|
|
|
|
|
# Scalar context and we've got results. Return the first one. |
115
|
|
|
|
|
|
|
return $properties[0]; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Scalar context and we don't have anything. |
119
|
|
|
|
|
|
|
return undef; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
################################################## |
123
|
|
|
|
|
|
|
sub xml_parse { |
124
|
|
|
|
|
|
|
################################################## |
125
|
|
|
|
|
|
|
my($self, $xml) = @_; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
my $xs = XML::Simple->new(); |
128
|
|
|
|
|
|
|
return $xs->XMLin($xml, ForceArray => [ @FORCE_ARRAY_FIELDS ]); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |