Braintree/Util.pm

filter: Statementstmt 25.8% 15 / 58 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 26.6% 4 / 15 Podpod 0.0% 0 / 11 totaltotal 17.4% 19 / 109 CC 15 SCAR 22.8
CC
15
Cov
19%
equal_arrays
20.0
flatten
12.0
difference_arrays
12.0
CRAP 9.8
« Braintree/Xml.pm ↑ Summary Braintree/Digest.pm »
1 package Net::Braintree::Util;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use URI::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our @ISA = qw(Exporter);
8 1 our @EXPORT = qw(to_instance_array flatten is_hashref is_arrayref hash_to_query_string equal_arrays difference_arrays validate_id contains);
9  
10 0 ▶sub flatten {
Subroutine flatten: not called CC=3 SCAR=24.8
Pod undocumented
11 0 my($hash, $namespace) = @_;
12 0 my %flat_hash = ();
13 0 ▶ while (my ($key, $value) = each(%$hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$hash) 0 0 0
14 0 ▶ if (is_hashref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_hashref($value)) { } 0 0 0
15 0 my $sub_entries = flatten($value, add_namespace($key, $namespace));
16 0 %flat_hash = (%flat_hash, %$sub_entries);
17 } else {
18 0 $flat_hash{add_namespace($key, $namespace)} = $value;
19 }
20 }
21 0 return \%flat_hash;
22 }
23  
24 0 ▶sub add_namespace {
Subroutine add_namespace: not called CC=2 SCAR=17.9
Pod undocumented
25 0 my ($key, $namespace) = @_;
26 0 ▶ return $key unless $namespace;
Branch: 1 branch
BranchTrueFalseTotal
unless $namespace 0 0 0
27 0 return "${namespace}[${key}]";
28 }
29  
30 0 ▶sub is_hashref {
Subroutine is_hashref: not called CC=1 SCAR=6.9
Pod undocumented
31 0 ref(shift) eq 'HASH';
32 }
33  
34 0 ▶sub is_arrayref {
Subroutine is_arrayref: not called CC=1 SCAR=6.9
Pod undocumented
35 0 ref(shift) eq 'ARRAY';
36 }
37  
38 0 ▶sub equal_arrays {
Subroutine equal_arrays: not called CC=4 SCAR=30.0
Pod undocumented
39 0 my ($first, $second) = @_;
40 0 ▶ return 0 unless @$first == @$second;
Branch: 1 branch
BranchTrueFalseTotal
unless @$first == @$second 0 0 0
41 0 ▶ for (my $i = 0; $i < @$first; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$first) 0 0 0
42 0 ▶ return 0 if $first->[$i] ne $second->[$i];
Branch: 1 branch
BranchTrueFalseTotal
if $first->[$i] ne $second->[$i] 0 0 0
43 }
44 0 return 1;
45 }
46  
47 0 ▶sub difference_arrays {
Subroutine difference_arrays: not called CC=3 SCAR=24.8
Pod undocumented
48 0 my ($array1, $array2) = @_;
49 0 my @diff;
50 0 foreach my $element (@$array1) {
51 0 ▶ push(@diff, $element) unless contains($element, $array2);
Branch: 1 branch
BranchTrueFalseTotal
unless contains($element, $array2) 0 0 0
52 }
53 0 return \@diff;
54 }
55  
56 0 ▶sub hash_to_query_string {
Subroutine hash_to_query_string: not called CC=1 SCAR=6.9
Pod undocumented
57 0 my $query = URI::Query -> new(flatten(shift));
58 0 return $query->stringify();
59 }
60  
61 0 ▶sub to_instance_array {
Subroutine to_instance_array: not called CC=3 SCAR=24.8
Pod undocumented
62 0 my ($attrs, $class) = @_;
63 0 my @result = ();
64 0 ▶ if(ref $attrs ne "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attrs ne 'ARRAY') { } 0 0 0
65 0 push(@result, $class->new($attrs));
66 } else {
67 0 for(@$attrs) {
68 0 push(@result, $class->new($_));
69 }
70 }
71 0 return \@result;
72 }
73 0 ▶sub trim {
Subroutine trim: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my $string = shift;
75 0 $string =~ s/^\s+//;
76 0 $string =~ s/\s+$//;
77 0 return $string;
78 }
79  
80 0 ▶sub validate_id {
Subroutine validate_id: not called CC=3 SCAR=24.8
Pod undocumented
81 0 my $id = shift;
82 0 ▶ return 0 if(!defined($id) || trim($id) eq "");
Branch: 1 branch
BranchTrueFalseTotal
if not defined $id or trim($id) eq "" 0 0 0
Condition0%0/3
not defined $id or trim($id) eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $id or trim($id) eq ""
not defined $id trim($id) eq ""
Truth table0%0/3
not(A) or B
A= not defined $idB= trim($id) eq ""
ABresult
1X1
011
000
83 0 return 1;
84 }
85  
86 0 ▶sub contains {
Subroutine contains: not called CC=3 SCAR=24.8
Pod undocumented
87 0 my ($element, $array) = @_;
88 0 for (@$array) {
89 0 ▶ return 1 if $_ eq $element;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $element 0 0 0
90 }
91 0 return 0;
92 }
93 1 1;
« Braintree/Xml.pm ↑ Summary Braintree/Digest.pm »