1
1
package Paws::Net::XMLResponse ;
2
2
use Moose;
3
- use XML::Hash::XS qw/ / ;
3
+ use XML::Hash::XS 0.54 qw/ / ; # 0.54 introduces suppress_empty option
4
4
5
5
use Carp qw( croak) ;
6
6
use Paws::Exception;
@@ -9,15 +9,15 @@ package Paws::Net::XMLResponse;
9
9
default => sub {
10
10
return XML::Hash::XS-> new(
11
11
force_array => qr / ^(?:item|Errors)/ i ,
12
- # SuppressEmpty => undef,
12
+ suppress_empty => undef ,
13
13
);
14
14
}
15
15
);
16
16
17
17
sub unserialize_response {
18
18
my ($self , $response ) = @_ ;
19
19
20
- if (not defined $response -> content or $response -> content eq ' ' ) {
20
+ if (not defined $response -> content or $response -> content eq ' ' ) {
21
21
return Paws::Exception-> new(
22
22
message => ' HTTP error with no body in HTTP response' ,
23
23
code => ' InvalidContent' ,
@@ -27,7 +27,6 @@ package Paws::Net::XMLResponse;
27
27
}
28
28
29
29
my $struct = eval { $self -> _xml_parser-> xml2hash($response -> content) };
30
- $struct = _emulate_xml_simple_supress_empty($struct );
31
30
if ($@ ){
32
31
return Paws::Exception-> throw(
33
32
message => $@ ,
@@ -39,20 +38,6 @@ package Paws::Net::XMLResponse;
39
38
return $struct ;
40
39
}
41
40
42
- sub _emulate_xml_simple_supress_empty {
43
- my ($struct ) = @_ ;
44
- return undef unless $struct ;
45
- foreach (keys %$struct ) {
46
- if (ref $struct -> {$_ } eq ' HASH' ) {
47
- _emulate_xml_simple_supress_empty($struct -> {$_ })
48
- }
49
- elsif (defined $struct -> {$_ } && $struct -> {$_ } eq ' ' ) {
50
- $struct -> {$_ } = undef ;
51
- }
52
- }
53
- return $struct ;
54
- }
55
-
56
41
sub process {
57
42
my ($self , $call_object , $response ) = @_ ;
58
43
@@ -68,7 +53,7 @@ package Paws::Net::XMLResponse;
68
53
69
54
my $struct = $self -> unserialize_response( $response );
70
55
return $struct if (ref ($struct ) eq ' Paws::Exception' );
71
-
56
+
72
57
my ($code , $error , $request_id );
73
58
74
59
if (exists $struct -> {Errors }){
@@ -121,7 +106,7 @@ package Paws::Net::XMLResponse;
121
106
}
122
107
$value_ref = ref ($value );
123
108
}
124
-
109
+
125
110
if ($value_ref eq ' ARRAY' ) {
126
111
return $att_class -> new(Map => { map { ( $_ -> { $xml_keys } => $_ -> { $xml_values } ) } @$value } );
127
112
} elsif ($value_ref eq ' HASH' ) {
@@ -147,7 +132,7 @@ package Paws::Net::XMLResponse;
147
132
}
148
133
$value_ref = ref ($value );
149
134
}
150
-
135
+
151
136
my $inner_class = $att_class -> meta-> get_attribute(' Map' )-> type_constraint-> name;
152
137
($inner_class ) = ($inner_class =~ m /\[ (.*)\] $ / );
153
138
Paws-> load_class(" $inner_class " );
@@ -158,13 +143,13 @@ package Paws::Net::XMLResponse;
158
143
return $att_class -> new(Map => { $value -> { $xml_keys } => $self -> new_from_result_struct($inner_class , $value -> { $xml_values }) });
159
144
} elsif (not defined $value ){
160
145
return $att_class -> new(Map => {});
161
- }
146
+ }
162
147
}
163
148
164
149
sub new_from_result_struct {
165
150
my ($self , $class , $result ) = @_ ;
166
151
my %args ;
167
-
152
+
168
153
if ($class -> does(' Paws::API::StrToObjMapParser' )) {
169
154
return $self -> handle_response_strtoobjmap($class , $result );
170
155
} elsif ($class -> does(' Paws::API::StrToNativeMapParser' )) {
@@ -264,7 +249,7 @@ package Paws::Net::XMLResponse;
264
249
}
265
250
$value_ref = ref ($value );
266
251
}
267
-
252
+
268
253
if ($type =~ m /\:\: / ) {
269
254
Paws-> load_class($type );
270
255
@@ -289,7 +274,7 @@ package Paws::Net::XMLResponse;
289
274
} else {
290
275
if (defined $value ){
291
276
if ($value_ref eq ' ARRAY' ) {
292
- $args { $att } = $value ;
277
+ $args { $att } = $value ;
293
278
} else {
294
279
$args { $att } = [ $value ];
295
280
}
@@ -314,16 +299,16 @@ package Paws::Net::XMLResponse;
314
299
315
300
my $unserialized_struct = $self -> unserialize_response( $response );
316
301
my $headers = $response -> headers;
317
- my $request_id = $headers -> {' x-amz-request-id' }
302
+ my $request_id = $headers -> {' x-amz-request-id' }
318
303
|| $headers -> {' x-amzn-requestid' }
319
- || $unserialized_struct -> {' requestId' }
320
- || $unserialized_struct -> {' RequestId' }
304
+ || $unserialized_struct -> {' requestId' }
305
+ || $unserialized_struct -> {' RequestId' }
321
306
|| $unserialized_struct -> {' RequestID' }
322
307
|| $unserialized_struct -> { ResponseMetadata }-> { RequestId };
323
308
324
309
# AWS has sent duplicate headers x-amx-request-id headers on some services. See issue 324 for more info
325
310
$request_id = (ref ($request_id ) eq ' ARRAY' ) ? $request_id -> [0] : $request_id ;
326
-
311
+
327
312
if ($returns ){
328
313
if ($call_object -> _result_key){
329
314
$unserialized_struct = $unserialized_struct -> { $call_object -> _result_key };
0 commit comments