11package Paws::Net::XMLResponse ;
22 use Moose;
3- use XML::Hash::XS qw/ / ;
3+ use XML::Hash::XS 0.54 qw/ / ; # 0.54 introduces suppress_empty option
44
55 use Carp qw( croak) ;
66 use Paws::Exception;
@@ -9,15 +9,15 @@ package Paws::Net::XMLResponse;
99 default => sub {
1010 return XML::Hash::XS-> new(
1111 force_array => qr / ^(?:item|Errors)/ i ,
12- # SuppressEmpty => undef,
12+ suppress_empty => undef ,
1313 );
1414 }
1515 );
1616
1717 sub unserialize_response {
1818 my ($self , $response ) = @_ ;
1919
20- if (not defined $response -> content or $response -> content eq ' ' ) {
20+ if (not defined $response -> content or $response -> content eq ' ' ) {
2121 return Paws::Exception-> new(
2222 message => ' HTTP error with no body in HTTP response' ,
2323 code => ' InvalidContent' ,
@@ -27,7 +27,6 @@ package Paws::Net::XMLResponse;
2727 }
2828
2929 my $struct = eval { $self -> _xml_parser-> xml2hash($response -> content) };
30- $struct = _emulate_xml_simple_supress_empty($struct );
3130 if ($@ ){
3231 return Paws::Exception-> throw(
3332 message => $@ ,
@@ -39,20 +38,6 @@ package Paws::Net::XMLResponse;
3938 return $struct ;
4039 }
4140
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-
5641 sub process {
5742 my ($self , $call_object , $response ) = @_ ;
5843
@@ -68,7 +53,7 @@ package Paws::Net::XMLResponse;
6853
6954 my $struct = $self -> unserialize_response( $response );
7055 return $struct if (ref ($struct ) eq ' Paws::Exception' );
71-
56+
7257 my ($code , $error , $request_id );
7358
7459 if (exists $struct -> {Errors }){
@@ -121,7 +106,7 @@ package Paws::Net::XMLResponse;
121106 }
122107 $value_ref = ref ($value );
123108 }
124-
109+
125110 if ($value_ref eq ' ARRAY' ) {
126111 return $att_class -> new(Map => { map { ( $_ -> { $xml_keys } => $_ -> { $xml_values } ) } @$value } );
127112 } elsif ($value_ref eq ' HASH' ) {
@@ -147,7 +132,7 @@ package Paws::Net::XMLResponse;
147132 }
148133 $value_ref = ref ($value );
149134 }
150-
135+
151136 my $inner_class = $att_class -> meta-> get_attribute(' Map' )-> type_constraint-> name;
152137 ($inner_class ) = ($inner_class =~ m /\[ (.*)\] $ / );
153138 Paws-> load_class(" $inner_class " );
@@ -158,13 +143,13 @@ package Paws::Net::XMLResponse;
158143 return $att_class -> new(Map => { $value -> { $xml_keys } => $self -> new_from_result_struct($inner_class , $value -> { $xml_values }) });
159144 } elsif (not defined $value ){
160145 return $att_class -> new(Map => {});
161- }
146+ }
162147 }
163148
164149 sub new_from_result_struct {
165150 my ($self , $class , $result ) = @_ ;
166151 my %args ;
167-
152+
168153 if ($class -> does(' Paws::API::StrToObjMapParser' )) {
169154 return $self -> handle_response_strtoobjmap($class , $result );
170155 } elsif ($class -> does(' Paws::API::StrToNativeMapParser' )) {
@@ -264,7 +249,7 @@ package Paws::Net::XMLResponse;
264249 }
265250 $value_ref = ref ($value );
266251 }
267-
252+
268253 if ($type =~ m /\:\: / ) {
269254 Paws-> load_class($type );
270255
@@ -289,7 +274,7 @@ package Paws::Net::XMLResponse;
289274 } else {
290275 if (defined $value ){
291276 if ($value_ref eq ' ARRAY' ) {
292- $args { $att } = $value ;
277+ $args { $att } = $value ;
293278 } else {
294279 $args { $att } = [ $value ];
295280 }
@@ -314,16 +299,16 @@ package Paws::Net::XMLResponse;
314299
315300 my $unserialized_struct = $self -> unserialize_response( $response );
316301 my $headers = $response -> headers;
317- my $request_id = $headers -> {' x-amz-request-id' }
302+ my $request_id = $headers -> {' x-amz-request-id' }
318303 || $headers -> {' x-amzn-requestid' }
319- || $unserialized_struct -> {' requestId' }
320- || $unserialized_struct -> {' RequestId' }
304+ || $unserialized_struct -> {' requestId' }
305+ || $unserialized_struct -> {' RequestId' }
321306 || $unserialized_struct -> {' RequestID' }
322307 || $unserialized_struct -> { ResponseMetadata }-> { RequestId };
323308
324309 # AWS has sent duplicate headers x-amx-request-id headers on some services. See issue 324 for more info
325310 $request_id = (ref ($request_id ) eq ' ARRAY' ) ? $request_id -> [0] : $request_id ;
326-
311+
327312 if ($returns ){
328313 if ($call_object -> _result_key){
329314 $unserialized_struct = $unserialized_struct -> { $call_object -> _result_key };
0 commit comments