Amazon.pm

filter: Statementstmt 81.0% 990 / 1221 Branchbran 72.9% 538 / 738 Conditioncond 47.6% 30 / 63 MC/DCmcdc 14.6% 6 / 41 Subroutinesub 91.4% 172 / 188 Podpod 5.2% 1 / 19 totaltotal 76.5% 1737 / 2270 CC 433 SCAR 21.8
CC
433
Cov
77%
fetch_url
204.9
request
15.5
intl_url
13.9
CRAP 8.9
↑ Summary Amazon/Property.pm »
1 ###################################################################
2 package Net::Amazon;
3 ######################################################################
4 # Mike Schilli <m@perlmeister.com>, 2003
5 ######################################################################
6  
7 26 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 26 our $VERSION = '0.62';
12 26 our $WSDL_DATE = '2011-08-01';
13 26 our $Locale = 'us';
14 26 our @CANNED_RESPONSES = ();
15 26 our $IS_CANNED = 0;
16  
17 26 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 26 ▶use HTTP::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 26 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 26 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 26 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 26 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 26 ▶use Log::Log4perl qw(:easy get_logger);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 26 ▶use Time::HiRes qw(usleep gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 26 ▶use Digest::SHA qw(hmac_sha256_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 26 ▶use URI::Escape qw(uri_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # Each key represents a search() type, and each value indicates which
29 # Net::Amazon::Request:: class to use to handle it.
30 26 ▶use constant SEARCH_TYPE_CLASS_MAP => {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 actor => 'Actor',
32 artist => 'Artist',
33 all => 'All',
34 author => 'Author',
35 asin => 'ASIN',
36 blended => 'Blended',
37 browsenode => 'BrowseNode',
38 director => 'Director',
39 ean => 'EAN',
40 exchange => 'Exchange',
41 isbn => 'ISBN',
42 keyword => 'Keyword',
43 manufacturer => 'Manufacturer',
44 musiclabel => 'MusicLabel',
45 power => 'Power',
46 publisher => 'Publisher',
47 seller => 'Seller',
48 similar => 'Similar',
49 textstream => 'TextStream',
50 title => 'Title',
51 upc => 'UPC',
52 26 };
53  
54 ##################################################
55 28 ▶sub new {
Subroutine new: called CC=5 SCAR=17.4
Pod undocumented
56 ##################################################
57 28 my($class, %options) = @_;
58  
59 28 ▶ if(! exists $options{token}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options{"token"}) 0 28 28
60 0 die "Mandatory paramter 'token' not defined";
61 }
62  
63 28 ▶ if(! exists $options{secret_key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options{"secret_key"}) 0 28 28
64 0 die "Mandatory paramter 'secret_key' not defined";
65 }
66  
67 28 ▶ if(! exists $options{associate_tag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options{"associate_tag"}) 0 28 28
68 0 die "Mandatory paramter 'associate_tag' not defined";
69 }
70  
71 28 my $self = {
72 strict => 1,
73 response_dump => 0,
74 rate_limit => 1.0, # 1 req/sec
75 max_pages => 5,
76 ua => LWP::UserAgent->new(),
77 compress => 1,
78 %options,
79 };
80  
81 # XXX: this has to be set as soon as possible to ensure
82 # the validators pick up the correct locale. I don't
83 # like the way this works, and need to think of a better
84 # solution.
85 28 ▶ if (exists $self->{locale}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"locale"}) 3 25 28
86 3 $Net::Amazon::Locale = $self->{locale};
87 }
88  
89 28 help_xml_simple_choose_a_parser();
90  
91 28 bless $self, $class;
92 }
93  
94 ##################################################
95 11 ▶sub search {
Subroutine search: called CC=3 SCAR=11.4
Pod documented
96 ##################################################
97 11 my($self, %params) = @_;
98  
99 11 foreach my $key ( keys %params ) {
100 15 ▶ next unless ( my $class = SEARCH_TYPE_CLASS_MAP->{$key} );
Branch: 1 branch
BranchTrueFalseTotal
unless my $class = {"actor" => "Actor","all" => "All","artist" => "Artist","asin" => "ASIN","author" => "Author","blended" => "Blended","browsenode" => "BrowseNode","director" => "Director","ean" => "EAN","exchange" => "Exchange","isbn" => "ISBN","keyword" => "Keyword","manufacturer" => "Manufacturer","musiclabel" => "MusicLabel","power" => "Power","publisher" => "Publisher","seller" => "Seller","similar" => "Similar","textstream" => "TextStream","title" => "Title","upc" => "UPC"}->{$key} 4 11 15
101
102 11 return $self->_make_request($class, \%params);
103 }
104  
105 # FIX?
106 # This seems like it really should be a die() instead...this is
107 # indicative of a programming problem. Generally speaking, it's
108 # best to issue warnings from a module--you can't be sure that the
109 # client has a stderr to begin with, or that he wants errors
110 # spewed to it.
111 0 warn "No Net::Amazon::Request type could be determined";
112  
113 0 return undef;
114 }
115  
116 ##################################################
117 34 ▶sub intl_url {
Subroutine intl_url: called CC=9 SCAR=26.3
Pod undocumented
118 ##################################################
119 34 my($self, $url) = @_;
120  
121 34 ▶ if(! exists $self->{locale}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"locale"}) 31 3 34
122 31 return $url;
123 }
124  
125 3 ▶ if (0) {
Branch: 7 branches
BranchTrueFalseTotal
if (do { $self->{'locale'} eq 'ca' }) { } 0 3 3
elsif ($self->{'locale'} eq 'de') { } 2 1 3
elsif ($self->{'locale'} eq 'es') { } 0 1 1
elsif ($self->{'locale'} eq 'fr') { } 0 1 1
elsif ($self->{'locale'} eq 'jp') { } 0 1 1
elsif ($self->{'locale'} eq 'it') { } 0 1 1
elsif ($self->{'locale'} eq 'uk') { } 1 0 1
126 } elsif ($self->{locale} eq "ca") {
127 0 $url =~ s/\.com/.ca/;
128 } elsif ($self->{locale} eq "de") {
129 2 $url =~ s/\.com/.de/;
130 } elsif ($self->{locale} eq "es") {
131 0 $url =~ s/\.com/.es/;
132 } elsif ($self->{locale} eq "fr") {
133 0 $url =~ s/\.com/.fr/;
134 } elsif ($self->{locale} eq "jp") {
135 0 $url =~ s/\.com/.co.jp/;
136 } elsif ($self->{locale} eq "it") {
137 0 $url =~ s/\.com/.it/;
138 } elsif ($self->{locale} eq "uk") {
139 1 $url =~ s/\.com/.co.uk/;
140 }
141  
142 3 return $url;
143 }
144  
145 ##################################################
146 34 ▶sub request {
Subroutine request: called CC=13 SCAR=27.4
Pod undocumented
147 ##################################################
148 34 my($self, $request) = @_;
149  
150 34 my $resp_class = $request->response_class();
151  
152 34 ▶ eval "require $resp_class;" or
Branch: 1 branch
BranchTrueFalseTotal
eval "require $resp_class;" or die "Cannot find '${resp_class}'" 34 0 34
153 die "Cannot find '$resp_class'";
154  
155 34 my $res = $resp_class->new();
156  
157 34 my $url = URI->new($self->intl_url($request->amzn_xml_url()));
158 my $page = (defined $request->page()) ?
159 34 ▶ ($request->page() - 1) * $self->{max_pages} + 1 :
Branch: 1 branch
BranchTrueFalseTotal
defined $request->page ? : 33 1 34
160 0;
161 34 my $ref;
162 34 my $max_pages_in_this_search = $self->{max_pages} + $page - 1;
163  
164 REQUEST: {
165 34 my %params = $request->params(page => $page);
166 34 ▶ $params{locale} = $self->{locale} if exists $self->{locale};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"locale"} 3 31 34
167  
168 $url->query_form(
169 'Service' => 'AWSECommerceService',
170 'AWSAccessKeyId' => $self->{token},
171 'Version' => $WSDL_DATE,
172 'AssociateTag' => $self->{associate_tag},
173 34 map { $_, $params{$_} } sort keys %params,
174 );
175
176 # Signed requests will have different URLs, which breaks caching.
177 # Get a cachable URL before signing the request.
178 34 my $url_cachablestr = $url->as_string;
179  
180 # New signature for >=2009-03-31. Do not alter URL after this!
181 34 ▶ $url = $self->_sign_request($url) if exists $self->{secret_key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"secret_key"} 34 0 34
182  
183 0 ▶ DEBUG(sub { "request: params = " . Dumper(\%params) . "\n"});
Subroutine __ANON__: not called CC=1 SCAR=1.2
184  
185 34 my $urlstr = $url->as_string;
186  
187 0 ▶ DEBUG(sub { "urlstr=" . $urlstr });
Subroutine __ANON__: not called CC=1 SCAR=1.2
188  
189 34 my $xml = fetch_url($self, $urlstr, $url_cachablestr, $res);
190  
191 34 ▶ if(!defined $xml) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $xml) 0 34 34
192 0 return $res;
193 }
194  
195 0 ▶ DEBUG(sub { "Received [ " . $xml . "]" });
Subroutine __ANON__: not called CC=1 SCAR=1.2
196  
197 # Let the response class parse the XML
198 34 $ref = $res->xml_parse($xml);
199  
200 # DEBUG(sub { Data::Dumper::Dumper($ref) });
201  
202 34 ▶ if(! defined $ref) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ref) 0 34 34
203 0 ERROR("Invalid XML");
204 0 $res->messages( [ "Invalid XML" ]);
205 0 $res->status("");
206 0 return $res;
207 }
208  
209 34 $res->current_page($ref, $page);
210 34 $res->set_total_results($ref);
211
212 34 my $rc = $res->is_page_error($ref);
213 34 ▶ if ($rc == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rc == 0) { } 2 32 34
elsif ($rc == -1) { } 0 32 32
214 2 return $res;
215 } elsif ($rc == -1) {
216 0 last;
217 }
218  
219 32 my $new_items = $res->xmlref_add($ref);
220  
221 32 DEBUG("Received valid XML ($new_items items)");
222  
223 # Stop if we've fetched max_pages already
224 32 ▶ if(defined $page && $max_pages_in_this_search <= $page) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $page and $max_pages_in_this_search <= $page) 2 30 32
Condition66%2/3
defined $page and $max_pages_in_this_search <= $page
!ll&&!rl&&r
0302
MC/DC50%1/2
defined $page and $max_pages_in_this_search <= $page
defined $page $max_pages_in_this_search <= $page
Truth table66%2/3
A and B
A= defined $pageB= $max_pages_in_this_search <= $page
ABresult
0X0
100
111
225 2 DEBUG("Fetched max_pages ($max_pages_in_this_search) -- stopping");
226 2 last;
227 }
228  
229 30 ▶ if($res->is_page_available($ref, $new_items, $page)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_page_available($ref, $new_items, $page)) 0 30 30
230 0 $page++;
231 0 redo REQUEST;
232 }
233  
234 # We're gonna fall out of this loop here.
235 }
236  
237 32 $res->status(1);
238 # We have a valid response, so if TotalResults isn't set,
239 # we most likely have a single response
240 32 ▶ $res->total_results(1) unless defined $res->total_results();
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res->total_results 14 18 32
241 32 return $res;
242 }
243  
244 ##################################################
245 34 ▶sub fetch_url {
Subroutine fetch_url: called CC=16 SCAR=53.2
Pod undocumented
246 ##################################################
247 34 my($self, $url, $url_cachablestr, $res) = @_;
248  
249 34 my $max_retries = 2;
250  
251 34 INFO("Fetching $url");
252  
253 34 ▶ if(@CANNED_RESPONSES) {
Branch: 1 branch
BranchTrueFalseTotal
if (@Net::Amazon::CANNED_RESPONSES) 34 0 34
254 34 $IS_CANNED = 1;
255 34 INFO("Serving canned response (testing)");
256 34 return shift @CANNED_RESPONSES;
257 }
258  
259 0 ▶ if(exists $self->{cache}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"cache"}) 0 0 0
260 0 my $resp = $self->{cache}->get($url_cachablestr);
261 0 ▶ if(defined $resp) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resp) 0 0 0
262 0 INFO("Serving from cache");
263 0 return $resp;
264 }
265  
266 0 INFO("Cache miss");
267 }
268  
269 0 my $ua = $self->{ua};
270 0 $ua->env_proxy();
271  
272 0 my $resp;
273  
274 {
275 # wait up to a second before the next request so
276 # as to not violate Amazon's 1 query per second
277 # rule (or the configured rate_limit).
278 0 ▶ $self->pause() if $self->{strict};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"strict"} 0 0 0
279  
280 {
281 0 my $req = GET $url;
282  
283 $req->header("Accept-Encoding" => [ HTTP::Message::decodable() ])
284 0 ▶ if $self->{compress};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"compress"} 0 0 0
285  
286 0 $resp = $ua->request($req);
287 }
288  
289 0 ▶ $self->reset_timer() if $self->{strict};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"strict"} 0 0 0
290  
291 0 ▶ if($resp->is_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->is_error) 0 0 0
292 # retry on 503 Service Unavailable errors
293 0 ▶ if ($resp->code == 503) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->code == 503) { } 0 0 0
294 0 ▶ if ($max_retries-- >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_retries-- >= 0) { } 0 0 0
295 0 INFO("Temporary Amazon error 503, retrying");
296 0 redo;
297 } else {
298 0 INFO("Out of retries, giving up");
299 0 $res->status("");
300 0 $res->messages( [ "Too many temporary Amazon errors" ] );
301 0 return undef;
302 }
303 } else {
304 0 $res->status("");
305 0 $res->messages( [ $resp->message ] );
306 0 return undef;
307 }
308 }
309  
310 0 ▶ if($self->{response_dump}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"response_dump"}) 0 0 0
311 0 my $dumpfile = "response-$self->{response_dump}.txt";
312 0 ▶ open FILE, ">$dumpfile" or die "Cannot open $dumpfile";
Branch: 1 branch
BranchTrueFalseTotal
open FILE, ">$dumpfile" or die "Cannot open $dumpfile" 0 0 0
313 0 print FILE $resp->decoded_content();
314 0 close FILE;
315 0 $self->{response_dump}++;
316 }
317  
318 0 ▶ if($resp->decoded_content =~ /<Errors>/ &&
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->decoded_content =~ /<Errors>/ and $resp->decoded_content =~ /Please retry/i) 0 0 0
Condition0%0/3
$resp->decoded_content =~ /<Errors>/ and $resp->decoded_content =~ /Please retry/i
!ll&&!rl&&r
000
MC/DC0%0/2
$resp->decoded_content =~ /<Errors>/ and $resp->decoded_content =~ /Please retry/i
$resp->decoded_content =~ /<Errors>/ $resp->decoded_content =~ /Please retry/i
Truth table0%0/3
A and B
A= $resp->decoded_content =~ /<Errors>/B= $resp->decoded_content =~ /Please retry/i
ABresult
0X0
100
111
319 # Is this the same value of AWS4?
320 $resp->decoded_content =~ /Please retry/i) {
321 0 ▶ if($max_retries-- >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_retries-- >= 0) { } 0 0 0
322 0 INFO("Temporary Amazon error, retrying");
323 0 redo;
324 } else {
325 0 INFO("Out of retries, giving up");
326 0 $res->status("");
327 0 $res->messages( [ "Too many temporary Amazon errors" ] );
328 0 return undef;
329 }
330 }
331 }
332  
333 0 ▶ if(exists $self->{cache}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"cache"}) 0 0 0
334 0 $self->{cache}->set($url_cachablestr, $resp->decoded_content());
335 }
336  
337 0 return $resp->decoded_content();
338 }
339  
340 ##################################################
341 # Poor man's Class::Struct
342 ##################################################
343 3116 ▶sub make_accessor {
Subroutine make_accessor: called CC=3 SCAR=11.1
Pod undocumented
344 ##################################################
345 3116 my($package, $name) = @_;
346  
347 26 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
348  
349 3116 my $code = <<EOT;
350 *{"$package\\::$name"} = sub {
351 my(\$self, \$value) = \@_;
352  
353 if(defined \$value) {
354 \$self->{$name} = \$value;
355 }
356 if(exists \$self->{$name}) {
357 return (\$self->{$name});
358 } else {
359 return "";
360 }
361 }
362 EOT
363 3116 ▶ if(! defined *{"$package\::$name"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined *{"${package}::$name";}) 3116 0 3116
364 0 ▶ eval $code or die "$@";
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: not called CC=3 SCAR=11.1
Subroutine __ANON__: not called CC=3 SCAR=11.1
Subroutine __ANON__: not called CC=3 SCAR=11.1
Subroutine __ANON__: not called CC=3 SCAR=11.1
Subroutine __ANON__: not called CC=3 SCAR=11.1
Subroutine __ANON__: not called CC=3 SCAR=11.1
Subroutine __ANON__: not called CC=3 SCAR=11.1
Subroutine __ANON__: not called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: not called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 257 branches
BranchTrueFalseTotal
eval $code or die "$@" 3116 0 3116
if (defined $value) 55 1 56
if (exists $self->{'status'}) { } 56 0 56
if (defined $value) 25 1 26
if (exists $self->{'messages'}) { } 26 0 26
if (defined $value) 23 1 24
if (exists $self->{'items'}) { } 24 0 24
if (defined $value) 3 21 24
if (exists $self->{'xmlref'}) { } 4 20 24
if (defined $value) 54 33 87
if (exists $self->{'total_results'}) { } 87 0 87
if (defined $value) 198 26 224
if (exists $self->{'publisher'}) { } 206 18 224
if (defined $value) 216 4 220
if (exists $self->{'binding'}) { } 220 0 220
if (defined $value) 186 34 220
if (exists $self->{'isbn'}) { } 190 30 220
if (defined $value) 78 122 200
if (exists $self->{'dewey_decimal'}) { } 81 119 200
if (defined $value) 158 41 199
if (exists $self->{'numpages'}) { } 161 38 199
if (defined $value) 115 83 198
if (exists $self->{'edition'}) { } 116 82 198
if (defined $value) 166 34 200
if (exists $self->{'ean'}) { } 170 30 200
if (defined $value) 194 4 198
if (exists $self->{'publication_date'}) { } 196 2 198
if (defined $value) 9 63 72
if (exists $self->{'brand'}) { } 10 62 72
if (defined $value) 69 2 71
if (exists $self->{'ean'}) { } 71 0 71
if (defined $value) 69 2 71
if (exists $self->{'label'}) { } 71 0 71
if (defined $value) 69 3 72
if (exists $self->{'manufacturer'}) { } 72 0 72
if (defined $value) 63 6 69
if (exists $self->{'model'}) { } 65 4 69
if (defined $value) 66 1 67
if (exists $self->{'mpn'}) { } 67 0 67
if (defined $value) 66 1 67
if (exists $self->{'publisher'}) { } 67 0 67
if (defined $value) 66 1 67
if (exists $self->{'studio'}) { } 67 0 67
if (defined $value) 67 2 69
if (exists $self->{'upc'}) { } 69 0 69
if (defined $value) 6 8 14
if (exists $self->{'warranty'}) { } 8 6 14
if (defined $value) 36 3 39
if (exists $self->{'binding'}) { } 39 0 39
if (defined $value) 36 3 39
if (exists $self->{'genre'}) { } 39 0 39
if (defined $value) 36 2 38
if (exists $self->{'label'}) { } 38 0 38
if (defined $value) 6 32 38
if (exists $self->{'manufacturer'}) { } 7 31 38
if (defined $value) 30 1 31
if (exists $self->{'publisher'}) { } 31 0 31
if (defined $value) 30 1 31
if (exists $self->{'release_date'}) { } 31 0 31
if (defined $value) 30 1 31
if (exists $self->{'studio'}) { } 31 0 31
if (defined $value) 60 11 71
if (exists $self->{'title'}) { } 71 0 71
if (defined $value) 30 1 31
if (exists $self->{'track_sequence'}) { } 31 0 31
if (defined $value) 30 1 31
if (exists $self->{'running_time'}) { } 31 0 31
if (defined $value) 48 3 51
if (exists $self->{'studio'}) { } 51 0 51
if (defined $value) 48 2 50
if (exists $self->{'media'}) { } 50 0 50
if (defined $value) 46 4 50
if (exists $self->{'nummedia'}) { } 48 2 50
if (defined $value) 46 4 50
if (exists $self->{'upc'}) { } 48 2 50
if (defined $value) 48 2 50
if (exists $self->{'mpaa_rating'}) { } 50 0 50
if (defined $value) 44 7 51
if (exists $self->{'region_code'}) { } 47 4 51
if (defined $value) 48 3 51
if (exists $self->{'label'}) { } 51 0 51
if (defined $value) 48 3 51
if (exists $self->{'running_time'}) { } 51 0 51
if (defined $value) 48 2 50
if (exists $self->{'publisher'}) { } 50 0 50
if (defined $value) 48 3 51
if (exists $self->{'ean'}) { } 51 0 51
if (defined $value) 2 46 48
if (exists $self->{'theatrical_release_date'}) { } 2 46 48
if (defined $value) 70 32 102
if (exists $self->{'album'}) { } 102 0 102
if (defined $value) 67 16 83
if (exists $self->{'label'}) { } 80 3 83
if (defined $value) 70 2 72
if (exists $self->{'media'}) { } 72 0 72
if (defined $value) 67 5 72
if (exists $self->{'nummedia'}) { } 69 3 72
if (defined $value) 64 8 72
if (exists $self->{'upc'}) { } 66 6 72
if (defined $value) 67 5 72
if (exists $self->{'ean'}) { } 69 3 72
if (defined $value) 67 5 72
if (exists $self->{'studio'}) { } 69 3 72
if (defined $value) 67 4 71
if (exists $self->{'publisher'}) { } 68 3 71
if (defined $value) 58 13 71
if (exists $self->{'release_date'}) { } 59 12 71
if (defined $value) 70 1 71
if (exists $self->{'binding'}) { } 71 0 71
if (defined $value) 8 0 8
if (exists $self->{'brand'}) { } 8 0 8
if (defined $value) 6 2 8
if (exists $self->{'ean'}) { } 6 2 8
if (defined $value) 3 5 8
if (exists $self->{'esrb_rating'}) { } 3 5 8
if (defined $value) 8 0 8
if (exists $self->{'label'}) { } 8 0 8
if (defined $value) 8 0 8
if (exists $self->{'media'}) { } 8 0 8
if (defined $value) 8 0 8
if (exists $self->{'manufacturer'}) { } 8 0 8
if (defined $value) 1 7 8
if (exists $self->{'nummedia'}) { } 1 7 8
if (defined $value) 8 0 8
if (exists $self->{'publisher'}) { } 8 0 8
if (defined $value) 8 0 8
if (exists $self->{'studio'}) { } 8 0 8
if (defined $value) 14 0 14
if (exists $self->{'brand'}) { } 14 0 14
if (defined $value) 14 0 14
if (exists $self->{'ean'}) { } 14 0 14
if (defined $value) 14 0 14
if (exists $self->{'esrb_rating'}) { } 14 0 14
if (defined $value) 14 0 14
if (exists $self->{'label'}) { } 14 0 14
if (defined $value) 14 0 14
if (exists $self->{'upc'}) { } 14 0 14
if (defined $value) 14 1 15
if (exists $self->{'manufacturer'}) { } 15 0 15
if (defined $value) 8 6 14
if (exists $self->{'media'}) { } 8 6 14
if (defined $value) 8 6 14
if (exists $self->{'nummedia'}) { } 8 6 14
if (defined $value) 14 0 14
if (exists $self->{'publisher'}) { } 14 0 14
if (defined $value) 14 0 14
if (exists $self->{'studio'}) { } 14 0 14
if (defined $value) 0 0 0
if (exists $self->{'date'}) { } 0 0 0
if (defined $value) 0 0 0
if (exists $self->{'asin'}) { } 0 0 0
if (defined $value) 0 0 0
if (exists $self->{'rating'}) { } 0 0 0
if (defined $value) 0 0 0
if (exists $self->{'summary'}) { } 0 0 0
if (defined $value) 0 0 0
if (exists $self->{'content'}) { } 0 0 0
if (defined $value) 0 0 0
if (exists $self->{'total_votes'}) { } 0 0 0
if (defined $value) 0 0 0
if (exists $self->{'helpful_votes'}) { } 0 0 0
if (defined $value) 0 0 0
if (exists $self->{'customer_id'}) { } 0 0 0
if (defined $value) 20 0 20
if (exists $self->{'customer_name'}) { } 20 0 20
if (defined $value) 20 0 20
if (exists $self->{'customer_location'}) { } 20 0 20
if (defined $value) 0 21 21
if (exists $self->{'average_customer_rating'}) { } 0 21 21
if (defined $value) 0 21 21
if (exists $self->{'total_reviews'}) { } 0 21 21
if (defined $value) 0 20 20
if (exists $self->{'total_review_pages'}) { } 0 20 20
if (defined $value) 345 72 417
if (exists $self->{'SalesRank'}) { } 347 70 417
if (defined $value) 375 208 583
if (exists $self->{'ASIN'}) { } 563 20 583
if (defined $value) 40 355 395
if (exists $self->{'DetailPageURL'}) { } 40 355 395
if (defined $value) 21 375 396
if (exists $self->{'ProductDescription'}) { } 21 375 396
if (defined $value) 142 402 544
if (exists $self->{'NumMedia'}) { } 145 399 544
if (defined $value) 374 385 759
if (exists $self->{'NumberOfOfferings'}) { } 374 385 759
if (defined $value) 152 281 433
if (exists $self->{'LargeImageWidth'}) { } 171 262 433
if (defined $value) 130 274 404
if (exists $self->{'MediumImageUrl'}) { } 139 265 404
if (defined $value) 169 280 449
if (exists $self->{'SuperSaverShipping'}) { } 222 227 449
if (defined $value) 270 153 423
if (exists $self->{'MediumImageHeight'}) { } 292 131 423
if (defined $value) 272 291 563
if (exists $self->{'Catalog'}) { } 435 128 563
if (defined $value) 131 286 417
if (exists $self->{'SmallImageUrl'}) { } 153 264 417
if (defined $value) 286 171 457
if (exists $self->{'ThirdPartyNewPrice'}) { } 336 121 457
if (defined $value) 153 266 419
if (exists $self->{'CurrencyCode'}) { } 175 244 419
if (defined $value) 136 278 414
if (exists $self->{'Availability'}) { } 155 259 414
if (defined $value) 279 228 507
if (exists $self->{'SmallImageWidth'}) { } 367 140 507
if (defined $value) 266 295 561
if (exists $self->{'RawListPrice'}) { } 432 129 561
if (defined $value) 261 231 492
if (exists $self->{'OurPrice'}) { } 357 135 492
if (defined $value) 138 332 470
if (exists $self->{'MediumImageWidth'}) { } 213 257 470
if (defined $value) 151 244 395
if (exists $self->{'CollectiblePrice'}) { } 151 244 395
if (defined $value) 268 151 419
if (exists $self->{'Binding'}) { } 292 127 419
if (defined $value) 238 163 401
if (exists $self->{'SimilarProducts'}) { } 243 158 401
if (defined $value) 213 311 524
if (exists $self->{'title'}) { } 342 182 524
if (defined $value) 284 155 439
if (exists $self->{'ListPrice'}) { } 323 116 439
if (defined $value) 134 345 479
if (exists $self->{'LargeImageUrl'}) { } 213 266 479
if (defined $value) 195 212 407
if (exists $self->{'CollectibleCount'}) { } 207 200 407
if (defined $value) 142 289 431
if (exists $self->{'Title'}) { } 177 254 431
if (defined $value) 190 285 475
if (exists $self->{'ImageUrlMedium'}) { } 266 209 475
if (defined $value) 94 327 421
if (exists $self->{'TotalOffers'}) { } 120 301 421
if (defined $value) 235 217 452
if (exists $self->{'UsedCount'}) { } 272 180 452
if (defined $value) 189 221 410
if (exists $self->{'ImageUrlSmall'}) { } 233 177 410
if (defined $value) 210 405 615
if (exists $self->{'SmallImageHeight'}) { } 402 213 615
if (defined $value) 267 140 407
if (exists $self->{'UsedPrice'}) { } 279 128 407
if (defined $value) 168 258 426
if (exists $self->{'ImageUrlLarge'}) { } 199 227 426
if (defined $value) 271 144 415
if (exists $self->{'Manufacturer'}) { } 286 129 415
if (defined $value) 205 259 464
if (exists $self->{'ReleaseDate'}) { } 290 174 464
if (defined $value) 146 318 464
if (exists $self->{'ThirdPartyNewCount'}) { } 201 263 464
if (defined $value) 186 235 421
if (exists $self->{'LargeImageHeight'}) { } 231 190 421
if (defined $value) 249 212 461
if (exists $self->{'year'}) { } 370 91 461
if (defined $value) 309 1 310
if (exists $self->{'review_set'}) { } 310 0 310
if (defined $value) 0 0 0
if (exists $self->{'image_set'}) { } 0 0 0
if (defined $value) 1 1 2
if (exists $self->{'offer_set'}) { } 2 0 2
365 }
366 }
367  
368 # An accessor for backward compatability with AWS3.
369 ##################################################
370 96 ▶sub make_compatible_accessor{
Subroutine make_compatible_accessor: called CC=3 SCAR=12.2
Pod undocumented
371 ##################################################
372 96 my($package, $old_name, $new_name) = @_;
373  
374 26 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
375  
376 96 my $code = <<EOT;
377 *{"$package\\::$old_name"} = sub {
378 my(\$self, \$value) = \@_;
379  
380 if(defined \$value) {
381 \$self->{$new_name} = \$value;
382 }
383 if(exists \$self->{$new_name}) {
384 return (\$self->{$new_name});
385 } else {
386 return "";
387 }
388 }
389 EOT
390 96 ▶ if(! defined *{"$package\::$old_name"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined *{"${package}::$old_name";}) 96 0 96
391 0 ▶ eval $code or die "$@";
Subroutine __ANON__: called CC=3 SCAR=12.7
Subroutine __ANON__: called CC=3 SCAR=12.7
Subroutine __ANON__: called CC=3 SCAR=12.7
Subroutine __ANON__: called CC=3 SCAR=12.7
Branch: 9 branches
BranchTrueFalseTotal
eval $code or die "$@" 96 0 96
if (defined $value) 0 19 19
if (exists $self->{'ASIN'}) { } 19 0 19
if (defined $value) 0 12 12
if (exists $self->{'title'}) { } 12 0 12
if (defined $value) 0 17 17
if (exists $self->{'Binding'}) { } 17 0 17
if (defined $value) 0 10 10
if (exists $self->{'DetailPageURL'}) { } 10 0 10
392 }
393 }
394  
395 ##################################################
396 # Make accessors for arrays
397 ##################################################
398 362 ▶sub make_array_accessor {
Subroutine make_array_accessor: called CC=3 SCAR=11.6
Pod undocumented
399 ##################################################
400 362 my($package, $name) = @_;
401  
402 26 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
403  
404 362 my $code = <<EOT;
405 *{"$package\\::$name"} = sub {
406 my(\$self, \$nameref) = \@_;
407 if(defined \$nameref) {
408 if(ref \$nameref eq "ARRAY") {
409 \$self->{$name} = \$nameref;
410 } else {
411 \$self->{$name} = [\$nameref];
412 }
413 }
414 # Return a list
415 if(exists \$self->{$name} and
416 ref \$self->{$name} eq "ARRAY") {
417 return \@{\$self->{$name}};
418 }
419  
420 return undef;
421 }
422 EOT
423  
424 362 ▶ if(! defined *{"$package\::$name"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined *{"${package}::$name";}) 362 0 362
425 0 ▶ eval $code or die "$@";
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Subroutine __ANON__: called CC=5 SCAR=17.1
Branch: 46 branches
BranchTrueFalseTotal
eval $code or die "$@" 362 0 362
if (defined $nameref) 140 169 309
if (ref $nameref eq 'ARRAY') { } 140 0 140
if (exists $self->{"authors"} and ref $self->{"authors"} eq "ARRAY") 281 28 309
if (defined $nameref) 6 6 12
if (ref $nameref eq 'ARRAY') { } 0 6 6
if (exists $self->{"platforms"} and ref $self->{"platforms"} eq "ARRAY") 12 0 12
if (defined $nameref) 6 0 6
if (ref $nameref eq 'ARRAY') { } 6 0 6
if (exists $self->{"features"} and ref $self->{"features"} eq "ARRAY") 6 0 6
if (defined $nameref) 30 13 43
if (ref $nameref eq 'ARRAY') { } 30 0 30
if (exists $self->{"artists"} and ref $self->{"artists"} eq "ARRAY") 43 0 43
if (defined $nameref) 44 7 51
if (ref $nameref eq 'ARRAY') { } 44 0 44
if (exists $self->{"actors"} and ref $self->{"actors"} eq "ARRAY") 47 4 51
if (defined $nameref) 38 14 52
if (ref $nameref eq 'ARRAY') { } 38 0 38
if (exists $self->{"directors"} and ref $self->{"directors"} eq "ARRAY") 41 11 52
if (defined $nameref) 48 4 52
if (ref $nameref eq 'ARRAY') { } 42 6 48
if (exists $self->{"features"} and ref $self->{"features"} eq "ARRAY") 52 0 52
if (defined $nameref) 44 6 50
if (ref $nameref eq 'ARRAY') { } 44 0 44
if (exists $self->{"starring"} and ref $self->{"starring"} eq "ARRAY") 46 4 50
if (defined $nameref) 70 34 104
if (ref $nameref eq 'ARRAY') { } 70 0 70
if (exists $self->{"artists"} and ref $self->{"artists"} eq "ARRAY") 104 0 104
if (defined $nameref) 70 1 71
if (ref $nameref eq 'ARRAY') { } 70 0 70
if (exists $self->{"tracks"} and ref $self->{"tracks"} eq "ARRAY") 71 0 71
if (defined $nameref) 4 10 14
if (ref $nameref eq 'ARRAY') { } 3 1 4
if (exists $self->{"platforms"} and ref $self->{"platforms"} eq "ARRAY") 8 6 14
if (defined $nameref) 14 8 22
if (ref $nameref eq 'ARRAY') { } 5 9 14
if (exists $self->{"platforms"} and ref $self->{"platforms"} eq "ARRAY") 22 0 22
if (defined $nameref) 0 14 14
if (ref $nameref eq 'ARRAY') { } 0 0 0
if (exists $self->{"authors"} and ref $self->{"authors"} eq "ARRAY") 0 14 14
if (defined $nameref) 395 1 396
if (ref $nameref eq 'ARRAY') { } 395 0 395
if (exists $self->{"browse_nodes"} and ref $self->{"browse_nodes"} eq "ARRAY") 396 0 396
if (defined $nameref) 395 5 400
if (ref $nameref eq 'ARRAY') { } 395 0 395
if (exists $self->{"similar_asins"} and ref $self->{"similar_asins"} eq "ARRAY") 400 0 400
Condition44%20/45
exists $self->{"authors"} and ref $self->{"authors"} eq "ARRAY"
!ll&&!rl&&r
280281
exists $self->{"platforms"} and ref $self->{"platforms"} eq "ARRAY"
!ll&&!rl&&r
0012
exists $self->{"features"} and ref $self->{"features"} eq "ARRAY"
!ll&&!rl&&r
006
exists $self->{"artists"} and ref $self->{"artists"} eq "ARRAY"
!ll&&!rl&&r
0043
exists $self->{"actors"} and ref $self->{"actors"} eq "ARRAY"
!ll&&!rl&&r
4047
exists $self->{"directors"} and ref $self->{"directors"} eq "ARRAY"
!ll&&!rl&&r
11041
exists $self->{"features"} and ref $self->{"features"} eq "ARRAY"
!ll&&!rl&&r
0052
exists $self->{"starring"} and ref $self->{"starring"} eq "ARRAY"
!ll&&!rl&&r
4046
exists $self->{"artists"} and ref $self->{"artists"} eq "ARRAY"
!ll&&!rl&&r
00104
exists $self->{"tracks"} and ref $self->{"tracks"} eq "ARRAY"
!ll&&!rl&&r
0071
exists $self->{"platforms"} and ref $self->{"platforms"} eq "ARRAY"
!ll&&!rl&&r
608
exists $self->{"platforms"} and ref $self->{"platforms"} eq "ARRAY"
!ll&&!rl&&r
0022
exists $self->{"authors"} and ref $self->{"authors"} eq "ARRAY"
!ll&&!rl&&r
1400
exists $self->{"browse_nodes"} and ref $self->{"browse_nodes"} eq "ARRAY"
!ll&&!rl&&r
00396
exists $self->{"similar_asins"} and ref $self->{"similar_asins"} eq "ARRAY"
!ll&&!rl&&r
00400
MC/DC50%1/2
exists $self->{"authors"} and ref $self->{"authors"} eq "ARRAY"
exists $self->{"authors"} ref $self->{"authors"} eq "ARRAY"
MC/DC0%0/2
exists $self->{"platforms"} and ref $self->{"platforms"} eq "ARRAY"
exists $self->{"platforms"} ref $self->{"platforms"} eq "ARRAY"
MC/DC0%0/2
exists $self->{"features"} and ref $self->{"features"} eq "ARRAY"
exists $self->{"features"} ref $self->{"features"} eq "ARRAY"
MC/DC0%0/2
exists $self->{"artists"} and ref $self->{"artists"} eq "ARRAY"
exists $self->{"artists"} ref $self->{"artists"} eq "ARRAY"
MC/DC50%1/2
exists $self->{"actors"} and ref $self->{"actors"} eq "ARRAY"
exists $self->{"actors"} ref $self->{"actors"} eq "ARRAY"
MC/DC50%1/2
exists $self->{"directors"} and ref $self->{"directors"} eq "ARRAY"
exists $self->{"directors"} ref $self->{"directors"} eq "ARRAY"
MC/DC0%0/2
exists $self->{"features"} and ref $self->{"features"} eq "ARRAY"
exists $self->{"features"} ref $self->{"features"} eq "ARRAY"
MC/DC50%1/2
exists $self->{"starring"} and ref $self->{"starring"} eq "ARRAY"
exists $self->{"starring"} ref $self->{"starring"} eq "ARRAY"
MC/DC0%0/2
exists $self->{"artists"} and ref $self->{"artists"} eq "ARRAY"
exists $self->{"artists"} ref $self->{"artists"} eq "ARRAY"
MC/DC0%0/2
exists $self->{"tracks"} and ref $self->{"tracks"} eq "ARRAY"
exists $self->{"tracks"} ref $self->{"tracks"} eq "ARRAY"
MC/DC50%1/2
exists $self->{"platforms"} and ref $self->{"platforms"} eq "ARRAY"
exists $self->{"platforms"} ref $self->{"platforms"} eq "ARRAY"
MC/DC0%0/2
exists $self->{"platforms"} and ref $self->{"platforms"} eq "ARRAY"
exists $self->{"platforms"} ref $self->{"platforms"} eq "ARRAY"
MC/DC0%0/2
exists $self->{"authors"} and ref $self->{"authors"} eq "ARRAY"
exists $self->{"authors"} ref $self->{"authors"} eq "ARRAY"
MC/DC0%0/2
exists $self->{"browse_nodes"} and ref $self->{"browse_nodes"} eq "ARRAY"
exists $self->{"browse_nodes"} ref $self->{"browse_nodes"} eq "ARRAY"
MC/DC0%0/2
exists $self->{"similar_asins"} and ref $self->{"similar_asins"} eq "ARRAY"
exists $self->{"similar_asins"} ref $self->{"similar_asins"} eq "ARRAY"
Truth table66%2/3
A and B
A= exists $self->{"authors"}B= ref $self->{"authors"} eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= exists $self->{"platforms"}B= ref $self->{"platforms"} eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= exists $self->{"features"}B= ref $self->{"features"} eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= exists $self->{"artists"}B= ref $self->{"artists"} eq "ARRAY"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= exists $self->{"actors"}B= ref $self->{"actors"} eq "ARRAY"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= exists $self->{"directors"}B= ref $self->{"directors"} eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= exists $self->{"features"}B= ref $self->{"features"} eq "ARRAY"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= exists $self->{"starring"}B= ref $self->{"starring"} eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= exists $self->{"artists"}B= ref $self->{"artists"} eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= exists $self->{"tracks"}B= ref $self->{"tracks"} eq "ARRAY"
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= exists $self->{"platforms"}B= ref $self->{"platforms"} eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= exists $self->{"platforms"}B= ref $self->{"platforms"} eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= exists $self->{"authors"}B= ref $self->{"authors"} eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= exists $self->{"browse_nodes"}B= ref $self->{"browse_nodes"} eq "ARRAY"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= exists $self->{"similar_asins"}B= ref $self->{"similar_asins"} eq "ARRAY"
ABresult
0X0
100
111
426 }
427 }
428  
429 ##################################################
430 13711 ▶sub walk_hash_ref {
Subroutine walk_hash_ref: called CC=4 SCAR=13.9
Pod undocumented
431 ##################################################
432 13711 my ($package, $href, $aref) = @_;
433  
434 13711 ▶ return $href if scalar(@$aref) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$aref == 0 0 13711 13711
435  
436 13711 my @a;
437 13711 push @a, $_ for @$aref;
438  
439 13711 my $tail = pop @a;
440 13711 my $ref = $href;
441  
442 13711 for my $part (@a) {
443 20460 $ref = $ref->{$part};
444 }
445
446 13711 return $ref->{$tail};
447 }
448  
449  
450 ##################################################
451 0 ▶sub artist {
Subroutine artist: not called CC=1 SCAR=6.9
Pod undocumented
452 ##################################################
453 0 my($self, $nameref) = @_;
454  
455 # Only return the first artist
456 0 return ($self->artists($nameref))[0];
457 }
458  
459 ##################################################
460 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=6.9
Pod undocumented
461 ##################################################
462 0 my($self) = @_;
463 0 return $self->{Version};
464 }
465  
466 ##################################################
467 34 ▶sub current_page {
Subroutine current_page: called CC=2 SCAR=6.9
Pod undocumented
468 ##################################################
469 34 my($self, $ref, $page) = @_;
470 34 ▶ if(exists $ref->{Items}->{TotalPages}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ref->{"Items"}{"TotalPages"}) 19 15 34
471 19 INFO("Page $page/$ref->{Items}->{TotalPages}");
472 }
473 }
474  
475 ##################################################
476 34 ▶sub set_total_results {
Subroutine set_total_results: called CC=2 SCAR=6.9
Pod undocumented
477 ##################################################
478 34 my($self, $ref) = @_;
479 34 ▶ if(exists $ref->{Items}->{TotalResults}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ref->{"Items"}{"TotalResults"}) 19 15 34
480 19 $self->total_results( $ref->{Items}->{TotalResults} );
481 }
482 }
483  
484 ##################################################
485 34 ▶sub is_page_error {
Subroutine is_page_error: called CC=4 SCAR=15.2
Pod undocumented
486 ##################################################
487 34 my($self, $ref) = @_;
488  
489 34 ▶ if(exists $ref->{Items}->{Request}->{Errors}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ref->{"Items"}{"Request"}{"Errors"}) 2 32 34
490 2 my $errref = $ref->{Items}->{Request}->{Errors};
491  
492 2 ▶ if (ref($errref->{Error}) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $errref->{'Error'} eq 'ARRAY') { } 0 2 2
493 0 my @errors;
494 0 for my $e (@{$errref->{Error}}) {
495 0 push @errors, $e->{Message};
496 }
497 # multiple errors, set arrary ref
498 0 $self->messages( \@errors );
499 } else {
500 # single error, create array
501 2 $self->messages( [ $errref->{Error}->{Message} ] );
502 }
503  
504 2 ERROR("Fetch Error: " . $self->message );
505 2 $self->status("");
506 2 return 0;
507 }
508 32 return 1;
509 }
510  
511 ##################################################
512 29 ▶sub is_page_available {
Subroutine is_page_available: called CC=4 SCAR=15.0
Pod undocumented
513 ##################################################
514 29 my($self, $ref, $new_items, $page) = @_;
515 29 ▶ if(exists $ref->{Items}->{TotalPages} and
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ref->{"Items"}{"TotalPages"} and $ref->{"Items"}{"TotalPages"} > $page and $Net::Amazon::IS_CANNED ne 1) 0 29 29
Condition83%5/6
exists $ref->{"Items"}{"TotalPages"} and $ref->{"Items"}{"TotalPages"} > $page and $Net::Amazon::IS_CANNED ne 1
!ll&&!rl&&r
2090
exists $ref->{"Items"}{"TotalPages"} and $ref->{"Items"}{"TotalPages"} > $page
!ll&&!rl&&r
1379
MC/DC0%0/3
exists $ref->{"Items"}{"TotalPages"} and $ref->{"Items"}{"TotalPages"} > $page and $Net::Amazon::IS_CANNED ne 1
exists $ref->{"Items"}{"TotalPages"} $ref->{"Items"}{"TotalPages"} > $page $Net::Amazon::IS_CANNED ne 1
Truth table75%3/4
A and B and C
A= exists $ref->{"Items"}{"TotalPages"}B= $ref->{"Items"}{"TotalPages"} > $pageC= $Net::Amazon::IS_CANNED ne 1
ABCresult
0XX0
10X0
1100
1111
516 $ref->{Items}->{TotalPages} > $page and
517 $IS_CANNED ne 1) {
518 0 DEBUG("Page $page of $ref->{Items}->{TotalPages} fetched - continuing");
519 0 return 1;
520 }
521 29 return 0;
522 }
523  
524 ##################################################
525 30 ▶sub xmlref_add {
Subroutine xmlref_add: called CC=6 SCAR=18.3
Pod undocumented
526 ##################################################
527 30 my($self, $xmlref) = @_;
528  
529 30 my $nof_items_added = 0;
530 30 ▶ return $nof_items_added unless defined $xmlref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $xmlref 0 30 30
531  
532 # Push a nested hash structure, retrieved via XMLSimple, onto the
533 # object's internal 'xmlref' entry, which holds a ref to an array,
534 # whichs elements are refs to hashes holding an item's attributes
535 # (like OurPrice etc.)
536  
537 #DEBUG("xmlref_add ", Data::Dumper::Dumper($xmlref));
538  
539 30 ▶ unless(ref($self->{xmlref}) eq "HASH" &&
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self->{"xmlref"} eq "HASH" and ref $self->{"xmlref"}{"Items"} eq "ARRAY") 30 0 30
Condition33%1/3
ref $self->{"xmlref"} eq "HASH" and ref $self->{"xmlref"}{"Items"} eq "ARRAY"
!ll&&!rl&&r
0300
MC/DC0%0/2
ref $self->{"xmlref"} eq "HASH" and ref $self->{"xmlref"}{"Items"} eq "ARRAY"
ref $self->{"xmlref"} eq "HASH" ref $self->{"xmlref"}{"Items"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $self->{"xmlref"} eq "HASH"B= ref $self->{"xmlref"}{"Items"} eq "ARRAY"
ABresult
0X0
100
111
540 ref($self->{xmlref}->{Items}) eq "ARRAY") {
541 30 $self->{xmlref}->{Items} = [];
542 }
543  
544 30 ▶ if(ref($xmlref->{Items}->{Item}) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $xmlref->{'Items'}{'Item'} eq 'ARRAY') { } 18 12 30
545 18 push @{$self->{xmlref}->{Items}}, @{$xmlref->{Items}->{Item}};
546 18 $nof_items_added = scalar @{$xmlref->{Items}->{Item}};
547 } else {
548 12 ▶ if (exists $xmlref->{Items}->{Item}->{ItemAttributes}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $xmlref->{"Items"}{"Item"}{"ItemAttributes"}) 12 0 12
549 12 push @{$self->{xmlref}->{Items}}, $xmlref->{Items}->{Item};
550 12 $nof_items_added = 1;
551 }
552 }
553  
554 30 DEBUG("xmlref_add (after):", Data::Dumper::Dumper($self));
555 30 return $nof_items_added;
556 }
557  
558 ##################################################
559 28 ▶sub help_xml_simple_choose_a_parser {
Subroutine help_xml_simple_choose_a_parser: called CC=3 SCAR=12.0
Pod undocumented
560 ##################################################
561
562 28 eval "require XML::Parser";
563 28 ▶ unless($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 28 28
564 0 $XML::Simple::PREFERRED_PARSER = "XML::Parser";
565 0 return;
566 }
567  
568 28 eval "require XML::SAX::PurePerl";
569 28 ▶ unless($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 28 0 28
570 28 $XML::Simple::PREFERRED_PARSER = "XML::SAX::PurePerl";
571 28 return;
572 }
573 }
574  
575 ##################################################
576 # This timer makes sure we don't query Amazon more
577 # than once a second.
578 ##################################################
579 0 ▶sub reset_timer {
Subroutine reset_timer: not called CC=1 SCAR=6.9
Pod undocumented
580 ##################################################
581  
582 0 my $self = shift;
583 0 $self->{t0} = [gettimeofday];
584 }
585  
586 ##################################################
587 # Pause for up to a second if necessary.
588 ##################################################
589 0 ▶sub pause {
Subroutine pause: not called CC=3 SCAR=24.8
Pod undocumented
590 ##################################################
591  
592 0 my $self = shift;
593 0 ▶ return unless ($self->{t0});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"t0"} 0 0 0
594  
595 0 my $t1 = [gettimeofday];
596 my $dur = (1.0/$self->{rate_limit} -
597 0 tv_interval($self->{t0}, $t1)) * 1000000;
598 0 ▶ if($dur > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dur > 0) 0 0 0
599 # Use a pseudo subclass for the logger, since the app
600 # might not want to log that as 'ERROR'. Log4perl's
601 # inheritance mechanism makes sure it does the right
602 # thing for the current class.
603 0 my $logger = get_logger(__PACKAGE__ . "::RateLimit");
604 0 $logger->error("Ratelimiting: Sleeping $dur microseconds");
605 0 usleep($dur);
606 }
607 }
608  
609 ##
610 ## 'PRIVATE' METHODS
611 ##
612  
613 # $self->_make_request( TYPE, PARAMS )
614 #
615 # Takes a TYPE that corresponds to a Net::Amazon::Request
616 # class, require()s that class, instantiates it, and returns
617 # the result of that instance's request() method.
618 #
619 11 ▶sub _make_request {
Subroutine _make_request: called CC=1 SCAR=0.0
620 11 my ($self, $type, $params) = @_;
621  
622 11 my $class = "Net::Amazon::Request::$type";
623  
624 # XXX: change me back, this makes debugging a little difficult.
625 11 eval "require $class";
626  
627 11 my $req = $class->new(%{$params});
628
629 11 return $self->request($req);
630 }
631  
632 # $self->_sign_request( URI )
633 #
634 # Takes a URI object that corresponds to a Net::Amazon::Request
635 # adds the required Timestamp and Signature parameters, and returns it
636 # See http://docs.amazonwebservices.com/AWSECommerceService/2009-03-31/DG/Query_QueryAuth.html
637 36 ▶sub _sign_request {
Subroutine _sign_request: called CC=4 SCAR=13.9
638 36 my ($self,$uri) = @_;
639 36 ▶ return $uri unless exists $self->{secret_key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"secret_key"} 0 36 36
640 # This assumes no duplicated keys. Safe assumption?
641 36 my %query = $uri->query_form;
642 36 my @now = gmtime;
643 36 ▶ $query{Timestamp} ||= sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$now[5]+1900,$now[4]+1,@now[3,2,1,0]);
Condition66%2/3
$query{"Timestamp"} ||= sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $now[5] + 1900, $now[4] + 1, @now[3, 2, 1, 0])
l!l&&r!l&&!r
2340
MC/DC0%0/2
$query{"Timestamp"} ||= sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $now[5] + 1900, $now[4] + 1, @now[3, 2, 1, 0])
$query{"Timestamp"} sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $now[5] + 1900, $now[4] + 1, @now[3, 2, 1, 0])
Truth table66%2/3
A ||= B
A= $query{"Timestamp"}B= sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $now[5] + 1900, $now[4] + 1, @now[3, 2, 1, 0])
ABresult
1X1
011
000
644 36 my $qstring = join '&', map {"$_=". uri_escape($query{$_},"^A-Za-z0-9\-_.~")} sort keys %query;
645 # Use chr(10), not "\n" which varies by platform
646 36 my $signme = join chr(10),"GET",$uri->host,$uri->path,$qstring;
647 36 my $sig = hmac_sha256_base64($signme, $self->{secret_key});
648 # Digest does not properly pad b64 strings
649 36 ▶ $sig .= '=' while length($sig) % 4;
Branch: 1 branch
BranchTrueFalseTotal
length($sig) % 4 and do { $sig .= '=' } 36 36 72
650 36 $sig = uri_escape($sig,"^A-Za-z0-9\-_.~");
651 36 $qstring .= "&Signature=$sig";
652 36 $uri->query( $qstring );
653 36 return $uri;
654 }
655  
656 26 1;
657  
658 __END__
↑ Summary Amazon/Property.pm »