| 1 | # Connector::Builtin::Memory | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Proxy class for reading YAML configuration | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Written by Scott Hardin, Martin Bartosch and Oliver Welter | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # for the OpenXPKI project 2012 | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # THIS IS NOT WORKING IN A FORKING ENVIRONMENT! | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | package Connector::Builtin::Memory; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use English; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | extends 'Connector::Builtin'; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 | has '+LOCATION' => ( required => 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | has 'primary_attribute' => ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | predicate => 'has_primary_attribute', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | sub _build_config { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_config: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | $self->_config( {} ); | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 303 | ▶ | sub _get_node { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_node: called CC=13 SCAR=26.2
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 303 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 303 | my @path = $self->_build_path_with_prefix( shift ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 303 | $self->log()->trace('get node for path'. Dumper \@path); | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 303 | my $ptr = $self->_config(); | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 303 | ▶ | while ( scalar @path ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 795 | my $entry = shift @path; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 795 | ▶ | if ( ref $ptr eq 'HASH' && exists $ptr->{$entry} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
ref $ptr eq "HASH" and exists $ptr->{$entry}
MC/DC100%2/2
ref $ptr eq "HASH" and exists $ptr->{$entry}
ref $ptr eq "HASH"
exists $ptr->{$entry}
Truth table100%3/3
A and B
A= ref $ptr eq "HASH"B= exists $ptr->{$entry}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 681 | my $type = ref $ptr->{$entry}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 681 | ▶ | if ( $type eq 'HASH' || $type eq 'ARRAY' || scalar @path == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$type eq "HASH" or $type eq "ARRAY" or scalar @path == 0
$type eq "HASH" or $type eq "ARRAY"
MC/DC100%3/3
$type eq "HASH" or $type eq "ARRAY" or scalar @path == 0
$type eq "HASH"
$type eq "ARRAY"
scalar @path == 0
Truth table100%4/4
A or B or C
A= $type eq "HASH"B= $type eq "ARRAY"C= scalar @path == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 677 | $ptr = $ptr->{$entry}; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | $self->log()->debug("tried to walk over unexpected node type: $type"); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | return $self->_node_not_exists( $entry ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ▶ | elsif ( ref $ptr eq 'ARRAY' && $entry =~ m{\A\d+\z} && exists $ptr->[$entry] ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
ref $ptr eq "ARRAY" and $entry =~ /\A\d+\z/ and exists $ptr->[$entry]
ref $ptr eq "ARRAY" and $entry =~ /\A\d+\z/
MC/DC66%2/3
ref $ptr eq "ARRAY" and $entry =~ /\A\d+\z/ and exists $ptr->[$entry]
ref $ptr eq "ARRAY"
$entry =~ /\A\d+\z/
exists $ptr->[$entry]
Truth table75%3/4
A and B and C
A= ref $ptr eq "ARRAY"B= $entry =~ /\A\d+\z/C= exists $ptr->[$entry]
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | my $type = ref $ptr->[$entry]; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | if ( $type eq 'HASH' || $type eq 'ARRAY' || scalar @path == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$type eq "HASH" or $type eq "ARRAY" or scalar @path == 0
$type eq "HASH" or $type eq "ARRAY"
MC/DC0%0/3
$type eq "HASH" or $type eq "ARRAY" or scalar @path == 0
$type eq "HASH"
$type eq "ARRAY"
scalar @path == 0
Truth table25%1/4
A or B or C
A= $type eq "HASH"B= $type eq "ARRAY"C= scalar @path == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | $ptr = $ptr->[$entry]; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->log()->debug("tried to walk over unexpected node type: $type"); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return $self->_node_not_exists( $entry ); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 112 | return $self->_node_not_exists($entry); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 187 | return $ptr; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 64 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=7 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 64 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 64 | my $value = $self->_get_node( shift ); | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 64 | ▶ | return $self->_node_not_exists() unless (defined $value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 56 | ▶ | if (ref $value ne '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | die "requested value is not a scalar" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->has_primary_attribute and ref $value eq "HASH"
MC/DC0%0/2
$self->has_primary_attribute and ref $value eq "HASH"
$self->has_primary_attribute
ref $value eq "HASH"
Truth table33%1/3
A and B
A= $self->has_primary_attributeB= ref $value eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | unless ($self->has_primary_attribute() && ref $value eq 'HASH'); | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | return $self->_node_not_exists() | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | unless (defined $value->{$self->primary_attribute}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | die "primary_attribute is not a scalar" | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | unless (ref $value->{$self->primary_attribute} eq ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | return $value->{$self->primary_attribute}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 55 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | sub get_size { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_size: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | my $node = $self->_get_node( shift ); | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | ▶ | return 0 unless(defined $node); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | ▶ | if ( ref $node ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | die "requested value is not a list" | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | return scalar @{$node}; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | ▶ | sub get_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_list: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 6 | my $path = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 6 | my $node = $self->_get_node( $path ); | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | return $self->_node_not_exists( $path ) unless(defined $node); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 5 | ▶ | if ( ref $node ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | die "requested value is not a list" | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 5 | return @{$node}; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 13 | ▶ | sub get_keys { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_keys: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 13 | my $path = shift; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 13 | my $node = $self->_get_node( $path ); | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return @{[]} unless(defined $node); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 13 | ▶ | if ( ref $node ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | die "requested value is not a hash" | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 13 | return keys %{$node}; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 7 | ▶ | sub get_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_hash: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 7 | my $path = shift; | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 7 | my $node = $self->_get_node( $path ); | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 7 | ▶ | return $self->_node_not_exists( $path ) unless(defined $node); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | ▶ | if ( ref $node ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | die "requested value is not a hash" | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 6 | return { %$node }; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 190 | ▶ | sub get_meta { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_meta: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 190 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 190 | my $node = $self->_get_node( shift ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 190 | $self->log()->trace('get_node returned '. Dumper $node); | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 190 | ▶ | if (!defined $node) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | # die_on_undef already handled by get_node | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 100 | return; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 90 | my $meta = {}; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 90 | ▶ | if (ref $node eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 33 | $meta = {TYPE => "scalar", VALUE => $node }; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } elsif (ref $node eq "SCALAR") { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 20 | $meta = {TYPE => "reference", VALUE => $$node }; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } elsif (ref $node eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 5 | $meta = {TYPE => "list", VALUE => $node }; | |||||||||||||||||||||||||||||||||||||||||
| 180 | } elsif (ref $node eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 29 | my @keys = keys(%{$node}); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 29 | $meta = {TYPE => "hash", VALUE => \@keys }; | |||||||||||||||||||||||||||||||||||||||||
| 183 | ▶ | } elsif (blessed($node) && $node->isa('Connector')) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($node) and $node->isa("Connector")
MC/DC0%0/2
builtin::blessed($node) and $node->isa("Connector")
builtin::blessed($node)
$node->isa("Connector")
Truth table33%1/3
A and B
A= builtin::blessed($node)B= $node->isa("Connector")
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | $meta = {TYPE => "connector", VALUE => $node }; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | die "Unsupported node type: " . ref $node; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 90 | return $meta; | |||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 19 | ▶ | sub exists { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exists: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 19 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 19 | my $value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 19 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 197 | 19 | $value = defined $self->_get_node( shift ); | |||||||||||||||||||||||||||||||||||||||||
| 198 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 19 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 10 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=7 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 10 | my @path = $self->_build_path_with_prefix( shift ); | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 10 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 10 | my $ptr = $self->_config(); | |||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 10 | ▶ | while (scalar @path > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 6 | my $entry = shift @path; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 6 | ▶ | if (!exists $ptr->{$entry}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | $ptr->{$entry} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 216 | } elsif (ref $ptr->{$entry} ne "HASH") { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | confess('Try to step over a value node at ' . $entry); | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 6 | $ptr = $ptr->{$entry}; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 10 | my $entry = shift @path; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 10 | ▶ | if (!defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | delete $ptr->{$entry}; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 9 | ▶ | if (exists $ptr->{$entry}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if (ref $ptr->{$entry} ne ref $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | confess('Try to override data type at node ' . $entry); | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 9 | $ptr->{$entry} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 9 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 9 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 9 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 243 | __END__ | ||||||||||||||||||||||||||||||||||||||||||