blib/lib/Paws/Net/JsonResponse.pm

filter: Statementstmt 90.4% 142 / 157 Branchbran 80.9% 68 / 84 Conditioncond 71.1% 37 / 52 MC/DCmcdc 27.2% 9 / 33 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 7 totaltotal 77.6% 268 / 345 CC 63 SCAR 33.6
CC
63
Cov
84%
new_from_result_struct
50.1
error_to_exception
8.8
handle_response_strtoobjmap
6.1
CRAP 28.9
« blib/lib/Paws/ApiGateway.pm ↑ Summary blib/lib/Paws/Net/XMLResponse.pm »
1 package Paws::Net::JsonResponse;
2 13 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶ use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶ use Paws::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶ use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 92 ▶ sub process {
Subroutine process: called CC=4 SCAR=13.9
Pod undocumented
9 92 my ($self, $call_object, $response) = @_;
10  
11 92 ▶ if ($response->has_header('x-amz-crc32')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->has_header("x-amz-crc32")) 3 89 92
12 3 require String::CRC32;
13 3 my $crc = String::CRC32::crc32($response->content);
14 3 ▶ return Paws::Exception->new(
Branch: 1 branch
BranchTrueFalseTotal
if $crc != $response->header("x-amz-crc32") 0 3 3
15 code => 'Crc32Error',
16 message => 'Content CRC32 mismatch',
17 request_id => $response->header('x-amzn-requestid'),
18 ) if ($crc != $response->header('x-amz-crc32'));
19 }
20  
21 92 ▶ if ( $response->status >= 300 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->status >= 300) { } 34 58 92
22 34 return $self->error_to_exception($call_object, $response);
23 } else {
24 58 return $self->response_to_object($call_object, $response);
25 }
26 }
27
28 84 ▶ sub unserialize_response {
Subroutine unserialize_response: called CC=4 SCAR=13.9
Pod undocumented
29 84 my ($self, $response) = @_;
30  
31 84 ▶ return {} if (not defined $response->content or $response->content eq '');
Branch: 1 branch
BranchTrueFalseTotal
if not defined $response->content or $response->content eq "" 11 73 84
Condition100%3/3
not defined $response->content or $response->content eq ""
l!l&&r!l&&!r
5673
MC/DC100%2/2
not defined $response->content or $response->content eq ""
not defined $response->content $response->content eq ""
Truth table100%3/3
not(A) or B
A= not defined $response->contentB= $response->content eq ""
ABresult
1X1
011
000
32  
33 73 my $struct = eval { decode_json( $response->content ) };
34 73 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 5 68 73
35 5 return Paws::Exception->throw(
36 message => $@,
37 code => 'InvalidContent',
38 request_id => '',
39 http_status => $response->status,
40 );
41 }
42 68 return $struct;
43 }
44  
45 34 ▶ sub error_to_exception {
Subroutine error_to_exception: called CC=8 SCAR=21.7
Pod undocumented
46 34 my ($self, $call_object, $response) = @_;
47
48 34 my $struct = $self->unserialize_response( $response );
49 30 my ($message, $request_id);
50  
51 30 ▶ my $code = $struct->{__type} // 'InvalidContent';
Condition100%2/2
$struct->{"__type"} // "InvalidContent"
l!l
1812
MC/DC100%1/1
$struct->{"__type"} // "InvalidContent"
$struct->{"__type"}
Truth table100%2/2
A
A= $struct->{"__type"}
Aresult
11
00
52 30 ▶ if ($code =~ m/#/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /#/) 2 28 30
53 2 $code = (split /#/, $code)[1];
54 }
55  
56 30 ▶ if (exists $struct->{message}){
Branch: 2 branches
BranchTrueFalseTotal
if (exists $struct->{'message'}) { } 12 18 30
elsif (exists $struct->{'Message'}) { } 0 18 18
57 12 ▶ $message = $struct->{message} // '';
Condition50%1/2
$struct->{"message"} // ""
l!l
120
MC/DC0%0/1
$struct->{"message"} // ""
$struct->{"message"}
Truth table50%1/2
A
A= $struct->{"message"}
Aresult
11
00
58 } elsif (exists $struct->{Message}){
59 0 ▶ $message = $struct->{Message} // '';
Condition0%0/2
$struct->{"Message"} // ""
l!l
00
MC/DC0%0/1
$struct->{"Message"} // ""
$struct->{"Message"}
Truth table0%0/2
A
A= $struct->{"Message"}
Aresult
11
00
60 } else {
61 18 $message = $code;
62 }
63  
64 30 ▶ $request_id = $response->header('x-amzn-requestid') // '';
Condition50%1/2
$response->header("x-amzn-requestid") // ""
l!l
300
MC/DC0%0/1
$response->header("x-amzn-requestid") // ""
$response->header("x-amzn-requestid")
Truth table50%1/2
A
A= $response->header("x-amzn-requestid")
Aresult
11
00
65  
66 30 Paws::Exception->new(
67 message => $message,
68 code => $code,
69 request_id => $request_id,
70 http_status => $response->status,
71 );
72 }
73  
74 4 ▶ sub handle_response_strtonativemap {
Subroutine handle_response_strtonativemap: called CC=2 SCAR=7.6
Pod undocumented
75 4 my ($self, $att_class, $value) = @_;
76  
77 4 ▶ if (not defined $value){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value) { } 0 4 4
78 0 return $att_class->new(Map => {});
79 } else {
80 4 return $att_class->new(Map => $value);
81 }
82 }
83  
84 9 ▶ sub handle_response_strtoobjmap {
Subroutine handle_response_strtoobjmap: called CC=6 SCAR=18.1
Pod undocumented
85 9 my ($self, $att_class, $value) = @_;
86  
87 9 my $is_array = 0;
88 9 my $inner_class;
89 9 my $class = $att_class->meta->get_attribute('Map')->type_constraint->name;
90  
91 9 ▶ if (my ($array_type) = ($class =~ m/^HashRef\[ArrayRef\[(.*)\]\]$/)){
Branch: 2 branches
BranchTrueFalseTotal
if (my($array_type) = $class =~ /^HashRef\[ArrayRef\[(.*)\]\]$/) { } 3 6 9
elsif (my($inner_type) = $class =~ /^HashRef\[(.*)\]$/) { } 6 0 6
92 3 $inner_class = $array_type;
93 3 $is_array = 1;
94 } elsif (my ($inner_type) = ($class =~ m/^HashRef\[(.*)\]$/)) {
95 6 $inner_class = $inner_type;
96 6 $is_array = 0;
97 }
98  
99 9 Paws->load_class("$inner_class");
100  
101 9 ▶ if ($is_array) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_array) { } 3 6 9
102 3 ▶ if (not defined $value){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value) { } 0 3 3
103 0 return $att_class->new(Map => {});
104 } else {
105 return $att_class->new(Map => {
106 3 map { my $k = $_; ($k => [ map { $self->new_from_result_struct($inner_class, $_) } @{ $value->{ $k } } ] ) } keys %$value
107 });
108 }
109 } else {
110 6 ▶ if (not defined $value){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value) { } 0 6 6
111 0 return $att_class->new(Map => {});
112 } else {
113 return $att_class->new(Map => {
114 6 map { ($_ => $self->new_from_result_struct($inner_class, $value->{ $_ }) ) } keys %$value
115 });
116 }
117 }
118 }
119  
120 115 ▶ sub new_from_result_struct {
Subroutine new_from_result_struct: called CC=39 SCAR=39.1
Pod undocumented
121 115 my ($self, $class, $result) = @_;
122 115 my %args;
123  
124 115 ▶ if (do { state %d; $d{$class} //= $class->does('Paws::API::StrToObjMapParser')}) {
Branch: 2 branches
BranchTrueFalseTotal
if (do { state %d; $d{$class} //= $class->does('Paws::API::StrToObjMapParser') }) { } 2 113 115
elsif (do { state %d; $d{$class} //= $class->does('Paws::API::StrToNativeMapParser') }) { } 0 113 113
Condition66%2/3
$d{$class} //= $class->does("Paws::API::StrToObjMapParser")
l!l&&r!l&&!r
63520
MC/DC0%0/2
$d{$class} //= $class->does("Paws::API::StrToObjMapParser")
$d{$class} $class->does("Paws::API::StrToObjMapParser")
Truth table66%2/3
A //= B
A= $d{$class}B= $class->does("Paws::API::StrToObjMapParser")
ABresult
1X1
011
000
125 2 return $self->handle_response_strtoobjmap($class, $result);
126 113 ▶ } elsif (do { state %d; $d{$class} //= $class->does('Paws::API::StrToNativeMapParser')}) {
Condition66%2/3
$d{$class} //= $class->does("Paws::API::StrToNativeMapParser")
l!l&&r!l&&!r
62510
MC/DC0%0/2
$d{$class} //= $class->does("Paws::API::StrToNativeMapParser")
$d{$class} $class->does("Paws::API::StrToNativeMapParser")
Truth table66%2/3
A //= B
A= $d{$class}B= $class->does("Paws::API::StrToNativeMapParser")
ABresult
1X1
011
000
127 0 return $self->handle_response_strtonativemap($class, $result);
128 } else {
129 113 ▶ foreach my $att (do { state %d; @{$d{$class} //= [$class->meta->get_attribute_list]}}) {
Condition100%2/2
$d{$class} //= [$class->meta->get_attribute_list]
l!l
6251
MC/DC100%1/1
$d{$class} //= [$class->meta->get_attribute_list]
$d{$class}
Truth table100%2/2
A
A= $d{$class}
Aresult
11
00
130 731 ▶ next if (not my $meta = do { state %d; exists $d{$class}{$att} ? $d{$class}{$att} : $d{$class}{$att} = $class->meta->get_attribute($att)});
Branch: 2 branches
BranchTrueFalseTotal
unless my $meta = do { state %d; exists $d{$class}{$att} ? $d{$class}{$att} : $d{$class}{$att} = $class->meta->get_attribute($att) } 0 731 731
exists $d{$class}{$att} ? : 471 260 731
131  
132 731 ▶ my $key = do { state %d; $d{$class}{$att} //= $meta->does('NameInRequest') } ? $meta->request_name :
Branch: 1 branch
BranchTrueFalseTotal
do { state %d; $d{$class}{$att} //= $meta->does('ParamInHeader') } ? : 0 625 625
Condition66%2/3
$d{$class}{$att} //= $meta->does("NameInRequest")
l!l&&r!l&&!r
4712600
MC/DC0%0/2
$d{$class}{$att} //= $meta->does("NameInRequest")
$d{$class}{$att} $meta->does("NameInRequest")
Truth table66%2/3
A //= B
A= $d{$class}{$att}B= $meta->does("NameInRequest")
ABresult
1X1
011
000
133 731 ▶ do { state %d; $d{$class}{$att} //= $meta->does('ParamInHeader') } ? lc($meta->header_name) : $att;
Branch: 1 branch
BranchTrueFalseTotal
do { state %d; $d{$class}{$att} //= $meta->does('NameInRequest') } ? : 106 625 731
Condition66%2/3
$d{$class}{$att} //= $meta->does("ParamInHeader")
l!l&&r!l&&!r
4371880
MC/DC0%0/2
$d{$class}{$att} //= $meta->does("ParamInHeader")
$d{$class}{$att} $meta->does("ParamInHeader")
Truth table66%2/3
A //= B
A= $d{$class}{$att}B= $meta->does("ParamInHeader")
ABresult
1X1
011
000
134  
135 731 my $att_type = $meta->type_constraint;
136  
137 # use Data::Dumper;
138 # print STDERR "USING KEY: $key\n";
139 # print STDERR "$att IS A '$att_type' TYPE\n";
140 # print STDERR "VALUE: " . Dumper($result);
141 # my $extracted_val = $result->{ $key };
142 # print STDERR "RESULT >>> $extracted_val\n";
143  
144 # We'll consider that an attribute without brackets [] isn't an array type
145 731 ▶ if ($att_type !~ m/\[.*\]$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $att_type =~ /\[.*\]$/) { } 575 156 731
elsif (my($type) = $att_type =~ /^ArrayRef\[(.*)\]$/) { } 118 38 156
146 575 my $value = $result->{ $key };
147 575 my $value_ref = ref($value);
148  
149 575 ▶ if ($att_type =~ m/\:\:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($att_type =~ /\:\:/) { } 130 445 575
150 # Make the att_type stringify for module loading
151 130 Paws->load_class("$att_type");
152 130 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 29 101 130
153 29 ▶ if (not $value_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $value_ref) { } 0 29 29
154 0 $args{ $att } = $value;
155 } else {
156 29 my $att_class = $att_type->class;
157  
158 29 ▶ if (do { state %d; $d{$att_class} //= $att_class->does('Paws::API::StrToObjMapParser')}) {
Branch: 3 branches
BranchTrueFalseTotal
if (do { state %d; $d{$att_class} //= $att_class->does('Paws::API::StrToObjMapParser') }) { } 6 23 29
elsif (do { state %d; $d{$att_class} //= $att_class->does('Paws::API::StrToNativeMapParser') }) { } 4 19 23
elsif (do { state %d; $d{$att_class} //= $att_class->does('Paws::API::MapParser') }) { } 0 19 19
Condition66%2/3
$d{$att_class} //= $att_class->does("Paws::API::StrToObjMapParser")
l!l&&r!l&&!r
13160
MC/DC0%0/2
$d{$att_class} //= $att_class->does("Paws::API::StrToObjMapParser")
$d{$att_class} $att_class->does("Paws::API::StrToObjMapParser")
Truth table66%2/3
A //= B
A= $d{$att_class}B= $att_class->does("Paws::API::StrToObjMapParser")
ABresult
1X1
011
000
159 6 $args{ $att } = $self->handle_response_strtoobjmap($att_class, $value);
160 23 ▶ } elsif (do { state %d; $d{$att_class} //= $att_class->does('Paws::API::StrToNativeMapParser')}) {
Condition66%2/3
$d{$att_class} //= $att_class->does("Paws::API::StrToNativeMapParser")
l!l&&r!l&&!r
12110
MC/DC0%0/2
$d{$att_class} //= $att_class->does("Paws::API::StrToNativeMapParser")
$d{$att_class} $att_class->does("Paws::API::StrToNativeMapParser")
Truth table66%2/3
A //= B
A= $d{$att_class}B= $att_class->does("Paws::API::StrToNativeMapParser")
ABresult
1X1
011
000
161 4 $args{ $att } = $self->handle_response_strtonativemap($att_class, $value);
162 19 ▶ } elsif (do { state %d; $d{$att_class} //= $att_class->does('Paws::API::MapParser')}) {
Condition66%2/3
$d{$att_class} //= $att_class->does("Paws::API::MapParser")
l!l&&r!l&&!r
1180
MC/DC0%0/2
$d{$att_class} //= $att_class->does("Paws::API::MapParser")
$d{$att_class} $att_class->does("Paws::API::MapParser")
Truth table66%2/3
A //= B
A= $d{$att_class}B= $att_class->does("Paws::API::MapParser")
ABresult
1X1
011
000
163 0 my $xml_keys = $att_class->xml_keys;
164 0 my $xml_values = $att_class->xml_values;
165  
166 0 $args{ $att } = $att_class->new(map { ($_->{ $xml_keys } => $_->{ $xml_values }) } @$value);
167 } else {
168 19 $args{ $att } = $self->new_from_result_struct($att_class, $value);
169 }
170 }
171 }
172 } else {
173 445 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 253 192 445
174 253 ▶ if ($att_type eq 'Bool') {
Branch: 1 branch
BranchTrueFalseTotal
if ($att_type eq 'Bool') { } 9 244 253
175 9 ▶ if ($value eq 'true') {
Branch: 3 branches
BranchTrueFalseTotal
if ($value eq 'true') { } 8 1 9
elsif ($value eq 'false') { } 1 0 1
elsif ($value == 1) { } 0 0 0
176 8 $args{ $att } = 1;
177 } elsif ($value eq 'false') {
178 1 $args{ $att } = 0;
179 } elsif ($value == 1) {
180 0 $args{ $att } = 1;
181 } else {
182 0 $args{ $att } = 0;
183 }
184 } else {
185 244 $args{ $att } = $value;
186 }
187 }
188 }
189 } elsif (my ($type) = ($att_type =~ m/^ArrayRef\[(.*)\]$/)) {
190 118 my $value = $result->{ $att };
191 118 ▶ $value = $result->{ $key } if (not defined $value and $key ne $att);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value and $key ne $att 10 108 118
Condition100%3/3
not defined $value and $key ne $att
!ll&&!rl&&r
218710
MC/DC100%2/2
not defined $value and $key ne $att
not defined $value $key ne $att
Truth table100%3/3
not(A) and B
A= not defined $valueB= $key ne $att
ABresult
0X0
100
111
192 118 my $value_ref = ref($value);
193  
194 118 ▶ if ($type =~ m/\:\:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /\:\:/) { } 71 47 118
195 71 Paws->load_class($type);
196  
197 71 ▶ if (do { state %d; $d{$type} //= $type->does('Paws::API::StrToObjMapParser')}) {
Branch: 3 branches
BranchTrueFalseTotal
if (do { state %d; $d{$type} //= $type->does('Paws::API::StrToObjMapParser') }) { } 2 69 71
elsif (do { state %d; $d{$type} //= $type->does('Paws::API::StrToNativeMapParser') }) { } 0 69 69
elsif (do { state %d; $d{$type} //= $type->does('Paws::API::MapParser') }) { } 0 69 69
Condition66%2/3
$d{$type} //= $type->does("Paws::API::StrToObjMapParser")
l!l&&r!l&&!r
46250
MC/DC0%0/2
$d{$type} //= $type->does("Paws::API::StrToObjMapParser")
$d{$type} $type->does("Paws::API::StrToObjMapParser")
Truth table66%2/3
A //= B
A= $d{$type}B= $type->does("Paws::API::StrToObjMapParser")
ABresult
1X1
011
000
198 2 $args{ $att } = [ map { $self->handle_response_strtoobjmap($type, $_) } @$value ];
199 69 ▶ } elsif (do { state %d; $d{$type} //= $type->does('Paws::API::StrToNativeMapParser')}) {
Condition66%2/3
$d{$type} //= $type->does("Paws::API::StrToNativeMapParser")
l!l&&r!l&&!r
45240
MC/DC0%0/2
$d{$type} //= $type->does("Paws::API::StrToNativeMapParser")
$d{$type} $type->does("Paws::API::StrToNativeMapParser")
Truth table66%2/3
A //= B
A= $d{$type}B= $type->does("Paws::API::StrToNativeMapParser")
ABresult
1X1
011
000
200 0 $args{ $att } = [ map { $self->handle_response_strtonativemap($type, $_) } @$value ];
201 69 ▶ } elsif (do { state %d; $d{$type} //= $type->does('Paws::API::MapParser')}) {
Condition66%2/3
$d{$type} //= $type->does("Paws::API::MapParser")
l!l&&r!l&&!r
45240
MC/DC0%0/2
$d{$type} //= $type->does("Paws::API::MapParser")
$d{$type} $type->does("Paws::API::MapParser")
Truth table66%2/3
A //= B
A= $d{$type}B= $type->does("Paws::API::MapParser")
ABresult
1X1
011
000
202 0 die "MapParser Type in an Array. Please implement me";
203 } else {
204 69 $args{ $att } = [ map { $self->new_from_result_struct($type, $_) } @$value ];
205 }
206 } else {
207 47 ▶ if (defined $value){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 5 42 47
208 5 $args{ $att } = $value;
209 }
210 }
211 }
212 }
213 113 $class->new(%args);
214 }
215 }
216  
217 58 ▶ sub response_to_object {
Subroutine response_to_object: called CC=6 SCAR=17.9
Pod undocumented
218 58 my ($self, $call_object, $response) = @_;
219  
220 58 $call_object = $call_object->meta->name;
221  
222 58 ▶ my $returns = (defined $call_object->_returns) && ($call_object->_returns ne 'Paws::API::Response');
Condition66%2/3
defined $call_object->_returns && $call_object->_returns ne 'Paws::API::Response'
!ll&&!rl&&r
0850
MC/DC50%1/2
defined $call_object->_returns && $call_object->_returns ne 'Paws::API::Response'
defined $call_object->_returns $call_object->_returns ne 'Paws::API::Response'
Truth table66%2/3
A && B
A= defined $call_object->_returnsB= $call_object->_returns ne 'Paws::API::Response'
ABresult
0X0
100
111
223 58 ▶ my $ret_class = $returns ? $call_object->_returns : 'Paws::API::Response';
Branch: 1 branch
BranchTrueFalseTotal
$returns ? : 50 8 58
224 58 Paws->load_class($ret_class);
225  
226 58 my $headers = $response->headers;
227 58 ▶ my $request_id = $headers->{'x-amz-request-id'} || $headers->{'x-amzn-requestid'};
Condition100%3/3
$headers->{'x-amz-request-id'} || $headers->{'x-amzn-requestid'}
l!l&&r!l&&!r
231223
MC/DC100%2/2
$headers->{'x-amz-request-id'} || $headers->{'x-amzn-requestid'}
$headers->{'x-amz-request-id'} $headers->{'x-amzn-requestid'}
Truth table100%3/3
A || B
A= $headers->{'x-amz-request-id'}B= $headers->{'x-amzn-requestid'}
ABresult
1X1
011
000
228 # AWS has sent duplicate headers x-amx-request-id headers on some services. See issue 324 for more info
229 58 ▶ $request_id = (ref($request_id) eq 'ARRAY') ? $request_id->[0] : $request_id;
Branch: 1 branch
BranchTrueFalseTotal
ref $request_id eq 'ARRAY' ? : 2 56 58
230
231 58 ▶ return Paws::API::Response->new(_request_id => $request_id) if (not $returns);
Branch: 1 branch
BranchTrueFalseTotal
unless $returns 8 50 58
232  
233 50 my $unserialized_struct = $self->unserialize_response( $response );
234 49 $unserialized_struct->{ _request_id } = $request_id;
235 49 my $o_result = $self->new_from_result_struct($call_object->_returns, $unserialized_struct);
236 49 return $o_result;
237 }
238  
239 13 1;
« blib/lib/Paws/ApiGateway.pm ↑ Summary blib/lib/Paws/Net/XMLResponse.pm »