Rakuten/Utils.pm

filter: Statementstmt 100% 10 / 10 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod 100% 1 / 1 totaltotal 95.4% 21 / 22 CC 7 SCAR 19.5
CC
7
Cov
95%
turn_empty_hashrefs_into_empty_strings
7.0
CRAP 7.0
« Rakuten.pm ↑ Summary Rakuten/Response.pm »
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
BranchTrueFalseTotal
unless $hashref 2 3 5
33 3 ▶ die "Argument must be an hashref" unless ref($hashref) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hashref eq "HASH" 0 3 3
34 3 foreach my $k (keys %$hashref) {
35 7 ▶ if (my $ref = ref($hashref->{$k})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = ref $hashref->{$k}) 5 2 7
36 5 ▶ if ($ref eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref eq "HASH") 4 1 5
37 4 ▶ if (!%{$hashref->{$k}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%{$hashref->{$k};}) 1 3 4
38 1 $hashref->{$k} = '';
39 }
40 }
41 }
42 }
43 }
44  
45  
46  
47 5 1;
« Rakuten.pm ↑ Summary Rakuten/Response.pm »