| 1 | package Config::INI::RefVars; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 31 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 31 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 31 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 31 | ▶ | use feature ":5.10"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 31 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 31 | ▶ | use Config; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 31 | ▶ | use Cwd qw(abs_path); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 31 | ▶ | use File::Spec::Functions qw(catdir catfile file_name_is_absolute splitpath); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 31 | ▶ | use Config::INI::RefVars::Builtins; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 31 | our $VERSION = '1.07'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 31 | ▶ | use constant DFLT_TOCOPY_SECTION => "__TOCOPY__"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 31 | ▶ | use constant FLD_KEY_PREFIX => __PACKAGE__ . ' __ '; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 31 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 31 | EXPANDED => FLD_KEY_PREFIX . 'EXPANDED', | |||||||||||||||||||||||||||||||||||||||||
| 20 | CMNT_VL => FLD_KEY_PREFIX . 'CMNT_VL', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | TOCOPY_SECTION => FLD_KEY_PREFIX . 'TOCOPY_SECTION', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | CURR_TOCP_SECTION => FLD_KEY_PREFIX . 'CURR_TOCP_SECTION', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | TOCOPY_VARS => FLD_KEY_PREFIX . 'TOCOPY_VARS', | ||||||||||||||||||||||||||||||||||||||||||
| 24 | NOT_TOCOPY => FLD_KEY_PREFIX . 'NOT_TOCOPY', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | SECTIONS => FLD_KEY_PREFIX . 'SECTIONS', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | SECTIONS_H => FLD_KEY_PREFIX . 'SECTIONS_H', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | SRC_NAME => FLD_KEY_PREFIX . 'SRC_NAME', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | VARIABLES => FLD_KEY_PREFIX . 'VARIABLES', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | FUNCTIONS => FLD_KEY_PREFIX . 'FUNCTIONS', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | GLOBAL_VARS => FLD_KEY_PREFIX . 'GLOBAL_VARS', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | GLOBAL_MODE => FLD_KEY_PREFIX . 'GLOBAL_MODE', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | VREF_RE => FLD_KEY_PREFIX . 'VREF_RE', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | SEPARATOR => FLD_KEY_PREFIX . 'SEPARATOR', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | BACKUP => FLD_KEY_PREFIX . 'BACKUP', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | VARNAME_CHK_RE => FLD_KEY_PREFIX . 'VARNAME_CHK_RE', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | DISPATCH_TABLE => FLD_KEY_PREFIX . 'DISPATCH_TABLE', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | my %Globals = ('=:' => catdir("", ""), | ||||||||||||||||||||||||||||||||||||||||||
| 40 | '=::' => $Config{path_sep}, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 31 | '=VERSION' => $VERSION, | |||||||||||||||||||||||||||||||||||||||||
| 42 | '=devnull' => File::Spec::Functions::devnull(), | ||||||||||||||||||||||||||||||||||||||||||
| 43 | '=rootdir' => File::Spec::Functions::rootdir(), | ||||||||||||||||||||||||||||||||||||||||||
| 44 | '=tmpdir' => File::Spec::Functions::tmpdir(), | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # Match punctuation chars, but not the underscores. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 31 | my $Modifier_Char = '[^_[:^punct:]]'; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 31 | my ($_look_up, $_x_var_name, $_expand_vars, $_user_function_call, $_function_body, $_parse_ini); | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 122 | ▶ | my $_dispatch_sub = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 122 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 122 | ▶ | my $dispatch = $self->{+DISPATCH_TABLE} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | or croak("Internal error: dispatch table is not initialized"); | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 122 | ▶ | my $sub = $dispatch->{$name} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | or croak("unknown function '$name'"); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 116 | return $sub; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 168 | ▶ | my $_split_dispatch_spec = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 168 | my ($self, $spec) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 168 | $spec =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 168 | $spec =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 168 | ▶ | croak("empty function call") if $spec eq ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 164 | my @parts; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 164 | my $buf = ""; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 164 | my $level = 0; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 164 | foreach my $token (split(/(\$\(|\))/, $spec)) { | |||||||||||||||||||||||||||||||||||||||||
| 77 | 369 | ▶ | if ($token eq '$(') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 54 | ++$level; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 54 | $buf .= $token; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | elsif ($token eq ')') { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 54 | ▶ | croak("unterminated variable reference") if !$level; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 54 | --$level; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 54 | $buf .= $token; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 261 | foreach my $subtok (split(/(,)/, $token)) { | |||||||||||||||||||||||||||||||||||||||||
| 88 | 947 | ▶ | if ($subtok eq ',' && !$level) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$subtok eq "," and not $level
MC/DC100%2/2
$subtok eq "," and not $level
$subtok eq ","
not $level
Truth table100%3/3
A and not(B)
A= $subtok eq ","B= not $level
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 338 | push(@parts, $buf); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 338 | $buf = ""; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 609 | $buf .= $subtok; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 164 | ▶ | croak("unterminated variable reference") if $level; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 164 | push(@parts, $buf); | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 164 | ▶ | my $name = shift(@parts) // ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @parts // ""
MC/DC0%0/1
shift @parts // ""
shift @parts
Truth table50%1/2
A
A= shift @parts
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 164 | $name =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 164 | $name =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 164 | ▶ | croak("empty function name") if $name eq ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | @parts = map { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 164 | s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 338 | s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 338 | $_; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } @parts; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 164 | return ($name, @parts); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 119 | ▶ | my $_dispatch_call = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 119 | my ($self, $curr_sect, $spec, $seen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 119 | my ($name, @args) = $self->$_split_dispatch_spec($spec); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 117 | @args = map { $self->$_expand_vars($curr_sect, undef, $_, $seen, 1) } @args; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 117 | my $sub = $self->$_dispatch_sub($name); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 114 | ▶ | return $sub->(@args) // ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
&$sub(@args) // ""
MC/DC0%0/1
&$sub(@args) // ""
&$sub(@args)
Truth table50%1/2
A
A= &$sub(@args)
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 47 | ▶ | $_function_body = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 47 | my ($self, $curr_sect, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 47 | ▶ | my $functions = $self->{+FUNCTIONS} // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"Config::INI::RefVars __ FUNCTIONS"} // {}
MC/DC0%0/1
$self->{"Config::INI::RefVars __ FUNCTIONS"} // {}
$self->{"Config::INI::RefVars __ FUNCTIONS"}
Truth table50%1/2
A
A= $self->{"Config::INI::RefVars __ FUNCTIONS"}
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 47 | ▶ | if ($name =~ $self->{+VREF_RE}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 9 | my ($section, $basename) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 134 | return (exists($functions->{$section}) && exists($functions->{$section}{$basename})) ? | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | ▶ | ($section, $basename, $functions->{$section}{$basename}) : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $functions->{$section} and exists $functions->{$section}{$basename}
MC/DC100%2/2
exists $functions->{$section} and exists $functions->{$section}{$basename}
exists $functions->{$section}
exists $functions->{$section}{$basename}
Truth table100%3/3
A and B
A= exists $functions->{$section}B= exists $functions->{$section}{$basename}
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | return ($curr_sect, $name, $functions->{$curr_sect}{$name}) | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 38 | ▶ | if exists($functions->{$curr_sect}) && exists($functions->{$curr_sect}{$name}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $functions->{$curr_sect} and exists $functions->{$curr_sect}{$name}
MC/DC50%1/2
exists $functions->{$curr_sect} and exists $functions->{$curr_sect}{$name}
exists $functions->{$curr_sect}
exists $functions->{$curr_sect}{$name}
Truth table66%2/3
A and B
A= exists $functions->{$curr_sect}B= exists $functions->{$curr_sect}{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 31 | my $tocopy_section = $self->{+TOCOPY_SECTION}; | |||||||||||||||||||||||||||||||||||||||||
| 141 | return ($tocopy_section, $name, $functions->{$tocopy_section}{$name}) | ||||||||||||||||||||||||||||||||||||||||||
| 142 | if ($curr_sect ne $tocopy_section | ||||||||||||||||||||||||||||||||||||||||||
| 143 | && exists($functions->{$tocopy_section}) | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 31 | ▶ | && exists($functions->{$tocopy_section}{$name})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$curr_sect ne $tocopy_section and exists $functions->{$tocopy_section} and exists $functions->{$tocopy_section}{$name}
$curr_sect ne $tocopy_section and exists $functions->{$tocopy_section}
MC/DC33%1/3
$curr_sect ne $tocopy_section and exists $functions->{$tocopy_section} and exists $functions->{$tocopy_section}{$name}
$curr_sect ne $tocopy_section
exists $functions->{$tocopy_section}
exists $functions->{$tocopy_section}{$name}
Truth table50%2/4
A and B and C
A= $curr_sect ne $tocopy_sectionB= exists $functions->{$tocopy_section}C= exists $functions->{$tocopy_section}{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 49 | ▶ | $_user_function_call = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 49 | my ($self, $curr_sect, $spec, $seen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 49 | my ($name, @args) = $self->$_split_dispatch_spec($spec); | |||||||||||||||||||||||||||||||||||||||||
| 153 | 47 | @args = map { $self->$_expand_vars($curr_sect, undef, $_, $seen, 1) } @args; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 47 | my ($func_section, $func_name, $body) = $self->$_function_body($curr_sect, $name); | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 47 | ▶ | if (!defined($body)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 9 | ▶ | croak("unknown function '$name'") if $name =~ $self->{+VREF_RE}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 5 | ▶ | return $self->$_dispatch_sub($name)->(@args) // ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->$_dispatch_sub($name)->(@args) // ""
MC/DC0%0/1
$self->$_dispatch_sub($name)->(@args) // ""
$self->$_dispatch_sub($name)->(@args)
Truth table50%1/2
A
A= $self->$_dispatch_sub($name)->(@args)
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 38 | my $x_func_name = "[$func_section]#=$func_name"; | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 38 | ▶ | croak("recursive function '$x_func_name' calls itself") if exists($seen->{$x_func_name}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 34 | $seen->{$x_func_name} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 34 | my $variables = $self->{+VARIABLES}; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 34 | ▶ | my $sect_vars = $variables->{$curr_sect} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$variables->{$curr_sect} //= {}
MC/DC0%0/1
$variables->{$curr_sect} //= {}
$variables->{$curr_sect}
Truth table50%1/2
A
A= $variables->{$curr_sect}
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 34 | my (%had_arg, %old_arg, %param); | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 34 | for my $i (1 .. @args) { | |||||||||||||||||||||||||||||||||||||||||
| 173 | 43 | $param{$i} = $args[$i - 1]; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 34 | ▶ | while ($body =~ /\$\((\d+)\)/g) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 46 | ▶ | $param{$1} //= ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$param{$1} //= ""
MC/DC100%1/1
$param{$1} //= ""
$param{$1}
Truth table100%2/2
A
A= $param{$1}
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 34 | foreach my $arg (keys(%param)) { | |||||||||||||||||||||||||||||||||||||||||
| 181 | 45 | $had_arg{$arg} = exists($sect_vars->{$arg}); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 45 | ▶ | $old_arg{$arg} = $sect_vars->{$arg} if $had_arg{$arg}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 45 | $sect_vars->{$arg} = $param{$arg}; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 34 | my $result; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 34 | ▶ | eval { $result = $self->$_expand_vars($curr_sect, undef, $body, $seen, 1); 1; } or die($@); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 29 | foreach my $arg (keys(%param)) { | |||||||||||||||||||||||||||||||||||||||||
| 189 | 44 | ▶ | if ($had_arg{$arg}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 12 | $sect_vars->{$arg} = $old_arg{$arg}; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 32 | delete($sect_vars->{$arg}); | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 29 | delete($seen->{$x_func_name}); | |||||||||||||||||||||||||||||||||||||||||
| 197 | 29 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 28 | ▶ | my $_check_tocopy_vars = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 28 | my ($self, $tocopy_vars, $set) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 28 | ▶ | croak("'tocopy_vars': expected HASH ref") if ref($tocopy_vars) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 24 | $tocopy_vars = { %$tocopy_vars }; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 24 | ▶ | while (my ($var, $value) = each(%$tocopy_vars)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 55 | ▶ | croak("'tocopy_vars': value of '$var' is a ref, expected scalar") if ref($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 53 | ▶ | if (!defined($value)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 2 | carp("'tocopy_vars': value '$var' is undef - treated as empty string"); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | $tocopy_vars->{$var} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 53 | ▶ | croak("'tocopy_vars': variable '$var': name is not permitted") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$var =~ /^\s*$/ or $var =~ /^[=;]/
MC/DC50%1/2
$var =~ /^\s*$/ or $var =~ /^[=;]/
$var =~ /^\s*$/
$var =~ /^[=;]/
Truth table66%2/3
A or B
A= $var =~ /^\s*$/B= $var =~ /^[=;]/
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | if ($var =~ /^\s*$/ || $var =~ /^[=;]/); | ||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 18 | ▶ | $self->{+TOCOPY_VARS} = {%$tocopy_vars} if $set; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 18 | return $tocopy_vars; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 15 | ▶ | my $_check_not_tocopy = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.8
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 15 | my ($self, $not_tocopy, $set) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 15 | my $ref = ref($not_tocopy); | |||||||||||||||||||||||||||||||||||||||||
| 224 | 15 | ▶ | if ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 13 | foreach my $v (@$not_tocopy) { | |||||||||||||||||||||||||||||||||||||||||
| 226 | 20 | ▶ | croak("'not_tocopy': undefined value in array") if !defined($v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 18 | ▶ | croak("'not_tocopy': unexpected ref value in array") if ref($v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 9 | $not_tocopy = {map {$_ => undef} @$not_tocopy}; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | elsif ($ref eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $not_tocopy = %{$not_tocopy}; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | croak("'not_tocopy': unexpected type: must be ARRAY or HASH ref"); | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 9 | ▶ | $self->{+NOT_TOCOPY} = $not_tocopy if $set; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 9 | return $not_tocopy; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 193 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 193 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 193 | state $allowed_keys = { map { $_ => undef } qw(builtins | |||||||||||||||||||||||||||||||||||||||||
| 246 | cmnt_vl | ||||||||||||||||||||||||||||||||||||||||||
| 247 | global_mode | ||||||||||||||||||||||||||||||||||||||||||
| 248 | not_tocopy | ||||||||||||||||||||||||||||||||||||||||||
| 249 | separator | ||||||||||||||||||||||||||||||||||||||||||
| 250 | tocopy_section | ||||||||||||||||||||||||||||||||||||||||||
| 251 | tocopy_vars | ||||||||||||||||||||||||||||||||||||||||||
| 252 | varname_chk_re | ||||||||||||||||||||||||||||||||||||||||||
| 253 | )}; | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 193 | _check_args(\%args, $allowed_keys); | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 192 | ▶ | my $builtins = delete($args{builtins}) // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{"builtins"} // {}
MC/DC100%1/1
delete $args{"builtins"} // {}
delete $args{"builtins"}
Truth table100%2/2
A
A= delete $args{"builtins"}
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 192 | ▶ | croak("builtins must be a hash reference") if ref($builtins) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 192 | my $dispatch = Config::INI::RefVars::Builtins::default_dispatch_table(); | |||||||||||||||||||||||||||||||||||||||||
| 260 | 192 | foreach my $name (keys(%$builtins)) { | |||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | ▶ | croak("builtin '$name' is not a CODE reference") if ref($builtins->{$name}) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 4 | $dispatch->{$name} = $builtins->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 192 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 265 | +DISPATCH_TABLE() => $dispatch, | ||||||||||||||||||||||||||||||||||||||||||
| 266 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 192 | ▶ | croak("'tocopy_section': must not be a reference") if ref($args{tocopy_section}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 191 | ▶ | if (exists($args{separator})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 9 | state $allowed_sep_chars = "#!%&',./:~\\"; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 9 | my $sep = $args{separator}; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 9 | ▶ | croak("'separator': unexpected ref type, must be a scalar") if ref($sep); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 8 | ▶ | croak("'separator': invalid value. Allowed chars: $allowed_sep_chars") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | if $sep !~ m{^[\Q$allowed_sep_chars\E]+$}; | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 7 | $self->{+SEPARATOR} = $sep; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 7 | $self->{+VREF_RE} = qr/^(.*?)(?:\Q$sep\E)(.*)$/; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 182 | $self->{+VREF_RE} = qr/^\[\s*(.*?)\s*\](.*)$/; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 189 | $self->{+CMNT_VL} = $args{cmnt_vl}; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 189 | ▶ | $self->{+TOCOPY_SECTION} = $args{tocopy_section} // DFLT_TOCOPY_SECTION; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"tocopy_section"} // "__TOCOPY__"
MC/DC100%1/1
$args{"tocopy_section"} // "__TOCOPY__"
$args{"tocopy_section"}
Truth table100%2/2
A
A= $args{"tocopy_section"}
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 189 | ▶ | $self->$_check_tocopy_vars($args{tocopy_vars}, 1) if exists($args{tocopy_vars}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 184 | ▶ | $self->$_check_not_tocopy($args{not_tocopy}, 1) if exists($args{not_tocopy}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 181 | $self->{+GLOBAL_MODE} = !!$args{global_mode}; | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 181 | ▶ | if (exists($args{varname_chk_re})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | croak("'varname_chk_re': must be a compiled regex") | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | ▶ | if ref($args{varname_chk_re}) ne 'Regexp'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | $self->{+VARNAME_CHK_RE} = $args{varname_chk_re}; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 181 | return bless($self, $class); | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 10 | ▶ | my $_expand_value = sub { return $_[0]->$_expand_vars($_[1], undef, $_[2]); }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | # | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # We assume that this is called when the target section is still empty and if | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # tocopy vars exist. | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 304 | ▶ | my $_cp_tocopy_vars = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 304 | my ($self, $to_sect_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 304 | ▶ | my $comm_sec = $self->{+VARIABLES}{$self->{+TOCOPY_SECTION}} // die("no tocopy vars"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"Config::INI::RefVars __ VARIABLES"}{$self->{"Config::INI::RefVars __ TOCOPY_SECTION"}} // die("no tocopy vars")
MC/DC0%0/1
$self->{"Config::INI::RefVars __ VARIABLES"}{$self->{"Config::INI::RefVars __ TOCOPY_SECTION"}} // die("no tocopy vars")
$self->{"Config::INI::RefVars __ VARIABLES"}{$self->{"Config::INI::RefVars __ TOCOPY_SECTION"}}
Truth table50%1/2
A
A= $self->{"Config::INI::RefVars __ VARIABLES"}{$self->{"Config::INI::RefVars __ TOCOPY_SECTION"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 304 | my $not_tocopy = $self->{+NOT_TOCOPY}; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 304 | ▶ | my $to_sec = $self->{+VARIABLES}{$to_sect_name} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"Config::INI::RefVars __ VARIABLES"}{$to_sect_name} //= {}
MC/DC100%1/1
$self->{"Config::INI::RefVars __ VARIABLES"}{$to_sect_name} //= {}
$self->{"Config::INI::RefVars __ VARIABLES"}{$to_sect_name}
Truth table100%2/2
A
A= $self->{"Config::INI::RefVars __ VARIABLES"}{$to_sect_name}
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 304 | my $expanded = $self->{+EXPANDED}; | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 304 | foreach my $comm_var (keys(%$comm_sec)) { | |||||||||||||||||||||||||||||||||||||||||
| 313 | 156 | ▶ | next if exists($not_tocopy->{$comm_var}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 132 | $to_sec->{$comm_var} = $comm_sec->{$comm_var}; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 132 | my $comm_x_var_name = "[" . $self->{+TOCOPY_SECTION} . "]$comm_var"; | |||||||||||||||||||||||||||||||||||||||||
| 316 | $expanded->{"[$to_sect_name]$comm_var"} = undef | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 132 | ▶ | if exists($expanded->{$comm_x_var_name}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 14 | ▶ | my $_read_ini_file = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 14 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 14 | ▶ | open(my $fh, '<', $path) or croak("'$path': cannot open file: $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 14 | my @lines = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 14 | ▶ | close($fh) or croak("'$path': cannot close file: $!"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 14 | return \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 229 | ▶ | $_parse_ini = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=49 SCAR=42.6
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 229 | my ($self, $src, $curr_section, $include_stack, $src_dir, $src_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 229 | ▶ | croak("Internal error: argument is not an ARRAY ref") if ref($src) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 229 | ▶ | $src_name //= $self->{+SRC_NAME}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$src_name //= $self->{"Config::INI::RefVars __ SRC_NAME"}
MC/DC0%0/2
$src_name //= $self->{"Config::INI::RefVars __ SRC_NAME"}
$src_name
$self->{"Config::INI::RefVars __ SRC_NAME"}
Truth table33%1/3
A //= B
A= $src_nameB= $self->{"Config::INI::RefVars __ SRC_NAME"}
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 229 | ▶ | $src_dir //= '.'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$src_dir //= "."
MC/DC0%0/1
$src_dir //= "."
$src_dir
Truth table50%1/2
A
A= $src_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 229 | ▶ | $include_stack //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$include_stack //= {}
MC/DC0%0/1
$include_stack //= {}
$include_stack
Truth table50%1/2
A
A= $include_stack
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 229 | my $cmnt_vl = $self->{+CMNT_VL}; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 229 | my $sections = $self->{+SECTIONS}; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 229 | my $sections_h = $self->{+SECTIONS_H}; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 229 | my $expanded = $self->{+EXPANDED}; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 229 | my $variables = $self->{+VARIABLES}; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 229 | my $functions = $self->{+FUNCTIONS}; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 229 | my $tocopy_sec = $self->{+TOCOPY_SECTION}; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 229 | my $tocopy_vars = $variables->{$tocopy_sec}; # hash key need not to exist! | |||||||||||||||||||||||||||||||||||||||||
| 350 | 229 | my $global_mode = $self->{+GLOBAL_MODE}; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 229 | my $vnm_chk_re = $self->{+VARNAME_CHK_RE}; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 229 | my $tocopy_sec_declared; | |||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | my $i; # index in for() loop | ||||||||||||||||||||||||||||||||||||||||||
| 356 | 229 | ▶ | my $_fatal = sub { croak("'$src_name': ", $_[0], " at line ", $i + 1); }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | my $_include_file = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my ($include) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $include =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $include =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | $_fatal->("missing file name in include directive") if $include eq ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | $include = $self->$_expand_vars(defined($curr_section) ? $curr_section : $tocopy_sec, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 367 | $include, | ||||||||||||||||||||||||||||||||||||||||||
| 368 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 1, | ||||||||||||||||||||||||||||||||||||||||||
| 370 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | my $path = file_name_is_absolute($include) ? $include : catfile($src_dir, $include); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | my $abs_path = abs_path($path) or $_fatal->("'$include': cannot resolve include file"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | $_fatal->("'$include': recursive include") if exists($include_stack->{$abs_path}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | local $include_stack->{$abs_path} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my ($vol, $dirs) = splitpath($abs_path); | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | my $inc_dir = catdir(length($vol // "") ? $vol : (), $dirs); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$vol // ""
MC/DC0%0/1
$vol // ""
$vol
Truth table0%0/2
A
A= $vol
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my ($inc_tocopy_declared, $inc_curr_section) = | |||||||||||||||||||||||||||||||||||||||||
| 384 | $self->$_parse_ini($_read_ini_file->($abs_path), | ||||||||||||||||||||||||||||||||||||||||||
| 385 | $curr_section, | ||||||||||||||||||||||||||||||||||||||||||
| 386 | $include_stack, | ||||||||||||||||||||||||||||||||||||||||||
| 387 | $inc_dir, | ||||||||||||||||||||||||||||||||||||||||||
| 388 | $abs_path, | ||||||||||||||||||||||||||||||||||||||||||
| 389 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | $tocopy_sec_declared ||= $inc_tocopy_declared; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$tocopy_sec_declared ||= $inc_tocopy_declared
MC/DC0%0/2
$tocopy_sec_declared ||= $inc_tocopy_declared
$tocopy_sec_declared
$inc_tocopy_declared
Truth table0%0/3
A ||= B
A= $tocopy_sec_declaredB= $inc_tocopy_declared
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | $curr_section = $inc_curr_section if defined($inc_curr_section); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 229 | }; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 377 | ▶ | my $set_curr_section = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 377 | $curr_section = shift; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 377 | ▶ | if ($curr_section eq $tocopy_sec) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 57 | ▶ | $_fatal->("tocopy section '$tocopy_sec' must be first section") if @$sections; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 54 | ▶ | $tocopy_vars = $variables->{$tocopy_sec} = {} if !$tocopy_vars; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | 54 | ▶ | $functions->{$tocopy_sec} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$functions->{$tocopy_sec} //= {}
MC/DC0%0/1
$functions->{$tocopy_sec} //= {}
$functions->{$tocopy_sec}
Truth table50%1/2
A
A= $functions->{$tocopy_sec}
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 54 | $tocopy_sec_declared = 1; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | ▶ | elsif ($tocopy_vars && !$global_mode) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$tocopy_vars and not $global_mode
MC/DC50%1/2
$tocopy_vars and not $global_mode
$tocopy_vars
not $global_mode
Truth table66%2/3
A and not(B)
A= $tocopy_varsB= not $global_mode
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 304 | $self->$_cp_tocopy_vars($curr_section); | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 16 | $variables->{$curr_section} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 374 | ▶ | $functions->{$curr_section} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$functions->{$curr_section} //= {}
MC/DC100%1/1
$functions->{$curr_section} //= {}
$functions->{$curr_section}
Truth table100%2/2
A
A= $functions->{$curr_section}
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 374 | ▶ | $_fatal->("'$curr_section': duplicate header") if exists($sections_h->{$curr_section}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 373 | $sections_h->{$curr_section} = @$sections; # Index! | |||||||||||||||||||||||||||||||||||||||||
| 413 | 373 | push(@$sections, $curr_section); | |||||||||||||||||||||||||||||||||||||||||
| 414 | 229 | }; | |||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 229 | ▶ | for ($i = 0; $i < @$src; ++$i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 1492 | my $line = $src->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 1492 | $line =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 1492 | ▶ | next if $line eq ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 1303 | ▶ | if ($line =~ /^=include(?:\s+(.+))?\z/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | $_include_file->($1 // ""); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$1 // ""
MC/DC0%0/1
$1 // ""
$1
Truth table0%0/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 1303 | ▶ | if (index($line, ";!") == 0 || index($line, "=") == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
index($line, ";!") == 0 or index($line, "=") == 0
MC/DC100%2/2
index($line, ";!") == 0 or index($line, "=") == 0
index($line, ";!") == 0
index($line, "=") == 0
Truth table100%3/3
A or B
A= index($line, ";!") == 0B= index($line, "=") == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 2 | $_fatal->("directives are not yet supported"); | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 1301 | $line =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 431 | 1301 | ▶ | next if $line eq "" || $line =~ /^[;#]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$line eq "" or $line =~ /^[;#]/
MC/DC50%1/2
$line eq "" or $line =~ /^[;#]/
$line eq ""
$line =~ /^[;#]/
Truth table66%2/3
A or B
A= $line eq ""B= $line =~ /^[;#]/
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | # section header | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 1279 | ▶ | if (index($line, "[") == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 335 | $line =~ s/\s*[#;][^\]]*$//; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 335 | ▶ | $line =~ /^\[\s*(.*?)\s*\]$/ or $_fatal->("invalid section header"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 333 | $set_curr_section->($1); | |||||||||||||||||||||||||||||||||||||||||
| 438 | 329 | next; | |||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | # var = val | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 944 | ▶ | $line =~ s/\s+;.*$// if $cmnt_vl; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 944 | ▶ | $set_curr_section->($tocopy_sec) if !defined($curr_section); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 944 | ▶ | $line =~ /^(.*?)\s*($Modifier_Char*?)=(?:\s*)(.*)/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | or $_fatal->("neither section header nor key definition"); | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 943 | my ($var_name, $modifier, $value) = ($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 943 | ▶ | if ($modifier =~ s/\\\z//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 16 | ▶ | while ($value =~ s/\\\z//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 19 | ▶ | last if $i + 1 >= @$src; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 16 | my $next_line = $src->[++$i]; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 16 | $next_line =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 16 | ▶ | if (index($next_line, "=") == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 2 | $_fatal->("directive in line continuation"); | |||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||
| 459 | 14 | $value .= $next_line; | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 941 | ▶ | if ($vnm_chk_re) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 6 | ▶ | croak("'$var_name': var name does not match varname_chk_re") if $var_name !~ $vnm_chk_re; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 940 | my $x_var_name = $self->$_x_var_name($curr_section, $var_name); | |||||||||||||||||||||||||||||||||||||||||
| 467 | 940 | my $exp_flag = exists($expanded->{$x_var_name}); | |||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | 940 | ▶ | $_fatal->("empty variable name") if $var_name eq ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 938 | ▶ | my $sect_vars = $variables->{$curr_section} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$variables->{$curr_section} //= {}
MC/DC0%0/1
$variables->{$curr_section} //= {}
$variables->{$curr_section}
Truth table50%1/2
A
A= $variables->{$curr_section}
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 938 | ▶ | my $sect_funcs = $functions->{$curr_section} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$functions->{$curr_section} //= {}
MC/DC0%0/1
$functions->{$curr_section} //= {}
$functions->{$curr_section}
Truth table50%1/2
A
A= $functions->{$curr_section}
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 938 | ▶ | if ($modifier eq '#') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 41 | $sect_funcs->{$var_name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | elsif ($modifier eq "") { | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 694 | ▶ | delete $expanded->{$x_var_name} if $exp_flag; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 694 | $sect_vars->{$var_name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | elsif ($modifier eq '?') { | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 12 | ▶ | $sect_vars->{$var_name} = $value if !exists($sect_vars->{$var_name}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | elsif ($modifier eq '??') { | ||||||||||||||||||||||||||||||||||||||||||
| 485 | $sect_vars->{$var_name} = $value | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 9 | ▶ | if (!exists($sect_vars->{$var_name}) || $sect_vars->{$var_name} eq ""); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $sect_vars->{$var_name} or $sect_vars->{$var_name} eq ""
MC/DC100%2/2
not exists $sect_vars->{$var_name} or $sect_vars->{$var_name} eq ""
not exists $sect_vars->{$var_name}
$sect_vars->{$var_name} eq ""
Truth table100%3/3
not(A) or B
A= not exists $sect_vars->{$var_name}B= $sect_vars->{$var_name} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | elsif ($modifier eq '+') { | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 43 | ▶ | if (exists($sect_vars->{$var_name})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 30 | ▶ | $sect_vars->{$var_name} .= " " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | . ($exp_flag ? $self->$_expand_value($curr_section, $value) : $value); | ||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 494 | 13 | $sect_vars->{$var_name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | elsif ($modifier eq '.') { | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 31 | ▶ | $sect_vars->{$var_name} = ($sect_vars->{$var_name} // "") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$sect_vars->{$var_name} // ""
MC/DC100%1/1
$sect_vars->{$var_name} // ""
$sect_vars->{$var_name}
Truth table100%2/2
A
A= $sect_vars->{$var_name}
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | . ($exp_flag ? $self->$_expand_value($curr_section, $value) : $value); | ||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | elsif ($modifier eq ':') { | ||||||||||||||||||||||||||||||||||||||||||
| 502 | 84 | ▶ | delete $expanded->{$x_var_name} if $exp_flag; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 84 | $sect_vars->{$var_name} = $self->$_expand_vars($curr_section, $var_name, $value, undef, 1); | |||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | elsif ($modifier eq '+>') { | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 12 | ▶ | if (exists($sect_vars->{$var_name})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | $sect_vars->{$var_name} = | ||||||||||||||||||||||||||||||||||||||||||
| 508 | ($exp_flag ? $self->$_expand_value($curr_section, $value) : $value) | ||||||||||||||||||||||||||||||||||||||||||
| 509 | 8 | ▶ | . ' ' . $sect_vars->{$var_name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||
| 511 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 4 | $sect_vars->{$var_name} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 515 | elsif ($modifier eq '.>') { | ||||||||||||||||||||||||||||||||||||||||||
| 516 | $sect_vars->{$var_name} = ($exp_flag ? $self->$_expand_value($curr_section, $value) : $value) | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 11 | ▶ | . ($sect_vars->{$var_name} // ""); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$sect_vars->{$var_name} // ""
MC/DC100%1/1
$sect_vars->{$var_name} // ""
$sect_vars->{$var_name}
Truth table100%2/2
A
A= $sect_vars->{$var_name}
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 1 | $_fatal->("'$modifier': unsupported modifier"); | |||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 204 | return ($tocopy_sec_declared, $curr_section); | |||||||||||||||||||||||||||||||||||||||||
| 524 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | 243 | ▶ | sub parse_ini { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_ini: called CC=43 SCAR=37.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | 243 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 529 | 243 | my %args = (cleanup => 1, @_); | |||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | state $allowed_keys = { | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 243 | map { $_ => undef } qw(cleanup src src_name tocopy_section tocopy_vars not_tocopy) | |||||||||||||||||||||||||||||||||||||||||
| 533 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 243 | state $dflt_src_name = "INI data"; | |||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 243 | _check_args(\%args, $allowed_keys); | |||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | 242 | foreach my $scalar_arg (qw(tocopy_section src_name)) { | |||||||||||||||||||||||||||||||||||||||||
| 539 | 483 | ▶ | croak("'$scalar_arg': must not be a reference") if ref($args{$scalar_arg}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 240 | ▶ | delete $self->{+SRC_NAME} if exists($self->{+SRC_NAME}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 240 | ▶ | $self->{+SRC_NAME} = $args{src_name} if exists($args{src_name}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | my ($cleanup, $src, $tocopy_section, $tocopy_vars, $not_tocopy) | ||||||||||||||||||||||||||||||||||||||||||
| 546 | 240 | = @args{qw(cleanup src tocopy_section tocopy_vars not_tocopy)}; | |||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | 240 | ▶ | croak("'src': missing mandatory argument") if !defined($src); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | 239 | ▶ | my $backup = $self->{+BACKUP} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"Config::INI::RefVars __ BACKUP"} //= {}
MC/DC100%1/1
$self->{"Config::INI::RefVars __ BACKUP"} //= {}
$self->{"Config::INI::RefVars __ BACKUP"}
Truth table100%2/2
A
A= $self->{"Config::INI::RefVars __ BACKUP"}
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 239 | ▶ | if (defined($tocopy_section)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 8 | $backup->{tocopy_section} = $self->{+TOCOPY_SECTION}; | |||||||||||||||||||||||||||||||||||||||||
| 554 | 8 | $self->{+TOCOPY_SECTION} = $tocopy_section; | |||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||
| 556 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 231 | $tocopy_section = $self->{+TOCOPY_SECTION}; | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | 239 | $self->{+CURR_TOCP_SECTION} = $tocopy_section; | |||||||||||||||||||||||||||||||||||||||||
| 561 | 239 | $Globals{'=TO_CP_SEC'} = $tocopy_section; | |||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 239 | ▶ | if ($tocopy_vars) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 16 | $backup->{tocopy_vars} = $self->{+TOCOPY_VARS}; | |||||||||||||||||||||||||||||||||||||||||
| 565 | 16 | $self->$_check_tocopy_vars($tocopy_vars, 1); | |||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 234 | ▶ | if ($not_tocopy) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | 10 | $backup->{not_tocopy} = $self->{+NOT_TOCOPY}; | |||||||||||||||||||||||||||||||||||||||||
| 570 | 10 | $self->$_check_not_tocopy($not_tocopy, 1); | |||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 231 | $self->{+SECTIONS} = []; | |||||||||||||||||||||||||||||||||||||||||
| 574 | 231 | $self->{+SECTIONS_H} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 575 | 231 | $self->{+EXPANDED} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 576 | $self->{+VARIABLES} = { | ||||||||||||||||||||||||||||||||||||||||||
| 577 | 231 | ▶ | $tocopy_section => ($self->{+TOCOPY_VARS} ? {%{$self->{+TOCOPY_VARS}}} : {}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 231 | $self->{+FUNCTIONS} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 231 | my $global_vars = $self->{+GLOBAL_VARS} = {%Globals}; | |||||||||||||||||||||||||||||||||||||||||
| 582 | 231 | my $variables = $self->{+VARIABLES}; | |||||||||||||||||||||||||||||||||||||||||
| 583 | 231 | my $tocopy_sec_vars = $variables->{$tocopy_section}; | |||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | 231 | ▶ | if (my $ref_src = ref($src)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | 88 | ▶ | $self->{+SRC_NAME} = $dflt_src_name if !exists($self->{+SRC_NAME}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | 88 | ▶ | if ($ref_src eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | 87 | $src = [@$src]; | |||||||||||||||||||||||||||||||||||||||||
| 590 | 87 | foreach my $entry (@$src) { | |||||||||||||||||||||||||||||||||||||||||
| 591 | 525 | ▶ | croak("'src': unexpected ref type in array") if ref($entry); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | 524 | ▶ | if (!defined($entry)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | carp("'src': undef entry - treated as empty string"); | |||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | $entry = ""; | |||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 598 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | croak("'src': $ref_src: ref type not allowed"); | |||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 603 | 143 | ▶ | if (index($src, "\n") < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | 14 | my $path = $src; | |||||||||||||||||||||||||||||||||||||||||
| 605 | 14 | ▶ | my $abs_path = abs_path($path) or croak("'$path': cannot resolve file name"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 14 | $src = $_read_ini_file->($abs_path); | |||||||||||||||||||||||||||||||||||||||||
| 607 | 14 | ▶ | $self->{+SRC_NAME} = $path if !exists($self->{+SRC_NAME}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 14 | my ($vol, $dirs, $file) = splitpath($abs_path); | |||||||||||||||||||||||||||||||||||||||||
| 610 | 14 | ▶ | @{$global_vars}{'=INIfile', '=INIdir'} = ($file, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$vol // ""
MC/DC0%0/1
$vol // ""
$vol
Truth table50%1/2
A
A= $vol
| |||||||||||||||||||||||||||||||||||||||||||
| 611 | catdir(length($vol // "") ? $vol : (), $dirs), | ||||||||||||||||||||||||||||||||||||||||||
| 612 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 615 | 129 | $src = [split(/\n/, $src)]; | |||||||||||||||||||||||||||||||||||||||||
| 616 | 129 | ▶ | $self->{+SRC_NAME} = $dflt_src_name if !exists($self->{+SRC_NAME}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 229 | $global_vars->{'=srcname'} = $self->{+SRC_NAME}; | |||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | 229 | my $src_dir = '.'; | |||||||||||||||||||||||||||||||||||||||||
| 623 | 229 | my $include_stack = {}; | |||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | 229 | ▶ | if (!ref($args{src}) && index($args{src}, "\n") < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $args{"src"} and index($args{"src"}, "\n") == -1
MC/DC100%2/2
not ref $args{"src"} and index($args{"src"}, "\n") == -1
not ref $args{"src"}
index($args{"src"}, "\n") == -1
Truth table100%3/3
not(A) and B
A= not ref $args{"src"}B= index($args{"src"}, "\n") == -1
| |||||||||||||||||||||||||||||||||||||||||||
| 626 | my $abs_path = abs_path($args{src}) | ||||||||||||||||||||||||||||||||||||||||||
| 627 | 14 | ▶ | or croak("'$args{src}': cannot resolve file name"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | 14 | $include_stack->{$abs_path} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 629 | 14 | my ($vol, $dirs) = splitpath($abs_path); | |||||||||||||||||||||||||||||||||||||||||
| 630 | 14 | ▶ | $src_dir = catdir(length($vol // "") ? $vol : (), $dirs); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$vol // ""
MC/DC0%0/1
$vol // ""
$vol
Truth table50%1/2
A
A= $vol
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||
| 633 | my ($tocopy_sec_declared, undef) = $self->$_parse_ini($src, | ||||||||||||||||||||||||||||||||||||||||||
| 634 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 635 | $include_stack, | ||||||||||||||||||||||||||||||||||||||||||
| 636 | $src_dir, | ||||||||||||||||||||||||||||||||||||||||||
| 637 | 229 | $self->{+SRC_NAME}, | |||||||||||||||||||||||||||||||||||||||||
| 638 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | my @sections = ((exists($self->{+SECTIONS_H}{$tocopy_section}) ? () : $tocopy_section), | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 204 | ▶ | @{$self->{+SECTIONS}}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | 204 | foreach my $section (@sections) { | |||||||||||||||||||||||||||||||||||||||||
| 645 | 499 | my $sec_vars = $variables->{$section}; | |||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||
| 647 | 499 | foreach my $variable (keys(%$sec_vars)) { | |||||||||||||||||||||||||||||||||||||||||
| 648 | 960 | my $value = $sec_vars->{$variable}; | |||||||||||||||||||||||||||||||||||||||||
| 649 | 960 | $sec_vars->{$variable} = $self->$_expand_vars($section, $variable, $value); | |||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | 176 | ▶ | if ($cleanup) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | 171 | foreach my $section (keys(%$variables)) { | |||||||||||||||||||||||||||||||||||||||||
| 655 | 426 | my $sec_vars = $variables->{$section}; | |||||||||||||||||||||||||||||||||||||||||
| 656 | 426 | foreach my $var (keys(%$sec_vars)) { | |||||||||||||||||||||||||||||||||||||||||
| 657 | 846 | ▶ | delete $sec_vars->{$var} if index($var, '=') >= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 171 | ▶ | delete $variables->{$self->{+TOCOPY_SECTION}} if (!$tocopy_sec_declared && !%$tocopy_sec_vars); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tocopy_sec_declared or %$tocopy_sec_vars
MC/DC100%2/2
$tocopy_sec_declared or %$tocopy_sec_vars
$tocopy_sec_declared
%$tocopy_sec_vars
Truth table100%3/3
A or B
A= $tocopy_sec_declaredB= %$tocopy_sec_vars
| |||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 664 | 5 | ▶ | if ($self->{+GLOBAL_MODE}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 665 | 2 | foreach my $section (keys(%$variables)) { | |||||||||||||||||||||||||||||||||||||||||
| 666 | 6 | my $sec_vars = $variables->{$section}; | |||||||||||||||||||||||||||||||||||||||||
| 667 | 6 | $sec_vars->{'='} = $section; | |||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||
| 669 | 2 | @{$tocopy_sec_vars}{keys(%$global_vars)} = values(%$global_vars); | |||||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||||
| 671 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 672 | 3 | foreach my $section (keys(%$variables)) { | |||||||||||||||||||||||||||||||||||||||||
| 673 | 9 | my $sec_vars = $variables->{$section}; | |||||||||||||||||||||||||||||||||||||||||
| 674 | 9 | $sec_vars->{'='} = $section; | |||||||||||||||||||||||||||||||||||||||||
| 675 | 9 | @{$sec_vars}{keys(%$global_vars)} = values(%$global_vars); | |||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | 176 | ▶ | $self->{+TOCOPY_SECTION} = $backup->{tocopy_section} if exists($backup->{tocopy_section}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | 176 | ▶ | $self->{+TOCOPY_VARS} = $backup->{tocopy_vars} if exists($backup->{tocopy_vars}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 682 | 176 | ▶ | $self->{+NOT_TOCOPY} = $backup->{not_tocopy} if exists($backup->{not_tocopy}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 683 | 176 | $backup = {}; | |||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | 176 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | 11 | ▶ | sub current_tocopy_section { $_[0]->{+CURR_TOCP_SECTION} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
current_tocopy_section: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | 22 | ▶ | sub tocopy_section { $_[0]->{+TOCOPY_SECTION} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tocopy_section: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 691 | 20 | ▶ | sub global_mode { $_[0]->{+GLOBAL_MODE} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
global_mode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | 23 | ▶ | sub sections { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sections: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 694 | 23 | ▶ | return defined($_[0]->{+SECTIONS}) ? [@{$_[0]->{+SECTIONS}}] : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | 22 | ▶ | sub sections_h { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sections_h: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 698 | 22 | ▶ | return defined($_[0]->{+SECTIONS_H}) ? +{ %{$_[0]->{+SECTIONS_H}} } : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | 13 | ▶ | sub separator { $_[0]->{+SEPARATOR} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
separator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 702 | 7 | ▶ | sub src_name { $_[0]->{+SRC_NAME} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
src_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | 174 | ▶ | sub variables { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
variables: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 706 | 174 | ▶ | my $vars = $_[0]->{+VARIABLES} // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_[0]{"Config::INI::RefVars __ VARIABLES"} // (return undef)
MC/DC100%1/1
$_[0]{"Config::INI::RefVars __ VARIABLES"} // (return undef)
$_[0]{"Config::INI::RefVars __ VARIABLES"}
Truth table100%2/2
A
A= $_[0]{"Config::INI::RefVars __ VARIABLES"}
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | 173 | return { map { $_ => {%{$vars->{$_}}} } keys(%$vars) }; | |||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||
| 711 | 765 | ▶ | $_look_up = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=18 SCAR=29.1
| |||||||||||||||||||||||||||||||||||||||||||
| 712 | 765 | my ($self, $curr_sect, $variable) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 713 | 765 | my $matched = $variable =~ $self->{+VREF_RE}; | |||||||||||||||||||||||||||||||||||||||||
| 714 | 765 | ▶ | my ($v_section, $v_basename) = $matched ? ($1, $2) : ($curr_sect, $variable); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 715 | 765 | my $v_value; | |||||||||||||||||||||||||||||||||||||||||
| 716 | 765 | my $variables = $self->{+VARIABLES}; | |||||||||||||||||||||||||||||||||||||||||
| 717 | 765 | my $tocopy_section = $self->{+TOCOPY_SECTION}; | |||||||||||||||||||||||||||||||||||||||||
| 718 | 765 | ▶ | if (!exists($variables->{$v_section})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 719 | 67 | $v_value = ""; | |||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||
| 721 | elsif (exists($variables->{$v_section}{$v_basename})) { | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 330 | $v_value = $variables->{$v_section}{$v_basename}; | |||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||
| 724 | elsif ($v_basename !~ /\S/) { | ||||||||||||||||||||||||||||||||||||||||||
| 725 | 102 | $v_value = $v_basename; | |||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||
| 727 | elsif ($v_basename eq '=') { | ||||||||||||||||||||||||||||||||||||||||||
| 728 | 96 | $v_value = $v_section; | |||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | elsif ($v_basename =~ /^=(?:ENV|env):\s*(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 42 | ▶ | $v_value = $ENV{$1} // ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{$1} // ""
MC/DC100%1/1
$ENV{$1} // ""
$ENV{$1}
Truth table100%2/2
A
A= $ENV{$1}
| |||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||
| 733 | elsif ($v_basename =~ /^=CONFIG:\s*(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 734 | 6 | ▶ | $v_value = $Config{$1} // ""; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$Config::INI::RefVars::Config{$1} // ""
MC/DC0%0/1
$Config::INI::RefVars::Config{$1} // ""
$Config::INI::RefVars::Config{$1}
Truth table50%1/2
A
A= $Config::INI::RefVars::Config{$1}
| |||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | elsif (exists($self->{+GLOBAL_VARS}{$v_basename})) { | ||||||||||||||||||||||||||||||||||||||||||
| 737 | 66 | $v_value = $self->{+GLOBAL_VARS}{$v_basename}; | |||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||
| 739 | ▶ | elsif ($self->{+GLOBAL_MODE} && exists($variables->{$tocopy_section}{$v_basename})) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"Config::INI::RefVars __ GLOBAL_MODE"} and exists $variables->{$tocopy_section}{$v_basename}
MC/DC50%1/2
$self->{"Config::INI::RefVars __ GLOBAL_MODE"} and exists $variables->{$tocopy_section}{$v_basename}
$self->{"Config::INI::RefVars __ GLOBAL_MODE"}
exists $variables->{$tocopy_section}{$v_basename}
Truth table66%2/3
A and B
A= $self->{"Config::INI::RefVars __ GLOBAL_MODE"}B= exists $variables->{$tocopy_section}{$v_basename}
| |||||||||||||||||||||||||||||||||||||||||||
| 740 | 15 | ▶ | if (!$matched | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not $matched and $curr_sect ne $tocopy_section and exists $self->{"Config::INI::RefVars __ NOT_TOCOPY"}{$v_basename}
not $matched and $curr_sect ne $tocopy_section
MC/DC33%1/3
not $matched and $curr_sect ne $tocopy_section and exists $self->{"Config::INI::RefVars __ NOT_TOCOPY"}{$v_basename}
not $matched
$curr_sect ne $tocopy_section
exists $self->{"Config::INI::RefVars __ NOT_TOCOPY"}{$v_basename}
Truth table50%2/4
not(A) and B and C
A= not $matchedB= $curr_sect ne $tocopy_sectionC= exists $self->{"Config::INI::RefVars __ NOT_TOCOPY"}{$v_basename}
| |||||||||||||||||||||||||||||||||||||||||||
| 741 | && $curr_sect ne $tocopy_section | ||||||||||||||||||||||||||||||||||||||||||
| 742 | && exists($self->{+NOT_TOCOPY}{$v_basename}) | ||||||||||||||||||||||||||||||||||||||||||
| 743 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 744 | 2 | $v_value = ""; | |||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||
| 746 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 747 | 13 | $v_value = $variables->{$tocopy_section}{$v_basename}; | |||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||
| 750 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 751 | 41 | $v_value = ""; | |||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 765 | ▶ | die("Internal error") if !defined($v_value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 754 | 765 | ▶ | return wantarray ? ($v_section, $v_basename, $v_value) : $v_value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 755 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | # Extended name of a variable definition | ||||||||||||||||||||||||||||||||||||||||||
| 759 | 2724 | ▶ | $_x_var_name = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 760 | 2724 | my ($self, $curr_sect, $variable) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | 2724 | return ($variable, "[$curr_sect]$variable"); | |||||||||||||||||||||||||||||||||||||||||
| 763 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 2166 | ▶ | $_expand_vars = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=17 SCAR=28.3
| |||||||||||||||||||||||||||||||||||||||||||
| 767 | 2166 | my ($self, $curr_sect, $variable, $value, $seen, $not_seen) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 768 | 2166 | my $top = !$seen; | |||||||||||||||||||||||||||||||||||||||||
| 769 | 2166 | my @result = (""); | |||||||||||||||||||||||||||||||||||||||||
| 770 | 2166 | my @raw = (""); | |||||||||||||||||||||||||||||||||||||||||
| 771 | 2166 | my $level = 0; | |||||||||||||||||||||||||||||||||||||||||
| 772 | 2166 | my $x_variable_name; | |||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 2166 | ▶ | if (defined($variable)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | 1784 | ((my $var_basename), $x_variable_name) = $self->$_x_var_name($curr_sect, $variable); | |||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||
| 777 | 1784 | ▶ | if (exists($self->{+EXPANDED}{$x_variable_name})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | 205 | return $self->{+VARIABLES}{$curr_sect}{$variable}; | |||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||
| 780 | 1579 | ▶ | if ($var_basename =~ /^=(?:ENV|CONFIG):/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | 25 | return $self->$_look_up($curr_sect, $variable); | |||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | croak("recursive variable '$x_variable_name' references itself") | ||||||||||||||||||||||||||||||||||||||||||
| 785 | 1554 | ▶ | if exists($seen->{$x_variable_name}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||
| 787 | 1551 | ▶ | $seen->{$x_variable_name} = undef if !$not_seen; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | 1933 | foreach my $token (split(/(\$\(|\))/, $value)) { | |||||||||||||||||||||||||||||||||||||||||
| 791 | 4836 | ▶ | if ($token eq '$(') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 792 | 943 | ++$level; | |||||||||||||||||||||||||||||||||||||||||
| 793 | 943 | ▶ | $raw[$level - 1] .= '$(' if $level > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||
| 795 | ▶ | elsif ($token eq ')' && $level) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$token eq ")" and $level
MC/DC100%2/2
$token eq ")" and $level
$token eq ")"
$level
Truth table100%3/3
A and B
A= $token eq ")"B= $level
| |||||||||||||||||||||||||||||||||||||||||||
| 796 | 938 | my $raw_expr = $raw[$level]; | |||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | 938 | ▶ | if ($result[$level] eq '==') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 30 | $result[$level - 1] .= $variable; | |||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||
| 801 | elsif ($raw_expr =~ /^\s*=#\s*(.*)$/s) { | ||||||||||||||||||||||||||||||||||||||||||
| 802 | 49 | $result[$level - 1] .= $self->$_user_function_call($curr_sect, $1, $seen); | |||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||
| 804 | elsif ($raw_expr =~ /^\s*=&\s*(.*)$/s) { | ||||||||||||||||||||||||||||||||||||||||||
| 805 | 119 | $result[$level - 1] .= $self->$_dispatch_call($curr_sect, $1, $seen); | |||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||
| 807 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 808 | 740 | my ($ref_section, $ref_variable, $ref_value) = | |||||||||||||||||||||||||||||||||||||||||
| 809 | $self->$_look_up($curr_sect, $result[$level]); | ||||||||||||||||||||||||||||||||||||||||||
| 810 | 740 | $result[$level - 1] .= $self->$_expand_vars( | |||||||||||||||||||||||||||||||||||||||||
| 811 | $ref_section, | ||||||||||||||||||||||||||||||||||||||||||
| 812 | $ref_variable, | ||||||||||||||||||||||||||||||||||||||||||
| 813 | $ref_value, | ||||||||||||||||||||||||||||||||||||||||||
| 814 | $seen, | ||||||||||||||||||||||||||||||||||||||||||
| 815 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 816 | } | ||||||||||||||||||||||||||||||||||||||||||
| 817 | 896 | $raw[$level - 1] .= $raw_expr . ')'; | |||||||||||||||||||||||||||||||||||||||||
| 818 | 896 | pop(@result); | |||||||||||||||||||||||||||||||||||||||||
| 819 | 896 | pop(@raw); | |||||||||||||||||||||||||||||||||||||||||
| 820 | 896 | --$level; | |||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||
| 822 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 823 | 2955 | $result[$level] .= $token; | |||||||||||||||||||||||||||||||||||||||||
| 824 | 2955 | $raw[$level] .= $token; | |||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||
| 828 | 1891 | ▶ | croak("'$x_variable_name': unterminated variable reference") if $level; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | 1887 | $value = $result[0]; | |||||||||||||||||||||||||||||||||||||||||
| 830 | 1887 | ▶ | if ($x_variable_name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | 1510 | ▶ | $self->{+EXPANDED}{$x_variable_name} = undef if $top; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | 1510 | delete $seen->{$x_variable_name}; | |||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||
| 834 | 1887 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 835 | 31 | }; | |||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | # | ||||||||||||||||||||||||||||||||||||||||||
| 839 | # This is a function, not a method! | ||||||||||||||||||||||||||||||||||||||||||
| 840 | # | ||||||||||||||||||||||||||||||||||||||||||
| 841 | 436 | ▶ | sub _check_args { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_args: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 842 | 436 | my ($args, $allowed_args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 843 | 436 | foreach my $key (keys(%$args)) { | |||||||||||||||||||||||||||||||||||||||||
| 844 | 582 | ▶ | croak("'$key': unsupported argument") if !exists($allowed_args->{$key}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||
| 846 | 434 | delete @{$args}{ grep { !defined($args->{$_}) } keys(%$args) }; | |||||||||||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | 31 | 1; # End of Config::INI::RefVars | |||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||
| 853 | __END__ | ||||||||||||||||||||||||||||||||||||||||||