From 6c7661961806a7319b500eb715d43bd6b26345db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slobodan=20Mi=C5=A1kovi=C4=87?= Date: Thu, 26 Dec 2019 11:41:32 -0800 Subject: [PATCH 1/2] Emulate XML::Simple SuppressEmpty option --- lib/Paws/Net/XMLResponse.pm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/Paws/Net/XMLResponse.pm b/lib/Paws/Net/XMLResponse.pm index 11c4a54103..60d792d81b 100644 --- a/lib/Paws/Net/XMLResponse.pm +++ b/lib/Paws/Net/XMLResponse.pm @@ -9,6 +9,7 @@ package Paws::Net::XMLResponse; default => sub { return XML::Hash::XS->new( force_array => qr/^(?:item|Errors)/i, + # SuppressEmpty => undef, ); } ); @@ -26,6 +27,7 @@ package Paws::Net::XMLResponse; } my $struct = eval { $self->_xml_parser->xml2hash($response->content) }; + $struct = _emulate_xml_simple_supress_empty($struct); if ($@){ return Paws::Exception->throw( message => $@, @@ -37,6 +39,20 @@ package Paws::Net::XMLResponse; return $struct; } + sub _emulate_xml_simple_supress_empty { + my ($struct) = @_; + return undef unless $struct; + foreach (keys %$struct) { + if (ref $struct->{$_} eq 'HASH') { + _emulate_xml_simple_supress_empty($struct->{$_}) + } + elsif (defined $struct->{$_} && $struct->{$_} eq '') { + $struct->{$_} = undef; + } + } + return $struct; + } + sub process { my ($self, $call_object, $response) = @_; From 8e66cc9567b86e516981831d6c62c651487c4cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Slobodan=20Mi=C5=A1kovi=C4=87?= Date: Sat, 28 Dec 2019 14:11:44 -0800 Subject: [PATCH 2/2] Use XML::Hash::XS with native suppress_empty support --- cpanfile | 2 +- lib/Paws/Net/RestXMLResponse.pm | 3 ++- lib/Paws/Net/XMLResponse.pm | 19 ++----------------- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/cpanfile b/cpanfile index b81abe1c5c..fb58c3e4cf 100644 --- a/cpanfile +++ b/cpanfile @@ -7,7 +7,7 @@ requires 'Data::Compare'; requires 'URI'; requires 'Net::Amazon::Signature::V4'; requires 'JSON::MaybeXS'; -requires 'XML::Hash::XS'; +requires 'XML::Hash::XS', '>= 0.54'; # 0.54 introduces suppress_empty option requires 'IO::Socket::SSL'; requires 'DateTime'; requires 'DateTime::Format::ISO8601'; diff --git a/lib/Paws/Net/RestXMLResponse.pm b/lib/Paws/Net/RestXMLResponse.pm index 92ab6e8130..cf1077e78f 100644 --- a/lib/Paws/Net/RestXMLResponse.pm +++ b/lib/Paws/Net/RestXMLResponse.pm @@ -1,6 +1,6 @@ package Paws::Net::RestXMLResponse; use Moose; - use XML::Hash::XS qw//; + use XML::Hash::XS 0.54 qw//; # 0.54 introduces suppress_empty option use Carp qw(croak); use HTTP::Status; use Paws::Exception; @@ -12,6 +12,7 @@ package Paws::Net::RestXMLResponse; my $xml = XML::Hash::XS->new( force_array => qr/^(?:item|Errors)/i, + suppress_empty => undef, ); return $xml->xml2hash($data); } diff --git a/lib/Paws/Net/XMLResponse.pm b/lib/Paws/Net/XMLResponse.pm index 60d792d81b..0e70601d7a 100644 --- a/lib/Paws/Net/XMLResponse.pm +++ b/lib/Paws/Net/XMLResponse.pm @@ -1,6 +1,6 @@ package Paws::Net::XMLResponse; use Moose; - use XML::Hash::XS qw//; + use XML::Hash::XS 0.54 qw//; # 0.54 introduces suppress_empty option use Carp qw(croak); use Paws::Exception; @@ -9,7 +9,7 @@ package Paws::Net::XMLResponse; default => sub { return XML::Hash::XS->new( force_array => qr/^(?:item|Errors)/i, - # SuppressEmpty => undef, + suppress_empty => undef, ); } ); @@ -27,7 +27,6 @@ package Paws::Net::XMLResponse; } my $struct = eval { $self->_xml_parser->xml2hash($response->content) }; - $struct = _emulate_xml_simple_supress_empty($struct); if ($@){ return Paws::Exception->throw( message => $@, @@ -39,20 +38,6 @@ package Paws::Net::XMLResponse; return $struct; } - sub _emulate_xml_simple_supress_empty { - my ($struct) = @_; - return undef unless $struct; - foreach (keys %$struct) { - if (ref $struct->{$_} eq 'HASH') { - _emulate_xml_simple_supress_empty($struct->{$_}) - } - elsif (defined $struct->{$_} && $struct->{$_} eq '') { - $struct->{$_} = undef; - } - } - return $struct; - } - sub process { my ($self, $call_object, $response) = @_;