Skip to content

Commit 8e66cc9

Browse files
committed
Use XML::Hash::XS with native suppress_empty support
1 parent 6c76619 commit 8e66cc9

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

cpanfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ requires 'Data::Compare';
77
requires 'URI';
88
requires 'Net::Amazon::Signature::V4';
99
requires 'JSON::MaybeXS';
10-
requires 'XML::Hash::XS';
10+
requires 'XML::Hash::XS', '>= 0.54'; # 0.54 introduces suppress_empty option
1111
requires 'IO::Socket::SSL';
1212
requires 'DateTime';
1313
requires 'DateTime::Format::ISO8601';

lib/Paws/Net/RestXMLResponse.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package Paws::Net::RestXMLResponse;
22
use Moose;
3-
use XML::Hash::XS qw//;
3+
use XML::Hash::XS 0.54 qw//; # 0.54 introduces suppress_empty option
44
use Carp qw(croak);
55
use HTTP::Status;
66
use Paws::Exception;
@@ -12,6 +12,7 @@ package Paws::Net::RestXMLResponse;
1212

1313
my $xml = XML::Hash::XS->new(
1414
force_array => qr/^(?:item|Errors)/i,
15+
suppress_empty => undef,
1516
);
1617
return $xml->xml2hash($data);
1718
}

lib/Paws/Net/XMLResponse.pm

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package 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,7 +9,7 @@ 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
);
@@ -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

0 commit comments

Comments
 (0)