blib/lib/Paws/Net/RestXMLResponse.pm

filter: Statementstmt 61.4% 99 / 161 Branchbran 47.4% 55 / 116 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 6 totaltotal 56.2% 171 / 304 CC 62 SCAR 43.8
CC
62
Cov
56%
new_from_result_struct
112.1
handle_response_strtonativemap
72.0
handle_response_strtoobjmap
56.0
CRAP 79.5
« blib/lib/Paws/API/Caller.pm ↑ Summary blib/lib/Paws/SSM.pm »
1 package Paws::Net::RestXMLResponse;
2 17 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 17 with 'Paws::Net::ResponseRole';
4 17 ▶ use XML::Simple qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶ use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶ use Paws::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 79 ▶ sub unserialize_response {
Subroutine unserialize_response: called CC=4 SCAR=13.9
Pod undocumented
10 79 my ($self, $response) = @_;
11  
12 79 my $data = $response->content;
13 79 ▶ return Paws::Exception->new(
Branch: 1 branch
BranchTrueFalseTotal
if not defined $data or $data eq "" 6 73 79
Condition66%2/3
not defined $data or $data eq ""
l!l&&r!l&&!r
0673
MC/DC50%1/2
not defined $data or $data eq ""
not defined $data $data eq ""
Truth table66%2/3
not(A) or B
A= not defined $dataB= $data eq ""
ABresult
1X1
011
000
14 message => $@,
15 code => 'InvalidContent',
16 request_id => '', #$request_id,
17 http_status => $response->status,
18 ) if (not defined $data or $data eq '');
19
20 73 my $xml = XML::Simple->new(
21 ForceArray => qr/^(?:^item$|Errors)/i,
22 KeyAttr => '',
23 SuppressEmpty => undef,
24 );
25 73 my $struct = eval { $xml->parse_string($data) };
26 73 ▶ if ($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 2 71 73
27 2 return Paws::Exception->new(
28 message => $@,
29 code => 'InvalidContent',
30 request_id => '', #$request_id,
31 http_status => $response->status,
32 );
33 }
34  
35 71 return $struct;
36 }
37  
38 84 ▶ sub process {
Subroutine process: called CC=2 SCAR=6.9
Pod undocumented
39 84 my ($self, $call_object, $response) = @_;
40  
41 84 ▶ if ( $response->status >= 300 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->status >= 300) { } 9 75 84
42 9 return $self->error_to_exception($call_object, $response);
43 } else {
44 75 return $self->response_to_object($call_object, $response);
45 }
46 }
47  
48 9 ▶ sub error_to_exception {
Subroutine error_to_exception: called CC=4 SCAR=16.5
Pod undocumented
49 9 my ($self, $call_object, $response) = @_;
50  
51 9 my $struct = eval { $self->unserialize_response( $response ) };
52  
53 9 my ($message, $code, $request_id, $host_id);
54  
55 9 $message = status_message($response->status);
56 9 $code = $response->status;
57  
58 9 ▶ if (exists $struct->{RequestId}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $struct->{'RequestId'}) { } 9 0 9
elsif (exists $struct->{'RequestID'}) { } 0 0 0
elsif ($response->has_header('x-amzn-requestid')) { } 0 0 0
59 9 $request_id = $struct->{RequestId};
60 } elsif (exists $struct->{RequestID}){
61 0 $request_id = $struct->{RequestID};
62 } elsif ($response->has_header('x-amzn-requestid')) {
63 0 $request_id = $response->header('x-amzn-requestid');
64 } else {
65 0 $request_id = '';
66 }
67 9 $host_id = $response->header('x-amz-id-2');
68  
69 9 Paws::Exception->new(
70 message => $message,
71 code => $code,
72 request_id => $request_id,
73 host_id => $host_id,
74 http_status => $response->status,
75 );
76 }
77  
78 0 ▶ sub handle_response_strtonativemap {
Subroutine handle_response_strtonativemap: not called CC=8 SCAR=42.8
Pod undocumented
79 0 my ($self, $att_class, $value) = @_;
80 0 my $xml_keys = $att_class->xml_keys;
81 0 my $xml_values = $att_class->xml_values;
82  
83 0 my $value_ref = ref($value);
84 0 ▶ if ($value_ref eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value_ref eq "HASH") 0 0 0
85 0 ▶ if (exists $value->{ member }) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $value->{'member'}) { } 0 0 0
elsif (exists $value->{'entry'}) { } 0 0 0
elsif (keys %$value == 1) { } 0 0 0
86 0 $value = $value->{ member };
87 } elsif (exists $value->{ entry }) {
88 0 $value = $value->{ entry };
89 } elsif (keys %$value == 1) {
90 0 $value = $value->{ (keys %$value)[0] };
91 } else {
92 #die "Can't detect the item that has the array in the response hash";
93 }
94 0 $value_ref = ref($value);
95 }
96
97 0 my $inner_class = $att_class->meta->get_attribute('Map')->type_constraint->name;
98 0 ($inner_class) = ($inner_class =~ m/\[(.*)\]$/);
99 0 Paws->load_class("$inner_class");
100  
101 0 ▶ if ($value_ref eq 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if ($value_ref eq 'ARRAY') { } 0 0 0
elsif ($value_ref eq 'HASH') { } 0 0 0
elsif (not defined $value) { } 0 0 0
102 0 return $att_class->new(Map => { map { ( $_->{ $xml_keys } => $self->new_from_result_struct($inner_class, $_->{ $xml_values }) ) } @$value } );
103 } elsif ($value_ref eq 'HASH') {
104 0 return $att_class->new(Map => { $value->{ $xml_keys } => $self->new_from_result_struct($inner_class, $value->{ $xml_values }) });
105 } elsif (not defined $value){
106 0 return $att_class->new(Map => {});
107 }
108 }
109  
110 0 ▶ sub handle_response_strtoobjmap {
Subroutine handle_response_strtoobjmap: not called CC=7 SCAR=40.3
Pod undocumented
111 0 my ($self, $att_class, $value) = @_;
112 0 my $xml_keys = $att_class->xml_keys;
113 0 my $xml_values = $att_class->xml_values;
114  
115 0 my $value_ref = ref($value);
116 0 ▶ if ($value_ref eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value_ref eq "HASH") 0 0 0
117 0 ▶ if (exists $value->{ member }) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $value->{'member'}) { } 0 0 0
elsif (exists $value->{'entry'}) { } 0 0 0
elsif (keys %$value == 1) { } 0 0 0
118 0 $value = $value->{ member };
119 } elsif (exists $value->{ entry }) {
120 0 $value = $value->{ entry };
121 } elsif (keys %$value == 1) {
122 0 $value = $value->{ (keys %$value)[0] };
123 } else {
124 #die "Can't detect the item that has the array in the response hash";
125 }
126 0 $value_ref = ref($value);
127 }
128
129 0 ▶ if ($value_ref eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($value_ref eq 'ARRAY') { } 0 0 0
elsif ($value_ref eq 'HASH') { } 0 0 0
130 0 return $att_class->new(Map => { map { ( $_->{ $xml_keys } => $_->{ $xml_values } ) } @$value } );
131 } elsif ($value_ref eq 'HASH') {
132 0 return $att_class->new(Map => { $value->{ $xml_keys } => $value->{ $xml_values } } );
133 }
134 }
135  
136 4082 ▶ sub new_from_result_struct {
Subroutine new_from_result_struct: called CC=42 SCAR=47.2
Pod undocumented
137 4082 my ($self, $class, $result) = @_;
138 4082 my %args;
139
140 4082 ▶ if ($class->does('Paws::API::StrToObjMapParser')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class->does('Paws::API::StrToObjMapParser')) { } 0 4082 4082
elsif ($class->does('Paws::API::StrToNativeMapParser')) { } 0 4082 4082
141 0 return $self->handle_response_strtoobjmap($class, $result);
142 } elsif ($class->does('Paws::API::StrToNativeMapParser')) {
143 0 return $self->handle_response_strtonativemap($class, $result);
144 } else {
145 4082 foreach my $att ($class->meta->get_attribute_list) {
146 17276 ▶ next if (not my $meta = $class->meta->get_attribute($att));
Branch: 1 branch
BranchTrueFalseTotal
unless my $meta = $class->meta->get_attribute($att) 0 17276 17276
147  
148 17276 ▶ my $key = $meta->does('NameInRequest') ? $meta->request_name :
Branch: 2 branches
BranchTrueFalseTotal
$meta->does('NameInRequest') ? : 20 17256 17276
$meta->does('ParamInHeader') ? : 165 17091 17256
149 $meta->does('ParamInHeader') ? lc($meta->header_name) : $att;
150  
151 17276 my $att_type = $meta->type_constraint;
152 17276 my $att_is_required = $meta->is_required;
153  
154 # use Data::Dumper;
155 # print STDERR "USING KEY: $key\n";
156 # print STDERR "$att IS A '$att_type' TYPE\n";
157 # print STDERR "VALUE: " . Dumper($result);
158 # my $extracted_val = $result->{ $key };
159 # print STDERR "RESULT >>> $extracted_val\n";
160  
161 # Free-form paramaters passed in the HTTP headers
162 17276 ▶ if ($meta->does('Paws::API::Attribute::Trait::ParamInHeaders')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($meta->does('Paws::API::Attribute::Trait::ParamInHeaders')) { } 2 17274 17276
elsif (not $att_type =~ /\[.*\]$/) { } 17177 97 17274
elsif (my($type) = $att_type =~ /^ArrayRef\[(.*)\]$/) { } 97 0 97
163 2 Paws->load_class("$att_type");
164 2 my $att_class = $att_type->class;
165 2 my $header_prefix = $meta->header_prefix;
166 2 my @metadata_headers = map { my ($h, $nometa) = ($_, $_); $nometa =~ s/^$header_prefix//; [ $h, $nometa ] } grep /^$header_prefix/, keys %{$result};
167 2 $args{ $att } = $att_class->new( Map => { map { $_->[1] => $result->{$_->[0]} } @metadata_headers } );
168 }
169 # We'll consider that an attribute without brackets [] isn't an array type
170 elsif ($att_type !~ m/\[.*\]$/) {
171 17177 my $value = $result->{ $key };
172 17177 my $value_ref = ref($value);
173  
174 17177 ▶ if ($att_type =~ m/\:\:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($att_type =~ /\:\:/) { } 1842 15335 17177
175 # Make the att_type stringify for module loading
176 1842 Paws->load_class("$att_type");
177 1842 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 930 912 1842
178 930 ▶ if (not $value_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $value_ref) { } 0 930 930
179 0 $args{ $att } = $value;
180 } else {
181 930 my $att_class = $att_type->class;
182  
183 930 ▶ if ($att_class->does('Paws::API::StrToObjMapParser')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($att_class->does('Paws::API::StrToObjMapParser')) { } 0 930 930
elsif ($att_class->does('Paws::API::StrToNativeMapParser')) { } 0 930 930
elsif ($att_class->does('Paws::API::MapParser')) { } 0 930 930
184 0 $args{ $att } = $self->handle_response_strtoobjmap($att_class, $value);
185 } elsif ($att_class->does('Paws::API::StrToNativeMapParser')) {
186 0 $args{ $att } = $self->handle_response_strtonativemap($att_class, $value);
187 } elsif ($att_class->does('Paws::API::MapParser')) {
188 0 my $xml_keys = $att_class->xml_keys;
189 0 my $xml_values = $att_class->xml_values;
190  
191 #TODO: handle in one place
192 0 ▶ if ($value_ref eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value_ref eq "HASH") 0 0 0
193 0 ▶ if (exists $value->{ member }) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $value->{'member'}) { } 0 0 0
elsif (exists $value->{'entry'}) { } 0 0 0
elsif (keys %$value == 1) { } 0 0 0
194 0 $value = $value->{ member };
195 } elsif (exists $value->{ entry }) {
196 0 $value = $value->{ entry };
197 } elsif (keys %$value == 1) {
198 0 $value = $value->{ (keys %$value)[0] };
199 } else {
200 # Force it to be an arrayref and hope it is processed correctly
201 0 $value = [ $value ];
202 }
203 0 $value_ref = ref($value);
204 }
205  
206  
207 0 $args{ $att } = $att_class->new(map { ($_->{ $xml_keys } => $_->{ $xml_values }) } @$value);
208 } else {
209 930 $args{ $att } = $self->new_from_result_struct($att_class, $value);
210 }
211 }
212 } else {
213 ##########
214 # This loop is required to guard against cases (such as Paws::S3::CopyObject) where
215 # the root node is removed from the response when unserialising (see KeepRoot => 1 for
216 # XML::Simple) but is required to create the Paws object. This is mostly due to the
217 # implementation of the new_from_result_struct sub
218 912 my $att_class = $att_type->class;
219 eval {
220 912 $args{ $att } = $self->new_from_result_struct($att_class, $result);
221 912 1;
222 912 ▶ } or do {}
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $args{$att} = $self->new_from_result_struct($att_class, $result); 1 } } or do { () } 912 0 912
223 }
224 } else {
225 15335 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 12052 3283 15335
226 12052 ▶ if ($att_type eq 'Bool') {
Branch: 1 branch
BranchTrueFalseTotal
if ($att_type eq 'Bool') { } 54 11998 12052
227 54 ▶ if ($value eq 'true') {
Branch: 3 branches
BranchTrueFalseTotal
if ($value eq 'true') { } 28 26 54
elsif ($value eq 'false') { } 26 0 26
elsif ($value == 1) { } 0 0 0
228 28 $args{ $att } = 1;
229 } elsif ($value eq 'false') {
230 26 $args{ $att } = 0;
231 } elsif ($value == 1) {
232 0 $args{ $att } = 1;
233 } else {
234 0 $args{ $att } = 0;
235 }
236 } else {
237 11998 $args{ $att } = $value;
238 }
239 }
240 }
241 } elsif (my ($type) = ($att_type =~ m/^ArrayRef\[(.*)\]$/)) {
242 97 my $value = $result->{ $att };
243 97 ▶ $value = $result->{ $key } if (not defined $value and $key ne $att);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value and $key ne $att 10 87 97
Condition100%3/3
not defined $value and $key ne $att
!ll&&!rl&&r
474010
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
244 97 my $value_ref = ref($value);
245  
246 97 ▶ if ($value_ref eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value_ref eq "HASH") 12 85 97
247 12 ▶ if (exists $value->{ member }) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $value->{'member'}) { } 0 12 12
elsif (exists $value->{'entry'}) { } 0 12 12
elsif (keys %$value == 1) { } 9 3 12
248 0 $value = $value->{ member };
249 } elsif (exists $value->{ entry }) {
250 0 $value = $value->{ entry };
251 } elsif (keys %$value == 1) {
252 9 $value = $value->{ (keys %$value)[0] };
253 } else {
254 #die "Can't detect the item that has the array in the response hash";
255 }
256 12 $value_ref = ref($value);
257 }
258
259 97 ▶ if ($type =~ m/\:\:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /\:\:/) { } 96 1 97
260 96 Paws->load_class($type);
261  
262 96 my $val;
263 96 ▶ if (not defined $value) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $value) { } 44 52 96
elsif ($value_ref eq 'ARRAY') { } 45 7 52
elsif ($value_ref eq 'HASH') { } 7 0 7
264 44 $val = [ ];
265 } elsif ($value_ref eq 'ARRAY') {
266 45 $val = $value;
267 } elsif ($value_ref eq 'HASH') {
268 7 $val = [ $value ];
269 }
270  
271 96 ▶ if ($type->does('Paws::API::StrToObjMapParser')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type->does('Paws::API::StrToObjMapParser')) { } 0 96 96
elsif ($type->does('Paws::API::StrToNativeMapParser')) { } 0 96 96
elsif ($type->does('Paws::API::MapParser')) { } 0 96 96
272 0 $args{ $att } = [ map { $self->handle_response_strtoobjmap($type, $_) } @$val ];
273 } elsif ($type->does('Paws::API::StrToNativeMapParser')) {
274 0 $args{ $att } = [ map { $self->handle_response_strtonativemap($type, $_) } @$val ];
275 } elsif ($type->does('Paws::API::MapParser')) {
276 0 die "MapParser Type in an Array. Please implement me";
277 } else {
278 96 $args{ $att } = [ map { $self->new_from_result_struct($type, $_) } @$val ];
279 }
280 } else {
281 1 ▶ if (defined $value){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 1 0 1
282 1 ▶ if ($value_ref eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value_ref eq 'ARRAY') { } 1 0 1
283 1 $args{ $att } = $value;
284 } else {
285 0 $args{ $att } = [ $value ];
286 }
287 } else {
288 0 ▶ $args{ $att } = [] if ($att_is_required);
Branch: 1 branch
BranchTrueFalseTotal
if $att_is_required 0 0 0
289 }
290 }
291 }
292 }
293 4082 $class->new(%args);
294 }
295 }
296  
297  
298 17 1;
« blib/lib/Paws/API/Caller.pm ↑ Summary blib/lib/Paws/SSM.pm »