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 SCAR 51.2
CC
36
Cov
53%
delete_nested_hash_key
110.0
nested_hash_key_exists
17.3
get_nested_hash_value
11.4
CRAP 166.5
« lib/HTML/FormFu/Util.pm ↑ Summary lib/HTML/FormFu/Deploy.pm »
1 404 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::Role::NestedHashUtils;
4 404 $HTML::FormFu::Role::NestedHashUtils::VERSION = '2.06';
5 404 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 404 ▶use HTML::FormFu::Util qw( split_name );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 404 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub get_nested_hash_value {
11 3374 ▶ my ( $self, $param, $name ) = @_;
Subroutine get_nested_hash_value: called CC=9 SCAR=24.4
Pod undocumented
12  
13 3374 my ( $root, @names ) = split_name($name);
14  
15 3374 ▶ if ( !@names ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@names) 2719 655 3374
16 2719 ▶ return exists $param->{$root} ? $param->{$root} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $param->{$root} ? : 2336 383 2719
17 }
18  
19 655 my $ref = \$param->{$root};
20  
21 655 for (@names) {
22 681 ▶ if (/^(0|[1-9][0-9]*)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(0|[1-9][0-9]*)\z/) { } 0 681 681
23 0 ▶ croak "nested param clash for ARRAY $root"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "ARRAY" 0 0 0
24 if ref $$ref ne 'ARRAY';
25  
26 0 ▶ return if $1 > $#{$$ref};
Branch: 1 branch
BranchTrueFalseTotal
if $1 > $#{$$ref;} 0 0 0
27  
28 0 $ref = \( $$ref->[$1] );
29 }
30 else {
31 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
32  
33 632 $ref = \( $$ref->{$_} );
34 }
35 }
36  
37 606 return $$ref;
38 }
39  
40 sub set_nested_hash_value {
41 1687 ▶ my ( $self, $param, $name, $value ) = @_;
Subroutine set_nested_hash_value: called CC=8 SCAR=23.7
Pod undocumented
42  
43 1687 my ( $root, @names ) = split_name($name);
44  
45 1687 ▶ if ( !@names ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@names) 1183 504 1687
46 1183 return $param->{$root} = $value;
47 }
48  
49 504 my $ref = \$param->{$root};
50  
51 504 for (@names) {
52 541 ▶ if (/^(0|[1-9][0-9]*)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^(0|[1-9][0-9]*)\z/) { } 0 541 541
53 0 ▶ $$ref = [] if !defined $$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$ref 0 0 0
54  
55 0 ▶ croak "nested param clash for ARRAY $name"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "ARRAY" 0 0 0
56 if ref $$ref ne 'ARRAY';
57  
58 0 $ref = \( $$ref->[$1] );
59 }
60 else {
61 541 ▶ $$ref = {} if !defined $$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$ref 201 340 541
62  
63 541 ▶ croak "nested param clash for HASH $name"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "HASH" 0 541 541
64 if ref $$ref ne 'HASH';
65  
66 541 $ref = \( $$ref->{$_} );
67 }
68 }
69  
70 504 $$ref = $value;
71 }
72  
73 sub delete_nested_hash_key {
74 0 ▶ my ( $self, $param, $name ) = @_;
Subroutine delete_nested_hash_key: not called CC=10 SCAR=47.0
Pod undocumented
75  
76 0 my ( $root, @names ) = split_name($name);
77  
78 0 ▶ if ( !@names ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@names) 0 0 0
79 0 delete $param->{$root};
80 0 return;
81 }
82  
83 0 my $ref = \$param->{$root};
84  
85 0 for my $i ( 0 .. $#names ) {
86 0 my $name = $names[$i];
87  
88 0 ▶ if ( $name =~ /^(0|[1-9][0-9]*)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^(0|[1-9][0-9]*)\z/) { } 0 0 0
89 0 ▶ return if !defined $$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$ref 0 0 0
90  
91 0 ▶ croak "nested param clash for ARRAY $name"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "ARRAY" 0 0 0
92 if ref $$ref ne 'ARRAY';
93  
94 0 $ref = \( $$ref->[$1] );
95  
96 0 ▶ if ( $i == $#names ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#names) 0 0 0
97 0 croak "can't delete hash key for an array";
98 }
99 }
100 else {
101 0 ▶ return if !defined $$ref;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$ref 0 0 0
102  
103 0 ▶ croak "nested param clash for HASH $name"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "HASH" 0 0 0
104 if ref $$ref ne 'HASH';
105  
106 0 ▶ if ( $i == $#names ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#names) { } 0 0 0
107 0 delete $$ref->{$name};
108 }
109 else {
110 0 $ref = \( $$ref->{$name} );
111 }
112 }
113 }
114  
115 0 return;
116 }
117  
118 sub nested_hash_key_exists {
119 3223 ▶ my ( $self, $param, $name ) = @_;
Subroutine nested_hash_key_exists: called CC=12 SCAR=28.5
Pod undocumented
120  
121 3223 my ( $root, @names ) = split_name($name);
122  
123 3223 ▶ if ( !@names ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@names) 2564 659 3223
124 2564 ▶ return ( defined($root) && exists( $param->{$root} ) );
Condition66%2/3
defined $root && exists $param->{$root}
!ll&&!rl&&r
04472117
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
125 }
126  
127 659 my $ref = \$param->{$root};
128  
129 659 for my $i ( 0 .. $#names ) {
130 687 my $part = $names[$i];
131  
132 687 ▶ if ( $part =~ /^(0|[1-9][0-9]*)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /^(0|[1-9][0-9]*)\z/) { } 0 687 687
133 0 ▶ croak "nested param clash for ARRAY $root"
Branch: 1 branch
BranchTrueFalseTotal
if ref $$ref ne "ARRAY" 0 0 0
134 if ref $$ref ne 'ARRAY';
135  
136 0 ▶ if ( $i == $#names ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#names) 0 0 0
137 0 ▶ return $1 > $$ref->[$1] ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$1 > $$ref->[$1] ? : 0 0 0
138 }
139  
140 0 $ref = \( $$ref->[$1] );
141 }
142 else {
143 687 ▶ if ( $i == $#names ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#names) 659 28 687
144 659 ▶ return if !ref $$ref || ref($$ref) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $$ref or ref $$ref ne "HASH" 85 574 659
Condition100%3/3
not ref $$ref or ref $$ref ne "HASH"
l!l&&r!l&&!r
796574
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
145  
146 574 ▶ return exists $$ref->{$part} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $$ref->{$part} ? : 511 63 574
147 }
148  
149 28 $ref = \( $$ref->{$part} );
150 }
151 }
152  
153 0 return;
154 }
155  
156 404 1;
157  
158 __END__
159  
160 =pod
161  
162 =encoding UTF-8
163  
164 =head1 NAME
165  
166 HTML::FormFu::Role::NestedHashUtils
167  
168 =head1 VERSION
169  
170 version 2.06
171  
172 =head1 AUTHOR
173  
174 Carl Franks <cpan@fireartist.com>
175  
176 =head1 COPYRIGHT AND LICENSE
177  
178 This software is copyright (c) 2018 by Carl Franks.
179  
180 This is free software; you can redistribute it and/or modify it under
181 the same terms as the Perl 5 programming language system itself.
182  
183 =cut
« lib/HTML/FormFu/Util.pm ↑ Summary lib/HTML/FormFu/Deploy.pm »