API.pm

filter: Statementstmt 53.4% 561 / 1050 Branchbran 31.4% 158 / 502 Conditioncond 25.6% 140 / 546 MC/DCmcdc 6.6% 21 / 316 Subroutinesub 63.7% 72 / 113 Podpod 34.4% 10 / 29 totaltotal 37.6% 962 / 2556 CC 477 SCAR 70.7
CC
477
Cov
41%
decode_response
5236.8
invoke_api
1056.0
_get_endpoint_context_parameters
506.0
CRAP 1181.1
↑ Summary API/XML/Simple.pm »
1 package Amazon::API;
2  
3 # Generic interface to Amazon APIs (powered by Botocore)
4  
5 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 11 ▶use Amazon::API::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Amazon::API::Signature4;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Amazon::API::Constants qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Amazon::API::NullLogger;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use Amazon::API::Paginator;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use Amazon::API::HTTP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use Amazon::Credentials;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use Amazon::API::Botocore::Shape;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶use Amazon::API::Botocore::Shape::Serializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶use Amazon::API::Botocore::Shape::Utils qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
20 create_module_name
21 get_service_from_class
22 parse_timestamp
23 require_class
24 require_shape
25 11 );
26  
27 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 11 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 11 ▶use English qw( -no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 11 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 11 ▶use JSON qw(decode_json encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 11 ▶use List::Util qw(any all pairs none);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 11 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 11 ▶use Scalar::Util qw( reftype blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
35 11 ▶use Text::ParseWords qw(parse_line);
Subroutine BEGIN: called CC=1 SCAR=0.0
36 11 ▶use URI::Escape qw(uri_escape_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 11 Readonly::Scalar my $DEFAULT_REGION => 'us-east-1';
39 11 Readonly::Scalar my $REGIONAL_URL_FMT => '%s://%s.%s.amazonaws.com';
40 11 Readonly::Scalar my $GLOBAL_URL_FMT => '%s://%s.amazonaws.com';
41  
42 11 local $Data::Dumper::Pair = $COLON;
43 11 local $Data::Dumper::Useqq = $TRUE;
44 11 local $Data::Dumper::Terse = $TRUE;
45  
46 11 __PACKAGE__->follow_best_practice;
47  
48 11 __PACKAGE__->mk_accessors(
49 qw(
50 action
51 api
52 api_methods
53 api_protocol
54 botocore_client_context_params
55 client_context_params
56 botocore_metadata
57 botocore_operations
58 botocore_request_headers
59 botocore_shapes
60 compiled_endpoint_context
61 compiled_paginators
62 content_type
63 credentials
64 decode_always
65 endpoint_prefix
66 endpoint_rule_set
67 error
68 force_array
69 http_method
70 last_action
71 _log_level
72 localstack
73 logger
74 log_file
75 log4perl_layout
76 namespace
77 no_logger
78 paginators
79 print_error
80 protocol
81 raise_error
82 raise_serialization_errors
83 region
84 request_uri
85 resolved_endpoint
86 response
87 service
88 serializer
89 service_url_base
90 target
91 target_prefix
92 url
93 use_botocore
94 use_fips
95 use_force_path_style
96 use_dualstack
97 use_global_endpoint
98 use_legacy_paginator
99 user_agent
100 use_paginator
101 version
102 )
103 );
104  
105 11 our $VERSION = '2.8.2'; ## no critic (RequireInterpolationOfMetachars)
106 11 our $GIT_SHA = 'a579e96d3cea75fae728b31a50a98530f1c274a4';
107 11 our $GIT_DIRTY = 'a579e96d3cea75fae728b31a50a98530f1c274a4';
108  
109 11 our $VALIDATE_MODE = 'strict';
110  
111 11 our @EXPORT_OK = qw(
112 create_urlencoded_content
113 get_api_service
114 param_n
115 service
116 );
117  
118 11 ▶use parent qw( Exporter Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
119  
120 11 our @REQUIRED_KEYS = qw( aws_access_key_id aws_secret_access_key );
121  
122 ########################################################################
123 2 ▶sub choose(&) { ## no critic
Subroutine choose: called CC=3 SCAR=14.2
Pod undocumented
124 ########################################################################
125 2 my $code = shift;
126  
127 # Pass the correct context down to the block
128 2 ▶ if (wantarray) {
Branch: 2 branches
BranchTrueFalseTotal
if (wantarray) { } 0 2 2
elsif (defined wantarray) { } 2 0 2
129 0 return $code->();
130 }
131 elsif ( defined wantarray ) {
132 2 return scalar $code->();
133 }
134 else {
135 0 $code->();
136 0 return;
137 }
138 }
139  
140 ########################################################################
141 6 ▶sub new {
Subroutine new: called CC=8 SCAR=22.2
Pod documented
142 ########################################################################
143 6 my ( $class, @options ) = @_;
144  
145 6 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
060
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
146  
147 6 ▶ my %options = ref $options[0] ? %{ $options[0] } : @options;
Branch: 1 branch
BranchTrueFalseTotal
ref $options[0] ? : 1 5 6
148  
149 6 ▶ my $log_level = delete $options{log_level} // 'info';
Condition50%1/2
delete $options{"log_level"} // "info"
l!l
06
MC/DC0%0/1
delete $options{"log_level"} // "info"
delete $options{"log_level"}
Truth table50%1/2
A
A= delete $options{"log_level"}
Aresult
11
00
150  
151 6 my $self = $class->SUPER::new( \%options );
152  
153 6 ▶ if ( $self->get_localstack ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_localstack) 0 6 6
154 0 $self->set_url('http://localhost:4566');
155 }
156  
157 6 ▶ if ( $self->get_service_url_base ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_service_url_base) 1 5 6
158 1 $self->set_service( $self->get_service_url_base );
159 }
160  
161 6 ▶ croak 'service is required'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_service 0 6 6
162 if !$self->get_service;
163  
164 6 $self->_set_defaults( %options, log_level => $log_level );
165  
166 6 $self->_set_default_logger($log_level);
167  
168 6 $self->_create_methods;
169  
170 6 ▶ if ( $self->is_botocore_api ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_botocore_api) 0 6 6
171 0 my $serializer = Amazon::API::Botocore::Shape::Serializer->new(
172 logger => $self->get_logger,
173 service => get_service_from_class( ref $self ),
174 );
175 0 $self->set_serializer($serializer);
176 }
177  
178 6 $self->_validate_client_context_params;
179  
180 6 return $self;
181 }
182  
183 ########################################################################
184 10 ▶sub set_log_level {
Subroutine set_log_level: called CC=2 SCAR=6.9
Pod undocumented
185 ########################################################################
186 10 my ( $self, $log_level ) = @_;
187  
188 10 $log_level = lc $log_level;
189  
190 10 $self->set__log_level($log_level);
191  
192 10 my $logger = $self->get_logger;
193  
194 10 ▶ return $self
Branch: 1 branch
BranchTrueFalseTotal
unless $logger 6 4 10
195 if !$logger;
196  
197 4 $logger->level( $LOG4PERL_LOG_LEVELS{$log_level} );
198  
199 4 return $self;
200 }
201  
202 ########################################################################
203 1 ▶sub get_log_level {
Subroutine get_log_level: called CC=1 SCAR=0.0
Pod undocumented
204 ########################################################################
205 1 my ($self) = @_;
206  
207 1 return $self->get__log_level();
208 }
209  
210 ########################################################################
211 0 ▶sub service { goto &get_api_service; }
Subroutine service: not called CC=1 SCAR=6.9
Pod documented
212 ########################################################################
213  
214 ########################################################################
215 0 ▶sub get_api_service {
Subroutine get_api_service: not called CC=1 SCAR=6.9
Pod documented
216 ########################################################################
217 0 my ( $service, @args ) = @_;
218  
219 0 require Amazon::API::Role::Botocore;
220  
221 0 my $class = Amazon::API::Role::Botocore->module_name($service);
222  
223 0 require_class $class;
224  
225 0 return $class->new(@args);
226 }
227  
228 ########################################################################
229 1 ▶sub decode_response {
Subroutine decode_response: called CC=116 SCAR=85.6
Pod documented
230 ########################################################################
231 1 my ( $self, $response, $serialize ) = @_;
232  
233 1 ▶ $serialize //= $TRUE;
Condition33%1/3
$serialize //= $Amazon::API::TRUE
l!l&&r!l&&!r
010
MC/DC0%0/2
$serialize //= $Amazon::API::TRUE
$serialize $Amazon::API::TRUE
Truth table33%1/3
A //= B
A= $serializeB= $Amazon::API::TRUE
ABresult
1X1
011
000
234  
235 1 ▶ $response = $response || $self->get_response;
Condition33%1/3
$response || $self->get_response
l!l&&r!l&&!r
100
MC/DC0%0/2
$response || $self->get_response
$response $self->get_response
Truth table33%1/3
A || B
A= $responseB= $self->get_response
ABresult
1X1
011
000
236  
237 # could be Furl or HTTP?
238 1 ▶ if ( !blessed $response || !$response->can('content') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($response) and $response->can("content")) 0 1 1
Condition33%1/3
builtin::blessed($response) and $response->can("content")
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::blessed($response) and $response->can("content")
builtin::blessed($response) $response->can("content")
Truth table33%1/3
A and B
A= builtin::blessed($response)B= $response->can("content")
ABresult
0X0
100
111
239 0 ▶ croak q{can't decode response - not a response object: } . ( ref $response || 'non-reference' );
Condition0%0/2
ref $response || 'non-reference'
l!l
00
MC/DC0%0/1
ref $response || 'non-reference'
ref $response
Truth table0%0/2
A
A= ref $response
Aresult
11
00
240 }
241  
242 1 my $content = $response->content;
243  
244 1 ▶ my $has_response_content = defined $content && length $content;
Condition33%1/3
defined $content && length $content
!ll&&!rl&&r
001
MC/DC0%0/2
defined $content && length $content
defined $content length $content
Truth table33%1/3
A && B
A= defined $contentB= length $content
ABresult
0X0
100
111
245  
246 1 my $content_type = $response->content_type;
247  
248 # this is expected to fail if !$self->is_botocore_api
249 my ( $protocol, $botocore_action )
250 1 = eval { return ( $self->get_botocore_metadata->{protocol}, $self->get_botocore_action, ); };
251  
252 1 ▶ my $output = $botocore_action ? $botocore_action->{output} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$botocore_action ? : 1 0 1
253  
254 1 ▶ my $output_shape = $output ? $self->get_botocore_shapes->{ $output->{shape} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$output ? : 1 0 1
255 1 my $payload_shape;
256  
257 1 ▶ if ( $protocol
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol and $protocol =~ /^(?:rest-json|rest-xml)$/msx and $output_shape and $output_shape->{"payload"}) 0 1 1
Condition33%3/9
$protocol and $protocol =~ /^(?:rest-json|rest-xml)$/msx and $output_shape and $output_shape->{"payload"}
!ll&&!rl&&r
010
$protocol and $protocol =~ /^(?:rest-json|rest-xml)$/msx and $output_shape
!ll&&!rl&&r
001
$protocol and $protocol =~ /^(?:rest-json|rest-xml)$/msx
!ll&&!rl&&r
001
MC/DC0%0/4
$protocol and $protocol =~ /^(?:rest-json|rest-xml)$/msx and $output_shape and $output_shape->{"payload"}
$protocol $protocol =~ /^(?:rest-json|rest-xml)$/msx $output_shape $output_shape->{"payload"}
Truth table20%1/5
A and B and C and D
A= $protocolB= $protocol =~ /^(?:rest-json|rest-xml)$/msxC= $output_shapeD= $output_shape->{"payload"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
258 && $protocol =~ /^(?:rest-json|rest-xml)$/xsm
259 && $output_shape
260 && $output_shape->{payload} ) {
261 0 my $payload = $output_shape->{payload};
262  
263 0 my $member = $output_shape->{members}->{$payload};
264  
265 0 ▶ if ($member) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member) 0 0 0
266 0 $payload_shape = $self->get_botocore_shapes->{ $member->{shape} };
267 }
268 }
269  
270 my $payload_type
271 = $payload_shape
272 1 ▶ ? $payload_shape->{type} // $EMPTY
Branch: 1 branch
BranchTrueFalseTotal
$payload_shape ? : 0 1 1
Condition0%0/3
$payload_shape->{"type"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$payload_shape->{"type"} // $Amazon::API::EMPTY
$payload_shape->{"type"} $Amazon::API::EMPTY
Truth table0%0/3
A // B
A= $payload_shape->{"type"}B= $Amazon::API::EMPTY
ABresult
1X1
011
000
273 : $EMPTY;
274  
275 1 my $is_raw_payload = $payload_type =~ /^(?:blob|string)$/xsm;
276  
277 $self->get_logger->trace(
278 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
279 0 return Dumper(
280 [ protocol => $protocol,
281 response_content => $content,
282 ]
283 );
284 }
285 1 );
286  
287 1 my $decoded_content;
288  
289 1 ▶ if ( $has_response_content && !$is_raw_payload ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_response_content and not $is_raw_payload) 1 0 1
Condition33%1/3
$has_response_content and not $is_raw_payload
!ll&&!rl&&r
001
MC/DC0%0/2
$has_response_content and not $is_raw_payload
$has_response_content not $is_raw_payload
Truth table33%1/3
A and not(B)
A= $has_response_contentB= not $is_raw_payload
ABresult
0X0
100
111
290 1 $decoded_content = eval {
291 1 ▶ if ( $content_type =~ /json/xmsi ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($content_type =~ /json/imsx) { } 1 0 1
elsif ($content_type =~ /xml/imsx) { } 0 0 0
292 1 return decode_json($content);
293 }
294 elsif ( $content_type =~ /xml/xmsi ) {
295 # Use the local XML::Simple-compatible parser. It preserves
296 # whitespace-only character data when NormaliseSpace is disabled,
297 # which upstream XML::Simple 2.25 does not.
298 0 require Amazon::API::XML::Simple;
299  
300 ################################################################
301 # Maddening interpretation of XML output from these ass hats (-:|3
302 #
303 # A little more explanation: some rest-xml and ec2 protocol
304 # API responses have wrapper elements that are not part of the
305 # shape description...some do. It probably would have been
306 # best not to try to serialize this XML object here, but
307 # rather downstream when trying to create shapes from
308 # it. However, the serializer now tries to figure out whether
309 # to disgard the wrapper or keep it. The botocore metadata
310 # could have offered some clues, however I believe the
311 # serializers in Botocore have been tuned to specific APIs in
312 # some cases making it difficult to fix legacy mistakes in
313 # these APIs.
314 ################################################################
315  
316 return Amazon::API::XML::Simple::XMLin(
317 $content,
318 KeepRoot => $TRUE,
319 NormaliseSpace => 0,
320 SuppressEmpty => $FALSE,
321 ForceContent => $self->is_botocore_api && $botocore_action->{output},
322 0 ▶ ForceArray => ['item'],
Condition0%0/3
$self->is_botocore_api && $botocore_action->{'output'}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->is_botocore_api && $botocore_action->{'output'}
$self->is_botocore_api $botocore_action->{'output'}
Truth table0%0/3
A && B
A= $self->is_botocore_apiB= $botocore_action->{'output'}
ABresult
0X0
100
111
323 );
324  
325 }
326  
327 0 return;
328 };
329  
330 # disregard content_type (it might be misleading?)
331 # this is almost certainly going to be a problem somewhere...
332 1 ▶ if ( !defined $decoded_content || $EVAL_ERROR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $decoded_content or $Amazon::API::EVAL_ERROR) 0 1 1
Condition33%1/3
not defined $decoded_content or $Amazon::API::EVAL_ERROR
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $decoded_content or $Amazon::API::EVAL_ERROR
not defined $decoded_content $Amazon::API::EVAL_ERROR
Truth table33%1/3
not(A) or B
A= not defined $decoded_contentB= $Amazon::API::EVAL_ERROR
ABresult
1X1
011
000
333 0 $self->get_logger->warn("unable to decode content: $EVAL_ERROR");
334 0 $self->get_logger->warn('Trying again using JSON and XML decoders.');
335  
336 0 $decoded_content = eval { return decode_json($content); };
337  
338 0 ▶ if ( !defined $decoded_content || $EVAL_ERROR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $decoded_content or $Amazon::API::EVAL_ERROR) 0 0 0
Condition0%0/3
not defined $decoded_content or $Amazon::API::EVAL_ERROR
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $decoded_content or $Amazon::API::EVAL_ERROR
not defined $decoded_content $Amazon::API::EVAL_ERROR
Truth table0%0/3
not(A) or B
A= not defined $decoded_contentB= $Amazon::API::EVAL_ERROR
ABresult
1X1
011
000
339 0 require Amazon::API::XML::Simple;
340  
341 0 $decoded_content = eval {
342 0 ▶ return Amazon::API::XML::Simple::XMLin(
Branch: 1 branch
BranchTrueFalseTotal
$self->get_force_array ? : 0 0 0
343 $content,
344 NormaliseSpace => 0,
345 SuppressEmpty => $FALSE,
346 $self->get_force_array
347 ? ( ForceArray => ['item'] )
348 : (),
349 );
350 };
351 }
352 }
353 }
354  
355 1 ▶ $content = defined $decoded_content ? $decoded_content : $content;
Branch: 1 branch
BranchTrueFalseTotal
defined $decoded_content ? : 1 0 1
356  
357 $self->get_logger->trace(
358 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
359 0 return Dumper( [ content => $content ] );
360 }
361 1 );
362  
363 # we'll only have a serializer if this is a Botocore generated API
364 1 my $serializer = $self->get_serializer;
365  
366 1 ▶ if ($serializer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($serializer) 1 0 1
367 1 $serializer->set_protocol($protocol);
368 }
369  
370 1 ▶ my $is_json_protocol = $protocol && any { $protocol eq $_ } qw(json rest-json );
Subroutine __ANON__: called CC=1 SCAR=0.6
Condition33%1/3
$protocol && &any(sub { $protocol eq $_; } , 'json', 'rest-json')
!ll&&!rl&&r
001
MC/DC0%0/2
$protocol && &any(sub { $protocol eq $_; } , 'json', 'rest-json')
$protocol &any(sub { $protocol eq $_; } , 'json', 'rest-json')
Truth table33%1/3
A && B
A= $protocolB= &any(sub { $protocol eq $_; } , 'json', 'rest-json')
ABresult
0X0
100
111
371  
372 return {}
373 1 ▶ if $is_json_protocol && !$output;
Branch: 1 branch
BranchTrueFalseTotal
if $is_json_protocol and not $output 0 1 1
Condition33%1/3
$is_json_protocol and not $output
!ll&&!rl&&r
010
MC/DC0%0/2
$is_json_protocol and not $output
$is_json_protocol not $output
Truth table33%1/3
A and not(B)
A= $is_json_protocolB= not $output
ABresult
0X0
100
111
374  
375 return {}
376 if $protocol
377 1 ▶ && ( any { $protocol eq $_ } qw{rest-xml query} )
Subroutine __ANON__: called CC=1 SCAR=1.5
Branch: 1 branch
BranchTrueFalseTotal
if $protocol and &any(sub { $protocol eq $_; } , "rest-xml", "query") and not $output and not $has_response_content 0 1 1
Condition33%3/9
$protocol and &any(sub { $protocol eq $_; } , "rest-xml", "query") and not $output and not $has_response_content
!ll&&!rl&&r
100
$protocol and &any(sub { $protocol eq $_; } , "rest-xml", "query") and not $output
!ll&&!rl&&r
100
$protocol and &any(sub { $protocol eq $_; } , "rest-xml", "query")
!ll&&!rl&&r
010
MC/DC0%0/4
$protocol and &any(sub { $protocol eq $_; } , "rest-xml", "query") and not $output and not $has_response_content
$protocol &any(sub { $protocol eq $_; } , "rest-xml", "query") not $output not $has_response_content
Truth table20%1/5
A and B and not(C) and not(D)
A= $protocolB= &any(sub { $protocol eq $_; } , "rest-xml", "query")C= not $outputD= not $has_response_content
ABCDresult
0XXX0
10XX0
110X0
11100
11111
378 && !$output
379 && !$has_response_content;
380  
381 # JSON-family protocols model an empty response body as an empty
382 # structure when the operation has a structured output.
383 1 ▶ if ( $is_json_protocol
Branch: 1 branch
BranchTrueFalseTotal
if ($is_json_protocol and $output_shape and not $has_response_content and ($output_shape->{"type"} // "") eq "structure") 0 1 1
Condition27%3/11
$is_json_protocol and $output_shape and not $has_response_content and ($output_shape->{"type"} // "") eq "structure"
!ll&&!rl&&r
100
$is_json_protocol and $output_shape and not $has_response_content
!ll&&!rl&&r
010
$is_json_protocol and $output_shape
!ll&&!rl&&r
001
$output_shape->{"type"} // ""
l!l
00
MC/DC0%0/4
$is_json_protocol and $output_shape and not $has_response_content and ($output_shape->{"type"} // "") eq "structure"
$is_json_protocol $output_shape not $has_response_content $output_shape->{"type"}
Truth table20%1/5
A and B and not(C) and D
A= $is_json_protocolB= $output_shapeC= not $has_response_contentD= $output_shape->{"type"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
384 && $output_shape
385 && !$has_response_content
386 && ( $output_shape->{type} // q{} ) eq 'structure' ) {
387 0 $content = {};
388 }
389  
390 # In rest-json a payload response body is not the entire output
391 # structure. It is the value of the member named by the output
392 # shape's payload trait. Wrap it before serializing the output
393 # structure so scalar payloads do not hit the early scalar return.
394 1 ▶ if ( $protocol
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol and $protocol eq "rest-json" and $output_shape and $output_shape->{"payload"} and $has_response_content) 0 1 1
Condition33%4/12
$protocol and $protocol eq "rest-json" and $output_shape and $output_shape->{"payload"} and $has_response_content
!ll&&!rl&&r
100
$protocol and $protocol eq "rest-json" and $output_shape and $output_shape->{"payload"}
!ll&&!rl&&r
010
$protocol and $protocol eq "rest-json" and $output_shape
!ll&&!rl&&r
001
$protocol and $protocol eq "rest-json"
!ll&&!rl&&r
001
MC/DC0%0/5
$protocol and $protocol eq "rest-json" and $output_shape and $output_shape->{"payload"} and $has_response_content
$protocol $protocol eq "rest-json" $output_shape $output_shape->{"payload"} $has_response_content
Truth table16%1/6
A and B and C and D and E
A= $protocolB= $protocol eq "rest-json"C= $output_shapeD= $output_shape->{"payload"}E= $has_response_content
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
395 && $protocol eq 'rest-json'
396 && $output_shape
397 && $output_shape->{payload}
398 && $has_response_content ) {
399 0 my $payload = $output_shape->{payload};
400  
401 0 $content = { $payload => $content, };
402 }
403  
404 1 my $xml_empty_output;
405  
406 1 ▶ if ( $protocol
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol and &any(sub { $protocol eq $_; } , "rest-xml", "ec2", "query") and not $has_response_content and $output_shape and ($output_shape->{"type"} // $Amazon::API::EMPTY) eq "structure") 0 1 1
Condition26%4/15
$protocol and &any(sub { $protocol eq $_; } , "rest-xml", "ec2", "query") and not $has_response_content and $output_shape and ($output_shape->{"type"} // $Amazon::API::EMPTY) eq "structure"
!ll&&!rl&&r
100
$protocol and &any(sub { $protocol eq $_; } , "rest-xml", "ec2", "query") and not $has_response_content and $output_shape
!ll&&!rl&&r
100
$protocol and &any(sub { $protocol eq $_; } , "rest-xml", "ec2", "query") and not $has_response_content
!ll&&!rl&&r
100
$protocol and &any(sub { $protocol eq $_; } , "rest-xml", "ec2", "query")
!ll&&!rl&&r
010
$output_shape->{"type"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/6
$protocol and &any(sub { $protocol eq $_; } , "rest-xml", "ec2", "query") and not $has_response_content and $output_shape and ($output_shape->{"type"} // $Amazon::API::EMPTY) eq "structure"
$protocol &any(sub { $protocol eq $_; } , "rest-xml", "ec2", "query") not $has_response_content $output_shape $output_shape->{"type"} $Amazon::API::EMPTY
Truth table14%1/7
A and B and not(C) and D and E // F
A= $protocolB= &any(sub { $protocol eq $_; } , "rest-xml", "ec2", "query")C= not $has_response_contentD= $output_shapeE= $output_shape->{"type"}F= $Amazon::API::EMPTY
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
1111000
11111X1
1111011
407 3 ▶ && ( any { $protocol eq $_ } qw(rest-xml ec2 query) )
Subroutine __ANON__: called CC=1 SCAR=0.0
408 && !$has_response_content
409 && $output_shape
410 && ( $output_shape->{type} // $EMPTY ) eq 'structure' ) {
411 0 $content = {};
412 0 $xml_empty_output = $TRUE;
413 }
414  
415 1 ▶ if ( $protocol
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol and $protocol eq "rest-xml" and $output_shape and $output_shape->{"payload"} and $has_response_content) 0 1 1
Condition33%4/12
$protocol and $protocol eq "rest-xml" and $output_shape and $output_shape->{"payload"} and $has_response_content
!ll&&!rl&&r
100
$protocol and $protocol eq "rest-xml" and $output_shape and $output_shape->{"payload"}
!ll&&!rl&&r
100
$protocol and $protocol eq "rest-xml" and $output_shape
!ll&&!rl&&r
100
$protocol and $protocol eq "rest-xml"
!ll&&!rl&&r
010
MC/DC0%0/5
$protocol and $protocol eq "rest-xml" and $output_shape and $output_shape->{"payload"} and $has_response_content
$protocol $protocol eq "rest-xml" $output_shape $output_shape->{"payload"} $has_response_content
Truth table16%1/6
A and B and C and D and E
A= $protocolB= $protocol eq "rest-xml"C= $output_shapeD= $output_shape->{"payload"}E= $has_response_content
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
416 && $protocol eq 'rest-xml'
417 && $output_shape
418 && $output_shape->{payload}
419 && $has_response_content ) {
420  
421 0 my $payload = $output_shape->{payload};
422  
423 0 my $member = $output_shape->{members}->{$payload};
424  
425 0 ▶ if ($member) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member) 0 0 0
426 0 ▶ my $location_name = $member->{locationName} // $payload;
Condition0%0/3
$member->{"locationName"} // $payload
l!l&&r!l&&!r
000
MC/DC0%0/2
$member->{"locationName"} // $payload
$member->{"locationName"} $payload
Truth table0%0/3
A // B
A= $member->{"locationName"}B= $payload
ABresult
1X1
011
000
427  
428 0 ▶ if ( ref $content
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content and builtin::reftype($content) eq 'HASH') { } 0 0 0
Condition0%0/3
ref $content and builtin::reftype($content) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $content and builtin::reftype($content) eq "HASH"
ref $content builtin::reftype($content) eq "HASH"
Truth table0%0/3
A and B
A= ref $contentB= builtin::reftype($content) eq "HASH"
ABresult
0X0
100
111
429 && reftype($content) eq 'HASH' ) {
430 0 my $payload_shape_name = $member->{shape};
431  
432 0 my $payload_shape = $self->get_botocore_shapes->{$payload_shape_name};
433  
434 0 ▶ my $root_name = $payload_shape->{locationName} // $payload_shape_name;
Condition0%0/3
$payload_shape->{"locationName"} // $payload_shape_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$payload_shape->{"locationName"} // $payload_shape_name
$payload_shape->{"locationName"} $payload_shape_name
Truth table0%0/3
A // B
A= $payload_shape->{"locationName"}B= $payload_shape_name
ABresult
1X1
011
000
435  
436 0 ▶ if ( exists $content->{$root_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $content->{$root_name}) 0 0 0
437 0 $content = { $location_name => $content->{$root_name}, };
438 }
439 }
440 else {
441 0 $content = { $location_name => $content, };
442 }
443 }
444 }
445  
446 1 ▶ return $content
Branch: 1 branch
BranchTrueFalseTotal
unless ref $content and $serializer and $serialize 0 1 1
Condition33%2/6
ref $content and $serializer and $serialize
!ll&&!rl&&r
001
ref $content and $serializer
!ll&&!rl&&r
001
MC/DC0%0/3
ref $content and $serializer and $serialize
ref $content $serializer $serialize
Truth table25%1/4
A and B and C
A= ref $contentB= $serializerC= $serialize
ABCresult
0XX0
10X0
1100
1111
447 if !ref $content || !$serializer || !$serialize;
448  
449 1 ▶ return $decoded_content
Branch: 1 branch
BranchTrueFalseTotal
unless $output 0 1 1
450 if !$output;
451  
452 1 my $orig_content = $content;
453  
454 1 ▶ if ( $protocol && $protocol eq 'query' && ref $content eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol and $protocol eq "query" and ref $content eq "HASH") 0 1 1
Condition33%2/6
$protocol and $protocol eq "query" and ref $content eq "HASH"
!ll&&!rl&&r
100
$protocol and $protocol eq "query"
!ll&&!rl&&r
010
MC/DC0%0/3
$protocol and $protocol eq "query" and ref $content eq "HASH"
$protocol $protocol eq "query" ref $content eq "HASH"
Truth table25%1/4
A and B and C
A= $protocolB= $protocol eq "query"C= ref $content eq "HASH"
ABCresult
0XX0
10X0
1100
1111
455 0 my ($root_key) = grep {/Response$/xsm} keys %{$content};
456  
457 0 ▶ if ($root_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root_key) 0 0 0
458 0 $content = $content->{$root_key};
459 }
460  
461 0 ▶ if ( !$output->{resultWrapper}
Branch: 1 branch
BranchTrueFalseTotal
if (not $output->{"resultWrapper"} and ref $content and builtin::reftype($content) eq "HASH") 0 0 0
Condition0%0/6
not $output->{"resultWrapper"} and ref $content and builtin::reftype($content) eq "HASH"
!ll&&!rl&&r
000
not $output->{"resultWrapper"} and ref $content
!ll&&!rl&&r
000
MC/DC0%0/3
not $output->{"resultWrapper"} and ref $content and builtin::reftype($content) eq "HASH"
not $output->{"resultWrapper"} ref $content builtin::reftype($content) eq "HASH"
Truth table0%0/4
not(A) and B and C
A= not $output->{"resultWrapper"}B= ref $contentC= builtin::reftype($content) eq "HASH"
ABCresult
0XX0
10X0
1100
1111
462 && ref $content
463 && reftype($content) eq 'HASH' ) {
464 0 my ($result_wrapper) = grep {/Result$/xsm} keys %{$content};
465  
466 0 ▶ if ($result_wrapper) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result_wrapper) 0 0 0
467 0 $content = $content->{$result_wrapper};
468 }
469 }
470 }
471  
472 1 ▶ if ( $output->{resultWrapper} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($output->{"resultWrapper"}) 0 1 1
473 0 $content = $content->{ $output->{resultWrapper} };
474 }
475  
476 $self->get_logger->trace(
477 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
478 0 return Dumper(
479 [ content => $content,
480 botocore_action_output => $output,
481 ]
482 );
483 }
484 1 );
485  
486 1 $serializer->set_logger( $self->get_logger );
487  
488 1 ▶ my $exists = choose {
Subroutine __ANON__: called CC=4 SCAR=22.5
489 1 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $is_json_protocol and ref $content 1 0 1
Condition33%1/3
$is_json_protocol and ref $content
!ll&&!rl&&r
001
MC/DC0%0/2
$is_json_protocol and ref $content
$is_json_protocol ref $content
Truth table33%1/3
A and B
A= $is_json_protocolB= ref $content
ABresult
0X0
100
111
490 if $is_json_protocol && ref $content;
491  
492 0 ▶ return $xml_empty_output
Branch: 1 branch
BranchTrueFalseTotal
if defined $xml_empty_output 0 0 0
493 if defined $xml_empty_output;
494  
495 0 return;
496 1 };
497  
498 1 $content = eval {
499 return $serializer->serialize(
500 service => get_service_from_class( ref $self ),
501 shape => $output->{shape},
502 1 data => $content,
503 exists => $exists,
504 );
505 };
506  
507 # ...but this isn't necessarily where things STB
508 1 ▶ if ( !defined $content || $EVAL_ERROR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $content or $Amazon::API::EVAL_ERROR) 0 1 1
Condition33%1/3
not defined $content or $Amazon::API::EVAL_ERROR
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $content or $Amazon::API::EVAL_ERROR
not defined $content $Amazon::API::EVAL_ERROR
Truth table33%1/3
not(A) or B
A= not defined $contentB= $Amazon::API::EVAL_ERROR
ABresult
1X1
011
000
509 0 ▶ if ( $self->get_raise_serialization_errors ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->get_raise_serialization_errors) { } 0 0 0
elsif ($Amazon::API::EVAL_ERROR) { } 0 0 0
510 0 die $EVAL_ERROR;
511 }
512 elsif ($EVAL_ERROR) {
513 0 carp "ERROR: serializing error: please report this error\n$EVAL_ERROR";
514 0 $content = $orig_content;
515 }
516 }
517  
518 # Header-located output members never appear in the body. Lift them
519 # into the modeled result. For now these remain raw HTTP values;
520 # modeled header deserialization is handled separately.
521 1 ▶ my $output_members = $output_shape->{members} // {};
Condition50%1/2
$output_shape->{"members"} // {}
l!l
10
MC/DC0%0/1
$output_shape->{"members"} // {}
$output_shape->{"members"}
Truth table50%1/2
A
A= $output_shape->{"members"}
Aresult
11
00
522  
523 1 ▶ if ( ref $content eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content eq "HASH") 1 0 1
524 1 foreach my $member ( keys %{$output_members} ) {
525 2 my $spec = $output_members->{$member};
526 2 ▶ my $location = $spec->{location} // $EMPTY;
Condition66%2/3
$spec->{"location"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
110
MC/DC0%0/2
$spec->{"location"} // $Amazon::API::EMPTY
$spec->{"location"} $Amazon::API::EMPTY
Truth table66%2/3
A // B
A= $spec->{"location"}B= $Amazon::API::EMPTY
ABresult
1X1
011
000
527  
528 2 my $shape = $self->get_botocore_shapes->{ $spec->{shape} };
529  
530 2 ▶ if ( $location eq 'header' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($location eq 'header') { } 0 2 2
elsif ($location eq 'headers') { } 0 2 2
elsif ($location eq 'statusCode') { } 1 1 2
531 0 ▶ my $value = $response->header( $spec->{locationName} // $member );
Condition0%0/3
$spec->{"locationName"} // $member
l!l&&r!l&&!r
000
MC/DC0%0/2
$spec->{"locationName"} // $member
$spec->{"locationName"} $member
Truth table0%0/3
A // B
A= $spec->{"locationName"}B= $member
ABresult
1X1
011
000
532  
533 0 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 0 0
534 0 ▶ if ($is_json_protocol) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_json_protocol) { } 0 0 0
elsif ($protocol and $protocol eq 'rest-xml') { } 0 0 0
535 0 my $shape = $self->get_botocore_shapes->{ $spec->{shape} };
536  
537 0 my $data = $value;
538  
539 0 ▶ if ( $shape && ( $shape->{type} // $EMPTY ) eq 'list' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shape and ($shape->{"type"} // $Amazon::API::EMPTY) eq "list") 0 0 0
Condition0%0/6
$shape and ($shape->{"type"} // $Amazon::API::EMPTY) eq "list"
!ll&&!rl&&r
000
$shape->{"type"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/3
$shape and ($shape->{"type"} // $Amazon::API::EMPTY) eq "list"
$shape $shape->{"type"} $Amazon::API::EMPTY
Truth table0%0/4
A and B // C
A= $shapeB= $shape->{"type"}C= $Amazon::API::EMPTY
ABCresult
0XX0
1000
11X1
1011
540 0 my $member_shape = $self->get_botocore_shapes->{ $shape->{member}->{shape} };
541  
542 0 ▶ if ( $member_shape && ( $member_shape->{type} // $EMPTY ) eq 'timestamp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member_shape and ($member_shape->{'type'} // $Amazon::API::EMPTY) eq 'timestamp') { } 0 0 0
Condition0%0/6
$member_shape and ($member_shape->{"type"} // $Amazon::API::EMPTY) eq "timestamp"
!ll&&!rl&&r
000
$member_shape->{"type"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/3
$member_shape and ($member_shape->{"type"} // $Amazon::API::EMPTY) eq "timestamp"
$member_shape $member_shape->{"type"} $Amazon::API::EMPTY
Truth table0%0/4
A and B // C
A= $member_shapeB= $member_shape->{"type"}C= $Amazon::API::EMPTY
ABCresult
0XX0
1000
11X1
1011
543 0 $data = [ split /(?<=GMT),\s*(?=[A-Z][a-z]{2},)/xsm, $value ];
544 }
545 else {
546 0 $data = [ parse_line( qr/\s*,\s*/, $FALSE, $value, ) ];
547 }
548 }
549  
550 my $serialized_data = $serializer->serialize(
551 service => get_service_from_class( ref $self ),
552 shape => $spec->{shape},
553 0 data => $data,
554 exists => $TRUE,
555 );
556  
557 0 ▶ if ( $is_json_protocol && $spec->{jsonvalue} && defined $serialized_data ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_json_protocol and $spec->{"jsonvalue"} and defined $serialized_data) 0 0 0
Condition0%0/6
$is_json_protocol and $spec->{"jsonvalue"} and defined $serialized_data
!ll&&!rl&&r
000
$is_json_protocol and $spec->{"jsonvalue"}
!ll&&!rl&&r
000
MC/DC0%0/3
$is_json_protocol and $spec->{"jsonvalue"} and defined $serialized_data
$is_json_protocol $spec->{"jsonvalue"} defined $serialized_data
Truth table0%0/4
A and B and C
A= $is_json_protocolB= $spec->{"jsonvalue"}C= defined $serialized_data
ABCresult
0XX0
10X0
1100
1111
558 0 require MIME::Base64;
559  
560 0 $serialized_data = MIME::Base64::decode_base64($serialized_data);
561 }
562  
563 0 $content->{$member} = $serialized_data;
564 }
565 ▶ elsif ( $protocol && $protocol eq 'rest-xml' ) {
Condition0%0/3
$protocol and $protocol eq "rest-xml"
!ll&&!rl&&r
000
MC/DC0%0/2
$protocol and $protocol eq "rest-xml"
$protocol $protocol eq "rest-xml"
Truth table0%0/3
A and B
A= $protocolB= $protocol eq "rest-xml"
ABresult
0X0
100
111
566 0 ▶ my $type = $shape->{type} // $EMPTY;
Condition0%0/3
$shape->{"type"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$shape->{"type"} // $Amazon::API::EMPTY
$shape->{"type"} $Amazon::API::EMPTY
Truth table0%0/3
A // B
A= $shape->{"type"}B= $Amazon::API::EMPTY
ABresult
1X1
011
000
567  
568 0 ▶ if ( $type eq 'list' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'list') { } 0 0 0
elsif ($type eq 'boolean') { } 0 0 0
elsif ($type eq 'timestamp') { } 0 0 0
569 0 my $member_shape = $self->get_botocore_shapes->{ $shape->{member}->{shape} };
570  
571 0 ▶ my $data = choose {
Subroutine __ANON__: not called CC=4 SCAR=30.0
572 return [ split /(?<=GMT),\s*(?=[A-Z][a-z]{2},)/xsm, $value ]
573 0 ▶ if $member_shape && ( $member_shape->{type} // $EMPTY ) eq 'timestamp';
Branch: 1 branch
BranchTrueFalseTotal
if $member_shape and ($member_shape->{"type"} // $Amazon::API::EMPTY) eq "timestamp" 0 0 0
Condition0%0/6
$member_shape and ($member_shape->{"type"} // $Amazon::API::EMPTY) eq "timestamp"
!ll&&!rl&&r
000
$member_shape->{"type"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/3
$member_shape and ($member_shape->{"type"} // $Amazon::API::EMPTY) eq "timestamp"
$member_shape $member_shape->{"type"} $Amazon::API::EMPTY
Truth table0%0/4
A and B // C
A= $member_shapeB= $member_shape->{"type"}C= $Amazon::API::EMPTY
ABCresult
0XX0
1000
11X1
1011
574  
575 0 return [ parse_line( qr/\s*,\s*/, $FALSE, $value, ) ];
576 0 };
577  
578 $content->{$member} = $serializer->serialize(
579 service => get_service_from_class( ref $self ),
580 shape => $spec->{shape},
581 0 data => $data,
582 exists => $TRUE,
583 );
584 }
585 elsif ( $type eq 'boolean' ) {
586 0 ▶ if ( $value eq 'true' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value eq 'true') { } 0 0 0
elsif ($value eq 'false') { } 0 0 0
587 0 $content->{$member} = JSON::true;
588 }
589 elsif ( $value eq 'false' ) {
590 0 $content->{$member} = JSON::false;
591 }
592 else {
593 0 $content->{$member} = $value;
594 }
595 }
596 elsif ( $type eq 'timestamp' ) {
597 0 $content->{$member} = parse_timestamp($value);
598 }
599 else {
600 0 $content->{$member} = $value;
601 }
602 }
603 else {
604 0 $content->{$member} = $value;
605 }
606 }
607 }
608 elsif ( $location eq 'headers' ) {
609 0 ▶ my $prefix = $spec->{locationName} // $EMPTY;
Condition0%0/3
$spec->{"locationName"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$spec->{"locationName"} // $Amazon::API::EMPTY
$spec->{"locationName"} $Amazon::API::EMPTY
Truth table0%0/3
A // B
A= $spec->{"locationName"}B= $Amazon::API::EMPTY
ABresult
1X1
011
000
610  
611 0 my $headers = $response->headers;
612  
613 0 my %values;
614 0 my $header_prefix = lc $prefix;
615  
616 0 foreach my $name ( $headers->header_field_names ) {
617 0 my $header_name = lc $name;
618  
619 next
620 0 ▶ if length $header_prefix
Branch: 1 branch
BranchTrueFalseTotal
if length $header_prefix and index($header_name, $header_prefix) != 0 0 0 0
Condition0%0/3
length $header_prefix and index($header_name, $header_prefix) != 0
!ll&&!rl&&r
000
MC/DC0%0/2
length $header_prefix and index($header_name, $header_prefix) != 0
length $header_prefix index($header_name, $header_prefix) != 0
Truth table0%0/3
A and B
A= length $header_prefixB= index($header_name, $header_prefix) != 0
ABresult
0X0
100
111
621 && index( $header_name, $header_prefix ) != 0;
622  
623 0 ▶ my $key
Branch: 1 branch
BranchTrueFalseTotal
length $header_prefix ? : 0 0 0
624 = length $header_prefix
625 ? substr( $header_name, length $header_prefix )
626 : $header_name;
627  
628 next
629 0 ▶ if $key eq $EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if $key eq $Amazon::API::EMPTY 0 0 0
630  
631 0 $values{$key} = $response->header($name);
632 }
633  
634 0 ▶ if ( keys %values ) {
Branch: 2 branches
BranchTrueFalseTotal
if (keys %values) { } 0 0 0
elsif ($protocol and $protocol eq 'rest-xml') { } 0 0 0
635 0 ▶ if ($is_json_protocol) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_json_protocol) { } 0 0 0
636 $content->{$member} = $serializer->serialize(
637 service => get_service_from_class( ref $self ),
638 shape => $spec->{shape},
639 0 data => \%values,
640 exists => $TRUE,
641 );
642 }
643 else {
644 0 $content->{$member} = \%values;
645 }
646 }
647 ▶ elsif ( $protocol && $protocol eq 'rest-xml' ) {
Condition0%0/3
$protocol and $protocol eq "rest-xml"
!ll&&!rl&&r
000
MC/DC0%0/2
$protocol and $protocol eq "rest-xml"
$protocol $protocol eq "rest-xml"
Truth table0%0/3
A and B
A= $protocolB= $protocol eq "rest-xml"
ABresult
0X0
100
111
648 0 $content->{$member} = {};
649 }
650 }
651 elsif ( $location eq 'statusCode' ) {
652 1 $content->{$member} = $response->code;
653 }
654 }
655 }
656  
657 1 return $content;
658 }
659  
660 ########################################################################
661 1 ▶sub get_botocore_action {
Subroutine get_botocore_action: called CC=1 SCAR=0.0
Pod undocumented
662 ########################################################################
663 1 my ($self) = @_;
664  
665 1 return $self->get_botocore_operations->{ $self->get_action };
666 }
667  
668 ########################################################################
669 6 ▶sub is_botocore_shape {
Subroutine is_botocore_shape: called CC=2 SCAR=6.9
Pod undocumented
670 ########################################################################
671 6 my ($request) = @_;
672  
673 6 my $shape_name = ref $request;
674  
675 6 ▶ if ( $shape_name =~ /Botocore::Shape::([^:]+)::([^:]+)$/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shape_name =~ /Botocore::Shape::([^:]+)::([^:]+)$/msx) { } 3 3 6
676 3 $shape_name = $2;
677 }
678 else {
679 3 $shape_name = undef;
680 }
681  
682 6 return $shape_name;
683 }
684  
685 # returns the wire name for a member at the requested location;
686 # locationName overrides the modeled member name
687  
688 ########################################################################
689 18 ▶sub is_param_type {
Subroutine is_param_type: called CC=4 SCAR=14.1
Pod undocumented
690 ########################################################################
691 18 my ( $self, $shape_name, $param, $type ) = @_;
692  
693 18 my $members = $self->get_botocore_shapes->{$shape_name}->{members};
694 18 my $member = $members->{$param};
695  
696 18 my $location = $member->{location};
697  
698 $self->get_logger->trace(
699 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
700 0 return Dumper(
701 [ members => $members,
702 member => $member,
703 location => $location,
704 param => $param,
705 type => $type,
706 shape_name => $shape_name
707 ]
708 );
709 }
710 18 );
711  
712 18 ▶ return $EMPTY
Branch: 1 branch
BranchTrueFalseTotal
if not $location or $location ne $type 14 4 18
Condition100%3/3
not $location or $location ne $type
l!l&&r!l&&!r
1224
MC/DC100%2/2
not $location or $location ne $type
not $location $location ne $type
Truth table100%3/3
not(A) or B
A= not $locationB= $location ne $type
ABresult
1X1
011
000
713 if !$location || $location ne $type;
714  
715 4 ▶ return $member->{locationName} // $param;
Condition33%1/3
$member->{"locationName"} // $param
l!l&&r!l&&!r
400
MC/DC0%0/2
$member->{"locationName"} // $param
$member->{"locationName"} $param
Truth table33%1/3
A // B
A= $member->{"locationName"}B= $param
ABresult
1X1
011
000
716 }
717  
718 ########################################################################
719 4 ▶sub is_query_param {
Subroutine is_query_param: called CC=1 SCAR=0.0
Pod undocumented
720 ########################################################################
721 4 my ( $self, $shape_name, $param ) = @_;
722  
723 4 return $self->is_param_type( $shape_name, $param, 'querystring' );
724 }
725  
726 ########################################################################
727 7 ▶sub is_uri_param {
Subroutine is_uri_param: called CC=1 SCAR=0.0
Pod undocumented
728 ########################################################################
729 7 my ( $self, $shape_name, $param ) = @_;
730  
731 7 return $self->is_param_type( $shape_name, $param, 'uri' );
732 }
733  
734 ########################################################################
735 3 ▶sub create_botocore_request {
Subroutine create_botocore_request: called CC=6 SCAR=18.6
Pod undocumented
736 ########################################################################
737 3 my ( $self, %args ) = @_;
738  
739 3 my ( $parameters, $action ) = @args{qw(parameters action)};
740  
741 3 ▶ $action //= $self->get_action;
Condition33%1/3
$action //= $self->get_action
l!l&&r!l&&!r
030
MC/DC0%0/2
$action //= $self->get_action
$action $self->get_action
Truth table33%1/3
A //= B
A= $actionB= $self->get_action
ABresult
1X1
011
000
742  
743 3 ▶ croak 'no action'
Branch: 1 branch
BranchTrueFalseTotal
unless $action 0 3 3
744 if !$action;
745  
746 3 ▶ croak 'no parameters'
Branch: 1 branch
BranchTrueFalseTotal
unless $parameters 0 3 3
747 if !$parameters;
748  
749 3 ▶ croak 'not a botocore API'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_botocore_api($action) 0 3 3
750 if !$self->is_botocore_api($action);
751  
752 3 my $botocore_operations = $self->get_botocore_operations->{$action};
753  
754 3 my $input = $botocore_operations->{input};
755 3 my $shape = $input->{shape};
756  
757 3 my $class = require_shape( $shape, get_service_from_class($self) );
758  
759 3 ▶ croak "could not create request shape: $shape\n$EVAL_ERROR"
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 3 3
760 if !$class;
761  
762 3 ▶ local $Amazon::API::Botocore::Shape::LOGGER_SOURCE = sub { $self->get_logger };
Subroutine __ANON__: called CC=1 SCAR=0.0
763  
764 3 my $request = $class->new($parameters);
765  
766 3 return $request;
767 }
768  
769 ########################################################################
770 3 ▶sub find_content_type {
Subroutine find_content_type: called CC=5 SCAR=17.1
Pod undocumented
771 ########################################################################
772 3 my ($self) = @_;
773  
774 3 my $metadata = $self->get_botocore_metadata;
775 3 ▶ my $protocols = $metadata->{protocols} // [ $metadata->{protocol} ];
Condition50%1/2
$metadata->{"protocols"} // [$metadata->{"protocol"}]
l!l
03
MC/DC0%0/1
$metadata->{"protocols"} // [$metadata->{"protocol"}]
$metadata->{"protocols"}
Truth table50%1/2
A
A= $metadata->{"protocols"}
Aresult
11
00
776  
777 3 foreach my $protocol ( @{$protocols} ) {
778 3 ▶ next if !exists $SERVICE_CONTENT_TYPES{$protocol};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Amazon::API::SERVICE_CONTENT_TYPES{$protocol} 0 3 3
779  
780 3 my $content_type = $SERVICE_CONTENT_TYPES{$protocol};
781  
782 3 ▶ if ( $protocol eq 'json' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol eq "json") 0 3 3
783 0 $content_type = sprintf '%s-%s', $content_type, $metadata->{jsonVersion};
784 }
785  
786 3 $self->set_api_protocol($protocol);
787  
788 3 return $content_type;
789 }
790  
791 0 croak "ERROR: no support content type found\n";
792 }
793  
794 ########################################################################
795 # init_botocore_request( $self, $request)
796 ########################################################################
797  
798 # This function will accept either an object which is a sub-class of
799 # Amazon::API::Botocore::Shape, or a hash if the parameters have been
800 # constructed "by-hand",
801 #
802 # The parameters are used to populate both the URL if some parameters
803 # are passed in the URL and either a JSON or XML payload depending on
804 # the API type (rest-json, rest-xml).
805  
806 ########################################################################
807 3 ▶sub init_botocore_request {
Subroutine init_botocore_request: called CC=50 SCAR=56.8
Pod undocumented
808 ########################################################################
809 3 my ( $self, $request ) = @_;
810  
811 3 my $metadata = $self->get_botocore_metadata;
812  
813 3 my $protocol = $metadata->{protocol};
814  
815 3 ▶ my $content_type = $self->find_content_type // $EMPTY;
Condition33%1/3
$self->find_content_type // $Amazon::API::EMPTY
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->find_content_type // $Amazon::API::EMPTY
$self->find_content_type $Amazon::API::EMPTY
Truth table33%1/3
A // B
A= $self->find_content_typeB= $Amazon::API::EMPTY
ABresult
1X1
011
000
816 3 $self->set_content_type($content_type);
817  
818 3 ▶ $request //= {};
Condition50%1/2
$request //= {}
l!l
30
MC/DC0%0/1
$request //= {}
$request
Truth table50%1/2
A
A= $request
Aresult
11
00
819  
820 3 my $action = $self->get_action;
821  
822 3 my $botocore_operations = $self->get_botocore_operations->{$action};
823  
824 3 my $http = $botocore_operations->{http};
825  
826 3 my $method = $http->{method};
827  
828 $self->get_logger->trace(
829 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
830 0 return Dumper(
831 [ request => $request,
832 protocol => $protocol,
833 action => $action,
834 method => $method,
835 content_type => $content_type,
836 botocore_metadata => $metadata,
837 botocore_operations => $botocore_operations,
838 ]
839 );
840 }
841 3 );
842  
843 3 my $input = $botocore_operations->{input};
844  
845 3 ▶ if ( !$input ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($input) 0 3 3
846 0 $self->set_http_method($method);
847  
848 0 $self->_resolve_request_endpoint();
849  
850 0 ▶ return []
Branch: 1 branch
BranchTrueFalseTotal
if $protocol eq "query" or $protocol eq "ec2" 0 0 0
Condition0%0/3
$protocol eq "query" or $protocol eq "ec2"
l!l&&r!l&&!r
000
MC/DC0%0/2
$protocol eq "query" or $protocol eq "ec2"
$protocol eq "query" $protocol eq "ec2"
Truth table0%0/3
A or B
A= $protocol eq "query"B= $protocol eq "ec2"
ABresult
1X1
011
000
851 if $protocol eq 'query'
852 || $protocol eq 'ec2';
853  
854 return undef ## no critic
855 0 ▶ if $protocol eq 'rest-json';
Branch: 1 branch
BranchTrueFalseTotal
if $protocol eq "rest-json" 0 0 0
856  
857 0 return {};
858 }
859  
860 3 my $shape = $input->{shape};
861  
862 3 my $request_shape_name = is_botocore_shape($request);
863  
864 # if a shape object is passed, it must be the correct type
865 3 ▶ croak "$action requires a $shape object, not a $request_shape_name object"
Branch: 1 branch
BranchTrueFalseTotal
if $request_shape_name and $request_shape_name ne $shape 0 3 3
Condition33%1/3
$request_shape_name and $request_shape_name ne $shape
!ll&&!rl&&r
300
MC/DC0%0/2
$request_shape_name and $request_shape_name ne $shape
$request_shape_name $request_shape_name ne $shape
Truth table33%1/3
A and B
A= $request_shape_nameB= $request_shape_name ne $shape
ABresult
0X0
100
111
866 if $request_shape_name && $request_shape_name ne $shape;
867  
868 # try to create a Botocore request shape
869 3 my $boto_request;
870  
871 3 ▶ if ( !$request_shape_name && $self->is_botocore_api ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $request_shape_name and $self->is_botocore_api) 3 0 3
Condition33%1/3
not $request_shape_name and $self->is_botocore_api
!ll&&!rl&&r
003
MC/DC0%0/2
not $request_shape_name and $self->is_botocore_api
not $request_shape_name $self->is_botocore_api
Truth table33%1/3
not(A) and B
A= not $request_shape_nameB= $self->is_botocore_api
ABresult
0X0
100
111
872  
873 3 $boto_request = $self->create_botocore_request( parameters => $request );
874  
875 3 $self->_resolve_request_endpoint($boto_request);
876  
877 3 ▶ if ( !$boto_request ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $boto_request) { } 0 3 3
878 0 croak "could not create a botocore request object\n$EVAL_ERROR\n";
879 }
880 else {
881 3 $request_shape_name = is_botocore_shape($boto_request);
882  
883 3 $request = $boto_request;
884 }
885 }
886  
887 # some XML requests require an xmlns attribute
888 3 $self->find_namespace( $request, $input );
889  
890 3 my %parameters;
891  
892 # is the request a Botocore::Shape object? if so we can use metadata
893 # to create URI and payload, otherwise it's up to the caller to make
894 # sure the URI and the payload are correct...good luck!
895  
896 3 ▶ if ( !$request_shape_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $request_shape_name) { } 0 3 3
897 0 %parameters = %{$request};
898 }
899 else {
900 3 my $finalized_request = $request->finalize($protocol);
901  
902 $self->get_logger->trace(
903 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
904 0 return Dumper(
905 [ request => $request,
906 finalized_request => $finalized_request,
907 ]
908 );
909 }
910 3 );
911  
912 3 ▶ if ( $protocol =~ /rest\-(xml|json)/xsm ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($protocol =~ /rest\-(xml|json)/msx) { } 3 0 3
elsif ($protocol eq 'ec2') { } 0 0 0
elsif ($protocol eq 'query') { } 0 0 0
913 3 $finalized_request = { $request_shape_name => $finalized_request };
914 }
915 elsif ( $protocol eq 'ec2' ) {
916 0 ▶ $finalized_request = ref $finalized_request ? [ param_n($finalized_request) ] : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $finalized_request ? : 0 0 0
917 0 $self->set_http_method($method);
918 0 return $finalized_request;
919 }
920 elsif ( $protocol eq 'query' ) {
921 0 ▶ $finalized_request = ref $finalized_request ? [ query_param_n($finalized_request) ] : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $finalized_request ? : 0 0 0
922 0 $self->set_http_method($method);
923 0 return $finalized_request;
924 }
925  
926 $self->get_logger->trace(
927 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
928 0 return Dumper( [ finalized_request => $finalized_request, ] );
929 }
930 3 );
931  
932 3 ▶ if ( ref($finalized_request) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $finalized_request eq "HASH") 3 0 3
933 3 %parameters = %{$finalized_request};
934 }
935 }
936  
937 3 $self->set_http_method($method);
938  
939 3 my $uri;
940  
941 3 ▶ if ( $protocol =~ /^rest\-(json|xml)/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol =~ /^rest\-(json|xml)/msx) 3 0 3
942 3 ▶ my @args = @{ $http->{parsed_request_uri}->{parameters} // [] };
Condition50%1/2
$http->{"parsed_request_uri"}{"parameters"} // []
l!l
03
MC/DC0%0/1
$http->{"parsed_request_uri"}{"parameters"} // []
$http->{"parsed_request_uri"}{"parameters"}
Truth table50%1/2
A
A= $http->{"parsed_request_uri"}{"parameters"}
Aresult
11
00
943  
944 3 my $request_uri_tpl = $http->{parsed_request_uri}->{request_uri_tpl};
945  
946 $self->get_logger->trace(
947 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
948 0 return Dumper(
949 [ args => \@args,
950 request_uri_tpl => $request_uri_tpl,
951 request_shape_name => $request_shape_name,
952 input => $input,
953 ]
954 );
955 }
956 3 );
957  
958 # if the request is a shape, we've already checked for required
959 # parameters but some may be buried in the payload!
960 3 ▶ if ( !$request_shape_name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $request_shape_name) { } 0 3 3
961 0 foreach my $p (@args) {
962 croak 'required parameter ' . $p . ' not found.'
963 0 ▶ if !exists $parameters{$p};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $parameters{$p} 0 0 0
964 }
965  
966 0 $uri = sprintf $request_uri_tpl, @parameters{@args};
967 0 $self->set_request_uri($uri);
968  
969 0 delete @parameters{@args};
970 }
971 else {
972 3 my %cloned_http = %{$http};
973  
974 3 $self->_service_hook_before_parameter_build( $request, \%cloned_http );
975  
976 3 $uri = $cloned_http{requestUri}; # use the Botocore template
977  
978 3 my $shape_parameters = $parameters{$shape};
979  
980 $self->get_logger->trace(
981 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
982 0 return Dumper(
983 [ requestUri => $uri,
984 shape_parameters => $shape_parameters,
985 shape => $shape,
986 parameters => \%parameters,
987 ]
988 );
989 }
990 3 );
991  
992 3 foreach my $p ( keys %{$shape_parameters} ) {
993 7 ▶ if ( my $var = $self->is_uri_param( $request_shape_name, $p ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $var = $self->is_uri_param($request_shape_name, $p)) 3 4 7
994  
995 3 my $val = $shape_parameters->{$p};
996  
997 3 ▶ croak "$action: required uri parameter '$p' is undef\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 3 3
998 if !defined $val;
999  
1000 3 ▶ if ( $uri =~ /[{]\Q$var\E[+][}]/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri =~ /[{]\Q$var\E[+][}]/msx) { } 0 3 3
1001 0 $val = uri_escape_utf8( $val, q{^A-Za-z0-9\-._~/}, );
1002  
1003 0 $uri =~ s/[{]\Q$var\E[+][}]/$val/xsm;
1004 }
1005 else {
1006 3 $val = uri_escape_utf8($val);
1007  
1008 3 $uri =~ s/[{]\Q$var\E[}]/$val/xsm;
1009 }
1010  
1011 3 delete $shape_parameters->{$p};
1012 }
1013 }
1014  
1015 # we're not done yet...just to make things interesting, some
1016 # APIs embed request parameters in the uri, payload AND query
1017 # string!
1018  
1019 3 ▶ if ($request_shape_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_shape_name) 3 0 3
1020 3 my %query_parameters;
1021  
1022 3 my $shape_parameters = $parameters{$shape};
1023  
1024 3 foreach my $p ( keys %{$shape_parameters} ) {
1025 4 ▶ if ( my $var = $self->is_query_param( $request_shape_name, $p ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $var = $self->is_query_param($request_shape_name, $p)) 0 4 4
1026 0 $query_parameters{$var} = $shape_parameters->{$p};
1027 0 delete $shape_parameters->{$p};
1028 }
1029 }
1030  
1031 3 ▶ if ( keys %query_parameters ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %query_parameters) 0 3 3
1032 # $self->set_content_type(undef);
1033  
1034 0 $uri = sprintf '%s?%s', $uri, create_urlencoded_content( \%query_parameters );
1035 }
1036  
1037 # header-located members (e.g. UpdateDistribution's IfMatch ->
1038 # If-Match) are carried in the HTTP request headers, NOT the body.
1039 # Extract them here - like uri and querystring members above - so the
1040 # body serializer sees only the payload/body members. Leaving a header
1041 # member in place puts it in the body: for rest-xml that is a second
1042 # root element alongside the payload (two roots -> generate_xml croaks
1043 # / AWS MalformedInput), and its value never reaches the wire header.
1044 3 my %header_parameters;
1045  
1046 3 foreach my $p ( keys %{$shape_parameters} ) {
1047 4 my $header_name = $self->is_param_type( $request_shape_name, $p, 'header', );
1048  
1049 4 ▶ if ($header_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header_name) 1 3 4
1050 1 my $val = $shape_parameters->{$p};
1051  
1052 1 ▶ if ( defined $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 1 0 1
1053 1 $header_parameters{$header_name} = $val;
1054 }
1055  
1056 1 delete $shape_parameters->{$p};
1057  
1058 1 next;
1059 }
1060  
1061 3 my $header_prefix = $self->is_param_type( $request_shape_name, $p, 'headers', );
1062  
1063 3 ▶ if ($header_prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header_prefix) 0 3 3
1064 0 my $val = $shape_parameters->{$p};
1065  
1066 0 ▶ if ( ref $val
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val and builtin::reftype($val) eq "HASH" and exists $val->{"entry"}) 0 0 0
Condition0%0/6
ref $val and builtin::reftype($val) eq "HASH" and exists $val->{"entry"}
!ll&&!rl&&r
000
ref $val and builtin::reftype($val) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $val and builtin::reftype($val) eq "HASH" and exists $val->{"entry"}
ref $val builtin::reftype($val) eq "HASH" exists $val->{"entry"}
Truth table0%0/4
A and B and C
A= ref $valB= builtin::reftype($val) eq "HASH"C= exists $val->{"entry"}
ABCresult
0XX0
10X0
1100
1111
1067 && reftype($val) eq 'HASH'
1068 && exists $val->{entry} ) {
1069 0 ▶ foreach my $entry ( @{ $val->{entry} // [] } ) {
Condition0%0/2
$val->{"entry"} // []
l!l
00
MC/DC0%0/1
$val->{"entry"} // []
$val->{"entry"}
Truth table0%0/2
A
A= $val->{"entry"}
Aresult
11
00
1070 next
1071 0 ▶ if ref $entry ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $entry ne "HASH" 0 0 0
1072  
1073 0 my $key = $entry->{key};
1074 0 my $value = $entry->{value};
1075  
1076 next
1077 0 ▶ if !defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 0 0
1078  
1079 0 my $name
1080 = sprintf '%s%s',
1081 $header_prefix,
1082 $key;
1083  
1084 0 ▶ $header_parameters{$name} = defined $value ? $value : $EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
1085 }
1086 }
1087  
1088 0 delete $shape_parameters->{$p};
1089 }
1090 }
1091  
1092 3 $self->set_botocore_request_headers( \%header_parameters );
1093  
1094 3 ▶ if ( !keys %{$shape_parameters} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %{$shape_parameters;}) 0 3 3
1095 0 %parameters = ();
1096 }
1097 }
1098 }
1099  
1100 3 $self->set_request_uri($uri);
1101  
1102 # payload (I think) tells us where the actual object to pass will
1103 # be found in the request object. Since we may be formatting an
1104 # XML request we need to insert the namespace so our formatter can
1105 # properly serialize the request
1106 #
1107 # NOTE: %parameters keeps its $request_shape_name-keyed shape here -
1108 # it is NOT reassigned to the unwrapped payload contents. The generic
1109 # content-resolution below still looks up $parameters{$request_shape_name},
1110 # so reassigning %parameters here (as this block previously did) made
1111 # that later lookup find nothing, silently producing an empty request
1112 # body for every REST-XML/JSON operation with a declared payload member.
1113 # We only need to mutate the payload member in place to attach the
1114 # namespace attribute, if any.
1115 3 ▶ my $request_shape_def = $self->get_botocore_shapes->{$request_shape_name} // {};
Condition50%1/2
$self->get_botocore_shapes->{$request_shape_name} // {}
l!l
30
MC/DC0%0/1
$self->get_botocore_shapes->{$request_shape_name} // {}
$self->get_botocore_shapes->{$request_shape_name}
Truth table50%1/2
A
A= $self->get_botocore_shapes->{$request_shape_name}
Aresult
11
00
1116 3 my $payload_member = $request_shape_def->{payload};
1117  
1118 3 ▶ if ( $payload_member && $parameters{$request_shape_name}->{$payload_member} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($payload_member and $parameters{$request_shape_name}{$payload_member}) { } 2 1 3
elsif ($self->get_namespace) { } 1 0 1
Condition66%2/3
$payload_member and $parameters{$request_shape_name}{$payload_member}
!ll&&!rl&&r
102
MC/DC50%1/2
$payload_member and $parameters{$request_shape_name}{$payload_member}
$payload_member $parameters{$request_shape_name}{$payload_member}
Truth table66%2/3
A and B
A= $payload_memberB= $parameters{$request_shape_name}{$payload_member}
ABresult
0X0
100
111
1119 2 ▶ if ( $self->get_namespace ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_namespace) 2 0 2
1120 2 $parameters{$request_shape_name}->{$payload_member}->{_attr} = { xmlns => $self->get_namespace };
1121 }
1122 }
1123 elsif ( $self->get_namespace ) {
1124 1 $parameters{$request_shape_name}->{_attr} = { xmlns => $self->get_namespace };
1125 }
1126 }
1127  
1128 3 my $content = $self->_resolve_request_content( $request_shape_name, $protocol, $method, \%parameters );
1129  
1130 $self->get_logger->trace(
1131 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1132 0 return Dumper [
1133 namespace => $self->get_namespace,
1134 parameters => \%parameters,
1135 request_uri => $uri,
1136 content => $content,
1137 ];
1138 }
1139 3 );
1140  
1141 3 return $content;
1142 }
1143  
1144 ########################################################################
1145 0 ▶sub _service_hook_before_parameter_build { return; }
Subroutine _service_hook_before_parameter_build: not called CC=1 SCAR=6.9
1146 ########################################################################
1147  
1148 ########################################################################
1149 12 ▶sub _resolve_request_content {
Subroutine _resolve_request_content: called CC=41 SCAR=56.1
1150 ########################################################################
1151 12 my ( $self, $request_shape_name, $protocol, $method, $parameters ) = @_;
1152  
1153 12 my $content;
1154  
1155 12 ▶ if ( $protocol eq 'rest-json'
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol eq "rest-json" and not $request_shape_name) 0 12 12
Condition66%2/3
$protocol eq "rest-json" and not $request_shape_name
!ll&&!rl&&r
1110
MC/DC0%0/2
$protocol eq "rest-json" and not $request_shape_name
$protocol eq "rest-json" not $request_shape_name
Truth table66%2/3
A and not(B)
A= $protocol eq "rest-json"B= not $request_shape_name
ABresult
0X0
100
111
1156 && !$request_shape_name ) {
1157 0 return undef; ## no critic
1158 }
1159  
1160 12 ▶ if ( $request_shape_name
Branch: 1 branch
BranchTrueFalseTotal
if ($request_shape_name and $protocol =~ /rest\-(?:json|xml)/msx) { } 7 5 12
Condition66%2/3
$request_shape_name and $protocol =~ /rest\-(?:json|xml)/msx
!ll&&!rl&&r
057
MC/DC50%1/2
$request_shape_name and $protocol =~ /rest\-(?:json|xml)/msx
$request_shape_name $protocol =~ /rest\-(?:json|xml)/msx
Truth table66%2/3
A and B
A= $request_shape_nameB= $protocol =~ /rest\-(?:json|xml)/msx
ABresult
0X0
100
111
1161 && $protocol =~ /rest\-(?:json|xml)/xsm ) {
1162 7 my $inner = $parameters->{$request_shape_name};
1163  
1164 7 ▶ my $shape_def = $self->get_botocore_shapes->{$request_shape_name} // {};
Condition50%1/2
$self->get_botocore_shapes->{$request_shape_name} // {}
l!l
70
MC/DC0%0/1
$self->get_botocore_shapes->{$request_shape_name} // {}
$self->get_botocore_shapes->{$request_shape_name}
Truth table50%1/2
A
A= $self->get_botocore_shapes->{$request_shape_name}
Aresult
11
00
1165  
1166 7 my $payload_member = $shape_def->{payload};
1167  
1168 7 ▶ if ( !$inner
Branch: 3 branches
BranchTrueFalseTotal
if (not $inner && keys %{$inner;}) { } 1 6 7
elsif ($payload_member) { } 3 3 6
elsif ($protocol eq 'rest-xml') { } 2 1 3
Condition66%2/3
$inner && keys %{$inner;}
!ll&&!rl&&r
016
MC/DC50%1/2
$inner && keys %{$inner;}
$inner keys %{$inner;}
Truth table66%2/3
A && B
A= $innerB= keys %{$inner;}
ABresult
0X0
100
111
1169 7 || !keys %{$inner} ) {
1170 1 ▶ if ( $protocol eq 'rest-json' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol eq 'rest-json') { } 0 1 1
1171 0 ▶ if ($payload_member) {
Branch: 1 branch
BranchTrueFalseTotal
if ($payload_member) { } 0 0 0
1172 0 ▶ my $member = $shape_def->{members}->{$payload_member} // {};
Condition0%0/2
$shape_def->{"members"}{$payload_member} // {}
l!l
00
MC/DC0%0/1
$shape_def->{"members"}{$payload_member} // {}
$shape_def->{"members"}{$payload_member}
Truth table0%0/2
A
A= $shape_def->{"members"}{$payload_member}
Aresult
11
00
1173  
1174 0 my $payload_shape_name = $member->{shape};
1175  
1176 my $payload_shape
1177 = defined $payload_shape_name
1178 0 ▶ ? $self->get_botocore_shapes->{$payload_shape_name} // {}
Branch: 1 branch
BranchTrueFalseTotal
defined $payload_shape_name ? : 0 0 0
Condition0%0/2
$self->get_botocore_shapes->{$payload_shape_name} // {}
l!l
00
MC/DC0%0/1
$self->get_botocore_shapes->{$payload_shape_name} // {}
$self->get_botocore_shapes->{$payload_shape_name}
Truth table0%0/2
A
A= $self->get_botocore_shapes->{$payload_shape_name}
Aresult
11
00
1179 : {};
1180  
1181 0 ▶ my $payload_type = $payload_shape->{type} // $EMPTY;
Condition0%0/3
$payload_shape->{"type"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$payload_shape->{"type"} // $Amazon::API::EMPTY
$payload_shape->{"type"} $Amazon::API::EMPTY
Truth table0%0/3
A // B
A= $payload_shape->{"type"}B= $Amazon::API::EMPTY
ABresult
1X1
011
000
1182  
1183 $content
1184 = ( $payload_type eq 'structure' && !$payload_shape->{union} )
1185 0 ▶ ? {}
Branch: 1 branch
BranchTrueFalseTotal
$payload_type eq 'structure' && !$payload_shape->{'union'} ? : 0 0 0
Condition0%0/3
$payload_type eq "structure" and not $payload_shape->{"union"}
!ll&&!rl&&r
000
MC/DC0%0/2
$payload_type eq "structure" and not $payload_shape->{"union"}
$payload_type eq "structure" not $payload_shape->{"union"}
Truth table0%0/3
A and not(B)
A= $payload_type eq "structure"B= not $payload_shape->{"union"}
ABresult
0X0
100
111
1186 : undef;
1187 }
1188 else {
1189 0 ▶ my $members = $shape_def->{members} // {};
Condition0%0/2
$shape_def->{"members"} // {}
l!l
00
MC/DC0%0/1
$shape_def->{"members"} // {}
$shape_def->{"members"}
Truth table0%0/2
A
A= $shape_def->{"members"}
Aresult
11
00
1190  
1191 0 ▶ my $has_modeled_body = any {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1192 0 my $member = $members->{$_};
1193  
1194 0 ▶ my $location = $member->{location} // $EMPTY;
Condition0%0/3
$member->{"location"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$member->{"location"} // $Amazon::API::EMPTY
$member->{"location"} $Amazon::API::EMPTY
Truth table0%0/3
A // B
A= $member->{"location"}B= $Amazon::API::EMPTY
ABresult
1X1
011
000
1195  
1196 !$location
1197 0 ▶ && !$member->{hostLabel};
Condition0%0/3
$location || $member->{'hostLabel'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$location || $member->{'hostLabel'}
$location $member->{'hostLabel'}
Truth table0%0/3
A || B
A= $locationB= $member->{'hostLabel'}
ABresult
1X1
011
000
1198 }
1199 0 keys %{$members};
1200  
1201 0 ▶ $content
Branch: 1 branch
BranchTrueFalseTotal
$has_modeled_body ? : 0 0 0
1202 = $has_modeled_body
1203 ? {}
1204 : undef;
1205 }
1206 }
1207 else {
1208 1 $content = undef;
1209 }
1210 }
1211 elsif ($payload_member) {
1212 3 ▶ my $member = $shape_def->{members}->{$payload_member} // {};
Condition100%2/2
$shape_def->{"members"}{$payload_member} // {}
l!l
21
MC/DC100%1/1
$shape_def->{"members"}{$payload_member} // {}
$shape_def->{"members"}{$payload_member}
Truth table100%2/2
A
A= $shape_def->{"members"}{$payload_member}
Aresult
11
00
1213  
1214 3 ▶ my $member_name = $member->{locationName} // $payload_member;
Condition66%2/3
$member->{"locationName"} // $payload_member
l!l&&r!l&&!r
210
MC/DC0%0/2
$member->{"locationName"} // $payload_member
$member->{"locationName"} $payload_member
Truth table66%2/3
A // B
A= $member->{"locationName"}B= $payload_member
ABresult
1X1
011
000
1215  
1216 3 my $payload = $inner->{$member_name};
1217  
1218 3 ▶ if ( $protocol eq 'rest-xml' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol eq 'rest-xml') { } 3 0 3
1219 3 my $payload_shape_name = $member->{shape};
1220  
1221 my $payload_shape
1222 = defined $payload_shape_name
1223 3 ▶ ? $self->get_botocore_shapes->{$payload_shape_name} // {}
Branch: 1 branch
BranchTrueFalseTotal
defined $payload_shape_name ? : 2 1 3
Condition50%1/2
$self->get_botocore_shapes->{$payload_shape_name} // {}
l!l
20
MC/DC0%0/1
$self->get_botocore_shapes->{$payload_shape_name} // {}
$self->get_botocore_shapes->{$payload_shape_name}
Truth table50%1/2
A
A= $self->get_botocore_shapes->{$payload_shape_name}
Aresult
11
00
1224 : {};
1225  
1226 3 ▶ my $payload_type = $payload_shape->{type} // $EMPTY;
Condition66%2/3
$payload_shape->{"type"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
210
MC/DC0%0/2
$payload_shape->{"type"} // $Amazon::API::EMPTY
$payload_shape->{"type"} $Amazon::API::EMPTY
Truth table66%2/3
A // B
A= $payload_shape->{"type"}B= $Amazon::API::EMPTY
ABresult
1X1
011
000
1227  
1228 3 ▶ if ( !$payload_shape_name ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $payload_shape_name) { } 1 2 3
elsif ($payload_type eq 'structure' or $payload_type eq 'union') { } 2 0 2
1229 1 $content = { $member_name => $payload, };
1230 }
1231 ▶ elsif ( $payload_type eq 'structure'
Condition33%1/3
$payload_type eq "structure" or $payload_type eq "union"
l!l&&r!l&&!r
200
MC/DC0%0/2
$payload_type eq "structure" or $payload_type eq "union"
$payload_type eq "structure" $payload_type eq "union"
Truth table33%1/3
A or B
A= $payload_type eq "structure"B= $payload_type eq "union"
ABresult
1X1
011
000
1232 || $payload_type eq 'union' ) {
1233 my $root_name
1234 = ( $member->{locationName} && $member->{locationName} ne $payload_member )
1235 ? $member->{locationName}
1236 2 ▶ : $payload_shape->{locationName} // $payload_shape_name;
Branch: 1 branch
BranchTrueFalseTotal
$member->{'locationName'} && $member->{'locationName'} ne $payload_member ? : 0 2 2
Condition33%2/6
$member->{"locationName"} and $member->{"locationName"} ne $payload_member
!ll&&!rl&&r
020
$payload_shape->{"locationName"} // $payload_shape_name
l!l&&r!l&&!r
020
MC/DC0%0/2
$member->{"locationName"} and $member->{"locationName"} ne $payload_member
$member->{"locationName"} $member->{"locationName"} ne $payload_member
MC/DC0%0/2
$payload_shape->{"locationName"} // $payload_shape_name
$payload_shape->{"locationName"} $payload_shape_name
Truth table33%1/3
A and B
A= $member->{"locationName"}B= $member->{"locationName"} ne $payload_member
ABresult
0X0
100
111
Truth table33%1/3
A // B
A= $payload_shape->{"locationName"}B= $payload_shape_name
ABresult
1X1
011
000
1237  
1238 2 my $namespace = $payload_shape->{xmlNamespace};
1239  
1240 2 ▶ if ($namespace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($namespace) 0 2 2
1241 0 ▶ if ( ref $namespace
Branch: 1 branch
BranchTrueFalseTotal
if (ref $namespace and builtin::reftype($namespace) eq 'HASH') { } 0 0 0
Condition0%0/3
ref $namespace and builtin::reftype($namespace) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $namespace and builtin::reftype($namespace) eq "HASH"
ref $namespace builtin::reftype($namespace) eq "HASH"
Truth table0%0/3
A and B
A= ref $namespaceB= builtin::reftype($namespace) eq "HASH"
ABresult
0X0
100
111
1242 && reftype($namespace) eq 'HASH' ) {
1243 0 my $uri = $namespace->{uri};
1244  
1245 0 my $prefix = $namespace->{prefix};
1246  
1247 0 ▶ if ( defined $uri ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uri) 0 0 0
1248 0 ▶ my $attribute
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 0 0
1249 = $prefix
1250 ? sprintf 'xmlns:%s', $prefix
1251 : 'xmlns';
1252  
1253 0 $payload->{_attr}->{$attribute} = $uri;
1254 }
1255 }
1256 else {
1257 0 $payload->{_attr}->{xmlns} = $namespace;
1258 }
1259 }
1260  
1261 2 $content = { $root_name => $payload, };
1262 }
1263 else {
1264 0 $content = $payload;
1265 }
1266 }
1267 else {
1268 0 $content = $payload;
1269 }
1270 }
1271 elsif ( $protocol eq 'rest-xml' ) {
1272 2 ▶ my $root_name = $shape_def->{locationName} // $request_shape_name;
Condition33%1/3
$shape_def->{"locationName"} // $request_shape_name
l!l&&r!l&&!r
020
MC/DC0%0/2
$shape_def->{"locationName"} // $request_shape_name
$shape_def->{"locationName"} $request_shape_name
Truth table33%1/3
A // B
A= $shape_def->{"locationName"}B= $request_shape_name
ABresult
1X1
011
000
1273  
1274 2 $content = { $root_name => $inner, };
1275 }
1276 else {
1277 1 $content = $inner;
1278 }
1279 }
1280 else {
1281 5 $content = $parameters;
1282 }
1283  
1284 12 ▶ if ( $protocol !~ /rest\-(?:json|xml)/xsm
Branch: 1 branch
BranchTrueFalseTotal
if (not $protocol =~ /rest\-(?:json|xml)/msx and $method ne "POST" and not keys %{$parameters;}) 1 11 12
Condition83%5/6
not $protocol =~ /rest\-(?:json|xml)/msx and $method ne "POST" and not keys %{$parameters;}
!ll&&!rl&&r
1101
not $protocol =~ /rest\-(?:json|xml)/msx and $method ne "POST"
!ll&&!rl&&r
741
MC/DC66%2/3
not $protocol =~ /rest\-(?:json|xml)/msx and $method ne "POST" and not keys %{$parameters;}
not $protocol =~ /rest\-(?:json|xml)/msx $method ne "POST" not keys %{$parameters;}
Truth table75%3/4
not(A) and B and not(C)
A= not $protocol =~ /rest\-(?:json|xml)/msxB= $method ne "POST"C= not keys %{$parameters;}
ABCresult
0XX0
10X0
1100
1111
1285 && $method ne 'POST'
1286 1 && !keys %{$parameters} ) {
1287 1 $content = undef;
1288 }
1289  
1290 12 return $content;
1291 }
1292  
1293 ########################################################################
1294 # namespaces may be buried a bit in the members specfication of
1295 # request objects or can be part of the specification for the request
1296 # method itself (cloudfront.CreateInvalidationBatch)
1297 ########################################################################
1298 # _resolve_request_content( $request_shape_name, $protocol, $method, \%parameters )
1299 #
1300 # Resolves the request body ("content") from the built parameter hash,
1301 # per protocol. Extracted from init_botocore_request so the
1302 # body-serialization decision can be unit-tested in isolation (see
1303 # t/06-content-resolution.t) without credentials, network, shape
1304 # building, or URI construction. Returns a hashref (the body), or undef
1305 # when there is no body to send.
1306 #
1307 # - rest-xml, no payload : shape-name IS the root element -> wrap inner
1308 # under the shape name (xmlns rides the root)
1309 # - rest-xml, payload : payload member IS the root -> inner as-is
1310 # - rest-json : body is the inner members -> inner as-is
1311 # - json / query / ec2 : body is the flat parameter hash -> \%parameters
1312 # - non-POST, no params : no body -> undef
1313  
1314 ########################################################################
1315 3 ▶sub find_namespace {
Subroutine find_namespace: called CC=10 SCAR=29.2
Pod undocumented
1316 ########################################################################
1317 3 my ( $self, $request, $input ) = @_;
1318  
1319 3 my $has_namespace;
1320  
1321 3 ▶ foreach my $member ( keys %{ $request->{members} // {} } ) {
Condition50%1/2
$request->{"members"} // {}
l!l
30
MC/DC0%0/1
$request->{"members"} // {}
$request->{"members"}
Truth table50%1/2
A
A= $request->{"members"}
Aresult
11
00
1322 my $namespace
1323 4 = $request->{members}->{$member}->{xmlNamespace};
1324  
1325 next
1326 4 ▶ if !ref $namespace;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $namespace 1 3 4
1327  
1328 next
1329 3 ▶ if reftype($namespace) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($namespace) ne "HASH" 0 3 3
1330  
1331 3 $has_namespace = $namespace->{uri};
1332  
1333 last
1334 3 ▶ if defined $has_namespace;
Branch: 1 branch
BranchTrueFalseTotal
if defined $has_namespace 3 0 3
1335 }
1336  
1337 3 ▶ if ( !$has_namespace && $input->{xmlNamespace} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $has_namespace and $input->{"xmlNamespace"}) 0 3 3
Condition33%1/3
not $has_namespace and $input->{"xmlNamespace"}
!ll&&!rl&&r
300
MC/DC0%0/2
not $has_namespace and $input->{"xmlNamespace"}
not $has_namespace $input->{"xmlNamespace"}
Truth table33%1/3
not(A) and B
A= not $has_namespaceB= $input->{"xmlNamespace"}
ABresult
0X0
100
111
1338 0 my $namespace = $input->{xmlNamespace};
1339  
1340 0 ▶ if ( ref $namespace && reftype($namespace) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $namespace and builtin::reftype($namespace) eq 'HASH') { } 0 0 0
Condition0%0/3
ref $namespace and builtin::reftype($namespace) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $namespace and builtin::reftype($namespace) eq "HASH"
ref $namespace builtin::reftype($namespace) eq "HASH"
Truth table0%0/3
A and B
A= ref $namespaceB= builtin::reftype($namespace) eq "HASH"
ABresult
0X0
100
111
1341 0 $has_namespace = $namespace->{uri};
1342 }
1343 else {
1344 0 $has_namespace = $namespace;
1345 }
1346 }
1347  
1348 3 $self->set_namespace($has_namespace);
1349  
1350 3 return;
1351 }
1352  
1353 ########################################################################
1354 12 ▶sub is_botocore_api {
Subroutine is_botocore_api: called CC=1 SCAR=0.0
Pod undocumented
1355 ########################################################################
1356 12 my ($self) = @_;
1357  
1358 12 return defined $self->get_botocore_metadata;
1359 }
1360  
1361 ########################################################################
1362 9 ▶sub serialize_content {
Subroutine serialize_content: called CC=31 SCAR=56.5
Pod undocumented
1363 ########################################################################
1364 9 my ( $self, $parameters ) = @_;
1365  
1366 9 my $content = $parameters;
1367 9 my $action = $self->get_action;
1368 9 my $version = $self->get_version;
1369 9 my $content_type = $self->get_content_type;
1370  
1371 $self->get_logger->trace(
1372 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1373 0 return Dumper(
1374 [ content_type => $content_type,
1375 parameters => $parameters,
1376 service => $self->get_service,
1377 ]
1378 );
1379 }
1380 9 );
1381  
1382 9 ▶ my $protocol = $self->get_api_protocol // $EMPTY;
Condition66%2/3
$self->get_api_protocol // $Amazon::API::EMPTY
l!l&&r!l&&!r
360
MC/DC0%0/2
$self->get_api_protocol // $Amazon::API::EMPTY
$self->get_api_protocol $Amazon::API::EMPTY
Truth table66%2/3
A // B
A= $self->get_api_protocolB= $Amazon::API::EMPTY
ABresult
1X1
011
000
1383  
1384 9 ▶ if ( $protocol eq 'query' || $protocol eq 'ec2' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($protocol eq 'query' or $protocol eq 'ec2') { } 0 9 9
elsif ($protocol eq 'rest-json') { } 0 9 9
elsif ($content_type =~ /json/msx) { } 6 3 9
elsif ($parameters and ref $parameters and builtin::reftype($parameters) eq 'HASH' and $content_type =~ /xml/msx) { } 3 0 3
Condition33%1/3
$protocol eq "query" or $protocol eq "ec2"
l!l&&r!l&&!r
009
MC/DC0%0/2
$protocol eq "query" or $protocol eq "ec2"
$protocol eq "query" $protocol eq "ec2"
Truth table33%1/3
A or B
A= $protocol eq "query"B= $protocol eq "ec2"
ABresult
1X1
011
000
1385 0 ▶ $parameters //= [];
Condition0%0/2
$parameters //= []
l!l
00
MC/DC0%0/1
$parameters //= []
$parameters
Truth table0%0/2
A
A= $parameters
Aresult
11
00
1386  
1387 0 $content = create_urlencoded_content( $parameters, $action, $version, );
1388 }
1389 elsif ( $protocol eq 'rest-json' ) {
1390 return
1391 0 ▶ if !defined $parameters;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parameters 0 0 0
1392  
1393 0 ▶ my $botocore_action = $self->get_botocore_action // {};
Condition0%0/2
$self->get_botocore_action // {}
l!l
00
MC/DC0%0/1
$self->get_botocore_action // {}
$self->get_botocore_action
Truth table0%0/2
A
A= $self->get_botocore_action
Aresult
11
00
1394  
1395 0 my $input_shape_name = $botocore_action->{input}->{shape};
1396  
1397 my $input_shape
1398 = defined $input_shape_name
1399 0 ▶ ? $self->get_botocore_shapes->{$input_shape_name} // {}
Branch: 1 branch
BranchTrueFalseTotal
defined $input_shape_name ? : 0 0 0
Condition0%0/2
$self->get_botocore_shapes->{$input_shape_name} // {}
l!l
00
MC/DC0%0/1
$self->get_botocore_shapes->{$input_shape_name} // {}
$self->get_botocore_shapes->{$input_shape_name}
Truth table0%0/2
A
A= $self->get_botocore_shapes->{$input_shape_name}
Aresult
11
00
1400 : {};
1401  
1402 0 my $payload_member = $input_shape->{payload};
1403  
1404 0 ▶ if ($payload_member) {
Branch: 1 branch
BranchTrueFalseTotal
if ($payload_member) { } 0 0 0
1405 0 ▶ my $member = $input_shape->{members}->{$payload_member} // {};
Condition0%0/2
$input_shape->{"members"}{$payload_member} // {}
l!l
00
MC/DC0%0/1
$input_shape->{"members"}{$payload_member} // {}
$input_shape->{"members"}{$payload_member}
Truth table0%0/2
A
A= $input_shape->{"members"}{$payload_member}
Aresult
11
00
1406  
1407 0 my $payload_shape_name = $member->{shape};
1408  
1409 my $payload_shape
1410 = defined $payload_shape_name
1411 0 ▶ ? $self->get_botocore_shapes->{$payload_shape_name} // {}
Branch: 1 branch
BranchTrueFalseTotal
defined $payload_shape_name ? : 0 0 0
Condition0%0/2
$self->get_botocore_shapes->{$payload_shape_name} // {}
l!l
00
MC/DC0%0/1
$self->get_botocore_shapes->{$payload_shape_name} // {}
$self->get_botocore_shapes->{$payload_shape_name}
Truth table0%0/2
A
A= $self->get_botocore_shapes->{$payload_shape_name}
Aresult
11
00
1412 : {};
1413  
1414 0 ▶ my $payload_type = $payload_shape->{type} // $EMPTY;
Condition0%0/3
$payload_shape->{"type"} // $Amazon::API::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$payload_shape->{"type"} // $Amazon::API::EMPTY
$payload_shape->{"type"} $Amazon::API::EMPTY
Truth table0%0/3
A // B
A= $payload_shape->{"type"}B= $Amazon::API::EMPTY
ABresult
1X1
011
000
1415  
1416 0 ▶ if ( $payload_shape->{document}
Branch: 1 branch
BranchTrueFalseTotal
if ($payload_shape->{'document'} or $payload_type eq 'structure' or $payload_type eq 'union') { } 0 0 0
Condition0%0/6
$payload_shape->{"document"} or $payload_type eq "structure" or $payload_type eq "union"
l!l&&r!l&&!r
000
$payload_shape->{"document"} or $payload_type eq "structure"
l!l&&r!l&&!r
000
MC/DC0%0/3
$payload_shape->{"document"} or $payload_type eq "structure" or $payload_type eq "union"
$payload_shape->{"document"} $payload_type eq "structure" $payload_type eq "union"
Truth table0%0/4
A or B or C
A= $payload_shape->{"document"}B= $payload_type eq "structure"C= $payload_type eq "union"
ABCresult
1XX1
01X1
0011
0000
1417 || $payload_type eq 'structure'
1418 || $payload_type eq 'union' ) {
1419 0 $content = encode_json($parameters);
1420 }
1421 else {
1422 0 $content = $parameters;
1423 }
1424 }
1425 else {
1426 delete $parameters->{_attr}
1427 0 ▶ if ref $parameters
Branch: 1 branch
BranchTrueFalseTotal
if ref $parameters and builtin::reftype($parameters) eq "HASH" 0 0 0
Condition0%0/3
ref $parameters and builtin::reftype($parameters) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $parameters and builtin::reftype($parameters) eq "HASH"
ref $parameters builtin::reftype($parameters) eq "HASH"
Truth table0%0/3
A and B
A= ref $parametersB= builtin::reftype($parameters) eq "HASH"
ABresult
0X0
100
111
1428 && reftype($parameters) eq 'HASH';
1429  
1430 0 $content = encode_json($parameters);
1431 }
1432 }
1433 elsif ( $content_type =~ /json/xsm ) {
1434 6 ▶ $parameters = {}
Branch: 1 branch
BranchTrueFalseTotal
if not $parameters && ref $parameters or builtin::reftype($parameters) ne "HASH" 3 3 6
Condition66%4/6
not $parameters && ref $parameters or builtin::reftype($parameters) ne "HASH"
l!l&&r!l&&!r
303
$parameters && ref $parameters
!ll&&!rl&&r
303
MC/DC33%1/3
not $parameters && ref $parameters or builtin::reftype($parameters) ne "HASH"
$parameters ref $parameters builtin::reftype($parameters) ne "HASH"
Truth table50%2/4
not(A && B) or C
A= $parametersB= ref $parametersC= builtin::reftype($parameters) ne "HASH"
ABCresult
0XX1
10X1
1111
1100
1435 if !$parameters
1436 || !ref $parameters
1437 || reftype($parameters) ne 'HASH';
1438  
1439 6 delete $parameters->{_attr};
1440  
1441 $content
1442 6 ▶ = ( $self->get_http_method eq 'GET' && !keys %{$parameters} )
Branch: 1 branch
BranchTrueFalseTotal
$self->get_http_method eq 'GET' && !keys(%{$parameters;}) ? : 3 3 6
Condition66%2/3
$self->get_http_method eq "GET" and not keys %{$parameters;}
!ll&&!rl&&r
303
MC/DC50%1/2
$self->get_http_method eq "GET" and not keys %{$parameters;}
$self->get_http_method eq "GET" not keys %{$parameters;}
Truth table66%2/3
A and not(B)
A= $self->get_http_method eq "GET"B= not keys %{$parameters;}
ABresult
0X0
100
111
1443 ? undef
1444 : encode_json($parameters);
1445 }
1446 ▶ elsif ( $parameters
Condition33%3/9
$parameters and ref $parameters and builtin::reftype($parameters) eq "HASH" and $content_type =~ /xml/msx
!ll&&!rl&&r
003
$parameters and ref $parameters and builtin::reftype($parameters) eq "HASH"
!ll&&!rl&&r
003
$parameters and ref $parameters
!ll&&!rl&&r
003
MC/DC0%0/4
$parameters and ref $parameters and builtin::reftype($parameters) eq "HASH" and $content_type =~ /xml/msx
$parameters ref $parameters builtin::reftype($parameters) eq "HASH" $content_type =~ /xml/msx
Truth table20%1/5
A and B and C and D
A= $parametersB= ref $parametersC= builtin::reftype($parameters) eq "HASH"D= $content_type =~ /xml/msx
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1447 && ref $parameters
1448 && reftype($parameters) eq 'HASH'
1449 && $content_type =~ /xml/xms ) {
1450 return
1451 3 ▶ if !keys %{$parameters};
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$parameters;} 0 3 3
1452  
1453 3 $content = $self->generate_xml($parameters);
1454 }
1455  
1456 6 return $content;
1457 }
1458  
1459 ########################################################################
1460 # invoke_api( action, parameters, content-type, headers)
1461 ########################################################################
1462 0 ▶sub invoke_api {
Subroutine invoke_api: not called CC=32 SCAR=69.6
Pod documented
1463 ########################################################################
1464 0 my ( $self, @args ) = @_;
1465  
1466 0 my ( $action, $parameters, $content_type, $headers )
1467 = $self->_unpack_args( \@args, qw(action parameters content_type headers) );
1468  
1469 # use_botocore overrides the creation of a Botocore request
1470 # object. In that case the arguments are expected to conform to the
1471 # format specified for this particular AWS API.
1472 0 ▶ my $use_botocore = choose {
Subroutine __ANON__: not called CC=5 SCAR=34.0
1473 0 ▶ return $FALSE
Branch: 1 branch
BranchTrueFalseTotal
if $parameters and not ref $parameters 0 0 0
Condition0%0/3
$parameters and not ref $parameters
!ll&&!rl&&r
000
MC/DC0%0/2
$parameters and not ref $parameters
$parameters not ref $parameters
Truth table0%0/3
A and not(B)
A= $parametersB= not ref $parameters
ABresult
0X0
100
111
1474 if $parameters && !ref $parameters;
1475  
1476 0 ▶ return $FALSE
Branch: 1 branch
BranchTrueFalseTotal
if $parameters and builtin::reftype($parameters) ne "HASH" 0 0 0
Condition0%0/3
$parameters and builtin::reftype($parameters) ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$parameters and builtin::reftype($parameters) ne "HASH"
$parameters builtin::reftype($parameters) ne "HASH"
Truth table0%0/3
A and B
A= $parametersB= builtin::reftype($parameters) ne "HASH"
ABresult
0X0
100
111
1477 if $parameters && reftype($parameters) ne 'HASH';
1478  
1479 0 return $self->is_botocore_api;
1480 0 };
1481  
1482 0 my $protocol = eval { $self->get_botocore_metadata->{protocol}; };
1483  
1484 $self->get_logger->trace(
1485 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1486 0 return Dumper(
1487 [ parameters => $parameters,
1488 'content-type' => $content_type,
1489 protocol => $protocol,
1490 use_botocore => $use_botocore,
1491 is_botocore_api => $self->is_botocore_api,
1492 ]
1493 );
1494 }
1495 0 );
1496  
1497 0 $self->set_action($action);
1498 0 $self->set_last_action($action);
1499 0 $self->set_error(undef);
1500  
1501 # Check to see if caller is sending a blessed object, possibly a
1502 # Botocore request object using a class that does not have the
1503 # Botocore metadata
1504 0 ▶ croak sprintf qq{"%s" was not generated with Botocore support.\nParameters should be simple objects, not blessed.\n},
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($parameters) and not $self->is_botocore_api 0 0 0
Condition0%0/3
builtin::blessed($parameters) and not $self->is_botocore_api
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($parameters) and not $self->is_botocore_api
builtin::blessed($parameters) not $self->is_botocore_api
Truth table0%0/3
A and not(B)
A= builtin::blessed($parameters)B= not $self->is_botocore_api
ABresult
0X0
100
111
1505 ref $self
1506 if blessed($parameters) && !$self->is_botocore_api;
1507  
1508 # save the caller's parameters before converting them to a request shape
1509 0 my $original_content = $parameters;
1510  
1511 0 my $legacy_paginator;
1512 my $paginator;
1513  
1514 0 ▶ if ( $use_botocore && $self->get_use_paginator && $self->get_decode_always ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_botocore and $self->get_use_paginator and $self->get_decode_always) 0 0 0
Condition0%0/6
$use_botocore and $self->get_use_paginator and $self->get_decode_always
!ll&&!rl&&r
000
$use_botocore and $self->get_use_paginator
!ll&&!rl&&r
000
MC/DC0%0/3
$use_botocore and $self->get_use_paginator and $self->get_decode_always
$use_botocore $self->get_use_paginator $self->get_decode_always
Truth table0%0/4
A and B and C
A= $use_botocoreB= $self->get_use_paginatorC= $self->get_decode_always
ABCresult
0XX0
10X0
1100
1111
1515  
1516 0 my $compiled_paginators = $self->get_compiled_paginators;
1517  
1518 0 ▶ if ( $self->get_use_legacy_paginator || !defined $compiled_paginators ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->get_use_legacy_paginator or not defined $compiled_paginators) { } 0 0 0
elsif (my $definition = $compiled_paginators->{$action}) { } 0 0 0
elsif ($self->_init_paginator($use_botocore, $action)) { } 0 0 0
Condition0%0/3
$self->get_use_legacy_paginator or not defined $compiled_paginators
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_use_legacy_paginator or not defined $compiled_paginators
$self->get_use_legacy_paginator not defined $compiled_paginators
Truth table0%0/3
A or not(B)
A= $self->get_use_legacy_paginatorB= not defined $compiled_paginators
ABresult
1X1
011
000
1519 0 $legacy_paginator = $self->_init_paginator( $use_botocore, $action );
1520 }
1521 elsif ( my $definition = $compiled_paginators->{$action} ) {
1522 0 ▶ $paginator = Amazon::API::Paginator->new(
Condition0%0/2
$original_content // {}
l!l
00
MC/DC0%0/1
$original_content // {}
$original_content
Truth table0%0/2
A
A= $original_content
Aresult
11
00
1523 definition => $definition,
1524 parameters => $original_content // {},
1525 );
1526 }
1527 elsif ( $self->_init_paginator( $use_botocore, $action ) ) {
1528 0 croak "missing compiled paginator definition for $action";
1529 }
1530 }
1531  
1532 0 ▶ my $limit_key = $legacy_paginator ? $legacy_paginator->{limit_key} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$legacy_paginator ? : 0 0 0
1533 0 ▶ my $limit = $limit_key ? $parameters->{$limit_key} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$limit_key ? : 0 0 0
1534  
1535 # set content type and parameters
1536 0 ▶ if ($use_botocore) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_botocore) { } 0 0 0
1537 0 $parameters = $self->init_botocore_request($parameters);
1538 0 $content_type = $self->get_content_type;
1539 }
1540 else {
1541 # try to automatically set content type
1542 0 ▶ $content_type ||= $self->set_content_type( $self->_set_content_type );
Condition0%0/3
$content_type ||= $self->set_content_type($self->_set_content_type)
l!l&&r!l&&!r
000
MC/DC0%0/2
$content_type ||= $self->set_content_type($self->_set_content_type)
$content_type $self->set_content_type($self->_set_content_type)
Truth table0%0/3
A ||= B
A= $content_typeB= $self->set_content_type($self->_set_content_type)
ABresult
1X1
011
000
1543  
1544 0 ▶ if ( !$parameters && $content_type =~ /json/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $parameters and $content_type =~ /json/msx) 0 0 0
Condition0%0/3
not $parameters and $content_type =~ /json/msx
!ll&&!rl&&r
000
MC/DC0%0/2
not $parameters and $content_type =~ /json/msx
not $parameters $content_type =~ /json/msx
Truth table0%0/3
not(A) and B
A= not $parametersB= $content_type =~ /json/msx
ABresult
0X0
100
111
1545 0 $parameters = {};
1546 }
1547 }
1548  
1549 0 my $serialized_content = $self->serialize_content($parameters);
1550  
1551 $self->get_logger->trace(
1552 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1553 0 Dumper [
1554 content_type => $content_type,
1555 parameters => $parameters,
1556 serialized_content => $serialized_content
1557 ];
1558 }
1559 0 );
1560  
1561 0 my $page_count = 0;
1562 0 my @paged_results;
1563 my $previous_token;
1564  
1565 0 ▶ while ($TRUE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Amazon::API::TRUE) 0 0 0
1566  
1567 0 ++$page_count;
1568  
1569 0 ▶ $self->get_logger->debug( sub { return Dumper( [ page => $page_count ] ) } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
1570  
1571 0 my $rsp = $self->submit(
1572 content => $serialized_content,
1573 content_type => $content_type,
1574 headers => $headers,
1575 );
1576  
1577 $self->get_logger->trace(
1578 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1579 0 return Dumper(
1580 [ decode_always => $self->get_decode_always,
1581 content => $rsp->content
1582 ]
1583 );
1584 }
1585 0 );
1586  
1587 0 $self->set_response($rsp);
1588  
1589 last
1590 0 ▶ if !$self->_check_response($rsp);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_check_response($rsp) 0 0 0
1591  
1592 # non-botocore or raw content path
1593 0 ▶ if ( !$legacy_paginator && !$paginator ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($legacy_paginator or $paginator) 0 0 0
Condition0%0/3
$legacy_paginator or $paginator
l!l&&r!l&&!r
000
MC/DC0%0/2
$legacy_paginator or $paginator
$legacy_paginator $paginator
Truth table0%0/3
A or B
A= $legacy_paginatorB= $paginator
ABresult
1X1
011
000
1594 0 ▶ return $rsp->content
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_decode_always 0 0 0
1595 if !$self->get_decode_always;
1596  
1597 0 return $self->decode_response;
1598 }
1599  
1600 0 my $result = $self->decode_response;
1601  
1602 0 ▶ if ($paginator) {
Branch: 1 branch
BranchTrueFalseTotal
if ($paginator) 0 0 0
1603 0 $paginator->add_page($result);
1604  
1605 last
1606 0 ▶ if !$paginator->has_next_page;
Branch: 1 branch
BranchTrueFalseTotal
unless $paginator->has_next_page 0 0 0
1607  
1608 0 $serialized_content = $self->serialize_content( $self->init_botocore_request( $paginator->next_parameters ) );
1609  
1610 0 next;
1611 }
1612  
1613 $self->get_logger->trace(
1614 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1615 0 return Dumper(
1616 [ paginator => $legacy_paginator,
1617 paged_results => @paged_results,
1618 result => $result
1619 ]
1620 );
1621 }
1622 0 );
1623  
1624 0 my $actual_result = dig( $result, $legacy_paginator, 'result_key' );
1625  
1626 0 ▶ last if !$actual_result;
Branch: 1 branch
BranchTrueFalseTotal
unless $actual_result 0 0 0
1627  
1628 0 push @paged_results, @{$actual_result};
1629  
1630 $self->get_logger->trace(
1631 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1632 return Dumper(
1633 [ result => $actual_result,
1634 paged_results => \@paged_results,
1635 more_results => $legacy_paginator->{more_results},
1636 0 paginator => $legacy_paginator,
1637 ]
1638 );
1639 }
1640 0 );
1641  
1642 0 ▶ last if !dig( $result, $legacy_paginator, 'more_results' );
Branch: 1 branch
BranchTrueFalseTotal
unless dig($result, $legacy_paginator, "more_results") 0 0 0
1643  
1644 0 ▶ $limit //= $result->{$limit_key};
Condition0%0/3
$limit //= $result->{$limit_key}
l!l&&r!l&&!r
000
MC/DC0%0/2
$limit //= $result->{$limit_key}
$limit $result->{$limit_key}
Truth table0%0/3
A //= B
A= $limitB= $result->{$limit_key}
ABresult
1X1
011
000
1645  
1646 0 my $next_token = dig( $result, $legacy_paginator, 'output_token' );
1647  
1648 0 ▶ croak "ERROR: legacy paginator received the same token twice for $action"
Branch: 1 branch
BranchTrueFalseTotal
if defined $previous_token and defined $next_token and $previous_token eq $next_token 0 0 0
Condition0%0/6
defined $previous_token and defined $next_token and $previous_token eq $next_token
!ll&&!rl&&r
000
defined $previous_token and defined $next_token
!ll&&!rl&&r
000
MC/DC0%0/3
defined $previous_token and defined $next_token and $previous_token eq $next_token
defined $previous_token defined $next_token $previous_token eq $next_token
Truth table0%0/4
A and B and C
A= defined $previous_tokenB= defined $next_tokenC= $previous_token eq $next_token
ABCresult
0XX0
10X0
1100
1111
1649 if defined $previous_token
1650 && defined $next_token
1651 && $previous_token eq $next_token;
1652  
1653 0 $previous_token = $next_token;
1654  
1655 $serialized_content = $self->serialize_content(
1656 $self->init_botocore_request(
1657 0 ▶ { %{$original_content}, $limit ? ( $limit_key => $limit ) : (), $legacy_paginator->{input_token} => $next_token, }
Branch: 1 branch
BranchTrueFalseTotal
$limit ? : 0 0 0
1658 )
1659 );
1660  
1661 }
1662  
1663 0 ▶ return $paginator->result
Branch: 1 branch
BranchTrueFalseTotal
if $paginator 0 0 0
1664 if $paginator;
1665  
1666 0 return bury( \@paged_results, $legacy_paginator, 'result_key' );
1667 }
1668  
1669 ########################################################################
1670 # the analog to dig, we need to set the result to a hash element specified
1671 # by a dot encoded string. Example: DistributionList.Item
1672 ########################################################################
1673 0 ▶sub bury {
Subroutine bury: not called CC=4 SCAR=30.0
Pod undocumented
1674 ########################################################################
1675 0 my ( $result, $paginator, $key ) = @_;
1676  
1677 0 ▶ return $result
Branch: 1 branch
BranchTrueFalseTotal
unless $paginator 0 0 0
1678 if !$paginator;
1679  
1680 0 $key = $paginator->{$key};
1681  
1682 0 ▶ return { $key => $result }
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /[.]/msx 0 0 0
1683 if $key !~ /[.]/xsm;
1684  
1685 0 my $parent = {};
1686 0 my $child = $parent;
1687  
1688 0 my @keys = split /[.]/xsm, $key;
1689  
1690 0 my $result_key = pop @keys; # remove last element
1691  
1692 0 foreach (@keys) {
1693 0 $child->{$_} = {};
1694 0 $child = $child->{$_};
1695 }
1696  
1697 0 $child->{$result_key} = $result;
1698  
1699 0 return $parent;
1700 }
1701  
1702 ########################################################################
1703 # follow the . encoded key to find the hash element
1704 # example: DistributionList.Items
1705 ########################################################################
1706 0 ▶sub dig {
Subroutine dig: not called CC=6 SCAR=37.4
Pod undocumented
1707 ########################################################################
1708 0 my ( $result, $paginator, $key, $delete ) = @_;
1709  
1710 return $result
1711 0 ▶ if !$paginator || !$paginator->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $paginator and $paginator->{$key} 0 0 0
Condition0%0/3
$paginator and $paginator->{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
$paginator and $paginator->{$key}
$paginator $paginator->{$key}
Truth table0%0/3
A and B
A= $paginatorB= $paginator->{$key}
ABresult
0X0
100
111
1712  
1713 0 $key = $paginator->{$key};
1714  
1715 0 ▶ return $result->{$key}
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /[.]/msx 0 0 0
1716 if $key !~ /[.]/xsm;
1717  
1718 0 foreach ( split /[.]/xsm, $key ) {
1719 0 $result = $result->{$_};
1720 0 $key = $_;
1721 }
1722  
1723 0 ▶ if ($delete) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delete) 0 0 0
1724 0 delete $result->{$key};
1725 }
1726  
1727 0 return $result;
1728 }
1729  
1730 ########################################################################
1731 0 ▶sub print_error {
Subroutine print_error: not called CC=5 SCAR=34.0
Pod documented
1732 ########################################################################
1733 0 my ($self) = @_;
1734  
1735 0 my $error = eval {
1736 0 my $last_error = $self->get_error;
1737  
1738 0 ▶ return "$last_error"
Branch: 1 branch
BranchTrueFalseTotal
if $last_error and ref($last_error) =~ /Amazon::API::Error/msx 0 0 0
Condition0%0/3
$last_error and ref($last_error) =~ /Amazon::API::Error/msx
!ll&&!rl&&r
000
MC/DC0%0/2
$last_error and ref($last_error) =~ /Amazon::API::Error/msx
$last_error ref($last_error) =~ /Amazon::API::Error/msx
Truth table0%0/3
A and B
A= $last_errorB= ref($last_error) =~ /Amazon::API::Error/msx
ABresult
0X0
100
111
1739 if $last_error && ref($last_error) =~ /Amazon::API::Error/xms;
1740  
1741 0 return $last_error;
1742 };
1743  
1744 0 ▶ $error //= $EVAL_ERROR;
Condition0%0/3
$error //= $Amazon::API::EVAL_ERROR
l!l&&r!l&&!r
000
MC/DC0%0/2
$error //= $Amazon::API::EVAL_ERROR
$error $Amazon::API::EVAL_ERROR
Truth table0%0/3
A //= B
A= $errorB= $Amazon::API::EVAL_ERROR
ABresult
1X1
011
000
1745  
1746 0 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
1747 0 print {*STDERR} $error;
1748 }
1749  
1750 0 return $error;
1751 }
1752  
1753 ########################################################################
1754 2 ▶sub get_valid_token {
Subroutine get_valid_token: called CC=6 SCAR=22.9
Pod undocumented
1755 ########################################################################
1756 2 my ($self) = @_;
1757  
1758 2 my $credentials = $self->get_credentials;
1759  
1760 return
1761 2 ▶ if !$credentials->get_token;
Branch: 1 branch
BranchTrueFalseTotal
unless $credentials->get_token 0 2 2
1762  
1763 2 ▶ if ( $credentials->can('is_token_expired') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($credentials->can("is_token_expired")) 2 0 2
1764 2 ▶ if ( $credentials->is_token_expired ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($credentials->is_token_expired) 0 2 2
1765 0 ▶ croak 'token expired'
Branch: 1 branch
BranchTrueFalseTotal
unless $credentials->can("refresh_token") and $credentials->refresh_token 0 0 0
Condition0%0/3
$credentials->can("refresh_token") and $credentials->refresh_token
!ll&&!rl&&r
000
MC/DC0%0/2
$credentials->can("refresh_token") and $credentials->refresh_token
$credentials->can("refresh_token") $credentials->refresh_token
Truth table0%0/3
A and B
A= $credentials->can("refresh_token")B= $credentials->refresh_token
ABresult
0X0
100
111
1766 if !$credentials->can('refresh_token') || !$credentials->refresh_token;
1767 }
1768 }
1769  
1770 2 $self->get_logger->trace('valid session token present');
1771  
1772 2 return $credentials->get_token;
1773 }
1774  
1775 ########################################################################
1776 1 ▶sub submit {
Subroutine submit: called CC=12 SCAR=29.0
Pod documented
1777 ########################################################################
1778 1 my ( $self, %options ) = @_;
1779  
1780 1 ▶ $self->get_logger->trace( sub { return Dumper [ submit => $self->_sanitize( \%options ) ] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
1781  
1782 1 ▶ my $method = $self->get_http_method || 'POST';
Condition50%1/2
$self->get_http_method || 'POST'
l!l
10
MC/DC0%0/1
$self->get_http_method || 'POST'
$self->get_http_method
Truth table50%1/2
A
A= $self->get_http_method
Aresult
11
00
1783 1 ▶ my $headers = $options{headers} || [];
Condition50%1/2
$options{'headers'} || []
l!l
10
MC/DC0%0/1
$options{'headers'} || []
$options{'headers'}
Truth table50%1/2
A
A= $options{'headers'}
Aresult
11
00
1784  
1785 1 my $url = $self->get_url;
1786  
1787 1 ▶ my $botocore_protocol = eval { $self->get_botocore_metadata->{protocol} } // $EMPTY;
Condition33%1/3
eval { do { $self->get_botocore_metadata->{"protocol"} } } // $Amazon::API::EMPTY
l!l&&r!l&&!r
010
MC/DC0%0/2
eval { do { $self->get_botocore_metadata->{"protocol"} } } // $Amazon::API::EMPTY
eval { do { $self->get_botocore_metadata->{"protocol"} } } $Amazon::API::EMPTY
Truth table33%1/3
A // B
A= eval { do { $self->get_botocore_metadata->{"protocol"} } }B= $Amazon::API::EMPTY
ABresult
1X1
011
000
1788  
1789 1 ▶ if ( $botocore_protocol =~ /^rest\-(json|xml)/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($botocore_protocol =~ /^rest\-(json|xml)/msx) 0 1 1
1790 0 ▶ croak 'no request URI provided for rest-json call'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_request_uri 0 0 0
1791 if !$self->get_request_uri;
1792  
1793 0 $url .= $self->get_request_uri;
1794 }
1795  
1796 $self->get_logger->trace(
1797 1 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1798 1 return Dumper [
1799 method => $method,
1800 url => $url,
1801 headers => $self->_sanitize($headers),
1802 ];
1803 }
1804 1 );
1805  
1806 1 my $request = HTTP::Request->new( $method, $url, $headers );
1807  
1808 # apply header-located request members extracted in init_botocore_request
1809 # (e.g. If-Match) before signing so they are part of the signed request.
1810 # One-shot: clear the stash so it cannot leak into a subsequent call.
1811 1 my $botocore_request_headers = $self->get_botocore_request_headers;
1812  
1813 1 ▶ if ($botocore_request_headers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($botocore_request_headers) 0 1 1
1814 0 foreach my $header_name ( sort keys %{$botocore_request_headers} ) {
1815 0 $request->header( $header_name => $botocore_request_headers->{$header_name} );
1816 }
1817  
1818 0 $self->set_botocore_request_headers(undef);
1819 }
1820  
1821 # 1. set the header
1822 # 2. set the content
1823 # 3. sign the request
1824 # 4. send the request & return result
1825  
1826 # see IMPLEMENTATION NOTES for an explanation
1827 1 ▶ if ( $self->get_api || $self->get_target_prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_api or $self->get_target_prefix) 0 1 1
Condition33%1/3
$self->get_api or $self->get_target_prefix
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->get_api or $self->get_target_prefix
$self->get_api $self->get_target_prefix
Truth table33%1/3
A or B
A= $self->get_apiB= $self->get_target_prefix
ABresult
1X1
011
000
1828 0 $request = $self->_set_x_amz_target($request);
1829 }
1830  
1831 1 $self->_set_request_content( request => $request, %options );
1832 1 my $credentials = $self->get_credentials;
1833  
1834 1 ▶ if ( my $token = $self->get_valid_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $self->get_valid_token) 1 0 1
1835 1 $request->header( 'X-Amz-Security-Token' => $token );
1836 }
1837  
1838 1 my $auth_scheme = $self->_get_auth_scheme;
1839  
1840 Amazon::API::Signature4->new(
1841 -access_key => $credentials->get_aws_access_key_id,
1842 -secret_key => $credentials->get_aws_secret_access_key,
1843 -security_token => $credentials->get_token || undef,
1844 service => $auth_scheme->{signingName},
1845 region => $auth_scheme->{signingRegion},
1846 disable_double_encoding => $auth_scheme->{disableDoubleEncoding},
1847 1 ▶ )->sign( $request, $auth_scheme->{signingRegion} );
Condition50%1/2
$credentials->get_token || undef
l!l
10
MC/DC0%0/1
$credentials->get_token || undef
$credentials->get_token
Truth table50%1/2
A
A= $credentials->get_token
Aresult
11
00
1848  
1849 1 ▶ $self->get_logger->trace( sub { return Dumper( [ request => $self->_sanitize($request) ] ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
1850  
1851 # make the request, return response object
1852 1 my $ua = $self->get_user_agent;
1853 1 my $rsp = $ua->request($request);
1854  
1855 $self->get_logger->trace(
1856 1 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1857 1 return Dumper [ response => $rsp ];
1858 }
1859 1 );
1860  
1861 1 return $rsp;
1862 }
1863  
1864 ########################################################################
1865 1 ▶sub _get_auth_scheme {
Subroutine _get_auth_scheme: called CC=1 SCAR=3.3
1866 ########################################################################
1867 1 my ($self) = @_;
1868  
1869 1 my $default = {
1870 name => 'sigv4',
1871 signingName => $self->get_service,
1872 signingRegion => $self->get_region,
1873 };
1874  
1875 1 my $endpoint = $self->get_resolved_endpoint;
1876  
1877 1 ▶ my $auth_scheme = choose {
Subroutine __ANON__: called CC=7 SCAR=37.7
1878 1 ▶ return $default
Branch: 1 branch
BranchTrueFalseTotal
unless $endpoint 1 0 1
1879 if !$endpoint;
1880  
1881 0 ▶ my $properties = $endpoint->{properties} // {};
Condition0%0/2
$endpoint->{"properties"} // {}
l!l
00
MC/DC0%0/1
$endpoint->{"properties"} // {}
$endpoint->{"properties"}
Truth table0%0/2
A
A= $endpoint->{"properties"}
Aresult
11
00
1882 0 my $auth_schemes = $properties->{authSchemes};
1883  
1884 0 ▶ return $default
Branch: 1 branch
BranchTrueFalseTotal
unless $auth_schemes 0 0 0
1885 if !$auth_schemes;
1886  
1887 0 foreach my $scheme ( @{$auth_schemes} ) {
1888 next
1889 0 ▶ if ( $scheme->{name} // q{} ) ne 'sigv4';
Branch: 1 branch
BranchTrueFalseTotal
if ($scheme->{"name"} // "") ne "sigv4" 0 0 0
Condition0%0/2
$scheme->{"name"} // ""
l!l
00
MC/DC0%0/1
$scheme->{"name"} // ""
$scheme->{"name"}
Truth table0%0/2
A
A= $scheme->{"name"}
Aresult
11
00
1890  
1891 0 return { %{$default}, %{$scheme}, };
1892 }
1893 0 croak 'endpoint does not provide a supported SigV4 authentication scheme';
1894 1 };
1895  
1896 1 return $auth_scheme;
1897 }
1898  
1899 # +------------------+
1900 # | EXPORTED METHODS |
1901 # +------------------+
1902  
1903 ########################################################################
1904 4 ▶sub generate_xml {
Subroutine generate_xml: called CC=4 SCAR=26.7
Pod documented
1905 ########################################################################
1906 4 my ( $self, $data ) = @_;
1907  
1908 4 require XML::Twig;
1909  
1910 0 my @root_keys = keys %{$data};
1911  
1912 0 ▶ croak sprintf
Branch: 1 branch
BranchTrueFalseTotal
if @root_keys > 1 0 0 0
1913 "generate_xml: refusing to emit malformed XML with %d root elements (%s); a request body must have exactly one root\n",
1914 scalar @root_keys, join q{, }, sort @root_keys
1915 if @root_keys > 1;
1916  
1917 0 my @elements;
1918 0 for my $key (@root_keys) {
1919 0 push @elements, _to_xml( $key, $data->{$key} );
1920 }
1921  
1922 0 my $xml = qq{<?xml version="1.0" encoding="UTF-8"?>\n};
1923 0 $xml .= $_->sprint . "\n" for @elements;
1924  
1925 $self->get_logger->trace(
1926 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1927 0 return Dumper(
1928 [ data => $data,
1929 xml => $xml
1930 ]
1931 );
1932 }
1933 0 );
1934  
1935 0 return $xml;
1936 }
1937  
1938 ########################################################################
1939 0 ▶sub query_param_n {
Subroutine query_param_n: not called CC=1 SCAR=6.9
Pod undocumented
1940 ########################################################################
1941 0 my (@args) = @_;
1942  
1943 0 return Amazon::API::Botocore::Shape::Utils::query_param_n(@args);
1944 }
1945  
1946 ########################################################################
1947 0 ▶sub param_n {
Subroutine param_n: not called CC=1 SCAR=6.9
Pod documented
1948 ########################################################################
1949 0 my (@args) = @_;
1950  
1951 0 return Amazon::API::Botocore::Shape::Utils::param_n(@args);
1952 }
1953  
1954 ########################################################################
1955 # create_urlencoded_content(parameters, action, version)
1956 # input:
1957 # parameters:
1958 # SCALAR - query string to encode (x=y&w=z...)
1959 # ARRAY - either an array of hashes or...
1960 # key/value pairs of the form x=y or...
1961 # key/values pairs
1962 # HASH - key/value pairs, if the value is an array then
1963 # it is assumed to be a list of hashes
1964 # action: API method
1965 # version: wsdl version for API
1966 #
1967 # output:
1968 # URL encodode query string
1969 #
1970 ########################################################################
1971 6 ▶sub create_urlencoded_content {
Subroutine create_urlencoded_content: called CC=19 SCAR=31.9
Pod documented
1972 ########################################################################
1973 6 my ( $parameters, $action, $version ) = @_;
1974  
1975 6 my @args;
1976 6 ▶ if ( $parameters && !ref $parameters ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($parameters and not ref $parameters) { } 1 5 6
elsif ($parameters and builtin::reftype($parameters) eq 'HASH') { } 2 3 5
elsif ($parameters and builtin::reftype($parameters) eq 'ARRAY') { } 3 0 3
Condition66%2/3
$parameters and not ref $parameters
!ll&&!rl&&r
051
MC/DC50%1/2
$parameters and not ref $parameters
$parameters not ref $parameters
Truth table66%2/3
A and not(B)
A= $parametersB= not ref $parameters
ABresult
0X0
100
111
1977 1 @args = map { split /=/xsm, $_, 2 } split /&/xsm, $parameters;
1978 }
1979 ▶ elsif ( $parameters && reftype($parameters) eq 'HASH' ) {
Condition66%2/3
$parameters and builtin::reftype($parameters) eq "HASH"
!ll&&!rl&&r
032
MC/DC50%1/2
$parameters and builtin::reftype($parameters) eq "HASH"
$parameters builtin::reftype($parameters) eq "HASH"
Truth table66%2/3
A and B
A= $parametersB= builtin::reftype($parameters) eq "HASH"
ABresult
0X0
100
111
1980 2 foreach my $key ( keys %{$parameters} ) {
1981  
1982 3 ▶ if ( ref $parameters->{$key}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $parameters->{$key} and builtin::reftype($parameters->{$key}) eq 'ARRAY') { } 0 3 3
Condition33%1/3
ref $parameters->{$key} and builtin::reftype($parameters->{$key}) eq "ARRAY"
!ll&&!rl&&r
300
MC/DC0%0/2
ref $parameters->{$key} and builtin::reftype($parameters->{$key}) eq "ARRAY"
ref $parameters->{$key} builtin::reftype($parameters->{$key}) eq "ARRAY"
Truth table33%1/3
A and B
A= ref $parameters->{$key}B= builtin::reftype($parameters->{$key}) eq "ARRAY"
ABresult
0X0
100
111
1983 && reftype( $parameters->{$key} ) eq 'ARRAY' ) {
1984 0 for my $value ( @{ $parameters->{$key} } ) {
1985 0 ▶ if ( ref $value && reftype($value) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and builtin::reftype($value) eq 'HASH') { } 0 0 0
Condition0%0/3
ref $value and builtin::reftype($value) eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and builtin::reftype($value) eq "HASH"
ref $value builtin::reftype($value) eq "HASH"
Truth table0%0/3
A and B
A= ref $valueB= builtin::reftype($value) eq "HASH"
ABresult
0X0
100
111
1986 0 push @args, %{$value};
1987 }
1988 else {
1989 0 push @args, $key, $value;
1990 }
1991 }
1992 }
1993 else {
1994 3 push @args, $key, $parameters->{$key};
1995 }
1996 }
1997 }
1998 ▶ elsif ( $parameters && reftype($parameters) eq 'ARRAY' ) {
Condition33%1/3
$parameters and builtin::reftype($parameters) eq "ARRAY"
!ll&&!rl&&r
003
MC/DC0%0/2
$parameters and builtin::reftype($parameters) eq "ARRAY"
$parameters builtin::reftype($parameters) eq "ARRAY"
Truth table33%1/3
A and B
A= $parametersB= builtin::reftype($parameters) eq "ARRAY"
ABresult
0X0
100
111
1999 3 ▶ if ( any {ref} @{$parameters} ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
if (&any(sub { ref $_; } , @{$parameters;})) { } 1 2 3
elsif (&any(sub { /=/msx; } , @{$parameters;})) { } 1 1 2
2000 1 @args = map { %{$_} } @{$parameters};
2001 }
2002 2 ▶ elsif ( any {/=/xsm} @{$parameters} ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
2003 1 @args = map { split /=/xsm, $_, 2 } @{$parameters};
2004 }
2005 else {
2006 1 @args = @{$parameters};
2007 }
2008 }
2009  
2010 6 my $content;
2011  
2012 6 ▶ if ( $action && !any { $_ eq 'Action' } @args ) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if ($action and not &any(sub { $_ eq "Action"; } , @args)) 4 2 6
Condition100%3/3
$action and not &any(sub { $_ eq "Action"; } , @args)
!ll&&!rl&&r
114
MC/DC100%2/2
$action and not &any(sub { $_ eq "Action"; } , @args)
$action not &any(sub { $_ eq "Action"; } , @args)
Truth table100%3/3
A and not(B)
A= $actionB= not &any(sub { $_ eq "Action"; } , @args)
ABresult
0X0
100
111
2013 4 push @args, 'Action', $action;
2014 }
2015  
2016 6 my %arg_hash = @args;
2017  
2018 6 ▶ if ( $version && !exists $arg_hash{Version} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version and not exists $arg_hash{"Version"}) 4 2 6
Condition100%3/3
$version and not exists $arg_hash{"Version"}
!ll&&!rl&&r
114
MC/DC100%2/2
$version and not exists $arg_hash{"Version"}
$version not exists $arg_hash{"Version"}
Truth table100%3/3
A and not(B)
A= $versionB= not exists $arg_hash{"Version"}
ABresult
0X0
100
111
2019 4 push @args, 'Version', $version;
2020 }
2021  
2022 return join $AMPERSAND,
2023 6 map { sprintf '%s=%s', uri_escape_utf8( $_->[0] ), uri_escape_utf8( $_->[1] ) } grep { defined $_->[1] } pairs @args;
2024 }
2025  
2026 ########################################################################
2027 0 ▶sub has_keys {
Subroutine has_keys: not called CC=3 SCAR=24.8
Pod undocumented
2028 ########################################################################
2029 0 my ( $self, %options ) = @_;
2030  
2031 # note that self should NOT really have keys! Not sure why I added this test
2032 0 ▶ my %creds = keys %options ? %options : map { $_ => $self->{$_} } @REQUIRED_KEYS;
Branch: 1 branch
BranchTrueFalseTotal
keys %options ? : 0 0 0
2033  
2034 0 ▶ return $creds{aws_secret_access_key} && $creds{aws_access_key_id};
Condition0%0/3
$creds{'aws_secret_access_key'} && $creds{'aws_access_key_id'}
!ll&&!rl&&r
000
MC/DC0%0/2
$creds{'aws_secret_access_key'} && $creds{'aws_access_key_id'}
$creds{'aws_secret_access_key'} $creds{'aws_access_key_id'}
Truth table0%0/3
A && B
A= $creds{'aws_secret_access_key'}B= $creds{'aws_access_key_id'}
ABresult
0X0
100
111
2035 }
2036  
2037 # +-----------------+
2038 # | PRIVATE METHODS |
2039 # +-----------------+
2040  
2041 ########################################################################
2042 0 ▶sub _unpack_args {
Subroutine _unpack_args: not called CC=3 SCAR=24.8
2043 ########################################################################
2044 0 my ( $self, $args, @var_names ) = @_;
2045  
2046 0 return @{$args}
2047 0 ▶ if @{$args} > 1 || !ref $args->[0];
Branch: 1 branch
BranchTrueFalseTotal
if @{$args;} > 1 or not ref $args->[0] 0 0 0
Condition0%0/3
@{$args;} > 1 or not ref $args->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
@{$args;} > 1 or not ref $args->[0]
@{$args;} > 1 not ref $args->[0]
Truth table0%0/3
A or not(B)
A= @{$args;} > 1B= not ref $args->[0]
ABresult
1X1
011
000
2048  
2049 0 return @{ $args->[0] }{@var_names};
2050 }
2051  
2052 ########################################################################
2053 6 ▶sub _validate_client_context_params {
Subroutine _validate_client_context_params: called CC=5 SCAR=18.6
2054 ########################################################################
2055 6 my ($self) = @_;
2056  
2057 6 ▶ my $parameters = $self->get_client_context_params // {};
Condition50%1/2
$self->get_client_context_params // {}
l!l
06
MC/DC0%0/1
$self->get_client_context_params // {}
$self->get_client_context_params
Truth table50%1/2
A
A= $self->get_client_context_params
Aresult
11
00
2058 6 ▶ my $definitions = $self->get_botocore_client_context_params // {};
Condition50%1/2
$self->get_botocore_client_context_params // {}
l!l
06
MC/DC0%0/1
$self->get_botocore_client_context_params // {}
$self->get_botocore_client_context_params
Truth table50%1/2
A
A= $self->get_botocore_client_context_params
Aresult
11
00
2059  
2060 6 foreach my $name ( keys %{$parameters} ) {
2061 croak "unknown client context parameter '$name'"
2062 0 ▶ if !exists $definitions->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $definitions->{$name} 0 0 0
2063 }
2064  
2065 6 return $self;
2066 }
2067  
2068 ########################################################################
2069 0 ▶sub _check_response {
Subroutine _check_response: not called CC=4 SCAR=30.0
2070 ########################################################################
2071 0 my ( $self, $rsp ) = @_;
2072  
2073 0 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $rsp->is_success 0 0 0
2074 if $rsp->is_success;
2075  
2076 0 $self->set_error(
2077 Amazon::API::Error->new(
2078 { error => $rsp->code,
2079 message_raw => $rsp->content,
2080 content_type => scalar $rsp->content_type,
2081 api => ref $self,
2082 response => $rsp,
2083 action => $self->get_last_action,
2084 }
2085 )
2086 );
2087  
2088 0 ▶ die $self->get_error
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_raise_error 0 0 0
2089 if $self->get_raise_error;
2090  
2091 0 ▶ if ( $self->get_print_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_print_error) 0 0 0
2092 0 print {*STDERR} $self->get_error;
2093 }
2094  
2095 0 return;
2096 }
2097  
2098 ########################################################################
2099 0 ▶sub _init_paginator {
Subroutine _init_paginator: not called CC=15 SCAR=54.8
2100 ########################################################################
2101 0 my ( $self, $use_botocore, $action ) = @_;
2102  
2103 return
2104 0 ▶ if !$use_botocore || !$self->get_use_paginator || !$self->get_decode_always;
Branch: 1 branch
BranchTrueFalseTotal
unless $use_botocore and $self->get_use_paginator and $self->get_decode_always 0 0 0
Condition0%0/6
$use_botocore and $self->get_use_paginator and $self->get_decode_always
!ll&&!rl&&r
000
$use_botocore and $self->get_use_paginator
!ll&&!rl&&r
000
MC/DC0%0/3
$use_botocore and $self->get_use_paginator and $self->get_decode_always
$use_botocore $self->get_use_paginator $self->get_decode_always
Truth table0%0/4
A and B and C
A= $use_botocoreB= $self->get_use_paginatorC= $self->get_decode_always
ABCresult
0XX0
10X0
1100
1111
2105  
2106 0 my $paginators = $self->get_paginators;
2107  
2108 return
2109 0 ▶ if !$paginators || !$paginators->{pagination};
Branch: 1 branch
BranchTrueFalseTotal
unless $paginators and $paginators->{"pagination"} 0 0 0
Condition0%0/3
$paginators and $paginators->{"pagination"}
!ll&&!rl&&r
000
MC/DC0%0/2
$paginators and $paginators->{"pagination"}
$paginators $paginators->{"pagination"}
Truth table0%0/3
A and B
A= $paginatorsB= $paginators->{"pagination"}
ABresult
0X0
100
111
2110  
2111 0 my $paginator = $paginators->{pagination}->{$action};
2112  
2113 return
2114 0 ▶ if !$paginator;
Branch: 1 branch
BranchTrueFalseTotal
unless $paginator 0 0 0
2115  
2116 0 foreach my $marker (qw(input_token output_token result_key)) {
2117 croak "ERROR: legacy paginator does not support $action paginator marker $marker"
2118 0 ▶ if !defined $paginator->{$marker} || ref $paginator->{$marker};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $paginator->{$marker} or ref $paginator->{$marker} 0 0 0
Condition0%0/3
not defined $paginator->{$marker} or ref $paginator->{$marker}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $paginator->{$marker} or ref $paginator->{$marker}
not defined $paginator->{$marker} ref $paginator->{$marker}
Truth table0%0/3
not(A) or B
A= not defined $paginator->{$marker}B= ref $paginator->{$marker}
ABresult
1X1
011
000
2119 }
2120  
2121 0 foreach my $marker (qw(limit_key more_results)) {
2122 croak "ERROR: legacy paginator does not support $action paginator marker $marker"
2123 0 ▶ if defined $paginator->{$marker} && ref $paginator->{$marker};
Branch: 1 branch
BranchTrueFalseTotal
if defined $paginator->{$marker} and ref $paginator->{$marker} 0 0 0
Condition0%0/3
defined $paginator->{$marker} and ref $paginator->{$marker}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $paginator->{$marker} and ref $paginator->{$marker}
defined $paginator->{$marker} ref $paginator->{$marker}
Truth table0%0/3
A and B
A= defined $paginator->{$marker}B= ref $paginator->{$marker}
ABresult
0X0
100
111
2124 }
2125  
2126 croak "ERROR: legacy paginator does not support $action non_aggregate_keys"
2127 0 ▶ if defined $paginator->{non_aggregate_keys};
Branch: 1 branch
BranchTrueFalseTotal
if defined $paginator->{"non_aggregate_keys"} 0 0 0
2128  
2129 0 ▶ $paginator->{more_results} //= $paginator->{output_token};
Condition0%0/3
$paginator->{"more_results"} //= $paginator->{"output_token"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$paginator->{"more_results"} //= $paginator->{"output_token"}
$paginator->{"more_results"} $paginator->{"output_token"}
Truth table0%0/3
A //= B
A= $paginator->{"more_results"}B= $paginator->{"output_token"}
ABresult
1X1
011
000
2130  
2131 0 return $paginator;
2132 }
2133  
2134 # should not be called if we have a Botocore definition
2135 ########################################################################
2136 0 ▶sub _set_content_type {
Subroutine _set_content_type: not called CC=1 SCAR=6.9
2137 ########################################################################
2138 0 my ($self) = @_;
2139  
2140 0 return $self->get_content_type;
2141 }
2142  
2143 ########################################################################
2144 6 ▶sub _create_methods {
Subroutine _create_methods: called CC=6 SCAR=28.6
2145 ########################################################################
2146 6 my ($self) = @_;
2147  
2148 6 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
600
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
2149  
2150 6 ▶ if ( $self->get_api_methods ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_api_methods) 0 6 6
2151 11 ▶ no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
2152 11 ▶ no warnings 'redefine'; ## no critic (TestingAndDebugging::ProhibitNoWarnings)
Subroutine BEGIN: called CC=1 SCAR=0.0
2153  
2154 0 my $stash = \%{ __PACKAGE__ . $DOUBLE_COLON };
2155  
2156 0 foreach my $api ( @{ $self->get_api_methods } ) {
2157  
2158 0 my $method = lcfirst $api;
2159  
2160 0 $method =~ s/([[:lower:]])([[:upper:]])/$1_$2/xmsg;
2161 0 $method = lc $method;
2162  
2163 0 my $snake_case_method = $class . $DOUBLE_COLON . $method;
2164 0 my $camel_case_method = $class . $DOUBLE_COLON . $api;
2165  
2166 # snake case rules the day
2167  
2168 0 ▶ if ( !$stash->{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stash->{$method}) 0 0 0
2169 0 ▶ *{$snake_case_method} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2170 0 my $self = shift;
2171  
2172 0 $self->invoke_api( $api, @_ );
2173 0 };
2174 }
2175  
2176 # ...but some prefer camels
2177 0 ▶ if ( !$stash->{$api} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stash->{$api}) 0 0 0
2178 0 ▶ *{$camel_case_method} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2179 0 my $self = shift;
2180  
2181 0 $self->$method(@_);
2182 0 };
2183 }
2184 }
2185  
2186 }
2187  
2188 6 return $self;
2189 }
2190  
2191 ########################################################################
2192 6 ▶sub _set_default_logger {
Subroutine _set_default_logger: called CC=7 SCAR=20.6
2193 ########################################################################
2194 6 my ( $self, $log_level_string ) = @_;
2195  
2196 6 ▶ if ( $self->get_no_logger ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_no_logger) 5 1 6
2197 5 $self->set_logger( Amazon::API::NullLogger->new );
2198 5 return $self;
2199 }
2200  
2201 1 require Log::Log4perl;
2202  
2203 1 ▶ my $log_level_numeric = $LOG4PERL_LOG_LEVELS{ lc $log_level_string } // $LOG4PERL_LOG_LEVELS{info};
Condition33%1/3
$Amazon::API::LOG4PERL_LOG_LEVELS{lc $log_level_string} // $Amazon::API::LOG4PERL_LOG_LEVELS{"info"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$Amazon::API::LOG4PERL_LOG_LEVELS{lc $log_level_string} // $Amazon::API::LOG4PERL_LOG_LEVELS{"info"}
$Amazon::API::LOG4PERL_LOG_LEVELS{lc $log_level_string} $Amazon::API::LOG4PERL_LOG_LEVELS{"info"}
Truth table33%1/3
A // B
A= $Amazon::API::LOG4PERL_LOG_LEVELS{lc $log_level_string}B= $Amazon::API::LOG4PERL_LOG_LEVELS{"info"}
ABresult
1X1
011
000
2204 1 my $log_level_name = uc $log_level_string;
2205  
2206 1 ▶ my $pattern_layout = $self->get_log4perl_layout // $DEFAULT_LOG4PERL_LAYOUT;
Condition33%1/3
$self->get_log4perl_layout // $Amazon::API::DEFAULT_LOG4PERL_LAYOUT
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->get_log4perl_layout // $Amazon::API::DEFAULT_LOG4PERL_LAYOUT
$self->get_log4perl_layout $Amazon::API::DEFAULT_LOG4PERL_LAYOUT
Truth table33%1/3
A // B
A= $self->get_log4perl_layoutB= $Amazon::API::DEFAULT_LOG4PERL_LAYOUT
ABresult
1X1
011
000
2207  
2208 1 ▶ if ( !Log::Log4perl->initialized ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("Log::Log4perl"->initialized) 1 0 1
2209  
2210 1 my $appender_config_str;
2211  
2212 # 2. Determine Appender Configuration as a string
2213 1 my $file = $self->get_log_file;
2214  
2215 1 ▶ if ( defined $file && $file ne q{} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and $file ne '') { } 0 1 1
Condition33%1/3
defined $file and $file ne ""
!ll&&!rl&&r
100
MC/DC0%0/2
defined $file and $file ne ""
defined $file $file ne ""
Truth table33%1/3
A and B
A= defined $fileB= $file ne ""
ABresult
0X0
100
111
2216 0 $appender_config_str = qq{
2217 log4perl.appender.ROOT_APPENDER = Log::Log4perl::Appender::File
2218 log4perl.appender.ROOT_APPENDER.filename = $file
2219 log4perl.appender.ROOT_APPENDER.mode = append
2220 };
2221 }
2222 else {
2223 1 $appender_config_str = qq{
2224 log4perl.appender.ROOT_APPENDER = Log::Log4perl::Appender::Screen
2225 log4perl.appender.ROOT_APPENDER.stderr = 1
2226 };
2227 }
2228  
2229 # 3. Construct the full text blob configuration
2230 1 my $config_blob = qq{
2231 # Root Logger
2232 log4perl.rootLogger = $log_level_name, ROOT_APPENDER
2233  
2234 # Appender Definition (dynamic)
2235 $appender_config_str
2236  
2237 # Layout Definition
2238 log4perl.appender.ROOT_APPENDER.layout = Log::Log4perl::Layout::PatternLayout
2239 log4perl.appender.ROOT_APPENDER.layout.ConversionPattern = $pattern_layout
2240 };
2241  
2242 1 Log::Log4perl::init( \$config_blob ); # Pass a reference to the scalar string
2243 }
2244  
2245 1 my $logger = Log::Log4perl->get_logger( ref $self );
2246 1 $logger->level($log_level_numeric);
2247  
2248 1 $self->set_logger($logger);
2249  
2250 1 return $self;
2251 }
2252  
2253 ########################################################################
2254 6 ▶sub _set_defaults {
Subroutine _set_defaults: called CC=14 SCAR=34.4
2255 ########################################################################
2256 6 my ( $self, %options ) = @_;
2257  
2258 6 ▶ $self->set_raise_error( $self->get_raise_error // $TRUE );
Condition33%1/3
$self->get_raise_error // $Amazon::API::TRUE
l!l&&r!l&&!r
060
MC/DC0%0/2
$self->get_raise_error // $Amazon::API::TRUE
$self->get_raise_error $Amazon::API::TRUE
Truth table33%1/3
A // B
A= $self->get_raise_errorB= $Amazon::API::TRUE
ABresult
1X1
011
000
2259 6 ▶ $self->set_print_error( $self->get_print_error // $TRUE );
Condition33%1/3
$self->get_print_error // $Amazon::API::TRUE
l!l&&r!l&&!r
060
MC/DC0%0/2
$self->get_print_error // $Amazon::API::TRUE
$self->get_print_error $Amazon::API::TRUE
Truth table33%1/3
A // B
A= $self->get_print_errorB= $Amazon::API::TRUE
ABresult
1X1
011
000
2260 6 ▶ $self->set_use_paginator( $self->get_use_paginator // $TRUE );
Condition33%1/3
$self->get_use_paginator // $Amazon::API::TRUE
l!l&&r!l&&!r
060
MC/DC0%0/2
$self->get_use_paginator // $Amazon::API::TRUE
$self->get_use_paginator $Amazon::API::TRUE
Truth table33%1/3
A // B
A= $self->get_use_paginatorB= $Amazon::API::TRUE
ABresult
1X1
011
000
2261 6 ▶ $self->set_use_legacy_paginator( $self->get_use_legacy_paginator // $FALSE );
Condition33%1/3
$self->get_use_legacy_paginator // $Amazon::API::FALSE
l!l&&r!l&&!r
060
MC/DC0%0/2
$self->get_use_legacy_paginator // $Amazon::API::FALSE
$self->get_use_legacy_paginator $Amazon::API::FALSE
Truth table33%1/3
A // B
A= $self->get_use_legacy_paginatorB= $Amazon::API::FALSE
ABresult
1X1
011
000
2262 6 ▶ $self->set_decode_always( $self->get_decode_always // $TRUE );
Condition33%1/3
$self->get_decode_always // $Amazon::API::TRUE
l!l&&r!l&&!r
060
MC/DC0%0/2
$self->get_decode_always // $Amazon::API::TRUE
$self->get_decode_always $Amazon::API::TRUE
Truth table33%1/3
A // B
A= $self->get_decode_alwaysB= $Amazon::API::TRUE
ABresult
1X1
011
000
2263 6 ▶ $self->set_user_agent( $self->get_user_agent // Amazon::API::HTTP::UserAgent->new );
Condition66%2/3
$self->get_user_agent // "Amazon::API::HTTP::UserAgent"->new
l!l&&r!l&&!r
510
MC/DC0%0/2
$self->get_user_agent // "Amazon::API::HTTP::UserAgent"->new
$self->get_user_agent "Amazon::API::HTTP::UserAgent"->new
Truth table66%2/3
A // B
A= $self->get_user_agentB= "Amazon::API::HTTP::UserAgent"->new
ABresult
1X1
011
000
2264 6 ▶ $self->set_protocol( $self->get_protocol() // 'https' );
Condition50%1/2
$self->get_protocol // "https"
l!l
06
MC/DC0%0/1
$self->get_protocol // "https"
$self->get_protocol
Truth table50%1/2
A
A= $self->get_protocol
Aresult
11
00
2265 6 ▶ $self->set_http_method( $self->get_http_method // 'POST' ); # most API services are POST
Condition50%1/2
$self->get_http_method // "POST"
l!l
06
MC/DC0%0/1
$self->get_http_method // "POST"
$self->get_http_method
Truth table50%1/2
A
A= $self->get_http_method
Aresult
11
00
2266  
2267 6 my $region = $self->get_region;
2268  
2269 # note some APIs are global, hence an API may send '' to indicate global
2270 6 ▶ if ( !$region ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($region) 6 0 6
2271 6 ▶ $region = $ENV{AWS_REGION} || $ENV{AWS_DEFAULT_REGION} || $DEFAULT_REGION;
Condition33%2/6
$ENV{'AWS_REGION'} || $ENV{'AWS_DEFAULT_REGION'} || $DEFAULT_REGION
l!l&&r!l&&!r
060
$ENV{"AWS_REGION"} or $ENV{"AWS_DEFAULT_REGION"}
l!l&&r!l&&!r
006
MC/DC0%0/3
$ENV{'AWS_REGION'} || $ENV{'AWS_DEFAULT_REGION'} || $DEFAULT_REGION
$ENV{"AWS_REGION"} $ENV{"AWS_DEFAULT_REGION"} $DEFAULT_REGION
Truth table25%1/4
A or B || C
A= $ENV{"AWS_REGION"}B= $ENV{"AWS_DEFAULT_REGION"}C= $DEFAULT_REGION
ABCresult
1XX1
01X1
0011
0000
2272 6 $self->set_region($region);
2273 }
2274  
2275 6 $self->set_log_level( $options{log_level} );
2276  
2277 6 ▶ if ( !$self->get_credentials ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_credentials) 0 6 6
2278 0 ▶ if ( $self->has_keys(%options) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_keys(%options)) { } 0 0 0
2279 $self->set_credentials(
2280 Amazon::Credentials->new(
2281 { aws_secret_access_key => $options{aws_secret_access_key},
2282 aws_access_key_id => $options{aws_access_key_id},
2283 token => $options{token},
2284 region => $region,
2285 no_passkey_warning => $options{no_passkey_warning},
2286 }
2287 )
2288 0 );
2289 }
2290 else {
2291 $self->set_credentials(
2292 Amazon::Credentials->new(
2293 order => $options{order},
2294 region => $region,
2295 no_passkey_warning => $options{no_passkey_warning},
2296 )
2297 0 );
2298 }
2299 }
2300  
2301 # set URL last since it contains region
2302 6 $self->_set_url;
2303  
2304 6 return $self;
2305 }
2306  
2307 ########################################################################
2308 0 ▶sub _create_service_url_from_rule_set {
Subroutine _create_service_url_from_rule_set: not called CC=4 SCAR=30.0
2309 ########################################################################
2310 0 my ( $self, $endpoint_rule_set, $request_parameters ) = @_;
2311  
2312 0 require Amazon::API::EndpointResolver;
2313  
2314 0 ▶ $request_parameters //= {};
Condition0%0/2
$request_parameters //= {}
l!l
00
MC/DC0%0/1
$request_parameters //= {}
$request_parameters
Truth table0%0/2
A
A= $request_parameters
Aresult
11
00
2315  
2316 0 my $resolver = Amazon::API::EndpointResolver->new( endpoint_rule_set => $endpoint_rule_set, );
2317  
2318 my %parameters = (
2319 Region => $self->get_region,
2320 UseFIPS => $self->get_use_fips,
2321 UseDualStack => $self->get_use_dualstack,
2322 UseGlobalEndpoint => $self->get_use_global_endpoint,
2323 ForcePathStyle => $self->get_use_force_path_style,
2324 0 %{$request_parameters},
2325 );
2326  
2327 0 foreach my $name ( keys %parameters ) {
2328 0 ▶ next if exists $endpoint_rule_set->{parameters}->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $endpoint_rule_set->{"parameters"}{$name} 0 0 0
2329 0 delete $parameters{$name};
2330 }
2331  
2332 0 my $endpoint = $resolver->resolve(%parameters);
2333  
2334 0 $self->set_resolved_endpoint($endpoint);
2335  
2336 0 return $endpoint->{url};
2337 }
2338  
2339 ########################################################################
2340 3 ▶sub _resolve_request_endpoint {
Subroutine _resolve_request_endpoint: called CC=3 SCAR=17.9
2341 ########################################################################
2342 3 my ( $self, $request ) = @_;
2343  
2344 3 my $endpoint_rule_set = $self->get_endpoint_rule_set;
2345  
2346 return
2347 3 ▶ if !$endpoint_rule_set;
Branch: 1 branch
BranchTrueFalseTotal
unless $endpoint_rule_set 3 0 3
2348  
2349 0 my $parameters = $self->_get_endpoint_context_parameters($request);
2350  
2351 return
2352 0 ▶ if !%{$parameters};
Branch: 1 branch
BranchTrueFalseTotal
unless %{$parameters;} 0 0 0
2353  
2354 0 my $url = $self->_create_service_url_from_rule_set( $endpoint_rule_set, $parameters, );
2355  
2356 0 $self->set_url($url);
2357  
2358 0 return;
2359 }
2360  
2361 ########################################################################
2362 6 ▶sub _create_service_url {
Subroutine _create_service_url: called CC=6 SCAR=20.4
2363 ########################################################################
2364 6 my ($self) = @_;
2365  
2366 6 my $url;
2367  
2368 6 my $botocore_metadata = $self->get_botocore_metadata;
2369 6 my $service = $self->get_service;
2370 6 my $endpoint_rule_set = $self->get_endpoint_rule_set;
2371  
2372 6 ▶ return $self->_create_service_url_from_rule_set($endpoint_rule_set)
Branch: 1 branch
BranchTrueFalseTotal
if $endpoint_rule_set 0 6 6
2373 if $endpoint_rule_set;
2374  
2375 6 ▶ if ( $botocore_metadata && $botocore_metadata->{globalEndpoint} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($botocore_metadata and $botocore_metadata->{'globalEndpoint'}) { } 0 6 6
Condition33%1/3
$botocore_metadata and $botocore_metadata->{"globalEndpoint"}
!ll&&!rl&&r
600
MC/DC0%0/2
$botocore_metadata and $botocore_metadata->{"globalEndpoint"}
$botocore_metadata $botocore_metadata->{"globalEndpoint"}
Truth table33%1/3
A and B
A= $botocore_metadataB= $botocore_metadata->{"globalEndpoint"}
ABresult
0X0
100
111
2376 0 $url = sprintf '%s://%s', $self->get_protocol, $botocore_metadata->{globalEndpoint};
2377 }
2378 else {
2379 6 ▶ my $endpoint = $self->get_endpoint_prefix || $service;
Condition33%1/3
$self->get_endpoint_prefix || $service
l!l&&r!l&&!r
060
MC/DC0%0/2
$self->get_endpoint_prefix || $service
$self->get_endpoint_prefix $service
Truth table33%1/3
A || B
A= $self->get_endpoint_prefixB= $service
ABresult
1X1
011
000
2380  
2381 # this could probably be an else since we always set region to a default
2382 6 ▶ if ( $self->get_region ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_region) { } 6 0 6
2383 6 $url = sprintf $REGIONAL_URL_FMT, $self->get_protocol, $endpoint, $self->get_region;
2384 }
2385 else {
2386 0 $url = sprintf $REGIONAL_URL_FMT, $self->get_protocol, $endpoint, 'us-east-1';
2387 }
2388 }
2389  
2390 6 return $url;
2391 }
2392  
2393 ########################################################################
2394 6 ▶sub _set_url {
Subroutine _set_url: called CC=3 SCAR=13.6
2395 ########################################################################
2396 6 my ($self) = @_;
2397  
2398 6 my $url = $self->get_url;
2399  
2400 6 ▶ if ( !$url ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $url) { } 6 0 6
2401 6 $url = $self->_create_service_url;
2402 }
2403 else {
2404 0 ▶ if ( $url !~ /^https?/xmsi ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($url =~ /^https?/imsx) 0 0 0
2405 0 $url =~ s/^\///xms; # just remove leading slash...
2406 0 $url = $self->get_protocol . '://' . $url;
2407 }
2408  
2409 }
2410  
2411 6 $self->set_url($url);
2412  
2413 6 return $self;
2414 }
2415  
2416 ########################################################################
2417 0 ▶sub _set_x_amz_target {
Subroutine _set_x_amz_target: not called CC=3 SCAR=24.8
2418 ########################################################################
2419 0 my ( $self, $request ) = @_;
2420  
2421 0 my $target = $self->get_target_prefix;
2422 0 my $version = $self->get_version;
2423 0 my $api = $self->get_api;
2424 0 my $action = $self->get_action;
2425  
2426 0 ▶ if ( !$target ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target) 0 0 0
2427 0 ▶ $target = $version ? $api . $UNDERSCORE . $version : $api;
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
2428 }
2429  
2430 0 $target = $target . $DOT . $action;
2431  
2432 0 $self->set_target($target);
2433  
2434 0 $request->header( 'X-Amz-Target' => $target );
2435  
2436 0 return $request;
2437 }
2438  
2439 ########################################################################
2440 2 ▶sub _set_request_content {
Subroutine _set_request_content: called CC=5 SCAR=17.3
2441 ########################################################################
2442 2 my ( $self, %args ) = @_;
2443  
2444 2 my $request = $args{request};
2445 2 my $content = $args{content};
2446 2 ▶ my $content_type = $args{content_type} || $self->get_content_type;
Condition33%1/3
$args{'content_type'} || $self->get_content_type
l!l&&r!l&&!r
200
MC/DC0%0/2
$args{'content_type'} || $self->get_content_type
$args{'content_type'} $self->get_content_type
Truth table33%1/3
A || B
A= $args{'content_type'}B= $self->get_content_type
ABresult
1X1
011
000
2447  
2448 $self->get_logger->trace(
2449 2 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2450 2 return Dumper(
2451 [ method => $self->get_http_method,
2452 args => $self->_sanitize( \%args ),
2453 request => $self->_sanitize($request),
2454 content => $content,
2455 content_type => $content_type
2456 ]
2457 );
2458 }
2459 2 );
2460  
2461 2 ▶ if ( $self->get_http_method ne 'GET' || !defined $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_http_method ne 'GET' or not defined $content) { } 2 0 2
Condition33%1/3
$self->get_http_method ne "GET" or not defined $content
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->get_http_method ne "GET" or not defined $content
$self->get_http_method ne "GET" not defined $content
Truth table33%1/3
A or not(B)
A= $self->get_http_method ne "GET"B= not defined $content
ABresult
1X1
011
000
2462 2 ▶ if ($content_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content_type) 2 0 2
2463 2 $request->content_type( $content_type . '; charset=utf-8' );
2464 }
2465 2 $request->content($content);
2466 }
2467 else {
2468 0 $request->uri( $request->uri . $QUESTION_MARK . $content );
2469 }
2470  
2471 2 ▶ $self->get_logger->trace( sub { return Dumper( [ request => $self->_sanitize($request) ] ); } );
Subroutine __ANON__: called CC=1 SCAR=0.0
2472  
2473 2 return $request;
2474 }
2475  
2476 ########################################################################
2477 0 ▶sub _get_endpoint_context_parameters {
Subroutine _get_endpoint_context_parameters: not called CC=22 SCAR=62.3
2478 ########################################################################
2479 0 my ( $self, $request ) = @_;
2480  
2481 0 my %parameters;
2482  
2483 # clientContextParams
2484 0 ▶ my $client_context = $self->get_client_context_params // {};
Condition0%0/2
$self->get_client_context_params // {}
l!l
00
MC/DC0%0/1
$self->get_client_context_params // {}
$self->get_client_context_params
Truth table0%0/2
A
A= $self->get_client_context_params
Aresult
11
00
2485  
2486 0 ▶ my $client_definitions = $self->get_botocore_client_context_params // {};
Condition0%0/2
$self->get_botocore_client_context_params // {}
l!l
00
MC/DC0%0/1
$self->get_botocore_client_context_params // {}
$self->get_botocore_client_context_params
Truth table0%0/2
A
A= $self->get_botocore_client_context_params
Aresult
11
00
2487  
2488 0 foreach my $name ( keys %{$client_context} ) {
2489  
2490 0 my $value = $client_context->{$name};
2491  
2492 next
2493 0 ▶ if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
2494  
2495 0 $parameters{$name} = $value;
2496 }
2497  
2498 0 ▶ my $operation = $self->get_botocore_operations->{ $self->get_action } // {};
Condition0%0/2
$self->get_botocore_operations->{$self->get_action} // {}
l!l
00
MC/DC0%0/1
$self->get_botocore_operations->{$self->get_action} // {}
$self->get_botocore_operations->{$self->get_action}
Truth table0%0/2
A
A= $self->get_botocore_operations->{$self->get_action}
Aresult
11
00
2499  
2500 # operationContextParams
2501 0 ▶ if ($request) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request) 0 0 0
2502 0 ▶ my $compiled_endpoint_context = $self->get_compiled_endpoint_context // {};
Condition0%0/2
$self->get_compiled_endpoint_context // {}
l!l
00
MC/DC0%0/1
$self->get_compiled_endpoint_context // {}
$self->get_compiled_endpoint_context
Truth table0%0/2
A
A= $self->get_compiled_endpoint_context
Aresult
11
00
2503 0 ▶ my $compiled_context = $compiled_endpoint_context->{ $self->get_action } // {};
Condition0%0/2
$$compiled_endpoint_context{$self->get_action} // {}
l!l
00
MC/DC0%0/1
$$compiled_endpoint_context{$self->get_action} // {}
$$compiled_endpoint_context{$self->get_action}
Truth table0%0/2
A
A= $$compiled_endpoint_context{$self->get_action}
Aresult
11
00
2504  
2505 0 ▶ if ( %{$compiled_context} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$compiled_context;}) 0 0 0
2506 0 require Amazon::API::EndpointContext::Compiler;
2507  
2508 0 my $compiler = Amazon::API::EndpointContext::Compiler->new;
2509  
2510 0 foreach my $name ( keys %{$compiled_context} ) {
2511 0 my $value = $compiler->evaluate( $compiled_context->{$name}, $request, );
2512  
2513 next
2514 0 ▶ if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
2515  
2516 0 $parameters{$name} = $value;
2517 }
2518 }
2519  
2520 # contextParam
2521 0 ▶ foreach my $member_name ( keys %{ $request->{members} // {} } ) {
Condition0%0/2
$request->{"members"} // {}
l!l
00
MC/DC0%0/1
$request->{"members"} // {}
$request->{"members"}
Truth table0%0/2
A
A= $request->{"members"}
Aresult
11
00
2522 0 my $member = $request->{members}->{$member_name};
2523  
2524 0 my $context_param = $member->{contextParam};
2525  
2526 next
2527 0 ▶ if !$context_param;
Branch: 1 branch
BranchTrueFalseTotal
unless $context_param 0 0 0
2528  
2529 0 my $name = $context_param->{name};
2530  
2531 next
2532 0 ▶ if !defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
2533  
2534 0 my $value = $request->{_value}->{$member_name};
2535  
2536 next
2537 0 ▶ if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
2538  
2539 $value = $value->{_value}
2540 0 ▶ if ref $value && exists $value->{_value};
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and exists $value->{"_value"} 0 0 0
Condition0%0/3
ref $value and exists $value->{"_value"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and exists $value->{"_value"}
ref $value exists $value->{"_value"}
Truth table0%0/3
A and B
A= ref $valueB= exists $value->{"_value"}
ABresult
0X0
100
111
2541  
2542 0 $parameters{$name} = $value;
2543 }
2544 }
2545  
2546 # staticContextParams
2547 0 ▶ foreach my $name ( keys %{ $operation->{staticContextParams} // {} } ) {
Condition0%0/2
$operation->{"staticContextParams"} // {}
l!l
00
MC/DC0%0/1
$operation->{"staticContextParams"} // {}
$operation->{"staticContextParams"}
Truth table0%0/2
A
A= $operation->{"staticContextParams"}
Aresult
11
00
2548 my $value
2549 0 = $operation->{staticContextParams}->{$name}->{value};
2550  
2551 next
2552 0 ▶ if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
2553  
2554 0 $parameters{$name} = $value;
2555 }
2556  
2557 0 return \%parameters;
2558 }
2559  
2560 ########################################################################
2561 # Convert a Perl data object to XML using XML::Twig
2562 0 ▶sub _to_xml {
Subroutine _to_xml: not called CC=11 SCAR=48.8
2563 ########################################################################
2564 0 my ( $key, $value ) = @_;
2565  
2566 # Handle array references (multiple sibling elements with same tag)
2567 0 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 0 0
elsif (ref $value eq 'HASH') { } 0 0 0
2568 0 return map { _to_xml( $key, $_ ) } @{$value};
2569 }
2570  
2571 # Handle hash references (nested structures)
2572 elsif ( ref $value eq 'HASH' ) {
2573 0 ▶ my %attrs = exists $value->{_attr} ? %{ $value->{_attr} } : ();
Branch: 1 branch
BranchTrueFalseTotal
exists $value->{'_attr'} ? : 0 0 0
2574  
2575 0 my $element = XML::Twig::Elt->new( $key, \%attrs, );
2576  
2577 0 ▶ if ( exists $value->{_text} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $value->{"_text"}) 0 0 0
2578 0 ▶ $element->set_text( defined $value->{_text} ? $value->{_text} : $EMPTY );
Branch: 1 branch
BranchTrueFalseTotal
defined $value->{'_text'} ? : 0 0 0
2579 }
2580  
2581 0 for my $subkey ( keys %{$value} ) {
2582 next
2583 0 ▶ if $subkey eq '_attr' || $subkey eq '_text';
Branch: 1 branch
BranchTrueFalseTotal
if $subkey eq "_attr" or $subkey eq "_text" 0 0 0
Condition0%0/3
$subkey eq "_attr" or $subkey eq "_text"
l!l&&r!l&&!r
000
MC/DC0%0/2
$subkey eq "_attr" or $subkey eq "_text"
$subkey eq "_attr" $subkey eq "_text"
Truth table0%0/3
A or B
A= $subkey eq "_attr"B= $subkey eq "_text"
ABresult
1X1
011
000
2584  
2585 $_->paste( last_child => $element )
2586 0 for _to_xml( $subkey, $value->{$subkey}, );
2587 }
2588  
2589 0 return $element;
2590 }
2591  
2592 # Handle scalar values (text nodes)
2593 else {
2594 0 ▶ return XML::Twig::Elt->new( $key, defined $value ? $value : $EMPTY );
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
2595 }
2596 }
2597  
2598 ########################################################################
2599 25 ▶sub _sanitize {
Subroutine _sanitize: called CC=15 SCAR=27.1
2600 ########################################################################
2601 25 my ( $self, $value ) = @_;
2602  
2603 25 my %sensitive_headers = map { $_ => $TRUE } qw(
2604 authorization
2605 x-amz-security-token
2606 );
2607  
2608 25 ▶ if ( blessed($value) && $value->isa('HTTP::Request') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($value) and $value->isa("HTTP::Request")) 8 17 25
Condition66%2/3
builtin::blessed($value) and $value->isa("HTTP::Request")
!ll&&!rl&&r
1708
MC/DC50%1/2
builtin::blessed($value) and $value->isa("HTTP::Request")
builtin::blessed($value) $value->isa("HTTP::Request")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("HTTP::Request")
ABresult
0X0
100
111
2609 8 my $request = $value->clone;
2610  
2611 8 foreach my $header_name ( $request->header_field_names ) {
2612 next
2613 21 ▶ if !$sensitive_headers{ lc $header_name };
Branch: 1 branch
BranchTrueFalseTotal
unless $sensitive_headers{lc $header_name} 5 16 21
2614  
2615 16 $request->header( $header_name => '[REDACTED]' );
2616 }
2617  
2618 8 return $request;
2619 }
2620  
2621 17 ▶ if ( ref $value && reftype($value) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and builtin::reftype($value) eq "HASH") 4 13 17
Condition100%3/3
ref $value and builtin::reftype($value) eq "HASH"
!ll&&!rl&&r
944
MC/DC100%2/2
ref $value and builtin::reftype($value) eq "HASH"
ref $value builtin::reftype($value) eq "HASH"
Truth table100%3/3
A and B
A= ref $valueB= builtin::reftype($value) eq "HASH"
ABresult
0X0
100
111
2622 4 my %copy;
2623  
2624 4 foreach my $key ( keys %{$value} ) {
2625 13 ▶ if ( $sensitive_headers{ lc $key } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sensitive_headers{lc $key}) 2 11 13
2626 2 $copy{$key} = '[REDACTED]';
2627 2 next;
2628 }
2629  
2630 11 $copy{$key} = $self->_sanitize( $value->{$key} );
2631 }
2632  
2633 4 return \%copy;
2634 }
2635  
2636 13 ▶ if ( ref $value && reftype($value) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and builtin::reftype($value) eq "ARRAY") 4 9 13
Condition66%2/3
ref $value and builtin::reftype($value) eq "ARRAY"
!ll&&!rl&&r
904
MC/DC50%1/2
ref $value and builtin::reftype($value) eq "ARRAY"
ref $value builtin::reftype($value) eq "ARRAY"
Truth table66%2/3
A and B
A= ref $valueB= builtin::reftype($value) eq "ARRAY"
ABresult
0X0
100
111
2637 4 my @copy;
2638  
2639 4 ▶ for ( my $i = 0; $i < @{$value}; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$value;}) 10 4 14
2640 10 my $item = $value->[$i];
2641  
2642 10 ▶ if ( !ref $item
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $item and $sensitive_headers{lc $item} and $i + 1 < @{$value;}) 8 2 10
Condition66%4/6
not ref $item and $sensitive_headers{lc $item} and $i + 1 < @{$value;}
!ll&&!rl&&r
208
not ref $item and $sensitive_headers{lc $item}
!ll&&!rl&&r
028
MC/DC33%1/3
not ref $item and $sensitive_headers{lc $item} and $i + 1 < @{$value;}
not ref $item $sensitive_headers{lc $item} $i + 1 < @{$value;}
Truth table50%2/4
not(A) and B and C
A= not ref $itemB= $sensitive_headers{lc $item}C= $i + 1 < @{$value;}
ABCresult
0XX0
10X0
1100
1111
2643 && $sensitive_headers{ lc $item }
2644 8 && $i + 1 < @{$value} ) {
2645 8 push @copy, $item, '[REDACTED]';
2646 8 $i++;
2647 8 next;
2648 }
2649  
2650 2 push @copy, $self->_sanitize($item);
2651 }
2652  
2653 4 return \@copy;
2654 }
2655  
2656 9 return $value;
2657 }
2658  
2659 11 1;
2660  
2661 __END__
↑ Summary API/XML/Simple.pm »