| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | Config::Neat::Util - Common utility functions for other Config::Neat modules | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Copyright (C) 2012-2015 Igor Afanasyev <igor.afanasyev@gmail.com> | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | L<https://github.com/iafan/Config-Neat> | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =cut | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | package Config::Neat::Util; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 4 | our $VERSION = '1.4'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use Tie::IxHash; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 4 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 4 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 26 | new_ixhash | ||||||||||||||||||||||||||||
| 27 | to_ixhash | ||||||||||||||||||||||||||||
| 28 | to_ixhash_recursive | ||||||||||||||||||||||||||||
| 29 | is_number | ||||||||||||||||||||||||||||
| 30 | is_code | ||||||||||||||||||||||||||||
| 31 | is_hash | ||||||||||||||||||||||||||||
| 32 | is_ixhash | ||||||||||||||||||||||||||||
| 33 | is_any_hash | ||||||||||||||||||||||||||||
| 34 | is_array | ||||||||||||||||||||||||||||
| 35 | is_neat_array | ||||||||||||||||||||||||||||
| 36 | is_any_array | ||||||||||||||||||||||||||||
| 37 | is_scalar | ||||||||||||||||||||||||||||
| 38 | is_simple_array | ||||||||||||||||||||||||||||
| 39 | is_homogenous_simple_array | ||||||||||||||||||||||||||||
| 40 | hash_has_only_sequential_keys | ||||||||||||||||||||||||||||
| 41 | hash_has_sequential_keys | ||||||||||||||||||||||||||||
| 42 | get_next_auto_key | ||||||||||||||||||||||||||||
| 43 | offset_keys | ||||||||||||||||||||||||||||
| 44 | get_keys_in_order | ||||||||||||||||||||||||||||
| 45 | reorder_ixhash_numerically | ||||||||||||||||||||||||||||
| 46 | reorder_ixhash | ||||||||||||||||||||||||||||
| 47 | rename_ixhash_key | ||||||||||||||||||||||||||||
| 48 | read_file | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub new_ixhash { | ||||||||||||||||||||||||||||
| 52 | 634 | ▶ | my $new = {}; | ||||||||||||||||||||||||||
|
Subroutine
new_ixhash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 634 | tie(%$new, 'Tie::IxHash'); | |||||||||||||||||||||||||||
| 54 | 634 | return $new; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub to_ixhash { | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
to_ixhash: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | die "Not a regular hash" unless is_hash($node) && !is_ixhash($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
is_hash($node) and not is_ixhash($node)
MC/DC0%0/2
is_hash($node) and not is_ixhash($node)
is_hash($node)
not is_ixhash($node)
Truth table0%0/3
A and not(B)
A= is_hash($node)B= not is_ixhash($node)
| |||||||||||||||||||||||||||||
| 60 | 0 | my $new = new_ixhash; | |||||||||||||||||||||||||||
| 61 | 0 | map { $new->{$_} = $node->{$_} } keys %$node; | |||||||||||||||||||||||||||
| 62 | 0 | return $new; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub to_ixhash_recursive { | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my ($node) = @_; | ||||||||||||||||||||||||||
|
Subroutine
to_ixhash_recursive: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $result = is_hash($node) && !is_ixhash($node) ? to_ixhash($node) : $node; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
is_hash($node) and not is_ixhash($node)
MC/DC0%0/2
is_hash($node) and not is_ixhash($node)
is_hash($node)
not is_ixhash($node)
Truth table0%0/3
A and not(B)
A= is_hash($node)B= not is_ixhash($node)
| |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if (is_ixhash($result)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | map { | ||||||||||||||||||||||||||||
| 70 | 0 | $result->{$_} = to_ixhash_recursive($result->{$_}); | |||||||||||||||||||||||||||
| 71 | } keys %$result; | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 0 | return $result; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub is_number { | ||||||||||||||||||||||||||||
| 77 | 522 | ▶ | my $n = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_number: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 522 | ▶ | return defined $n && $n =~ m/^\d+$/; | ||||||||||||||||||||||||||
|
Condition66%2/3
defined $n && $n =~ /^\d+$/
MC/DC50%1/2
defined $n && $n =~ /^\d+$/
defined $n
$n =~ /^\d+$/
Truth table66%2/3
A && B
A= defined $nB= $n =~ /^\d+$/
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub is_code { | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_code: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | 0 | return ref($node) eq 'CODE'; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub is_hash { | ||||||||||||||||||||||||||||
| 87 | 5129 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 88 | 5129 | return ref($node) eq 'HASH'; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | sub is_ixhash { | ||||||||||||||||||||||||||||
| 92 | 285 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_ixhash: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 93 | 285 | ▶ | return undef unless is_hash($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 285 | return ref(tied(%$node)) eq 'Tie::IxHash'; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | sub is_any_hash { | ||||||||||||||||||||||||||||
| 98 | 4 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_any_hash: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 4 | ▶ | return is_hash($node) || is_ixhash($node); | ||||||||||||||||||||||||||
|
Condition33%1/3
is_hash($node) || is_ixhash($node)
MC/DC0%0/2
is_hash($node) || is_ixhash($node)
is_hash($node)
is_ixhash($node)
Truth table33%1/3
A || B
A= is_hash($node)B= is_ixhash($node)
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub is_array { | ||||||||||||||||||||||||||||
| 103 | 1415 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_array: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 1415 | return ref($node) eq 'ARRAY'; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | sub is_neat_array { | ||||||||||||||||||||||||||||
| 108 | 2173 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_neat_array: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 109 | 2173 | return ref($node) eq 'Config::Neat::Array'; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | sub is_any_array { | ||||||||||||||||||||||||||||
| 113 | 647 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_any_array: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | 647 | ▶ | return is_array($node) || is_neat_array($node); | ||||||||||||||||||||||||||
|
Condition66%2/3
is_array($node) || is_neat_array($node)
MC/DC50%1/2
is_array($node) || is_neat_array($node)
is_array($node)
is_neat_array($node)
Truth table66%2/3
A || B
A= is_array($node)B= is_neat_array($node)
| |||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | sub is_scalar { | ||||||||||||||||||||||||||||
| 118 | 1153 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_scalar: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 1153 | return (ref(\$node) eq 'SCALAR') or (ref($node) eq 'SCALAR'); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub is_simple_array { | ||||||||||||||||||||||||||||
| 123 | 32 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_simple_array: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 32 | ▶ | return 1 if is_scalar($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 32 | ▶ | return undef unless is_array($node) || is_neat_array($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
is_array($node) or is_neat_array($node)
MC/DC50%1/2
is_array($node) or is_neat_array($node)
is_array($node)
is_neat_array($node)
Truth table66%2/3
A or B
A= is_array($node)B= is_neat_array($node)
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 31 | foreach my $value (@$node) { | |||||||||||||||||||||||||||
| 129 | 50 | ▶ | return undef unless is_scalar($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 21 | return 1; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | sub is_homogenous_simple_array { | ||||||||||||||||||||||||||||
| 135 | 359 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
is_homogenous_simple_array: called CC=10 SCAR=23.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 359 | ▶ | return 1 if is_scalar($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 359 | ▶ | return undef unless is_array($node) || is_neat_array($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
is_array($node) or is_neat_array($node)
MC/DC100%2/2
is_array($node) or is_neat_array($node)
is_array($node)
is_neat_array($node)
Truth table100%3/3
A or B
A= is_array($node)B= is_neat_array($node)
| |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 258 | my $contains_hash = undef; | |||||||||||||||||||||||||||
| 141 | 258 | my $contains_array = undef; | |||||||||||||||||||||||||||
| 142 | 258 | my $contains_scalar = undef; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 258 | foreach my $value (@$node) { | |||||||||||||||||||||||||||
| 145 | 515 | ▶ | if (is_hash($value)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 146 | 17 | $contains_hash |= 1; | |||||||||||||||||||||||||||
| 147 | } elsif (is_any_array($value)) { | ||||||||||||||||||||||||||||
| 148 | 28 | $contains_array |= 1; | |||||||||||||||||||||||||||
| 149 | } else { | ||||||||||||||||||||||||||||
| 150 | 470 | $contains_scalar |= is_scalar($value); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 515 | ▶ | die "Mixing hashes with simple arrays/scalars within one node is not supported" if $contains_hash && $contains_scalar; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$contains_hash and $contains_scalar
MC/DC0%0/2
$contains_hash and $contains_scalar
$contains_hash
$contains_scalar
Truth table66%2/3
A and B
A= $contains_hashB= $contains_scalar
| |||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | 258 | ▶ | return $contains_scalar && !$contains_array; | ||||||||||||||||||||||||||
|
Condition66%2/3
$contains_scalar && !$contains_array
MC/DC50%1/2
$contains_scalar && !$contains_array
$contains_scalar
!$contains_array
Truth table66%2/3
A && not(B)
A= $contains_scalarB= !$contains_array
| |||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | sub hash_has_only_sequential_keys { | ||||||||||||||||||||||||||||
| 158 | 140 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
hash_has_only_sequential_keys: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 159 | 140 | return hash_has_sequential_keys($node, 1); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | sub hash_has_sequential_keys { | ||||||||||||||||||||||||||||
| 163 | 295 | ▶ | my ($node, $strict) = @_; | ||||||||||||||||||||||||||
|
Subroutine
hash_has_sequential_keys: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 164 | 295 | ▶ | die "Not a hash" unless is_hash($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 295 | my $i = 0; | |||||||||||||||||||||||||||
| 167 | map { | ||||||||||||||||||||||||||||
| 168 | 295 | ▶ | if (is_number($_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 73 | ▶ | return undef if $_ != $i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 65 | $i++; | |||||||||||||||||||||||||||
| 171 | } else { | ||||||||||||||||||||||||||||
| 172 | 327 | ▶ | return undef if $strict; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | } keys %$node; | ||||||||||||||||||||||||||||
| 175 | 156 | return 1; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | # supposed to be used against hash that matches the | ||||||||||||||||||||||||||||
| 179 | # `hash_has_sequential_keys() == true` criterion | ||||||||||||||||||||||||||||
| 180 | sub get_next_auto_key { | ||||||||||||||||||||||||||||
| 181 | 27 | ▶ | my $node = shift; | ||||||||||||||||||||||||||
|
Subroutine
get_next_auto_key: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 182 | 27 | ▶ | die "Not a hash" unless is_hash($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | # get max(key) | ||||||||||||||||||||||||||||
| 185 | 27 | my $i = -1; # so that next key will start with 0 | |||||||||||||||||||||||||||
| 186 | map { | ||||||||||||||||||||||||||||
| 187 | 27 | ▶ | $i = $_ if is_number($_) && $_ > $i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
is_number($_) and $_ > $i
MC/DC50%1/2
is_number($_) and $_ > $i
is_number($_)
$_ > $i
Truth table66%2/3
A and B
A= is_number($_)B= $_ > $i
| |||||||||||||||||||||||||||||
| 188 | } keys %$node; | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # return max + 1 | ||||||||||||||||||||||||||||
| 191 | 27 | return $i + 1; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | sub offset_keys { | ||||||||||||||||||||||||||||
| 195 | 11 | ▶ | my ($node, $offset) = @_; | ||||||||||||||||||||||||||
|
Subroutine
offset_keys: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 196 | 11 | ▶ | die "Not a Tie::IxHash" unless is_ixhash($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 11 | ▶ | return $node if $offset == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 2 | my $result = new_ixhash; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # remap keys | ||||||||||||||||||||||||||||
| 202 | map { | ||||||||||||||||||||||||||||
| 203 | 2 | ▶ | if (is_number($_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 3 | $result->{$_ + $offset} = $node->{$_}; | |||||||||||||||||||||||||||
| 205 | } else { | ||||||||||||||||||||||||||||
| 206 | 2 | $result->{$_} = $node->{$_}; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | } keys %$node; | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 2 | return $result; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | # accepts an array of hasrefs | ||||||||||||||||||||||||||||
| 214 | sub get_keys_in_order { | ||||||||||||||||||||||||||||
| 215 | 128 | ▶ | my $result = new_ixhash; | ||||||||||||||||||||||||||
|
Subroutine
get_keys_in_order: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | map { | ||||||||||||||||||||||||||||
| 218 | 128 | map { | |||||||||||||||||||||||||||
| 219 | 256 | $result->{$_} = 1; | |||||||||||||||||||||||||||
| 220 | } keys %$_; | ||||||||||||||||||||||||||||
| 221 | } @_; | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 128 | return keys %$result; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | sub reorder_ixhash_numerically { | ||||||||||||||||||||||||||||
| 227 | 0 | ▶ | my ($node) = @_; | ||||||||||||||||||||||||||
|
Subroutine
reorder_ixhash_numerically: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | die "Not a Tie::IxHash" unless is_ixhash($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | # sort keys numerically | ||||||||||||||||||||||||||||
| 231 | 0 | my @a = sort {$a <=> $b} keys %$node; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | return reorder_ixhash($node, \@a); | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | sub reorder_ixhash { | ||||||||||||||||||||||||||||
| 237 | 128 | ▶ | my ($node, $keysref) = @_; | ||||||||||||||||||||||||||
|
Subroutine
reorder_ixhash: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 238 | 128 | ▶ | die "Not a Tie::IxHash" unless is_ixhash($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 128 | my $result = new_ixhash; | |||||||||||||||||||||||||||
| 241 | 128 | ▶ | map { $result->{$_} = $node->{$_} if exists $node->{$_} } @$keysref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 128 | return $result; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | sub rename_ixhash_key { | ||||||||||||||||||||||||||||
| 247 | 18 | ▶ | my ($node, $from, $to) = @_; | ||||||||||||||||||||||||||
|
Subroutine
rename_ixhash_key: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 248 | 18 | ▶ | die "Not a Tie::IxHash" unless is_ixhash($node); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 18 | ▶ | die "Can\'t rename key '$from' to '$to', because the target key already exists" if exists $node->{$to}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 18 | my $result = new_ixhash; | |||||||||||||||||||||||||||
| 252 | map { | ||||||||||||||||||||||||||||
| 253 | 18 | ▶ | my $key = $_ eq $from ? $to : $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 25 | $result->{$key} = $node->{$_}; | |||||||||||||||||||||||||||
| 255 | } keys %$node; | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 18 | return $result; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | sub read_file { | ||||||||||||||||||||||||||||
| 261 | 97 | ▶ | my ($filename, $binmode) = @_; | ||||||||||||||||||||||||||
|
Subroutine
read_file: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 97 | ▶ | open(CFG, $filename) or die "Can't open [$filename]: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | 97 | ▶ | binmode(CFG, $binmode || ':utf8'); | ||||||||||||||||||||||||||
|
Condition50%1/2
$binmode || ':utf8'
MC/DC0%0/1
$binmode || ':utf8'
$binmode
Truth table50%1/2
A
A= $binmode
| |||||||||||||||||||||||||||||
| 265 | 97 | my $text = join('', <CFG>); | |||||||||||||||||||||||||||
| 266 | 97 | close(CFG); | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 97 | return $text; | |||||||||||||||||||||||||||
| 269 | } # end sub | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 4 | 1; | |||||||||||||||||||||||||||