blib/lib/Paws/Net/RestJsonResponse.pm

filter: Statementstmt 70.4% 74 / 105 Branchbran 66.2% 49 / 74 Conditioncond 57.1% 4 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 6 totaltotal 66.0% 136 / 206 CC 42 SCAR 36.0
CC
42
Cov
68%
new_from_result_struct
62.3
error_to_exception
9.2
handle_response_strtoobjmap
6.0
CRAP 36.7
« blib/lib/Paws/IAM.pm ↑ Summary blib/lib/Paws/RDS.pm »
1 package Paws::Net::RestJsonResponse;
2 10 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 with 'Paws::Net::ResponseRole';
4 10 ▶ use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶ use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶ use Paws::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 52 ▶ sub process {
Subroutine process: called CC=4 SCAR=16.6
Pod undocumented
9 52 my ($self, $call_object, $response) = @_;
10  
11 52 ▶ if ($response->has_header('x-amz-crc32')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->has_header("x-amz-crc32")) 0 52 52
12 0 require String::CRC32;
13 0 my $crc = String::CRC32::crc32($response->content);
14 0 ▶ return Paws::Exception->new(
Branch: 1 branch
BranchTrueFalseTotal
if $crc != $response->header("x-amz-crc32") 0 0 0
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 52 ▶ if ( $response->status >= 300 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->status >= 300) { } 24 28 52
22 24 return $self->error_to_exception($call_object, $response);
23 } else {
24 28 return $self->response_to_object($call_object, $response);
25 }
26 }
27
28 45 ▶ sub unserialize_response {
Subroutine unserialize_response: called CC=2 SCAR=6.9
Pod undocumented
29 45 my ($self, $response) = @_;
30  
31 45 my $struct = eval { decode_json( $response->content ) };
32 45 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 16 29 45
33 16 return Paws::Exception->throw(
34 message => $@,
35 code => 'InvalidContent',
36 request_id => '',
37 http_status => $response->status,
38 );
39 }
40 29 return $struct;
41 }
42  
43 24 ▶ sub error_to_exception {
Subroutine error_to_exception: called CC=9 SCAR=22.2
Pod undocumented
44 24 my ($self, $call_object, $response) = @_;
45
46 24 my $struct = $self->unserialize_response( $response );
47  
48 11 my ($message, $request_id, $code);
49  
50 11 ▶ $message = $struct->{message} if (exists $struct->{message});
Branch: 1 branch
BranchTrueFalseTotal
if exists $struct->{"message"} 5 6 11
51 11 ▶ $message = $struct->{Message} if (exists $struct->{Message});
Branch: 1 branch
BranchTrueFalseTotal
if exists $struct->{"Message"} 2 9 11
52 11 ▶ $message = 'Unrecognized error message format' if (not defined $message);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 5 6 11
53  
54 11 ▶ if ($response->has_header('x-amzn-errortype')){
Branch: 3 branches
BranchTrueFalseTotal
if ($response->has_header('x-amzn-errortype')) { } 4 7 11
elsif (exists $struct->{'Code'}) { } 0 7 7
elsif (exists $struct->{'code'}) { } 2 5 7
55 4 $code = (split /:/, $response->header('x-amzn-errortype'))[0];
56 } elsif (exists $struct->{Code}) {
57 0 $code = $struct->{Code};
58 } elsif (exists $struct->{ code }) {
59 2 $code = $struct->{ code };
60 } else {
61 5 $code = 'InvalidContent';
62 }
63 11 ▶ $request_id = $response->header('x-amzn-requestid') // '';
Condition50%1/2
$response->header("x-amzn-requestid") // ""
l!l
110
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
64  
65 11 ▶ Paws::Exception->new(
Condition50%1/2
$message // ""
l!l
110
MC/DC0%0/1
$message // ""
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
66 message => $message // '',
67 code => $code,
68 request_id => $request_id,
69 http_status => $response->status,
70 );
71 }
72  
73 5 ▶ sub handle_response_strtonativemap {
Subroutine handle_response_strtonativemap: called CC=2 SCAR=7.6
Pod undocumented
74 5 my ($self, $att_class, $value) = @_;
75  
76 5 ▶ if (not defined $value){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value) { } 0 5 5
77 0 return $att_class->new(Map => {});
78 } else {
79 5 return $att_class->new(Map => $value);
80 }
81 }
82  
83 0 ▶ sub handle_response_strtoobjmap {
Subroutine handle_response_strtoobjmap: not called CC=2 SCAR=17.9
Pod undocumented
84 0 my ($self, $att_class, $value) = @_;
85  
86 0 my $inner_class = $att_class->meta->get_attribute('Map')->type_constraint->name;
87 0 ($inner_class) = ($inner_class =~ m/\[(.*)\]$/);
88 0 Paws->load_class("$inner_class");
89  
90 0 ▶ if (not defined $value){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value) { } 0 0 0
91 0 return $att_class->new(Map => {});
92 } else {
93 return $att_class->new(Map => {
94 0 map { ($_ => $self->new_from_result_struct($inner_class, $value->{ $_ }) ) } keys %$value
95 });
96 }
97 }
98  
99 91 ▶ sub new_from_result_struct {
Subroutine new_from_result_struct: called CC=28 SCAR=41.3
Pod undocumented
100 91 my ($self, $class, $result) = @_;
101 91 my %args;
102
103 91 ▶ if ($class->does('Paws::API::StrToObjMapParser')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($class->does('Paws::API::StrToObjMapParser')) { } 0 91 91
elsif ($class->does('Paws::API::StrToNativeMapParser')) { } 0 91 91
104 0 return $self->handle_response_strtoobjmap($class, $result);
105 } elsif ($class->does('Paws::API::StrToNativeMapParser')) {
106 0 return $self->handle_response_strtonativemap($class, $result);
107 } else {
108 91 foreach my $att ($class->meta->get_attribute_list) {
109 609 ▶ next if (not my $meta = $class->meta->get_attribute($att));
Branch: 1 branch
BranchTrueFalseTotal
unless my $meta = $class->meta->get_attribute($att) 0 609 609
110  
111 609 ▶ my $key = $meta->does('NameInRequest') ? $meta->request_name :
Branch: 2 branches
BranchTrueFalseTotal
$meta->does('NameInRequest') ? : 0 609 609
$meta->does('ParamInHeader') ? : 10 599 609
112 $meta->does('ParamInHeader') ? lc($meta->header_name) : $att;
113  
114 609 my $att_type = $meta->type_constraint;
115  
116 # use Data::Dumper;
117 # print STDERR "USING KEY: $key\n";
118 # print STDERR "$att IS A '$att_type' TYPE\n";
119 # print STDERR "VALUE: " . Dumper($result);
120 # my $extracted_val = $result->{ $key };
121 # print STDERR "RESULT >>> $extracted_val\n";
122  
123 # We'll consider that an attribute without brackets [] isn't an array type
124 609 ▶ if ($att_type !~ m/\[.*\]$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $att_type =~ /\[.*\]$/) { } 503 106 609
elsif (my($type) = $att_type =~ /^ArrayRef\[(.*)\]$/) { } 106 0 106
125 503 my $value = $result->{ $key };
126 503 my $value_ref = ref($value);
127  
128 503 ▶ if ($att_type =~ m/\:\:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($att_type =~ /\:\:/) { } 70 433 503
129 # Make the att_type stringify for module loading
130 70 Paws->load_class("$att_type");
131 70 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 22 48 70
132 22 ▶ if (not $value_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $value_ref) { } 0 22 22
133 0 $args{ $att } = $value;
134 } else {
135 22 my $att_class = $att_type->class;
136  
137 22 ▶ if ($att_class->does('Paws::API::StrToObjMapParser')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($att_class->does('Paws::API::StrToObjMapParser')) { } 0 22 22
elsif ($att_class->does('Paws::API::StrToNativeMapParser')) { } 5 17 22
elsif ($att_class->does('Paws::API::MapParser')) { } 0 17 17
138 0 $args{ $att } = $self->handle_response_strtoobjmap($att_class, $value);
139 } elsif ($att_class->does('Paws::API::StrToNativeMapParser')) {
140 5 $args{ $att } = $self->handle_response_strtonativemap($att_class, $value);
141 } elsif ($att_class->does('Paws::API::MapParser')) {
142 0 my $xml_keys = $att_class->xml_keys;
143 0 my $xml_values = $att_class->xml_values;
144  
145 0 $args{ $att } = $att_class->new(map { ($_->{ $xml_keys } => $_->{ $xml_values }) } @$value);
146 } else {
147 17 $args{ $att } = $self->new_from_result_struct($att_class, $value);
148 }
149 }
150 }
151 } else {
152 433 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 373 60 433
153 373 ▶ if ($att_type eq 'Bool') {
Branch: 1 branch
BranchTrueFalseTotal
if ($att_type eq 'Bool') { } 24 349 373
154 24 ▶ if ($value eq 'true') {
Branch: 3 branches
BranchTrueFalseTotal
if ($value eq 'true') { } 12 12 24
elsif ($value eq 'false') { } 12 0 12
elsif ($value == 1) { } 0 0 0
155 12 $args{ $att } = 1;
156 } elsif ($value eq 'false') {
157 12 $args{ $att } = 0;
158 } elsif ($value == 1) {
159 0 $args{ $att } = 1;
160 } else {
161 0 $args{ $att } = 0;
162 }
163 } else {
164 349 $args{ $att } = $value;
165 }
166 }
167 }
168 } elsif (my ($type) = ($att_type =~ m/^ArrayRef\[(.*)\]$/)) {
169 106 my $value = $result->{ $att };
170 106 ▶ $value = $result->{ $key } if (not defined $value and $key ne $att);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value and $key ne $att 0 106 106
Condition66%2/3
not defined $value and $key ne $att
!ll&&!rl&&r
8980
MC/DC0%0/2
not defined $value and $key ne $att
not defined $value $key ne $att
Truth table66%2/3
not(A) and B
A= not defined $valueB= $key ne $att
ABresult
0X0
100
111
171 106 my $value_ref = ref($value);
172  
173 106 ▶ if ($type =~ m/\:\:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /\:\:/) { } 10 96 106
174 10 Paws->load_class($type);
175  
176 10 ▶ if ($type->does('Paws::API::StrToObjMapParser')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type->does('Paws::API::StrToObjMapParser')) { } 0 10 10
elsif ($type->does('Paws::API::StrToNativeMapParser')) { } 0 10 10
elsif ($type->does('Paws::API::MapParser')) { } 0 10 10
177 0 $args{ $att } = [ map { $self->handle_response_strtoobjmap($type, $_) } @$value ];
178 } elsif ($type->does('Paws::API::StrToNativeMapParser')) {
179 0 $args{ $att } = [ map { $self->handle_response_strtonativemap($type, $_) } @$value ];
180 } elsif ($type->does('Paws::API::MapParser')) {
181 0 die "MapParser Type in an Array. Please implement me";
182 } else {
183 10 $args{ $att } = [ map { $self->new_from_result_struct($type, $_) } @$value ];
184 }
185 } else {
186 96 ▶ if (defined $value){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 0 96 96
187 0 ▶ if ($value_ref eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($value_ref eq 'ARRAY') { } 0 0 0
188 0 $args{ $att } = $value;
189 } else {
190 0 $args{ $att } = [ $value ];
191 }
192 }
193 }
194 }
195 }
196 91 $class->new(%args);
197 }
198 }
199  
200 10 1;
« blib/lib/Paws/IAM.pm ↑ Summary blib/lib/Paws/RDS.pm »