| 1 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # This file is part of Config-Model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # This software is Copyright (c) 2005-2022 by Dominique Dumont. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | package Config::Model::Loader 2.169; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 59 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 59 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 59 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 59 | ▶ | use 5.10.1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 59 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 59 | ▶ | use Config::Model::Exception; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 59 | ▶ | use Log::Log4perl qw(get_logger :levels); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 59 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 59 | ▶ | use feature qw/postderef signatures/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 59 | ▶ | no warnings qw/experimental::postderef experimental::signatures/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 59 | my $logger = get_logger("Loader"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 59 | my $verbose_logger = get_logger("Verbose.Loader"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ## load stuff, similar to grab, but used to set items in the tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ## starting from this node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 59 | has start_node => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | isa => 'Config::Model::Node', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 59 | has instance => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | isa => 'Config::Model::Instance', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | lazy_build => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 30 | ▶ | sub _build_instance ($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_instance: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 30 | return $self->start_node->instance; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 59 | with 'Config::Model::Role::Utils'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | my %log_dispatch = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 42 | ▶ | name => sub { my $loc = $_[0]->location; return $loc ? $_[0]->get_type." '$loc'" : "root node"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 42 | ▶ | qs => sub { my $s = shift; unquote($s); return "'$s'"}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 4 | ▶ | qa => sub { return '"'.join('", "', @{$_[0]}).'"'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | s => sub { return $_[0] }, # nop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 25 | ▶ | leaf => sub { return $_[0]->get_type." '". $_[0]->location."' ".$_[0]->value_type;} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 59 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1534 | ▶ | sub _log_cmd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log_cmd: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1534 | my ($self, $cmd, $message, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1534 | ▶ | return unless $verbose_logger->is_info; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 56 | ▶ | return if $self->instance->initial_load; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 55 | $cmd =~ s/\n/\\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 55 | foreach my $p (@params) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 113 | $message =~ s/%(\w+)/$log_dispatch{$1}->($p)/e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 55 | ▶ | my $str = ref $cmd eq 'ARRAY' ? "@$cmd" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | : ref $cmd ? $$cmd : $cmd; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 55 | $verbose_logger->info("command '$str': $message"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 55 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 444 | ▶ | sub load ($self, %args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=14 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 444 | my $node = $self->start_node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 444 | ▶ | my $steps = delete $args{steps} // delete $args{step}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
delete $args{"steps"} // delete $args{"step"}
MC/DC0%0/2
delete $args{"steps"} // delete $args{"step"}
delete $args{"steps"}
delete $args{"step"}
Truth table66%2/3
A // B
A= delete $args{"steps"}B= delete $args{"step"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 444 | ▶ | croak "load error: missing 'steps' parameter" unless defined $steps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 444 | my $caller_is_root = delete $args{caller_is_root}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 444 | my $inst = $node->instance; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # tune value checking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 444 | ▶ | my $check = delete $args{check} || 'yes'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'check'} || 'yes'
MC/DC100%1/1
delete $args{'check'} || 'yes'
delete $args{'check'}
Truth table100%2/2
A
A= delete $args{'check'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 444 | ▶ | croak __PACKAGE__, "load: unexpected check $check" unless $check =~ /yes|no|skip/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # accept commands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 444 | ▶ | my $huge_string = ref $steps ? join( ' ', @$steps ) : $steps; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 444 | my @command = _split_string($huge_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | #print "command is ",join('+',@command),"\n" ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 444 | my $current_node = $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 444 | my $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 444 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 456 | $ret = $self->_load( $current_node, $check, \@command, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 441 | $logger->trace("_load returned $ret"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # found '!' command | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 441 | ▶ | if ( $ret eq 'root' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 12 | ▶ | $current_node = $caller_is_root ? $node : $current_node->root; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 12 | ▶ | if ($logger->debug) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $logger->debug("Setting current_node to root node: ".$current_node->name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } while ( $ret eq 'root' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 429 | ▶ | if (@command) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | my $str = "Error: could not execute the required command, "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | ▶ | if ($command[0] =~ m!^/([\w-]+)!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $str .= "the searched item '$1' was not found" ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | $str .= "you may have specified too many '-' in your command"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | ▶ | Config::Model::Exception::Load->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | command => $command[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | error => $str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | object => $node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | ) if $check eq 'yes'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 428 | ▶ | if (%args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | Config::Model::Exception::Internal->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | error => __PACKAGE__ . " load: unexpected parameters: " . join( ', ', keys %args ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 428 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # returns elt action id subaction value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1404 | ▶ | sub _split_cmd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_split_cmd: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1404 | my $cmd = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1404 | $logger->trace("split on: ->$cmd<-"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1404 | my $quoted_string = qr/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | (?: "(?: \\" | [^"] )*? ") | # double quoted string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | (?: '(?: \\' | [^'] )*? ') # single quoted string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | /x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # capture parameters between ( ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1404 | my $function_args = qr/(?: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | \( # opening ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | $quoted_string ,? | # quoted string, maybe with a comma | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | [^)"']+ # or any other char expect ) or a quoted string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | )+ # many times | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | \) # closing ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | )/x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # do a split on ' ' but take quoted string into account | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1404 | my @command = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | $cmd =~ m!^ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ($quoted_string | \w[\w-]*)? # element name can be alone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | (:~|:-[=~]?|:=~|:\.\w+|:[=<>@]?|~) # action | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | $function_args # capture parameters between ( ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | /[^/]+/ # regexp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | $quoted_string (?:,)? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | | [^#=\.<>]+ # non action chars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | )+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | (=~|\.=|=\.\w+|[=<>]) # apply regexp or assign or append | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | $function_args # capture parameters between ( ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | $quoted_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | | [^#\s"'] # or non whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | )+ # many | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | \# # optional annotation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | (?: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | $quoted_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | | [^\s] # or non whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | )+ # many | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | )? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | (.*) # leftover | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | !gx | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1404 | my $leftout = pop @command; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1404 | ▶ | if ($leftout) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | command => $cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | error => "Syntax error: spurious char at command end: '$leftout'. Did you forget double quotes ?" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1402 | return @command; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 59 | my %load_dispatch = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | node => \&_walk_node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | warped_node => \&_walk_node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | hash => \&_load_hash, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | check_list => \&_load_check_list, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | list => \&_load_list, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | leaf => \&_load_leaf, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # return 'done', 'root', 'up', 'error' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 673 | ▶ | sub _load { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load: called CC=32 SCAR=36.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 673 | my ( $self, $node, $check, $cmdref, $at_top_level ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 673 | ▶ | $at_top_level ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$at_top_level ||= 0
MC/DC100%1/1
$at_top_level ||= 0
$at_top_level
Truth table100%2/2
A
A= $at_top_level
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 673 | my $node_name = "'" . $node->name . "'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 673 | $logger->trace("_load: called on node $node_name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 673 | my $inst = $node->instance; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 673 | my $cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 673 | ▶ | while ( $cmd = shift @$cmdref ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1505 | ▶ | if ( $logger->is_debug ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 50 | my $msg = $cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 50 | $msg =~ s/\n/\\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 50 | $logger->debug("Loader: Executing cmd '$msg' on node $node_name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1505 | ▶ | next if $cmd =~ /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1505 | ▶ | if ( $cmd eq '!' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 23 | $self->_log_cmd(\$cmd,"Going from %name to root node", $node ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 23 | $logger->debug("_load: going to root, at_top_level is $at_top_level"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # Do not change current node as we don't want to mess up =~ commands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 23 | return 'root'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1482 | ▶ | if ( $cmd eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 151 | my $parent = $node->parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 151 | ▶ | if (defined $parent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 145 | $self->_log_cmd($cmd,'Going up from %name to %name', $node, $node->parent); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 6 | $self->_log_cmd($cmd,'Going up from %name to exit Loader.', $node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 151 | return 'up'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1331 | ▶ | if ( $cmd =~ m!^/([\w-]+)! ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 5 | my $search = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 5 | ▶ | if ($node->has_element($search)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 3 | $self->_log_cmd($cmd, 'Element %qs found in current node (%name).', $search, $node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | $cmd =~ s!^/!! ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | $self->_log_cmd( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | $cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 'Going up from %name to %name to search for element %qs.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | $node, $node->parent, $search | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | unshift @$cmdref, $cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | return 'up'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1329 | my ( $element_name, $action, $function_param, $id, $subaction, $value_function_param2, $value_param, $note ) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | _split_cmd($cmd); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # cannot unquote value as it may be a list of quoted string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 1327 | unquote($element_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # regexp ensure that only $value_function_param $value_param is set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1327 | ▶ | my $value = $value_function_param2 // $value_param ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$value_function_param2 // $value_param
MC/DC100%2/2
$value_function_param2 // $value_param
$value_function_param2
$value_param
Truth table100%3/3
A // B
A= $value_function_param2B= $value_param
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1327 | my @instructions = ( $element_name, $action, $function_param, $id, $subaction, $value, $note ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1327 | ▶ | if ( $logger->is_debug ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 45 | ▶ | my @disp = map { defined $_ ? "'$_'" : '<undef>' } @instructions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 45 | $logger->debug("_load instructions: @disp (from: $cmd)"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1327 | ▶ | if ( not defined $element_name and not defined $note ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $element_name or defined $note
MC/DC0%0/2
defined $element_name or defined $note
defined $element_name
defined $note
Truth table66%2/3
A or B
A= defined $element_nameB= defined $note
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | command => $cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | error => 'Syntax error: cannot find element in command' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1327 | ▶ | unless ( defined $node ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | command => $cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | error => "Error: Got undefined node" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1327 | ▶ | unless ( $node->isa("Config::Model::Node") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$node->isa("Config::Model::Node") or $node->isa("Config::Model::WarpedNode")
MC/DC0%0/2
$node->isa("Config::Model::Node") or $node->isa("Config::Model::WarpedNode")
$node->isa("Config::Model::Node")
$node->isa("Config::Model::WarpedNode")
Truth table66%2/3
A or B
A= $node->isa("Config::Model::Node")B= $node->isa("Config::Model::WarpedNode")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | or $node->isa("Config::Model::WarpedNode") ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | command => $cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | error => "Error: Expected a node (even a warped node), got '" . $node->name . "'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # below, has_element method from WarpedNode will raise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # exception if warped_node is not available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1327 | ▶ | if ( not defined $element_name and defined $note ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $element_name and defined $note
MC/DC50%1/2
not defined $element_name and defined $note
not defined $element_name
defined $note
Truth table66%2/3
not(A) and B
A= not defined $element_nameB= defined $note
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 5 | $self->_set_note($node, \$cmd, $note); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1322 | ▶ | unless ( $node->has_element($element_name) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 6 | ▶ | Config::Model::Exception::UnknownElement->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | object => $node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | element => $element_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | ) if $check eq 'yes'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | unshift @$cmdref, $cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | return 'error'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1316 | ▶ | unless ( $node->is_element_available( name => $element_name ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | ▶ | Config::Model::Exception::UnavailableElement->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | object => $node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | element => $element_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ) if $check eq 'yes'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | unshift @$cmdref, $cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | return 'error'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1315 | ▶ | unless ( $node->is_element_available( name => $element_name ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | Config::Model::Exception::RestrictedElement->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | object => $node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | element => $element_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | ) if $check eq 'yes'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | unshift @$cmdref, $cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | return 'error'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1315 | my $element_type = $node->element_type($element_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 1315 | my $method = $load_dispatch{$element_type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 1315 | ▶ | croak "_load: unexpected element type '$element_type' for $element_name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | unless defined $method; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1315 | $logger->debug("_load: calling $element_type loader on element $element_name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1315 | my $ret = $self->$method( $node, $check, \@instructions, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1305 | $logger->debug("_load: $element_type loader on element $element_name returned $ret"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1305 | ▶ | die "Internal error: method dispatched for $element_type returned an undefined value " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | unless defined $ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1305 | ▶ | if ( $ret eq 'error' or $ret eq 'done' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ret eq "error" or $ret eq "done"
MC/DC50%1/2
$ret eq "error" or $ret eq "done"
$ret eq "error"
$ret eq "done"
Truth table66%2/3
A or B
A= $ret eq "error"B= $ret eq "done"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 67 | $logger->debug("_load return: $node_name got $ret"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 67 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1238 | ▶ | if ( $ret eq 'root' and not $at_top_level ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ret eq "root" and not $at_top_level
MC/DC0%0/2
$ret eq "root" and not $at_top_level
$ret eq "root"
not $at_top_level
Truth table66%2/3
A and not(B)
A= $ret eq "root"B= not $at_top_level
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $logger->debug("_load return: $node_name got $ret"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | return 'root'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # ret eq up or ok -> go on with the loop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 411 | return 'done'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 50 | ▶ | sub _set_note { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_note: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 50 | my ($self, $target, $cmd, $note) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 50 | $self->_log_cmd($cmd, "Setting %name annotation to %qs", $target, $note); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 50 | $target->annotation($note); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 50 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1258 | ▶ | sub _load_note { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_note: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1258 | my ( $self, $target_obj, $note, $instructions, $cmdref, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1258 | unquote($note); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # apply note on target object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1258 | ▶ | if ( defined $note ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 45 | ▶ | if ( defined $target_obj ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 45 | $self->_set_note($target_obj, $cmd,$note); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | Config::Model::Exception::Load->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | command => $$cmdref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | error => "Error: cannot set annotation with '" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | . join( "','", grep { defined $_ } @$instructions ) . "'" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1258 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 30 | ▶ | sub _walk_node { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_walk_node: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 30 | my ( $self, $node, $check, $inst, $cmdref, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 30 | my $element_name = shift @$inst; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 30 | my $note = pop @$inst; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 30 | my $new_node = $node->fetch_element($element_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 30 | $self->_load_note( $new_node, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 30 | my @left = grep { defined $_ } @$inst; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 30 | ▶ | if (@left) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | command => $inst, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | object => $node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | error => "Don't know what to do with '@left' " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | . "for node element $element_name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 30 | $self->_log_cmd($cmd, 'Going down from %name to %name', $node, $new_node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 30 | return $self->_load( $new_node, $check, $cmdref ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # unquote modify the passed values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | ## no critic (Subroutines::RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 3818 | ▶ | sub unquote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unquote: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 3818 | for (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 5378 | ▶ | if (defined $_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 2704 | s/(?<!\\)\\n/\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 2704 | s/\\\\/\\/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # handle double quote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 2704 | ▶ | if (s/^"//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 230 | ▶ | s/"$// && s!\\"!"!g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # or single quotes, but not both! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | elsif (s/^'//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 3 | ▶ | s/'$// && s!\\'!'!g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 3818 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 19 | ▶ | sub _load_check_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_check_list: called CC=12 SCAR=34.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 19 | my ( $self, $node, $check, $inst, $cmdref, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 19 | my ( $element_name, $action, $f_arg, $id, $subaction, $value, $note ) = @$inst; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 19 | my $element = $node->fetch_element( name => $element_name, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 19 | ▶ | if ( defined $note and not defined $action and not defined $subaction ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $note and not defined $action and not defined $subaction
defined $note and not defined $action
MC/DC0%0/3
defined $note and not defined $action and not defined $subaction
defined $note
not defined $action
not defined $subaction
Truth table25%1/4
A and not(B) and not(C)
A= defined $noteB= not defined $actionC= not defined $subaction
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $self->_load_note( $element, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 19 | ▶ | if ( defined $action and $action eq '~' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $action and $action eq "~"
MC/DC50%1/2
defined $action and $action eq "~"
defined $action
$action eq "~"
Truth table66%2/3
A and B
A= defined $actionB= $action eq "~"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 1 | $logger->debug("_load_check_list: clear list"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | $self->_log_cmd($cmd, 'clearing %name.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # valid for check_list or list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 1 | $element->clear(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 1 | $self->_load_note( $element, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 1 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 18 | ▶ | if ( defined $subaction and $subaction eq '=' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $subaction and $subaction eq "="
MC/DC0%0/2
defined $subaction and $subaction eq "="
defined $subaction
$subaction eq "="
Truth table33%1/3
A and B
A= defined $subactionB= $subaction eq "="
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 18 | $logger->debug("_load_check_list: set whole list"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 18 | $self->_log_cmd($cmd, 'Setting %name items %qs.', $element, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # valid for check_list or list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 18 | $element->load( $value, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 18 | $self->_load_note( $element, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 18 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | if ( not defined $action and defined $subaction ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $action and defined $subaction
MC/DC0%0/2
not defined $action and defined $subaction
not defined $action
defined $subaction
Truth table0%0/3
not(A) and B
A= not defined $actionB= defined $subaction
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | Config::Model::Exception::Load->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | command => join( '', grep { defined $_} @$inst ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | error => "Wrong assignment with '$subaction' on check_list" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | my $a_str = defined $action ? $action : '<undef>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | Config::Model::Exception::Load->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | command => join( '', map { $_ || '' } @$inst ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_ || ''
MC/DC0%0/1
$_ || ''
$_
Truth table0%0/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | error => "Wrong assignment with '$a_str' on check_list" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # sub is called with ( $self, $element, $check, $instance, @function_args ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # function_args are the arguments passed to the load command | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | my %dispatch_action = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | list_leaf => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 3 | ▶ | ':.sort' => sub { $_[1]->sort; return 'ok';}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 5 | ▶ | ':.push' => sub { $_[1]->push( @_[ 5 .. $#_ ] ); return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 2 | ▶ | ':.unshift' => sub { $_[1]->unshift( @_[ 5 .. $#_ ] ); return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | ':.insert_at' => sub { $_[1]->insert_at( @_[ 5 .. $#_ ] ); return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 2 | ▶ | ':.insort' => sub { $_[1]->insort( @_[ 5 .. $#_ ] ); return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | ':.insert_before' => \&_insert_before, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | ':.ensure' => \&_ensure_list_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 'list_*' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | ▶ | ':.copy' => sub { $_[1]->copy( $_[5], $_[6] ); return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 3 | ▶ | ':.clear' => sub { $_[1]->clear; return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | hash_leaf => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 2 | ▶ | ':.insort' => sub { $_[1]->insort($_[5])->store($_[6]); return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | hash_node => => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | ':.insort' => \&_insort_hash_of_node, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 'hash_*' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 1 | ▶ | ':.sort' => sub { $_[1]->sort; return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 1 | ▶ | ':.copy' => sub { $_[1]->copy( $_[5], $_[6] ); return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 3 | ▶ | ':.rename' => sub { $_[1]->move( $_[5], $_[6] ); return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 4 | ▶ | ':.clear' => sub { $_[1]->clear; return 'ok';}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # part of list or hash. leaf element have their own dispatch table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # (%load_value_dispatch) because the signture of the sub ref are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | # different between the 2 dispatch tables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 59 | leaf => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | ':.rm_value' => \&_remove_by_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | ':.rm_match' => \&_remove_matched_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | ':.substitute' => \&_substitute_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | fallback => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | ':.rm' => \&_remove_by_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | ':.json' => \&_load_json_vector_data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 59 | my %equiv = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 'hash_*' => { qw/:@ :.sort :.move :.rename/}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | list_leaf => { qw/:@ :.sort :< :.push :> :.unshift/ }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # fix for cme gh#2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | leaf => { qw/:-= :.rm_value :-~ :.rm_match :=~ :.substitute/ }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | fallback => { qw/:- :.rm ~ :.rm/ }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 59 | ▶ | while ( my ($target, $sub_equiv) = each %equiv) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 236 | ▶ | while ( my ($new_action, $existing_action) = each %$sub_equiv) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 590 | $dispatch_action{$target}{$new_action} = $dispatch_action{$target}{$existing_action}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 100 | ▶ | sub _get_dispatch_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_dispatch_data: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 100 | my ($dispatch, $type, $cargo_type, $action) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | return $dispatch->{ $type.'_'.$cargo_type }{$action} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | || $dispatch->{$type.'_*'}{$action} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | || $dispatch->{$cargo_type}{$action} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 100 | ▶ | || $dispatch->{'fallback'}{$action}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/9
$$dispatch{$type . '_' . $cargo_type}{$action} || $$dispatch{$type . '_*'}{$action} || $dispatch->{$cargo_type}{$action} || $dispatch->{'fallback'}{$action}
$$dispatch{$type . '_' . $cargo_type}{$action} or $$dispatch{$type . '_*'}{$action} or $dispatch->{$cargo_type}{$action}
$$dispatch{$type . '_' . $cargo_type}{$action} or $$dispatch{$type . '_*'}{$action}
MC/DC100%4/4
$$dispatch{$type . '_' . $cargo_type}{$action} || $$dispatch{$type . '_*'}{$action} || $dispatch->{$cargo_type}{$action} || $dispatch->{'fallback'}{$action}
$$dispatch{$type . '_' . $cargo_type}{$action}
$$dispatch{$type . '_*'}{$action}
$dispatch->{$cargo_type}{$action}
$dispatch->{'fallback'}{$action}
Truth table100%5/5
A or B or C || D
A= $$dispatch{$type . '_' . $cargo_type}{$action}B= $$dispatch{$type . '_*'}{$action}C= $dispatch->{$cargo_type}{$action}D= $dispatch->{'fallback'}{$action}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 361 | ▶ | sub _get_dispatch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_dispatch: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 361 | my ($self, $element, $type, $cargo_type, $action, $cmd, @f_args, ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 361 | ▶ | return unless (defined $action and $action ne ':'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $action and $action ne ":"
MC/DC100%2/2
defined $action and $action ne ":"
defined $action
$action ne ":"
Truth table100%3/3
A and B
A= defined $actionB= $action ne ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 50 | my $dispatch = _get_dispatch_data(\%dispatch_action, $type => $cargo_type, $action); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 50 | ▶ | if ($dispatch) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 50 | ▶ | my $real_action = _get_dispatch_data(\%equiv, $type => $cargo_type, $action) // $action; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
_get_dispatch_data(\%equiv, $type, $cargo_type, $action) // $action
MC/DC0%0/2
_get_dispatch_data(\%equiv, $type, $cargo_type, $action) // $action
_get_dispatch_data(\%equiv, $type, $cargo_type, $action)
$action
Truth table66%2/3
A // B
A= _get_dispatch_data(\%equiv, $type, $cargo_type, $action)B= $action
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 50 | $self->_log_cmd($cmd, 'Running %qs on %name with %qa.', substr($real_action,2), $element, \@f_args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 50 | return $dispatch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 59 | ▶ | sub _insert_before { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert_before: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 3 | my ( $self, $element, $check, $inst, $cmdref, $before_str, @values ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 3 | ▶ | my $before = ($before_str =~ s!^/!! and $before_str =~ s!/$!!) ? qr/$before_str/ : $before_str; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$before_str =~ s[^/][] and $before_str =~ s[/$][]
MC/DC50%1/2
$before_str =~ s[^/][] and $before_str =~ s[/$][]
$before_str =~ s[^/][]
$before_str =~ s[/$][]
Truth table66%2/3
A and B
A= $before_str =~ s[^/][]B= $before_str =~ s[/$][]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 3 | $element->insert_before( $before, @values ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 3 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 3 | ▶ | sub _ensure_list_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ensure_list_value: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 3 | my ( $self, $element, $check, $inst, $cmdref, @values ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 3 | my %content = map { $_ => 1 } $element->fetch_all_values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 3 | foreach my $one_value (@values) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 7 | ▶ | next if $content{$one_value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 4 | $element->insort($one_value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 4 | $content{$one_value} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 3 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 11 | ▶ | sub _remove_by_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_by_id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 11 | my ( $self, $element, $check, $inst, $cmdref, $id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 11 | $logger->debug("_remove_by_id: removing id '$id'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 11 | $element->remove($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 10 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 5 | ▶ | sub _lazy_load ($function, $module) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lazy_load: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 5 | my $file = ($module =~ s!::!/!gr).".pm"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 5 | eval { require $file }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 5 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | die "Error: Loader function $function requires $module module. Please install this module.\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 3 | ▶ | sub __load_json_file ($file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__load_json_file: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 3 | _lazy_load(".json()", "JSON"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 3 | JSON->import(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # utf8 decode is done by JSON module, so slurp_raw must be used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 3 | return decode_json($file->slurp_raw); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 1 | ▶ | sub _load_json_vector_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_json_vector_data: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 1 | my ( $self, $element, $check, $inst, $cmdref, $vector ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 1 | $logger->debug("_load_json_vector_data: loading '$vector'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 1 | my ($file, @vector) = $self->__get_file_from_vector($element,$inst,$vector); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 1 | my $data = __load_json_file($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | # test for diff before clobbering ? What about deep data ??? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 1 | $element->load_data( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | data => __data_from_vector($data, @vector), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | check => $check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 1 | ▶ | sub _remove_by_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_by_value: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 1 | my ( $self, $element, $check, $inst, $cmdref, $rm_val ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 1 | $logger->debug("_remove_by_value value $rm_val"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 1 | foreach my $idx ( $element->fetch_all_indexes ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 5 | my $v = $element->fetch_with_id($idx)->fetch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 5 | ▶ | $element->delete($idx) if defined $v and $v eq $rm_val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $v and $v eq $rm_val
MC/DC50%1/2
defined $v and $v eq $rm_val
defined $v
$v eq $rm_val
Truth table66%2/3
A and B
A= defined $vB= $v eq $rm_val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 1 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 1 | ▶ | sub _remove_matched_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_matched_value: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1 | my ( $self, $element, $check, $inst, $cmdref, $rm_val ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | $logger->debug("_remove_matched_value $rm_val"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 1 | $rm_val =~ s!^/|/$!!g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 1 | foreach my $idx ( $element->fetch_all_indexes ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 5 | my $v = $element->fetch_with_id($idx)->fetch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 5 | ▶ | $element->delete($idx) if defined $v and $v =~ /$rm_val/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $v and $v =~ /$rm_val/
MC/DC100%2/2
defined $v and $v =~ /$rm_val/
defined $v
$v =~ /$rm_val/
Truth table100%3/3
A and B
A= defined $vB= $v =~ /$rm_val/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 1 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 2 | ▶ | sub _substitute_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_substitute_value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 2 | my ( $self, $element, $check, $inst, $cmdref, $s_val ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 2 | $logger->debug("_substitute_value $s_val"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 2 | foreach my $idx ( $element->fetch_all_indexes ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 8 | my $l = $element->fetch_with_id($idx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 8 | $self->_load_value( $l, $check, '=~', $s_val, $inst ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 2 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 1 | ▶ | sub _insort_hash_of_node { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insort_hash_of_node: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 1 | my ( $self, $element, $check, $inst, $cmdref, $id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 1 | my $node = $element->insort($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 1 | $logger->debug("_insort_hash_of_node: calling _load on node id $id"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 1 | return $self->_load( $node, $check, $cmdref ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 183 | ▶ | sub _load_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_list: called CC=24 SCAR=32.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 183 | my ( $self, $node, $check, $inst, $cmdref, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 183 | my ( $element_name, $action, $f_arg, $id, $subaction, $value, $note ) = @$inst; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 183 | my $element = $node->fetch_element( name => $element_name, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 183 | ▶ | my @f_args = grep { defined } ( ( $f_arg // $id // '' ) =~ /([^,"]+)|"([^"]+)"/g ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
($f_arg // $id) // ""
$f_arg // $id
MC/DC100%2/2
($f_arg // $id) // ""
$f_arg
$id
Truth table100%3/3
A // B
A= $f_argB= $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 183 | my $elt_type = $node->element_type($element_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 183 | my $cargo_type = $element->cargo_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 183 | ▶ | if ( defined $note and not defined $action and not defined $subaction ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $note and not defined $action and not defined $subaction
defined $note and not defined $action
MC/DC66%2/3
defined $note and not defined $action and not defined $subaction
defined $note
not defined $action
not defined $subaction
Truth table75%3/4
A and not(B) and not(C)
A= defined $noteB= not defined $actionC= not defined $subaction
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 3 | $self->_load_note( $element, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 3 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 180 | ▶ | if ( defined $action and $action eq ':=' and $cargo_type eq 'leaf' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $action and $action eq ":=" and $cargo_type eq "leaf"
defined $action and $action eq ":="
MC/DC66%2/3
defined $action and $action eq ":=" and $cargo_type eq "leaf"
defined $action
$action eq ":="
$cargo_type eq "leaf"
Truth table75%3/4
A and B and C
A= defined $actionB= $action eq ":="C= $cargo_type eq "leaf"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | # due to ':=' action, the value is contained in $id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 39 | $logger->debug("_load_list: set whole list with ':=' action"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # valid for check_list or list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 39 | $self->_log_cmd($cmd, 'Setting %name values to %qs.', $element, $id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 39 | $element->load( $id, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 37 | $self->_load_note( $element, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 37 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # compat mode for list=a,b,c,d commands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 141 | ▶ | if ( not defined $action | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not defined $action and defined $subaction and $subaction eq "=" and $cargo_type eq "leaf"
not defined $action and defined $subaction and $subaction eq "="
not defined $action and defined $subaction
MC/DC50%2/4
not defined $action and defined $subaction and $subaction eq "=" and $cargo_type eq "leaf"
not defined $action
defined $subaction
$subaction eq "="
$cargo_type eq "leaf"
Truth table60%3/5
not(A) and B and C and D
A= not defined $actionB= defined $subactionC= $subaction eq "="D= $cargo_type eq "leaf"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | and defined $subaction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | and $subaction eq '=' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | and $cargo_type eq 'leaf' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 33 | $logger->debug("_load_list: set whole list with '=' subaction'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | # valid for check_list or list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 33 | $self->_log_cmd($cmd, 'Setting %name values to %qs.', $element, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 33 | $element->load( $value, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 33 | $self->_load_note( $element, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 33 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 108 | unquote( $id, $value, $note ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 108 | ▶ | if ( my $dispatch = $self->_get_dispatch($element, list => $cargo_type, $action, $cmd, @f_args)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 31 | return $dispatch->( $self, $element, $check, $inst, $cmdref, @f_args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 77 | ▶ | if ( not defined $action and defined $subaction ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $action and defined $subaction
MC/DC0%0/2
not defined $action and defined $subaction
not defined $action
defined $subaction
Truth table66%2/3
not(A) and B
A= not defined $actionB= defined $subaction
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | Config::Model::Exception::Load->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | command => join( '', grep { defined $_} @$inst ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | error => "Wrong assignment with '$subaction' on " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | . "element type: $elt_type, cargo_type: $cargo_type" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 77 | ▶ | if ( defined $action and $action eq ':' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $action and $action eq ":"
MC/DC50%1/2
defined $action and $action eq ":"
defined $action
$action eq ":"
Truth table66%2/3
A and B
A= defined $actionB= $action eq ":"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 76 | my $obj = $element->fetch_with_id( index => $id, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 76 | $self->_load_note( $obj, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 76 | ▶ | if ( $cargo_type =~ /node/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | # remove possible leading or trailing quote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 39 | $self->_log_cmd($cmd,'Going down from %name to %name', $node, $obj ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 39 | return $self->_load( $obj, $check, $cmdref ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 37 | ▶ | return 'ok' unless defined $subaction; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 34 | ▶ | if ( $cargo_type =~ /leaf/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 34 | $logger->debug("_load_list: calling _load_value on $cargo_type id $id"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | # _log_cmd done in _load_value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 34 | ▶ | $self->_load_value( $obj, $check, $subaction, $value, $cmdref, $cmd ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | and return 'ok'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 1 | ▶ | my $a_str = defined $action ? $action : '<undef>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | Config::Model::Exception::Load->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 1 | ▶ | command => join( '', map { $_ || '' } @$inst ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_ || ''
MC/DC100%1/1
$_ || ''
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | error => "Wrong assignment with '$a_str' on " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | . "element type: $elt_type, cargo_type: $cargo_type" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 261 | ▶ | sub _load_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_hash: called CC=29 SCAR=35.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 261 | my ( $self, $node, $check, $inst, $cmdref, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 261 | my ( $element_name, $action, $f_arg, $id, $subaction, $value, $note ) = @$inst; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 261 | unquote( $id, $value, $note ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 261 | my $element = $node->fetch_element( name => $element_name, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 261 | my $cargo_type = $element->cargo_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 261 | ▶ | if ( defined $note and not defined $action ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $note and not defined $action
MC/DC100%2/2
defined $note and not defined $action
defined $note
not defined $action
Truth table100%3/3
A and not(B)
A= defined $noteB= not defined $action
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | # _log_cmd done in _load_note | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 4 | $self->_load_note( $element, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 4 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 257 | ▶ | if ( not defined $action ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | Config::Model::Exception::Load->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 1 | ▶ | command => join( '', map { $_ || '' } @$inst ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_ || ''
MC/DC100%1/1
$_ || ''
$_
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | error => "Missing key (e.g. '$element_name:some_key') on hash element, cargo_type: $cargo_type" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # loop requires $subaction so does not fit in the dispatch table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 256 | ▶ | if ( $action eq ':~' or $action eq ':.foreach_match' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$action eq ":~" or $action eq ":.foreach_match"
MC/DC50%1/2
$action eq ":~" or $action eq ":.foreach_match"
$action eq ":~"
$action eq ":.foreach_match"
Truth table66%2/3
A or B
A= $action eq ":~"B= $action eq ":.foreach_match"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 3 | my @keys = $element->fetch_all_indexes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 3 | my $ret = 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 3 | ▶ | my $pattern = $id // $f_arg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$id // $f_arg
MC/DC50%1/2
$id // $f_arg
$id
$f_arg
Truth table66%2/3
A // B
A= $idB= $f_arg
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 3 | ▶ | $pattern =~ s!^/|/$!!g if $pattern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 3 | ▶ | my @loop_on = $pattern ? grep { /$pattern/ } @keys : @keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 3 | ▶ | if ($logger->is_debug) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 1 | ▶ | my $str = $pattern ? " with regex /$pattern/" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 1 | $logger->debug("_load_hash: looping$str on keys @loop_on"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 3 | my @saved_cmd = @$cmdref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 3 | foreach my $loop_id ( @loop_on ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 11 | @$cmdref = @saved_cmd; # restore command before loop | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 11 | my $sub_elt = $element->fetch_with_id($loop_id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 11 | $self->_log_cmd($cmd,'Running foreach_map loop on %name.',$sub_elt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 11 | ▶ | if ( $cargo_type =~ /node/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | # remove possible leading or trailing quote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 9 | $ret = $self->_load( $sub_elt, $check, $cmdref ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | elsif ( $cargo_type =~ /leaf/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 2 | $ret = $self->_load_value( $sub_elt, $check, $subaction, $value, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | command => join( '', @$inst ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | error => "Hash assignment with '$action' on unexpected " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | . "cargo_type: $cargo_type" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 11 | $logger->debug("_load_hash: loop on id $loop_id returned $ret (left cmd: @$cmdref)"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | ▶ | if ( $ret eq 'error') { return $ret; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 3 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 253 | ▶ | my @f_args = grep { defined } ( ( $f_arg // $id // '' ) =~ /([^,"]+)|"([^"]+)"/g ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
($f_arg // $id) // ""
$f_arg // $id
MC/DC100%2/2
($f_arg // $id) // ""
$f_arg
$id
Truth table100%3/3
A // B
A= $f_argB= $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 253 | ▶ | if ( my $dispatch = $self->_get_dispatch($element, hash => $cargo_type, $action, $cmd, @f_args)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 19 | return $dispatch->( $self, $element, $check, $inst, $cmdref, @f_args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 234 | ▶ | if (not defined $id) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | command => join( '', @$inst ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | error => qq!Unexpected hash instruction: '$action' or missing id! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 234 | my $obj = $element->fetch_with_id( index => $id, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 234 | $self->_load_note( $obj, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 234 | ▶ | if ( $action eq ':' and $cargo_type =~ /node/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$action eq ":" and $cargo_type =~ /node/
MC/DC50%1/2
$action eq ":" and $cargo_type =~ /node/
$action eq ":"
$cargo_type =~ /node/
Truth table66%2/3
A and B
A= $action eq ":"B= $cargo_type =~ /node/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | # remove possible leading or trailing quote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 138 | $self->_log_cmd($cmd,'Going down from %name to %name', $node, $obj ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 138 | ▶ | if ( defined $subaction ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | command => join( '', @$inst ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | error => qq!Hash assignment with '$action"$id"$subaction"$value"' on unexpected ! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | . "cargo_type: $cargo_type" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 138 | return $self->_load( $obj, $check, $cmdref ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | ▶ | elsif ( $action eq ':' and defined $subaction and $cargo_type =~ /leaf/ ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$action eq ":" and defined $subaction and $cargo_type =~ /leaf/
$action eq ":" and defined $subaction
MC/DC33%1/3
$action eq ":" and defined $subaction and $cargo_type =~ /leaf/
$action eq ":"
defined $subaction
$cargo_type =~ /leaf/
Truth table50%2/4
A and B and C
A= $action eq ":"B= defined $subactionC= $cargo_type =~ /leaf/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | # _log_cmd is done in _load_value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 92 | $logger->debug("_load_hash: calling _load_value on leaf $id"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 92 | ▶ | $self->_load_value( $obj, $check, $subaction, $value, $cmdref, $cmd ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | and return 'ok'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | elsif ( $action eq ':' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 4 | $self->_log_cmd($cmd,'Creating empty %name.', $obj ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 4 | $logger->debug("_load_hash: created empty element of type $cargo_type"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 4 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | elsif ($action) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 0 | $logger->debug("_load_hash: giving up"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | Config::Model::Exception::Load->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | command => join( '', grep { defined $_ } @$inst ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | error => "Hash load with '$action' on unexpected " . "cargo_type: $cargo_type" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 822 | ▶ | sub _load_leaf { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_leaf: called CC=9 SCAR=22.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 822 | my ( $self, $node, $check, $inst, $cmdref, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 822 | my ( $element_name, $action, $f_arg, $id, $subaction, $value, $note ) = @$inst; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 822 | unquote( $id, $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 822 | my $element = $node->fetch_element( name => $element_name, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 822 | $self->_load_note( $element, $note, $inst, $cmdref, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 822 | ▶ | if ( defined $action and $element->isa('Config::Model::Value')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $action and $element->isa("Config::Model::Value")
MC/DC50%1/2
defined $action and $element->isa("Config::Model::Value")
defined $action
$element->isa("Config::Model::Value")
Truth table66%2/3
A and B
A= defined $actionB= $element->isa("Config::Model::Value")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 5 | ▶ | if ($action eq '~') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 4 | $self->_log_cmd($cmd, "Deleting %name.", $element ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 4 | $element->store(value => undef, check => $check); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | elsif ($action eq ':') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 1 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | command => $inst, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | error => "Error: list or hash command (':') detected on a leaf." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | . "(element '" . $element->name . "')" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | command => $inst, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | error => "Load error on leaf with " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | . "'$element_name$action$id' command " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | . "(element '" . $element->name . "')" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 821 | ▶ | return 'ok' unless defined $subaction; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 811 | ▶ | if ( $logger->is_debug ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 20 | ▶ | my $msg = defined $value ? $value : '<undef>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 20 | $msg =~ s/\n/\\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 20 | $logger->debug("_load_leaf: action '$subaction' value '$msg'"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 811 | my $res = $self->_load_value( $element, $check, $subaction, $value, $inst, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 809 | ▶ | return $res if $res ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | command => $inst, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | error => "Load error on leaf with " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | . "'$element_name$subaction$value' command " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | . "(element '" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | . $element->name . "')" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | # sub is called with ( $self, $element, $value, $check, $instructions ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | # function_args are the arguments passed to the load command | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | my %load_value_dispatch = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | '=' => \&_store_value , | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | '.=' => \&_append_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | '=~' => \&_apply_regexp_on_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | '=.file' => \&_store_file_in_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | '=.set_to_std_value' => \&_set_to_standard_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | '=.set_to_standard_value' => \&_set_to_standard_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | '=.json' => \&_store_json_vector_in_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | '=.yaml' => \&_store_yaml_vector_in_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | '=.ini' => \&_store_ini_vector_in_value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 1 | ▶ | '=.env' => sub { $_[1]->store( value => $ENV{$_[2]}, check => $_[3] ); return 'ok'; }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 59 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 917 | ▶ | sub _store_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_store_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 917 | my ( $self, $element, $value, $check, $instructions, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 917 | $self->_log_cmd($cmd, 'Setting %leaf to %qs.', $element, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 917 | $element->store( value => $value, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 917 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 8 | ▶ | sub _append_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_append_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 8 | my ( $self, $element, $value, $check, $instructions, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 8 | my $orig = $element->fetch( check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 8 | my $next = $orig.$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 8 | $self->_log_cmd( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | $cmd, 'Appending %qs to %leaf. Result is %qs.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | $value, $element, $next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 8 | return $element->store( value => $next, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 13 | ▶ | sub _apply_regexp_on_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_regexp_on_value: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 13 | my ( $self, $element, $value, $check, $instructions, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 13 | my $orig = $element->fetch( check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 13 | ▶ | if (defined $orig) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | # $value may change at each run and is like s/foo/bar/ do block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | # eval is not possible | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 11 | eval("\$orig =~ $value;"); ## no critic (ProhibitStringyEval) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 11 | my $res = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 11 | $self->_log_cmd( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | $cmd, "Applying regexp %qs to %leaf. Result is %qs.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | $value, $element, $orig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 11 | ▶ | if ($res) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | command => $instructions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | error => "Failed regexp '$value' on " . "element '" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | . $element->name . "' : $res" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 11 | return $element->store( value => $orig, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 2 | $self->_log_cmd( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | $cmd, "Not applying regexp %qs on undefined value of %leaf.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | $value, $element, $orig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 1 | ▶ | sub _set_to_standard_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_to_standard_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 1 | my ( $self, $element, $value, $check, $instructions, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | # check value is done by store | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | 1 | return $element->store($element->_fetch_std_no_check); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 1 | ▶ | sub _store_file_in_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_store_file_in_value: called CC=3 SCAR=13.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 1 | my ( $self, $element, $value, $check, $instructions, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 1 | ▶ | if ($value eq '-') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | ## no critic (InputOutput::ProhibitExplicitStdin) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | # user called a load function like .file(-), cannot use ARGV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 0 | $element->store( value => join('',<STDIN>), check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 1 | my $path = $element->root_path->child($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 1 | ▶ | if ($path->is_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 1 | return $element->store( value => $path->slurp_utf8, check => $check ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | command => $instructions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | error => "cannot read file $value" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 5 | ▶ | sub __data_from_vector { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__data_from_vector: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 5 | my ($data, @vector) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 5 | for my $step (@vector) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 9 | ▶ | $data = (ref($data) eq 'HASH') ? $data->{$step} : $data->[$step]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 5 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 7 | ▶ | sub __get_file_from_vector { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__get_file_from_vector: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 7 | my ($self, $element,$instructions,$raw_vector) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | 7 | my @vector = split m![/]+!m, $raw_vector; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | 7 | my $cur = path('.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 7 | my $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 7 | ▶ | while (my $subpath = shift @vector) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 25 | my $new_path = $cur->child($subpath); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | 25 | ▶ | if ($new_path->is_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 5 | $file = $new_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 5 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | elsif ($new_path->is_dir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 14 | $cur = $new_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 7 | ▶ | if (not defined $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 2 | my ( $element_name, $action, $f_arg, $id, $subaction, $value, $note ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | = @$instructions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 2 | ▶ | Config::Model::Exception::Load->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | command => "$element_name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | . ( $action ? "$action($f_arg)" : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | . ( $subaction ? "$subaction($value)" : '' ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | error => qq!Load error: Cannot find file in $value! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 5 | return ($file, @vector); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 4 | ▶ | sub _store_json_vector_in_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_store_json_vector_in_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 4 | my ( $self, $element, $value, $check, $instructions, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 4 | my ($file, @vector) = $self->__get_file_from_vector($element,$instructions,$value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 2 | my $data = __load_json_file($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 2 | return $element->store( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | value => __data_from_vector($data, @vector), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | check => $check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 1 | ▶ | sub _store_yaml_vector_in_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_store_yaml_vector_in_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 1 | my ( $self, $element, $value, $check, $instructions, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 1 | my ($file, @vector) = $self->__get_file_from_vector($element,$instructions,$value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 1 | _lazy_load(".yaml()", "YAML::PP"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 1 | my @data = YAML::PP->new()->load_file($file->stringify); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 1 | return $element->store( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | value => __data_from_vector(\@data, @vector), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | check => $check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 1 | ▶ | sub _store_ini_vector_in_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_store_ini_vector_in_value: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | 1 | my ( $self, $element, $value, $check, $instructions, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 1 | _lazy_load(".ini()", "Config::INI::Reader"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 1 | my ($file, @vector) = $self->__get_file_from_vector($element,$instructions,$value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 1 | ▶ | if (scalar @vector > 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 0 | die "$element calls .ini with too many elements in subpath @vector. Max is 2\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 1 | my $data = Config::INI::Reader->read_file($file->stringify); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 1 | return $element->store( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | value => __data_from_vector($data, @vector), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | check => $check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 947 | ▶ | sub _load_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_value: called CC=3 SCAR=13.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 947 | my ( $self, $element, $check, $subaction, $value, $instructions, $cmd ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | 947 | ▶ | if (not $element->isa('Config::Model::Value')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 0 | my $class = ref($element); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | command => $instructions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | error => "Load error: _load_value called on non Value object. ($class)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 947 | $logger->debug("_load_value: action '$subaction' value '$value' check $check"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 947 | my $dispatch = $load_value_dispatch{$subaction}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 947 | ▶ | if ($dispatch) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 947 | return $dispatch->( $self, $element, $value, $check, $instructions, $cmd ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 0 | Config::Model::Exception::Load->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | object => $element, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | command => $instructions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | error => "Unexpected operator or function on value: $subaction" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 0 | $logger->debug("_load_value: done returns ok"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 0 | return 'ok'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 59 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | # ABSTRACT: Load serialized data into config tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||