| 1 | package Marketplace::Rakuten::Utils; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Marketplace::Rakuten::Utils | ||||||||||
| 6 | |||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||
| 8 | |||||||||||
| 9 | Common routines for the L<Marketplace::Rakuten> classes. | ||||||||||
| 10 | |||||||||||
| 11 | =head1 EXPORTS | ||||||||||
| 12 | |||||||||||
| 13 | None. You have to call the full name of the functions, e.g. | ||||||||||
| 14 | |||||||||||
| 15 | Marketplace::Rakuten::Utils::turn_empty_hashrefs_into_empty_strings($data) | ||||||||||
| 16 | |||||||||||
| 17 | =head1 FUNCTIONS | ||||||||||
| 18 | |||||||||||
| 19 | =head2 turn_empty_hashrefs_into_empty_strings | ||||||||||
| 20 | |||||||||||
| 21 | The module used for the XML parsing, L<XML::LibXML::Simple>, doesn't | ||||||||||
| 22 | ignore empty tags, but instead return an empty hashref. With this | ||||||||||
| 23 | function (which doesn't recurse for deeper structures), the hashref | ||||||||||
| 24 | passed as argument will be modified to consider and empty hashref as | ||||||||||
| 25 | an empty string. | ||||||||||
| 26 | |||||||||||
| 27 | =cut | ||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | sub turn_empty_hashrefs_into_empty_strings { | ||||||||||
| 31 | 5 | ▶ | my ($hashref) = @_; | ||||||||
|
Subroutine
turn_empty_hashrefs_into_empty_strings: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||
| 32 | 5 | ▶ | die "Missing argument" unless $hashref; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 3 | ▶ | die "Argument must be an hashref" unless ref($hashref) eq 'HASH'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 3 | foreach my $k (keys %$hashref) { | |||||||||
| 35 | 7 | ▶ | if (my $ref = ref($hashref->{$k})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 5 | ▶ | if ($ref eq 'HASH') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 4 | ▶ | if (!%{$hashref->{$k}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 1 | $hashref->{$k} = ''; | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | } | ||||||||||
| 42 | } | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | 5 | 1; | |||||||||