lib/WebService/Braintree/Util.pm

filter: Statementstmt 100% 43 / 43 Branchbran 100% 14 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 6 totaltotal 92.5% 74 / 80 CC 10 SCAR 8.1
CC
10
Cov
100%
__flatten
3.0
to_instance_array
3.0
is_not_empty
3.0
CRAP 2.2
« lib/WebService/Braintree/UsBankAccountGateway.pm ↑ Summary lib/WebService/Braintree/_/MasterpassCard.pm »
1 # vim: sw=4 ts=4 ft=perl
2  
3 package # hide from pause
4 WebService::Braintree::Util;
5  
6 22 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 22 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 our @ISA = qw(Exporter);
11  
12 22 our @EXPORT_OK = qw(
13 hash_to_query_string
14 to_instance_array
15 is_not_empty validate_id
16 is_arrayref is_hashref
17 );
18  
19 22 ▶use URI::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # USED by ::TransparentRedirectGateway->build_tr_data and
22 # ::TestHelper->simulate_form_post_for_tr
23 4 ▶sub hash_to_query_string {
Subroutine hash_to_query_string: called CC=1 SCAR=0.0
Pod undocumented
24 4 my $query = URI::Query->new(__flatten(shift));
25 4 return $query->stringify();
26 }
27  
28 # USED only by __hash_to_query_string()
29 16 ▶sub __flatten {
Subroutine __flatten: called CC=3 SCAR=11.0
30 16 my($hash, $namespace) = @_;
31 16 my %flat_hash = ();
32 16 ▶ while (my ($key, $value) = each(%$hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$hash) 36 16 52
33 36 ▶ if (is_hashref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_hashref($value)) { } 7 29 36
34 7 my $sub_entries = __flatten($value, __add_namespace($key, $namespace));
35 7 %flat_hash = (%flat_hash, %$sub_entries);
36 } else {
37 29 $flat_hash{__add_namespace($key, $namespace)} = $value;
38 }
39 }
40 16 return \%flat_hash;
41 }
42  
43 # USED only by __flatten()
44 36 ▶sub __add_namespace {
Subroutine __add_namespace: called CC=2 SCAR=6.9
45 36 my ($key, $namespace) = @_;
46 36 ▶ return $key unless $namespace;
Branch: 1 branch
BranchTrueFalseTotal
unless $namespace 29 7 36
47 7 return "${namespace}[${key}]";
48 }
49  
50 2 ▶sub to_instance_array {
Subroutine to_instance_array: called CC=3 SCAR=11.0
Pod undocumented
51 2 my ($attrs, $class) = @_;
52 2 my @result = ();
53 2 ▶ if (! is_arrayref($attrs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not is_arrayref($attrs)) { } 1 1 2
54 1 push(@result, $class->new($attrs));
55 } else {
56 1 for (@$attrs) {
57 3 push(@result, $class->new($_));
58 }
59 }
60 2 return \@result;
61 }
62  
63 20 ▶sub is_not_empty {
Subroutine is_not_empty: called CC=3 SCAR=11.0
Pod undocumented
64 20 my $content = shift;
65 20 ▶ return if ! defined $content or length($content) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $content or length $content == 0 9 11 20
Condition100%3/3
not defined $content or length $content == 0
l!l&&r!l&&!r
2711
MC/DC100%2/2
not defined $content or length $content == 0
not defined $content length $content == 0
Truth table100%3/3
not(A) or B
A= not defined $contentB= length $content == 0
ABresult
1X1
011
000
66 11 return 1;
67 }
68  
69 20 ▶sub validate_id {
Subroutine validate_id: called CC=3 SCAR=11.0
Pod undocumented
70 20 my $id = shift;
71  
72 20 ▶ return if ! is_not_empty($id);
Branch: 1 branch
BranchTrueFalseTotal
unless is_not_empty($id) 9 11 20
73 11 ▶ return if $id =~ /\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $id =~ /\s/ 7 4 11
74  
75 4 return 1;
76 }
77  
78 393 ▶sub is_hashref {
Subroutine is_hashref: called CC=1 SCAR=0.0
Pod undocumented
79 393 ref(shift) eq 'HASH';
80 }
81  
82 965 ▶sub is_arrayref {
Subroutine is_arrayref: called CC=1 SCAR=0.0
Pod undocumented
83 965 ref(shift) eq 'ARRAY';
84 }
85  
86 22 1;
87 __END__
« lib/WebService/Braintree/UsBankAccountGateway.pm ↑ Summary lib/WebService/Braintree/_/MasterpassCard.pm »