lib/HTML/FormFu/Role/NestedHashUtils.pm

filter: Statementstmt 59.4% 47 / 79 Branchbran 39.2% 22 / 56 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 4 totaltotal 54.9% 89 / 162 CC 36 SCAR 35.5
CC
36
Cov
53%
delete_nested_hash_key
110.0
nested_hash_key_exists
17.3
get_nested_hash_value
11.4
CRAP 34.9
« lib/HTML/FormFu/Role/FormAndBlockMethods.pm ↑ Summary lib/HTML/FormFu/Constraint/DependOn.pm »
1 497 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::NestedHashUtils;
4 # ABSTRACT: role for nested hashes
5 497 $HTML::FormFu::Role::NestedHashUtils::VERSION = '2.09';
6 497 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 497 ▶use HTML::FormFu::Util qw( split_name );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 497 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3580 ▶sub get_nested_hash_value {
Subroutine get_nested_hash_value: called CC=9 SCAR=24.4
Pod undocumented
12 3580 my ( $self, $param, $name ) = @_;
13  
14 3580 my ( $root, @names ) = split_name($name);
15  
16 3580 ▶ if ( !@names ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@names) 2925 655 3580
17 2925 ▶ return exists $param->{$root} ? $param->{$root} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $param->{$root} ? : 2416 509 2925
18 }
19  
20 655 my $ref = \$param->{$root};
21  
22 655 for (@names) {
23 681 ▶ if (/^(0|[1-9][0-9]*)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(0|[1-9][0-9]*)\z/) { } 0 681 681
24 0 ▶ croak "nested param clash for ARRAY $root"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "ARRAY" 0 0 0
25 if ref $$ref ne 'ARRAY';
26  
27 0 ▶ return if $1 > $#{$$ref};
Branch: 1 branch
BranchTrueFalseTotal
if $1 > $#{$$ref;} 0 0 0
28  
29 0 $ref = \( $$ref->[$1] );
30 }
31 else {
32 681 ▶ return if ref $$ref ne 'HASH' || !exists $$ref->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "HASH" or not exists $$ref->{$_} 49 632 681
Condition100%3/3
ref $$ref ne "HASH" or not exists $$ref->{$_}
l!l&&r!l&&!r
2128632
MC/DC100%2/2
ref $$ref ne "HASH" or not exists $$ref->{$_}
ref $$ref ne "HASH" not exists $$ref->{$_}
Truth table100%3/3
A or not(B)
A= ref $$ref ne "HASH"B= not exists $$ref->{$_}
ABresult
1X1
011
000
33  
34 632 $ref = \( $$ref->{$_} );
35 }
36 }
37  
38 606 return $$ref;
39 }
40  
41 1726 ▶sub set_nested_hash_value {
Subroutine set_nested_hash_value: called CC=8 SCAR=23.7
Pod undocumented
42 1726 my ( $self, $param, $name, $value ) = @_;
43  
44 1726 my ( $root, @names ) = split_name($name);
45  
46 1726 ▶ if ( !@names ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@names) 1222 504 1726
47 1222 return $param->{$root} = $value;
48 }
49  
50 504 my $ref = \$param->{$root};
51  
52 504 for (@names) {
53 541 ▶ if (/^(0|[1-9][0-9]*)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(0|[1-9][0-9]*)\z/) { } 0 541 541
54 0 ▶ $$ref = [] if !defined $$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$ref 0 0 0
55  
56 0 ▶ croak "nested param clash for ARRAY $name"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "ARRAY" 0 0 0
57 if ref $$ref ne 'ARRAY';
58  
59 0 $ref = \( $$ref->[$1] );
60 }
61 else {
62 541 ▶ $$ref = {} if !defined $$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$ref 201 340 541
63  
64 541 ▶ croak "nested param clash for HASH $name"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "HASH" 0 541 541
65 if ref $$ref ne 'HASH';
66  
67 541 $ref = \( $$ref->{$_} );
68 }
69 }
70  
71 504 $$ref = $value;
72 }
73  
74 0 ▶sub delete_nested_hash_key {
Subroutine delete_nested_hash_key: not called CC=10 SCAR=47.0
Pod undocumented
75 0 my ( $self, $param, $name ) = @_;
76  
77 0 my ( $root, @names ) = split_name($name);
78  
79 0 ▶ if ( !@names ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@names) 0 0 0
80 0 delete $param->{$root};
81 0 return;
82 }
83  
84 0 my $ref = \$param->{$root};
85  
86 0 for my $i ( 0 .. $#names ) {
87 0 my $name = $names[$i];
88  
89 0 ▶ if ( $name =~ /^(0|[1-9][0-9]*)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^(0|[1-9][0-9]*)\z/) { } 0 0 0
90 0 ▶ return if !defined $$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$ref 0 0 0
91  
92 0 ▶ croak "nested param clash for ARRAY $name"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "ARRAY" 0 0 0
93 if ref $$ref ne 'ARRAY';
94  
95 0 $ref = \( $$ref->[$1] );
96  
97 0 ▶ if ( $i == $#names ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#names) 0 0 0
98 0 croak "can't delete hash key for an array";
99 }
100 }
101 else {
102 0 ▶ return if !defined $$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$ref 0 0 0
103  
104 0 ▶ croak "nested param clash for HASH $name"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "HASH" 0 0 0
105 if ref $$ref ne 'HASH';
106  
107 0 ▶ if ( $i == $#names ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#names) { } 0 0 0
108 0 delete $$ref->{$name};
109 }
110 else {
111 0 $ref = \( $$ref->{$name} );
112 }
113 }
114 }
115  
116 0 return;
117 }
118  
119 4010 ▶sub nested_hash_key_exists {
Subroutine nested_hash_key_exists: called CC=12 SCAR=28.5
Pod undocumented
120 4010 my ( $self, $param, $name ) = @_;
121  
122 4010 my ( $root, @names ) = split_name($name);
123  
124 4010 ▶ if ( !@names ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@names) 3029 981 4010
125 3029 ▶ return ( defined($root) && exists( $param->{$root} ) );
Condition66%2/3
defined $root && exists $param->{$root}
!ll&&!rl&&r
08302199
MC/DC50%1/2
defined $root && exists $param->{$root}
defined $root exists $param->{$root}
Truth table66%2/3
A && B
A= defined $rootB= exists $param->{$root}
ABresult
0X0
100
111
126 }
127  
128 981 my $ref = \$param->{$root};
129  
130 981 for my $i ( 0 .. $#names ) {
131 1009 my $part = $names[$i];
132  
133 1009 ▶ if ( $part =~ /^(0|[1-9][0-9]*)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /^(0|[1-9][0-9]*)\z/) { } 0 1009 1009
134 0 ▶ croak "nested param clash for ARRAY $root"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "ARRAY" 0 0 0
135 if ref $$ref ne 'ARRAY';
136  
137 0 ▶ if ( $i == $#names ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#names) 0 0 0
138 0 ▶ return $1 > $$ref->[$1] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$1 > $$ref->[$1] ? : 0 0 0
139 }
140  
141 0 $ref = \( $$ref->[$1] );
142 }
143 else {
144 1009 ▶ if ( $i == $#names ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#names) 981 28 1009
145 981 ▶ return if !ref $$ref || ref($$ref) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $$ref or ref $$ref ne "HASH" 407 574 981
Condition100%3/3
not ref $$ref or ref $$ref ne "HASH"
l!l&&r!l&&!r
4016574
MC/DC100%2/2
not ref $$ref or ref $$ref ne "HASH"
not ref $$ref ref $$ref ne "HASH"
Truth table100%3/3
not(A) or B
A= not ref $$refB= ref $$ref ne "HASH"
ABresult
1X1
011
000
146  
147 574 ▶ return exists $$ref->{$part} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $$ref->{$part} ? : 511 63 574
148 }
149  
150 28 $ref = \( $$ref->{$part} );
151 }
152 }
153  
154 0 return;
155 }
156  
157 497 1;
158  
159 __END__
« lib/HTML/FormFu/Role/FormAndBlockMethods.pm ↑ Summary lib/HTML/FormFu/Constraint/DependOn.pm »