Skip to content

Commit

Permalink
Use XML::Hash::XS with native suppress_empty support
Browse files Browse the repository at this point in the history
  • Loading branch information
slobo committed Dec 28, 2019
1 parent 6c76619 commit 8793b83
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 has suppress_empty support
requires 'IO::Socket::SSL';
requires 'DateTime';
requires 'DateTime::Format::ISO8601';
Expand Down
19 changes: 2 additions & 17 deletions lib/Paws/Net/XMLResponse.pm
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
);
}
);
Expand All @@ -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 => $@,
Expand All @@ -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) = @_;

Expand Down

0 comments on commit 8793b83

Please sign in to comment.