| 1 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # This file is part of App-Cme | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # ABSTRACT: Run a cme script | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | package App::Cme::Command::run ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | $App::Cme::Command::run::VERSION = '1.049'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use File::HomeDir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Config::Model 2.156; # for delete_instance | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Config::Model::Lister; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Log::Log4perl qw(get_logger :levels); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use YAML::PP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Encode qw(decode_utf8); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use App::Cme -command ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use base qw/App::Cme::Common/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use feature qw/postderef signatures/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | no warnings qw/experimental::postderef experimental::signatures/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | my $__test_home = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # used only by tests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub _set_test_home { $__test_home = shift; return;} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_test_home: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | my $home = $__test_home || File::HomeDir->my_home; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$__test_home || 'File::HomeDir'->my_home
MC/DC0%0/2
$__test_home || 'File::HomeDir'->my_home
$__test_home
'File::HomeDir'->my_home
Truth table33%1/3
A || B
A= $__test_homeB= 'File::HomeDir'->my_home
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | my @script_paths = map {path($_)} ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | "$home/.cme/scripts", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | "/etc/cme/scripts/", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | push @script_paths, path($INC{"Config/Model.pm"})->parent->child("Model/scripts") ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 19 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 19 | my ( $class, $app ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 19 | [ "arg=s@" => "script argument. run 'cme run <script> -doc' for possible arguments" ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | [ "backup:s" => "Create a backup of configuration files before saving." ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | [ "foreach=s" => "Run script in several directories. The list of directories " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | . "must be passed as a single argument, i.e. --foreach 'foo bar'. If this " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | . "argument is '-', the list is taken from STDIN."], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | [ "commit|c:s" => "commit change with passed message" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | [ "cat" => "Show the script file" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | [ "no-commit|nc!" => "skip commit to git" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | [ "doc!" => "show documention of script" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | [ "list!" => "list available scripts" ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $class->cme_global_options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 19 | ▶ | sub validate_args { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_args: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 19 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 19 | $self->check_unknown_args($args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 19 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 19 | ▶ | sub usage_desc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 19 | my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o" | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 19 | return "$desc [ script ] [ -args foo=12 [ -args bar=13 ]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub description { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | return $self->get_documentation; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 19 | ▶ | sub check_script_arguments ($self, $opt, $script_name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_script_arguments: called CC=8 SCAR=38.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 19 | ▶ | if ($opt->{list} or not $script_name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt->{"list"} or not $script_name
MC/DC0%0/2
$opt->{"list"} or not $script_name
$opt->{"list"}
not $script_name
Truth table33%1/3
A or not(B)
A= $opt->{"list"}B= not $script_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my @scripts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | foreach my $path ( @script_paths ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | next unless $path->is_dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | push @scripts, map {$_->basename} grep { ! /~$/ } $path->children(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | say $opt->{list} ? "Available scripts:" : "Missing script argument. Choose one of:"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | foreach my $script_path (sort @scripts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my ($file, $data) = $self->get_script_data($script_path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my $app_info = $data->{app} ? sprintf(" (app %s)", $data->{app}) : ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | printf("- %s%s\n",$script_path, $app_info ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | say ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | say "Run 'cme run <script> -doc' to get more details on a script."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 19 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 19 | ▶ | sub find_script_file ($self, $script_name) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_script_file: called CC=6 SCAR=25.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 19 | my $script; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 19 | ▶ | if ($script_name =~ m!/!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 19 | $script = path($script_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # check script in known locations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | foreach my $path ( @script_paths ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | next unless $path->is_dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $script = $path->child($script_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | last if $script->is_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 19 | ▶ | die "Error: cannot find script $script_name\n" unless $script->is_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 19 | return $script; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ## no critic (Subroutines::ProhibitManyArgs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 20 | ▶ | sub replace_var_in_value ($user_args, $script_var, $data, $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replace_var_in_value: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 20 | state $var_pattern = qr~(?<!\\) \$([a-zA-Z]\w+) (?!\s*{)~x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # change $var but not \$var, not $var{} and not $1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 20 | $value =~ s~ $var_pattern | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 21 | ▶ | ~ $user_args->{$1} // $script_var->{$1} // $ENV{$1} // $data->{default}{$1} // '$'.$1 ~xeg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%11/11
((($user_args->{$1} // $script_var->{$1}) // $ENV{$1}) // $data->{"default"}{$1}) // '$' . $1
(($user_args->{$1} // $script_var->{$1}) // $ENV{$1}) // $data->{"default"}{$1}
($user_args->{$1} // $script_var->{$1}) // $ENV{$1}
$user_args->{$1} // $script_var->{$1}
MC/DC100%4/4
((($user_args->{$1} // $script_var->{$1}) // $ENV{$1}) // $data->{"default"}{$1}) // '$' . $1
$user_args->{$1}
$script_var->{$1}
$ENV{$1}
$data->{"default"}{$1}
Truth table100%5/5
A // B // C // D
A= $user_args->{$1}B= $script_var->{$1}C= $ENV{$1}D= $data->{"default"}{$1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # register vars without replacements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 20 | foreach my $var ($value =~ m~ $var_pattern ~xg) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | $data->{missing}{$var} = 1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # now change \$var in $var | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 20 | $value =~ s!\\\$!\$!g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 20 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # replace variables with command arguments or eval'ed variables or env variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | ## no critic (Subroutines::ProhibitManyArgs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 17 | ▶ | sub replace_vars ($user_args, $script_var, $data, @items) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replace_vars: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 17 | foreach my $item (@items) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 51 | ▶ | if (ref $data->{$item} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 32 | my @new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 32 | foreach my $value ($data->{$item}->@*) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 19 | push @new, replace_var_in_value ($user_args, $script_var, $data, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 32 | $data->{$item} = \@new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | elsif ($data->{$item}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | $data->{$item} = replace_var_in_value ($user_args, $script_var, $data, $data->{$item}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 17 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 15 | ▶ | sub parse_script_lines ($script, $lines) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_script_lines: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 15 | my $parsed_data = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | app => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | doc => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | code => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | commit_msg => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # provide default values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | default => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | load => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | var => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 15 | my $line_nb = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # check content, store app | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 15 | ▶ | while ($lines->@*) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 43 | my $line = shift $lines->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 43 | $line_nb++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 43 | $line =~ s/#.*//; # remove comments | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 43 | $line =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 43 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 43 | my ($key,@value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 43 | ▶ | if ($line =~ /^---\s*(\w+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | $key = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | ▶ | while ($lines->[0] !~ /^---/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 9 | $lines->[0] =~ s/#.*//; # remove comments | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 9 | push @value, shift $lines->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | elsif ($line eq '---') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 37 | ($key,@value) = split /[\s:]+/, $line, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 40 | ▶ | next unless $key ; # empty line | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 40 | ▶ | parse_command($key, $parsed_data, $line_nb, \@value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | or die "Error in cme DSL file $script line $line_nb: unexpected '$key' instruction\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 14 | return $parsed_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 40 | ▶ | sub parse_command ($key, $parsed_data, $line_nb, $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_command: called CC=10 SCAR=23.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | ## no critic (ControlStructures::ProhibitCascadingIfElse) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 40 | ▶ | if ( $key =~ /^app/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 14 | $parsed_data->{app} = $value->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | elsif ( $key eq 'var' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 6 | push $parsed_data->{var}->@*, [ $line_nb, $value->@* ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | elsif ( $key eq 'default' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # multi-line default value is not supported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | my ( $dk, $dv ) = split /[\s:=]+/, $value->[0], 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | $parsed_data->{default}{$dk} = $dv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | elsif ( $key eq 'code' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | ▶ | die "Error line $line_nb: Cannot mix code and load section\n" if $parsed_data->{load}->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | push $parsed_data->{code}->@*, $value->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | elsif ( $key eq 'doc' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 2 | push $parsed_data->{doc}->@*, $value->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | elsif ( $key eq 'load' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 14 | ▶ | die "Error line $line_nb: Cannot mix code and load section\n" if $parsed_data->{code}->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 14 | push $parsed_data->{load}->@*, $value->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | elsif ( $key eq 'commit' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $parsed_data->{commit_msg} = join "\n", $value->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 39 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 17 | ▶ | sub process_script_vars ($user_args, $data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_script_vars: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # $var is used in eval'ed strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 17 | my %var; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # find if all variables are accounted for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 17 | $data->{missing} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # %args can be used in var section of a script. A new entry in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # added in %missing if the script tries to read an undefined value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 17 | tie my %args, 'App::Cme::Run::Var',$data->{missing}, $data->{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 17 | %args = $user_args->%*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 17 | ▶ | my $var = delete $data->{var} // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $data->{"var"} // []
MC/DC100%1/1
delete $data->{"var"} // []
delete $data->{"var"}
Truth table100%2/2
A
A= delete $data->{"var"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 17 | foreach my $eval_data ($var->@*) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 7 | my ($line_nb, @value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 7 | ▶ | if (ref $eval_data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # coming from text format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 6 | ($line_nb, @value) = $eval_data->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # eval'ed string comes from system file, not from user data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 6 | my $res = eval ("@value") ; ## no critic (ProhibitStringyEval) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | ▶ | die "Error in var specification line $line_nb: $@\n" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # coming from YAML format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | my $res = eval ($eval_data) ; ## no critic (ProhibitStringyEval) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | die "Error in var specification: $@\n" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 17 | replace_vars($user_args, \%var, $data, 'doc', 'load', 'commit_msg'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 17 | $data->{values} = {$data->{default}->%*, %var, $user_args->%*}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 17 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 18 | ▶ | sub parse_script ($script, $content, $user_args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_script: called CC=15 SCAR=28.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 18 | my $lines->@* = split /\n/,$content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 18 | ▶ | if ($lines->[0] =~ /Format:\s*perl/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | ## no critic (ProhibitStringyEval) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | my $data = eval($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | ▶ | die "Error in script $script (Perl format): $@\n" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | foreach my $forbidden (qw/load var default/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 3 | ▶ | die "Unexpected '$forbidden\ section in Perl format script $script\n" if $data->{$forbidden}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 1 | ▶ | die "Unexpected 'code' section in Perl format script $script. Please use a sub section.\n" if $data->{code}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 1 | return $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 17 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 17 | ▶ | if ($lines->[0] =~ /Format:\s*yaml/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | my $ypp = YAML::PP->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | $data = $ypp->load_string($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | foreach my $key (qw/doc code load var/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 8 | ▶ | next unless defined $data->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 3 | ▶ | next if ref $data->{$key} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 3 | $data->{$key} = [ $data->{$key} ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 2 | ▶ | $data->{default} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$data->{"default"} //= {}
MC/DC100%1/1
$data->{"default"} //= {}
$data->{"default"}
Truth table100%2/2
A
A= $data->{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | $data->{commit_msg} = delete $data->{commit}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 2 | ▶ | if ($data->{default} and ref $data->{default} ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$data->{"default"} and ref $data->{"default"} ne "HASH"
MC/DC0%0/2
$data->{"default"} and ref $data->{"default"} ne "HASH"
$data->{"default"}
ref $data->{"default"} ne "HASH"
Truth table33%1/3
A and B
A= $data->{"default"}B= ref $data->{"default"} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | die "default spec must be a hash ref, not a ", ref $data->{default} // 'scalar', "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
ref $data->{"default"} // "scalar"
MC/DC0%0/1
ref $data->{"default"} // "scalar"
ref $data->{"default"}
Truth table0%0/2
A
A= ref $data->{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 15 | $data = parse_script_lines ($script, $lines); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 16 | my $processed_data = process_script_vars ($user_args, $data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 16 | ▶ | if (not $processed_data->{app}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 1 | die "Missing 'app' parameter in script $script.\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 15 | return $processed_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | ▶ | sub process_commit_message($self, $root, $values, $msg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_commit_message: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # replace strings like "{{ config_load_path }}" in $msg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | $msg =~ s/\{\{(.*?)\}\}/$root->grab_value($1)/e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # replace strings like "$value" in $msg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | $msg =~ s/\$(\w+)/$values->{$1}/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | return $msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # returns: script file name, script data if script is *not* Perl code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 19 | ▶ | sub get_script_data ($self, $script_name, $opt = {}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_script_data: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 19 | my $script_file = $self->find_script_file($script_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 19 | my $content = $script_file->slurp_utf8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 19 | ▶ | if ($content =~ m/^#!/ and -x $script_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$content =~ /^#!/u and -x $script_file
MC/DC50%1/2
$content =~ /^#!/u and -x $script_file
$content =~ /^#!/u
-x $script_file
Truth table66%2/3
A and B
A= $content =~ /^#!/uB= -x $script_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | my ($app) = $content =~ /# app:\s?(.*?)\n/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 2 | my @doc = grep {s/^##\s?//;} split /\n/, $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | return $script_file, {doc => \@doc, app => $app}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # parse variables passed on command line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 17 | my %user_args = map { split '=',$_,2; } @{ $opt->{arg} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 17 | return ($script_file, parse_script($script_file, $content, \%user_args)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | ▶ | sub run_script_as_code ($self, $script_name, $script_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_script_as_code: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | splice @ARGV, 0,2; # remove 'run script' arguments | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | ▶ | my $done = eval $script_file->slurp_utf8."\n1;\n"; ## no critic (BuiltinFunctions::ProhibitStringyEval) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | ▶ | if (ref $done eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | warn "script $script_name returns a hash but it's processed as a plain script.", | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | " This may not be what you want\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 1 | ▶ | die "Error in script $script_name: $@\n" unless $done; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 19 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=12 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 19 | my ($self, $opt, $app_args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # cannot use logger until Config::Model is initialised | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # see Debian #839593 and perlunicook(1) section X 13 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 19 | @$app_args = map { decode_utf8($_, 1) } @$app_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 19 | my $script_name = shift @$app_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 19 | ▶ | return unless $self->check_script_arguments($opt, $script_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 19 | my ($script_file, $script_data) = $self->get_script_data($script_name, $opt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 17 | ▶ | if ($opt->{cat}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | print $script_file->slurp_utf8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 17 | my $commit_msg = $script_data->{commit_msg}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 17 | ▶ | if ($opt->doc) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | say join "\n", $script_data->{doc}->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | ▶ | say "will commit with message: '$commit_msg'" if $commit_msg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 16 | ▶ | if (not defined $script_data->{app}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | $self->run_script_as_code ($script_name, $script_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 15 | ▶ | if (my @missing = sort keys $script_data->{missing}->%*) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | die "Error: Missing variables '". join("', '",@missing) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | ."' in command arguments for script $script_file\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 3 | ."Please use option '".join(' ', map { "-arg $_=xxx"} @missing)."'\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 12 | $self->process_args($opt, [ $script_data->{app}, $app_args->@* ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # override commit message. may also trigger a commit even if none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # is specified in script | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 12 | ▶ | if ($opt->{commit}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $commit_msg = $opt->{commit}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 12 | ▶ | $opt->{_verbose} = 'Loader' if $opt->{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 12 | my ( $categories, $appli_info, $appli_map ) = Config::Model::Lister::available_models; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 12 | my $app = $script_data->{app}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 12 | ▶ | if ($opt->{foreach} and $appli_info->{$app}{_category} ne 'application') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt->{"foreach"} and $appli_info->{$app}{"_category"} ne "application"
MC/DC0%0/2
$opt->{"foreach"} and $appli_info->{$app}{"_category"} ne "application"
$opt->{"foreach"}
$appli_info->{$app}{"_category"} ne "application"
Truth table66%2/3
A and B
A= $opt->{"foreach"}B= $appli_info->{$app}{"_category"} ne "application"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | die "Cannot use --foreach option with $app. This option can only be used with ". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | join(' ', $categories->{application}->@*). ". Check your cme script.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # parse variables passed on command line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 12 | ▶ | if ($opt->{foreach}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | $self->run_foreach_loop($opt,$app_args, $script_data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 11 | my %user_args = map { split '=',$_,2; } @{ $opt->{arg} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 11 | $self->run_script ($opt, $app_args, $script_data, \%user_args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | ▶ | sub run_foreach_loop($self, $opt,$app_args, $script_data ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_foreach_loop: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | my %user_args = map { split '=',$_,2; } @{ $opt->{arg} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | ## no critic (BuiltinFunctions::ProhibitComplexMappings) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 1 | ▶ | my @dirs = map { chomp; split /\s+/; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | ($opt->{foreach} eq '-' ? <STDIN> : ($opt->{foreach})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 1 | my $start = path('.')->absolute; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | foreach my $d (@dirs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 3 | my $t_dir = $start->child($d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 3 | ▶ | if (not $t_dir->is_dir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | die "Cannot run script in $d: not a directory\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 3 | say "Running script in $t_dir ..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # instance is stored in Config::Model, so the name must be changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 3 | $opt->{instance_name} = $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # instance is persisted in $self, so its ref must be removed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 3 | delete $self->{_instance}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 3 | chdir $t_dir->stringify; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 3 | $self->run_script ($opt, $app_args, $script_data, {%user_args}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # once we're done, remove instance from Model to avoid memory leaks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 3 | $self->{_model}->delete_instance($d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | chdir $start->stringify; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 14 | ▶ | sub run_script ($self, $opt, $app_args, $script_data, $user_args){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_script: called CC=12 SCAR=27.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 14 | my $commit_msg = $script_data->{commit_msg}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 14 | my $stashed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # stash pending work | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 14 | ▶ | if ($commit_msg and not $opt->{no_commit}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$commit_msg and not $opt->{"no_commit"}
MC/DC0%0/2
$commit_msg and not $opt->{"no_commit"}
$commit_msg
not $opt->{"no_commit"}
Truth table33%1/3
A and not(B)
A= $commit_msgB= not $opt->{"no_commit"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $stashed = $self->autostash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | # call loads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 14 | my ($model, $inst, $root) = $self->init_cme($opt,$app_args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 14 | foreach my $load_str ($script_data->{load}->@*) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 12 | $root->load($load_str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 14 | ▶ | if ($script_data->{code}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 11 | my $to_run = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 11 | ▶ | while (my ($name, $value) = each $script_data->{values}->%*) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 11 | $to_run .= "my \$$name = '$value';\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 11 | $to_run .= join("\n",$script_data->{code}->@*); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 11 | my $res = eval($to_run); ## no critic (ProhibitStringyEval) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 11 | ▶ | die "Error in code specification: $@\ncode is: \n$to_run\n" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 14 | ▶ | if ($script_data->{sub}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | $script_data->{sub}->($root, $user_args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 14 | ▶ | if ($inst->needs_save) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 14 | $self->save($inst,$opt) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # commit if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 14 | ▶ | if ($commit_msg and not $opt->{no_commit}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$commit_msg and not $opt->{"no_commit"}
MC/DC0%0/2
$commit_msg and not $opt->{"no_commit"}
$commit_msg
not $opt->{"no_commit"}
Truth table33%1/3
A and not(B)
A= $commit_msgB= not $opt->{"no_commit"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | my $processed_msg = $self->process_commit_message( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $root, $script_data->{values}, $commit_msg | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $self->commit($processed_msg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | say "No change were applied"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 14 | ▶ | if ($stashed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | $self->pop_stash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | package App::Cme::Run::Var; ## no critic (Modules::ProhibitMultiplePackages) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 2 | $App::Cme::Run::Var::VERSION = '1.049'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 2 | require Tie::Hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | ## no critic (ClassHierarchies::ProhibitExplicitISA) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 2 | our @ISA = qw(Tie::ExtraHash); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 7 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 7 | my ($self, $key) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 7 | my ($h, $missing, $default) = @$self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 7 | ▶ | my $res = $h->{$key} // $default->{$key} ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$h->{$key} // $default->{$key}
MC/DC100%2/2
$h->{$key} // $default->{$key}
$h->{$key}
$default->{$key}
Truth table100%3/3
A // B
A= $h->{$key}B= $default->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 7 | ▶ | $missing->{$key} = 1 unless defined $res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 7 | ▶ | return $res // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$res // ""
MC/DC100%1/1
$res // ""
$res
Truth table100%2/2
A
A= $res
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||