| 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
| |||||||||||||||||||||||||||||
| 16 | 2719 | ▶ | return exists $param->{$root} ? $param->{$root} : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | croak "nested param clash for ARRAY $root" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | if ref $$ref ne 'ARRAY'; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | return if $1 > $#{$$ref}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | $ref = \( $$ref->[$1] ); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||||||||||
| 31 | 681 | ▶ | return if ref $$ref ne 'HASH' || !exists $$ref->{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $$ref ne "HASH" or not exists $$ref->{$_}
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->{$_}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $$ref = [] if !defined $$ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | croak "nested param clash for ARRAY $name" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | if ref $$ref ne 'ARRAY'; | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | $ref = \( $$ref->[$1] ); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||
| 61 | 541 | ▶ | $$ref = {} if !defined $$ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 541 | ▶ | croak "nested param clash for HASH $name" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return if !defined $$ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | croak "nested param clash for ARRAY $name" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | if ref $$ref ne 'ARRAY'; | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | $ref = \( $$ref->[$1] ); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ( $i == $#names ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | croak "can't delete hash key for an array"; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | else { | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | return if !defined $$ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | croak "nested param clash for HASH $name" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | if ref $$ref ne 'HASH'; | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( $i == $#names ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 124 | 2564 | ▶ | return ( defined($root) && exists( $param->{$root} ) ); | ||||||||||||||||||||||||||
|
Condition66%2/3
defined $root && exists $param->{$root}
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}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | croak "nested param clash for ARRAY $root" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | if ref $$ref ne 'ARRAY'; | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ( $i == $#names ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | return $1 > $$ref->[$1] ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | $ref = \( $$ref->[$1] ); | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||||||||
| 143 | 687 | ▶ | if ( $i == $#names ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 659 | ▶ | return if !ref $$ref || ref($$ref) ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $$ref or ref $$ref ne "HASH"
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"
| |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 574 | ▶ | return exists $$ref->{$part} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||