| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Config::General.pm - Generic Config Module | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Purpose: Provide a convenient way for loading | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # config values from a given file and | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # return it as hash structure | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # Copyright (c) 2000-2026 Thomas Linden <tlinden |AT| cpan.org>. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # All Rights Reserved. Std. disclaimer applies. | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # Licensed under the Artistic License 2.0. | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # namespace | ||||||||||||||||||||||||||||||||||||||||||
| 13 | package Config::General; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use English '-no_match_vars'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use FileHandle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use File::Spec::Functions qw(splitpath file_name_is_absolute catfile catpath); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use File::Glob qw/:glob/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # on debian with perl > 5.8.4 croak() doesn't work anymore without this. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # There is some require statement which dies 'cause it can't find Carp::Heavy, | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # I really don't understand, what the hell they made, but the debian perl | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # installation is definitely bullshit, damn! | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use Carp::Heavy; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | $Config::General::VERSION = "2.69"; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | our @EXPORT_OK = qw(ParseConfig SaveConfig SaveConfigString); | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | ▶ | use constant _UTF8_BOM => "\x{ef}\x{bb}\x{bf}"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 86 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # create new Config::General object | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 86 | my($this, @param ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 86 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table66%2/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # define default options | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 86 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 51 | # sha256 of current date | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # hopefully this lowers the probability that | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # this matches any configuration key or value out there | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # bugfix for rt.40925 | ||||||||||||||||||||||||||||||||||||||||||
| 55 | EOFseparator => 'ad7d7b87f5b81d2a0d5cb75294afeb91aa4801b1f8e8532dc1b633c0e1d47037', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | SlashIsDirectory => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | AllowMultiOptions => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | MergeDuplicateOptions => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | MergeDuplicateBlocks => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | LowerCaseNames => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ApacheCompatible => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | UseApacheInclude => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | IncludeRelative => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | IncludeDirectories => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | IncludeGlob => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | IncludeAgain => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | AutoLaunder => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | AutoTrue => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | AutoTrueFlags => { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | true => '^(on|yes|true|1)$', | ||||||||||||||||||||||||||||||||||||||||||
| 71 | false => '^(off|no|false|0)$', | ||||||||||||||||||||||||||||||||||||||||||
| 72 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | DefaultConfig => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | String => '', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | level => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | InterPolateVars => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | InterPolateEnv => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ExtendedAccess => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | SplitPolicy => 'guess', # also possible: whitespace, equalsign and custom | ||||||||||||||||||||||||||||||||||||||||||
| 80 | SplitDelimiter => 0, # must be set by the user if SplitPolicy is 'custom' | ||||||||||||||||||||||||||||||||||||||||||
| 81 | StoreDelimiter => 0, # will be set by me unless user uses 'custom' policy | ||||||||||||||||||||||||||||||||||||||||||
| 82 | CComments => 1, # by default turned on | ||||||||||||||||||||||||||||||||||||||||||
| 83 | BackslashEscape => 0, # deprecated | ||||||||||||||||||||||||||||||||||||||||||
| 84 | StrictObjects => 1, # be strict on non-existent keys in OOP mode | ||||||||||||||||||||||||||||||||||||||||||
| 85 | StrictVars => 1, # be strict on undefined variables in Interpolate mode | ||||||||||||||||||||||||||||||||||||||||||
| 86 | Tie => q(), # could be set to a perl module for tie'ing new hashes | ||||||||||||||||||||||||||||||||||||||||||
| 87 | parsed => 0, # internal state stuff for variable interpolation | ||||||||||||||||||||||||||||||||||||||||||
| 88 | files => {}, # which files we have read, if any | ||||||||||||||||||||||||||||||||||||||||||
| 89 | UTF8 => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | SaveSorted => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ForceArray => 0, # force single value array if value enclosed in [] | ||||||||||||||||||||||||||||||||||||||||||
| 92 | AllowSingleQuoteInterpolation => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 93 | NoEscape => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 94 | NormalizeBlock => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 95 | NormalizeOption => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | NormalizeValue => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | Plug => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | UseApacheIfDefine => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | Define => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | AlwaysQuoteOutput => 0 | ||||||||||||||||||||||||||||||||||||||||||
| 101 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | # create the class instance | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 86 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 86 | ▶ | if ($#param >= 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | # use of the new hash interface! | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 76 | $self->_prepare(@param); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | elsif ($#param == 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | # use of the old style | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 9 | $self->{ConfigFile} = $param[0]; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 9 | ▶ | if (ref($self->{ConfigFile}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $self->{ConfigHash} = delete $self->{ConfigFile}; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 118 | # this happens if $#param == -1,1 thus no param was given to new! | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | $self->{config} = $self->_hashref(); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | $self->{parsed} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | # find split policy to use for option/value separation | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 71 | $self->_splitpolicy(); | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | # bless into variable interpolation module if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 71 | $self->_blessvars(); | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | # process as usual | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 71 | ▶ | if (!$self->{parsed}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 70 | $self->_process(); | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 63 | ▶ | if ($self->{InterPolateVars}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 11 | $self->{config} = $self->_clean_stack($self->{config}); | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | # bless into OOP namespace if required | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 63 | $self->_blessoop(); | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 63 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 70 | ▶ | sub _process { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process: called CC=11 SCAR=28.6
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | # | ||||||||||||||||||||||||||||||||||||||||||
| 148 | # call _read() and _parse() on the given config | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 70 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 70 | ▶ | if ($self->{DefaultConfig} && $self->{InterPolateVars}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"DefaultConfig"} and $self->{"InterPolateVars"}
MC/DC50%1/2
$self->{"DefaultConfig"} and $self->{"InterPolateVars"}
$self->{"DefaultConfig"}
$self->{"InterPolateVars"}
Truth table66%2/3
A and B
A= $self->{"DefaultConfig"}B= $self->{"InterPolateVars"}
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 11 | $self->{DefaultConfig} = $self->_interpolate_hash($self->{DefaultConfig}); # FIXME: _hashref() ? | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 70 | ▶ | if (exists $self->{StringContent}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | # consider the supplied string as config file | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 14 | $self->_read($self->{StringContent}, 'SCALAR'); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 14 | $self->{config} = $self->_parse($self->{DefaultConfig}, $self->{content}); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | elsif (exists $self->{ConfigHash}) { | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 11 | ▶ | if (ref($self->{ConfigHash}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | # initialize with given hash | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 10 | $self->{config} = $self->{ConfigHash}; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 10 | $self->{parsed} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | croak "Config::General: Parameter -ConfigHash must be a hash reference!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | ▶ | elsif (ref($self->{ConfigFile}) eq 'GLOB' || ref($self->{ConfigFile}) eq 'FileHandle') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $self->{"ConfigFile"} eq "GLOB" or ref $self->{"ConfigFile"} eq "FileHandle"
MC/DC0%0/2
ref $self->{"ConfigFile"} eq "GLOB" or ref $self->{"ConfigFile"} eq "FileHandle"
ref $self->{"ConfigFile"} eq "GLOB"
ref $self->{"ConfigFile"} eq "FileHandle"
Truth table33%1/3
A or B
A= ref $self->{"ConfigFile"} eq "GLOB"B= ref $self->{"ConfigFile"} eq "FileHandle"
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | # use the file the glob points to | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $self->_read($self->{ConfigFile}); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $self->{config} = $self->_parse($self->{DefaultConfig}, $self->{content}); | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 45 | ▶ | if ($self->{ConfigFile}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | # open the file and read the contents in | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 45 | $self->{configfile} = $self->{ConfigFile}; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 45 | ▶ | if ( file_name_is_absolute($self->{ConfigFile}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | # look if this is an absolute path and save the basename if it is absolute | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my ($volume, $path, undef) = splitpath($self->{ConfigFile}); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $path =~ s#/$##; # remove eventually existing trailing slash | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if (! $self->{ConfigPath}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $self->{ConfigPath} = []; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | unshift @{$self->{ConfigPath}}, catpath($volume, $path, q()); | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 45 | $self->_open($self->{configfile}); | |||||||||||||||||||||||||||||||||||||||||
| 188 | # now, we parse immediately, getall simply returns the whole hash | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 42 | $self->{config} = $self->_hashref(); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 42 | $self->{config} = $self->_parse($self->{DefaultConfig}, $self->{content}); | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # hm, no valid config file given, so try it as an empty object | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $self->{config} = $self->_hashref(); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $self->{parsed} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 63 | ▶ | sub _blessoop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_blessoop: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | # | ||||||||||||||||||||||||||||||||||||||||||
| 203 | # bless into ::Extended if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 63 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 63 | ▶ | if ($self->{ExtendedAccess}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | # we are blessing here again, to get into the ::Extended namespace | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # for inheriting the methods available over there, which we doesn't have. | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 11 | bless $self, 'Config::General::Extended'; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 11 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 210 | 11 | require Config::General::Extended; | |||||||||||||||||||||||||||||||||||||||||
| 211 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 11 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | croak "Config::General: " . $EVAL_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | # return $self; | ||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 71 | ▶ | sub _blessvars { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_blessvars: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | # | ||||||||||||||||||||||||||||||||||||||||||
| 221 | # bless into ::Interpolated if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 71 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 71 | ▶ | if ($self->{InterPolateVars} || $self->{InterPolateEnv}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"InterPolateVars"} or $self->{"InterPolateEnv"}
MC/DC50%1/2
$self->{"InterPolateVars"} or $self->{"InterPolateEnv"}
$self->{"InterPolateVars"}
$self->{"InterPolateEnv"}
Truth table66%2/3
A or B
A= $self->{"InterPolateVars"}B= $self->{"InterPolateEnv"}
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | # InterPolateEnv implies InterPolateVars | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 11 | $self->{InterPolateVars} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | # we are blessing here again, to get into the ::InterPolated namespace | ||||||||||||||||||||||||||||||||||||||||||
| 228 | # for inheriting the methods available overthere, which we doesn't have here. | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 11 | bless $self, 'Config::General::Interpolated'; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 11 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 231 | 11 | require Config::General::Interpolated; | |||||||||||||||||||||||||||||||||||||||||
| 232 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 11 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | croak "Config::General: " . $EVAL_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | # pre-compile the variable regexp | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 11 | $self->{regex} = $self->_set_regex(); | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 71 | ▶ | sub _splitpolicy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_splitpolicy: called CC=9 SCAR=31.7
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | # | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # find out what split policy to use | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 71 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 71 | ▶ | if ($self->{SplitPolicy} ne 'guess') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | if ($self->{SplitPolicy} eq 'whitespace') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $self->{SplitDelimiter} = '\s+'; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if (!$self->{StoreDelimiter}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $self->{StoreDelimiter} = q( ); | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | elsif ($self->{SplitPolicy} eq 'equalsign') { | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $self->{SplitDelimiter} = '\s*=\s*'; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if (!$self->{StoreDelimiter}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $self->{StoreDelimiter} = ' = '; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | elsif ($self->{SplitPolicy} eq 'custom') { | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | ▶ | if (! $self->{SplitDelimiter} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | croak "Config::General: SplitPolicy set to 'custom' but no SplitDelimiter set.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | croak "Config::General: Unsupported SplitPolicy: $self->{SplitPolicy}.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 69 | ▶ | if (!$self->{StoreDelimiter}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 69 | $self->{StoreDelimiter} = q( ); | |||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 76 | ▶ | sub _prepare { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prepare: called CC=37 SCAR=41.3
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | # | ||||||||||||||||||||||||||||||||||||||||||
| 277 | # prepare the class parameters, mangle them, if there | ||||||||||||||||||||||||||||||||||||||||||
| 278 | # are options to reset or to override, do it here. | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 76 | my ($self, %conf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | # save the parameter list for ::Extended's new() calls | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 76 | $self->{Params} = \%conf; | |||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | # be backwards compatible | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 76 | ▶ | if (exists $conf{-file}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 6 | $self->{ConfigFile} = delete $conf{-file}; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 76 | ▶ | if (exists $conf{-hash}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | if (! $self->_validate_input_hash($conf{-hash})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | croak "Config::General: supplied -hash hash contains invalid keys or values!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $self->{ConfigHash} = delete $conf{-hash}; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | # store input, file, handle, or array | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 76 | ▶ | if (exists $conf{-ConfigFile}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 30 | $self->{ConfigFile} = delete $conf{-ConfigFile}; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 76 | ▶ | if (exists $conf{-ConfigHash}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 25 | ▶ | if (! $self->_validate_input_hash($conf{-ConfigHash})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 14 | croak "Config::General: supplied -ConfigHash hash contains invalid keys or values!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 11 | $self->{ConfigHash} = delete $conf{-ConfigHash}; | |||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | # store search path for relative configs, if any | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 62 | ▶ | if (exists $conf{-ConfigPath}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $configpath = delete $conf{-ConfigPath}; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | $self->{ConfigPath} = ref $configpath eq 'ARRAY' ? $configpath : [$configpath]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | # handle options which contains values we need (strings, hashrefs or the like) | ||||||||||||||||||||||||||||||||||||||||||
| 315 | 62 | ▶ | if (exists $conf{-String} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 15 | ▶ | if (not ref $conf{-String}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 13 | ▶ | if ( $conf{-String}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 13 | $self->{StringContent} = $conf{-String}; | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 13 | delete $conf{-String}; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | # re-implement arrayref support, removed after 2.22 as _read were | ||||||||||||||||||||||||||||||||||||||||||
| 323 | # re-organized | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # fixed bug#33385 | ||||||||||||||||||||||||||||||||||||||||||
| 325 | elsif(ref($conf{-String}) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | $self->{StringContent} = join "\n", @{$conf{-String}}; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | croak "Config::General: Parameter -String must be a SCALAR or ARRAYREF!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 14 | delete $conf{-String}; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 61 | ▶ | if (exists $conf{-Tie}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | ▶ | if ($conf{-Tie}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | $self->{Tie} = delete $conf{-Tie}; | |||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | $self->{DefaultConfig} = $self->_hashref(); | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 61 | ▶ | if (exists $conf{-FlagBits}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 2 | ▶ | if ($conf{-FlagBits} && ref($conf{-FlagBits}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$conf{"-FlagBits"} and ref $conf{"-FlagBits"} eq "HASH"
MC/DC0%0/2
$conf{"-FlagBits"} and ref $conf{"-FlagBits"} eq "HASH"
$conf{"-FlagBits"}
ref $conf{"-FlagBits"} eq "HASH"
Truth table33%1/3
A and B
A= $conf{"-FlagBits"}B= ref $conf{"-FlagBits"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | $self->{FlagBits} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 2 | $self->{FlagBitsFlags} = $conf{-FlagBits}; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | delete $conf{-FlagBits}; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 61 | ▶ | if (exists $conf{-DefaultConfig}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | ▶ | if ($conf{-DefaultConfig} && ref($conf{-DefaultConfig}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$conf{"-DefaultConfig"} and ref $conf{"-DefaultConfig"} eq "HASH"
MC/DC50%1/2
$conf{"-DefaultConfig"} and ref $conf{"-DefaultConfig"} eq "HASH"
$conf{"-DefaultConfig"}
ref $conf{"-DefaultConfig"} eq "HASH"
Truth table66%2/3
A and B
A= $conf{"-DefaultConfig"}B= ref $conf{"-DefaultConfig"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | # copy the hashref so that it is not being modified by subsequent calls, fixes bug#142095 | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 2 | ▶ | if (! $self->_validate_input_hash($conf{-DefaultConfig})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | croak "Config::General: supplied -DefaultConfig hash contains invalid keys or values!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | $self->{DefaultConfig} = $self->_copy($conf{-DefaultConfig}); | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | ▶ | elsif ($conf{-DefaultConfig} && ref($conf{-DefaultConfig}) eq q()) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$conf{"-DefaultConfig"} and ref $conf{"-DefaultConfig"} eq ""
MC/DC0%0/2
$conf{"-DefaultConfig"} and ref $conf{"-DefaultConfig"} eq ""
$conf{"-DefaultConfig"}
ref $conf{"-DefaultConfig"} eq ""
Truth table33%1/3
A and B
A= $conf{"-DefaultConfig"}B= ref $conf{"-DefaultConfig"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | $self->_read($conf{-DefaultConfig}, 'SCALAR'); | |||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | $self->{DefaultConfig} = $self->_parse($self->_hashref(), $self->{content}); | |||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | $self->{content} = (); | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 3 | delete $conf{-DefaultConfig}; | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | # handle options which may either be true or false | ||||||||||||||||||||||||||||||||||||||||||
| 366 | # allowing "human" logic about what is true and what is not | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 61 | foreach my $entry (keys %conf) { | |||||||||||||||||||||||||||||||||||||||||
| 368 | 76 | my $key = $entry; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 76 | $key =~ s/^\-//; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 76 | ▶ | if (! exists $self->{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | croak "Config::General: Unknown parameter: $entry => \"$conf{$entry}\" (key: <$key>)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 76 | ▶ | if ($conf{$entry} =~ /$self->{AutoTrueFlags}->{true}/io) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 62 | $self->{$key} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | elsif ($conf{$entry} =~ /$self->{AutoTrueFlags}->{false}/io) { | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 6 | $self->{$key} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 379 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 380 | # keep it untouched | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 8 | $self->{$key} = $conf{$entry}; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 61 | ▶ | if ($self->{MergeDuplicateOptions}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | # override if not set by user | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 6 | ▶ | if (! exists $conf{-AllowMultiOptions}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 6 | $self->{AllowMultiOptions} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 61 | ▶ | if ($self->{ApacheCompatible}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | # turn on all apache compatibility options which has | ||||||||||||||||||||||||||||||||||||||||||
| 394 | # been incorporated during the years... | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $self->{UseApacheInclude} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $self->{IncludeRelative} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | $self->{IncludeDirectories} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->{IncludeGlob} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $self->{SlashIsDirectory} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $self->{SplitPolicy} = 'whitespace'; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $self->{CComments} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $self->{UseApacheIfDefine} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 61 | ▶ | if ($self->{UseApacheIfDefine}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 3 | ▶ | if (exists $conf{-Define}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 3 | my $ref = ref($conf{-Define}); | |||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 3 | ▶ | if ($ref eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | $self->{Define} = {$conf{-Define} => 1}; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | elsif ($ref eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | $self->{Define} = {${$conf{-Define}} = 1}; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | elsif ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | my %h = map { $_ => 1 } @{$conf{-Define}}; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | $self->{Define} = \%h; | |||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | elsif ($ref eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | $self->{Define} = $conf{-Define}; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | croak qq{Config::General: Unsupported ref '$ref' for 'Define'}; | |||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 3 | delete $conf{-Define}; | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 49 | ▶ | sub getall { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getall: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | # | ||||||||||||||||||||||||||||||||||||||||||
| 434 | # just return the whole config hash | ||||||||||||||||||||||||||||||||||||||||||
| 435 | # | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 49 | my($this) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 49 | ▶ | return (exists $this->{config} ? %{$this->{config}} : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 1 | ▶ | sub files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
files: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | # | ||||||||||||||||||||||||||||||||||||||||||
| 443 | # return a list of files opened so far | ||||||||||||||||||||||||||||||||||||||||||
| 444 | # | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | my($this) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | ▶ | return (exists $this->{files} ? keys %{$this->{files}} : () ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 72 | ▶ | sub _open { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open: called CC=28 SCAR=39.9
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | # | ||||||||||||||||||||||||||||||||||||||||||
| 452 | # open the config file, or expand a directory or glob or include | ||||||||||||||||||||||||||||||||||||||||||
| 453 | # | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 72 | my($this, $basefile, $basepath) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 455 | 72 | my $cont; | |||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 72 | ($cont, $basefile, $basepath) = $this->_hook('pre_open', $basefile, $basepath); | |||||||||||||||||||||||||||||||||||||||||
| 458 | 72 | ▶ | return if(!$cont); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 72 | my($fh, $configfile); | |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 72 | ▶ | if($basepath) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | # if this doesn't work we can still try later the global config path to use | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 8 | $configfile = catfile($basepath, $basefile); | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 64 | $configfile = $basefile; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 72 | my $glob = qr/[*?\[\{\\]/; | |||||||||||||||||||||||||||||||||||||||||
| 471 | 72 | ▶ | if ($^O =~ /win/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | # fix for rt.cpan.org#116340: do only consider a backslash | ||||||||||||||||||||||||||||||||||||||||||
| 473 | # as meta escape char, but not if it appears on it's own, | ||||||||||||||||||||||||||||||||||||||||||
| 474 | # as it happens on windows platforms. | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | $glob = qr/(\\[*?\[\{\\]|[*?\[\{])/; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | 72 | ▶ | if ($this->{IncludeGlob} and $configfile =~ /$glob/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$this->{"IncludeGlob"} and $configfile =~ /$glob/
MC/DC100%2/2
$this->{"IncludeGlob"} and $configfile =~ /$glob/
$this->{"IncludeGlob"}
$configfile =~ /$glob/
Truth table100%3/3
A and B
A= $this->{"IncludeGlob"}B= $configfile =~ /$glob/
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | # Something like: *.conf (or maybe dir/*.conf) was included; expand it and | ||||||||||||||||||||||||||||||||||||||||||
| 480 | # pass each expansion through this method again. | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 4 | local $_; | |||||||||||||||||||||||||||||||||||||||||
| 482 | 4 | my @include = grep { -f $_ } bsd_glob($configfile, GLOB_BRACE | GLOB_QUOTE); | |||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | # applied patch by AlexK fixing rt.cpan.org#41030 | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 4 | ▶ | if ( !@include && defined $this->{ConfigPath} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not @include and defined $this->{"ConfigPath"}
MC/DC0%0/2
not @include and defined $this->{"ConfigPath"}
not @include
defined $this->{"ConfigPath"}
Truth table66%2/3
not(A) and B
A= not @includeB= defined $this->{"ConfigPath"}
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | foreach my $dir (@{$this->{ConfigPath}}) { | |||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my ($volume, $path, undef) = splitpath($basefile); | |||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if ( -d catfile( $dir, $path ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | push @include, grep { -f $_ } bsd_glob(catfile($dir, $basefile), GLOB_BRACE | GLOB_QUOTE); | |||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | # Multiple results or no expansion results (which is fine, | ||||||||||||||||||||||||||||||||||||||||||
| 496 | # include foo/* shouldn't fail if there isn't anything matching) | ||||||||||||||||||||||||||||||||||||||||||
| 497 | # rt.cpan.org#79869: local $this->{IncludeGlob}; | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 4 | foreach my $file (@include) { | |||||||||||||||||||||||||||||||||||||||||
| 499 | 6 | $this->_open($file); | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 68 | ▶ | if (!-e $configfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 3 | my $found; | |||||||||||||||||||||||||||||||||||||||||
| 506 | 3 | ▶ | if (defined $this->{ConfigPath}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | # try to find the file within ConfigPath | ||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | foreach my $dir (@{$this->{ConfigPath}}) { | |||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | if( -e catfile($dir, $basefile) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | $configfile = catfile($dir, $basefile); | |||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | last; # found it | |||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 3 | ▶ | if (!$found) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | my $path_message = defined $this->{ConfigPath} ? q( within ConfigPath: ) . join(q(.), @{$this->{ConfigPath}}) : q(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | 3 | croak qq{Config::General The file "$basefile" does not exist$path_message!}; | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | 65 | local ($RS) = $RS; | |||||||||||||||||||||||||||||||||||||||||
| 523 | 65 | ▶ | if (! $RS) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | carp(q(\$RS (INPUT_RECORD_SEPARATOR) is undefined. Guessing you want a line feed character)); | |||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | $RS = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | 65 | ▶ | if (-d $configfile and $this->{IncludeDirectories}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
-d $configfile and $this->{"IncludeDirectories"}
MC/DC50%1/2
-d $configfile and $this->{"IncludeDirectories"}
-d $configfile
$this->{"IncludeDirectories"}
Truth table66%2/3
A and B
A= -d $configfileB= $this->{"IncludeDirectories"}
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | # A directory was included; include all the files inside that directory in ASCII order | ||||||||||||||||||||||||||||||||||||||||||
| 530 | 1 | local *INCLUDEDIR; | |||||||||||||||||||||||||||||||||||||||||
| 531 | 1 | ▶ | opendir INCLUDEDIR, $configfile or croak "Config::General: Could not open directory $configfile!($!)\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | #my @files = sort grep { -f catfile($configfile, $_) } catfile($configfile, $_), readdir INCLUDEDIR; | ||||||||||||||||||||||||||||||||||||||||||
| 533 | # fixes rt.cpan.org#139261 | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 1 | my @files = sort grep { -f catfile($configfile, $_) } readdir INCLUDEDIR; | |||||||||||||||||||||||||||||||||||||||||
| 535 | 1 | closedir INCLUDEDIR; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | local $this->{CurrentConfigFilePath} = $configfile; | |||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | for (@files) { | |||||||||||||||||||||||||||||||||||||||||
| 538 | 5 | my $file = catfile($configfile, $_); | |||||||||||||||||||||||||||||||||||||||||
| 539 | 5 | ▶ | if (! exists $this->{files}->{$file} or $this->{IncludeAgain} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $this->{"files"}{$file} or $this->{"IncludeAgain"}
MC/DC0%0/2
not exists $this->{"files"}{$file} or $this->{"IncludeAgain"}
not exists $this->{"files"}{$file}
$this->{"IncludeAgain"}
Truth table33%1/3
not(A) or B
A= not exists $this->{"files"}{$file}B= $this->{"IncludeAgain"}
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | # support re-read if used urged us to do so, otherwise ignore the file | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 5 | $fh = $this->_openfile_for_read($file); | |||||||||||||||||||||||||||||||||||||||||
| 542 | 5 | $this->{files}->{"$file"} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 5 | $this->_read($fh); | |||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | warn "File $file already loaded. Use -IncludeAgain to load it again.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | elsif (-d $configfile) { | ||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | croak "Config::General: config file argument is a directory, expecting a file!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 553 | elsif (-e _) { | ||||||||||||||||||||||||||||||||||||||||||
| 554 | 64 | ▶ | if (exists $this->{files}->{$configfile} and not $this->{IncludeAgain}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $this->{"files"}{$configfile} and not $this->{"IncludeAgain"}
MC/DC100%2/2
exists $this->{"files"}{$configfile} and not $this->{"IncludeAgain"}
exists $this->{"files"}{$configfile}
not $this->{"IncludeAgain"}
Truth table100%3/3
A and not(B)
A= exists $this->{"files"}{$configfile}B= not $this->{"IncludeAgain"}
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | # do not read the same file twice, just return | ||||||||||||||||||||||||||||||||||||||||||
| 556 | 1 | warn "File $configfile already loaded. Use -IncludeAgain to load it again.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 560 | 63 | $fh = $this->_openfile_for_read($configfile); | |||||||||||||||||||||||||||||||||||||||||
| 561 | 63 | $this->{files}->{$configfile} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 63 | my ($volume, $path, undef) = splitpath($configfile); | |||||||||||||||||||||||||||||||||||||||||
| 564 | 63 | local $this->{CurrentConfigFilePath} = catpath($volume, $path, q()); | |||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | 63 | $this->_read($fh); | |||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 63 | return; | |||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 68 | ▶ | sub _openfile_for_read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_openfile_for_read: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | # | ||||||||||||||||||||||||||||||||||||||||||
| 575 | # actually open a file, turn on utf8 mode if requested by bom | ||||||||||||||||||||||||||||||||||||||||||
| 576 | # | ||||||||||||||||||||||||||||||||||||||||||
| 577 | 68 | my ($this, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 68 | ▶ | my $fh = IO::File->new( $file, 'r') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | or croak "Config::General: Could not open $file!($!)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | # attempt to read an initial utf8 byte-order mark (BOM) | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 68 | my $n_read = sysread $fh, my $read_BOM, length(_UTF8_BOM); | |||||||||||||||||||||||||||||||||||||||||
| 584 | 68 | ▶ | my $has_BOM = $n_read == length(_UTF8_BOM) && $read_BOM eq _UTF8_BOM; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$n_read == 3 && $read_BOM eq "\357\273\277"
MC/DC50%1/2
$n_read == 3 && $read_BOM eq "\357\273\277"
$n_read == 3
$read_BOM eq "\357\273\277"
Truth table66%2/3
A && B
A= $n_read == 3B= $read_BOM eq "\357\273\277"
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | # set utf8 perlio layer if BOM was found or if option -UTF8 is turned on | ||||||||||||||||||||||||||||||||||||||||||
| 587 | 68 | ▶ | binmode $fh, ":utf8" if $this->{UTF8} || $has_BOM; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$this->{"UTF8"} or $has_BOM
MC/DC100%2/2
$this->{"UTF8"} or $has_BOM
$this->{"UTF8"}
$has_BOM
Truth table100%3/3
A or B
A= $this->{"UTF8"}B= $has_BOM
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | # rewind to beginning of file if we read chars that were not the BOM | ||||||||||||||||||||||||||||||||||||||||||
| 590 | 68 | ▶ | sysseek $fh, 0, 0 if $n_read && !$has_BOM; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$n_read and not $has_BOM
MC/DC50%1/2
$n_read and not $has_BOM
$n_read
not $has_BOM
Truth table66%2/3
A and not(B)
A= $n_readB= not $has_BOM
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | 68 | return $fh; | |||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | 83 | ▶ | sub _read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read: called CC=49 SCAR=41.5
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | # | ||||||||||||||||||||||||||||||||||||||||||
| 599 | # store the config contents in @content | ||||||||||||||||||||||||||||||||||||||||||
| 600 | # and prepare it somewhat for easier parsing later | ||||||||||||||||||||||||||||||||||||||||||
| 601 | # (comments, continuing lines, and stuff) | ||||||||||||||||||||||||||||||||||||||||||
| 602 | # | ||||||||||||||||||||||||||||||||||||||||||
| 603 | 83 | my($this, $fh, $flag) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | 83 | my(@stuff, @content, $c_comment, $longline, $hier, $hierend, @hierdoc); | |||||||||||||||||||||||||||||||||||||||||
| 607 | 83 | local $_ = q(); | |||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 83 | ▶ | if ($flag && $flag eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$flag and $flag eq "SCALAR"
MC/DC50%1/2
$flag and $flag eq "SCALAR"
$flag
$flag eq "SCALAR"
Truth table66%2/3
A and B
A= $flagB= $flag eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 15 | ▶ | if (ref($fh) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | @stuff = @{$fh}; | |||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 613 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 614 | 15 | @stuff = split /\n/, $fh; | |||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||
| 617 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 618 | 68 | @stuff = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | 83 | my $cont; | |||||||||||||||||||||||||||||||||||||||||
| 622 | 83 | ($cont, $fh, @stuff) = $this->_hook('pre_read', $fh, @stuff); | |||||||||||||||||||||||||||||||||||||||||
| 623 | 83 | ▶ | return if(!$cont); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||
| 625 | 83 | ▶ | if ($this->{UseApacheIfDefine}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 626 | 3 | $this->_process_apache_ifdefine(\@stuff); | |||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 83 | foreach (@stuff) { | |||||||||||||||||||||||||||||||||||||||||
| 630 | 767 | ▶ | if ($this->{AutoLaunder}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | if (m/^(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | $_ = $1; | |||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | 767 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||
| 639 | 767 | ▶ | if ($hier) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | # inside here-doc, only look for $hierend marker | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 25 | ▶ | if (/^(\s*)\Q$hierend\E\s*$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | 7 | my $indent = $1; # preserve indentation | |||||||||||||||||||||||||||||||||||||||||
| 643 | 7 | $hier .= ' ' . $this->{EOFseparator}; # bugfix of rt.40925 | |||||||||||||||||||||||||||||||||||||||||
| 644 | # _parse will also preserver indentation | ||||||||||||||||||||||||||||||||||||||||||
| 645 | 7 | ▶ | if ($indent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | foreach (@hierdoc) { | |||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | s/^$indent//; # i.e. the end was: " EOF" then we remove " " from every here-doc line | |||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | $hier .= $_ . "\n"; # and store it in $hier | |||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||
| 651 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 652 | 7 | $hier .= join "\n", @hierdoc; # there was no indentation of the end-string, so join it 1:1 | |||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||
| 654 | 7 | push @{$this->{content}}, $hier; # push it onto the content stack | |||||||||||||||||||||||||||||||||||||||||
| 655 | 7 | @hierdoc = (); | |||||||||||||||||||||||||||||||||||||||||
| 656 | 7 | undef $hier; | |||||||||||||||||||||||||||||||||||||||||
| 657 | 7 | undef $hierend; | |||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 660 | # everything else onto the stack | ||||||||||||||||||||||||||||||||||||||||||
| 661 | 18 | push @hierdoc, $_; | |||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | 25 | next; | |||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | 742 | ▶ | if ($this->{CComments}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | # look for C-Style comments, if activated | ||||||||||||||||||||||||||||||||||||||||||
| 668 | 742 | ▶ | if (/(\s*\/\*.*\*\/\s*)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | # single c-comment on one line | ||||||||||||||||||||||||||||||||||||||||||
| 670 | 2 | s/\s*\/\*.*\*\/\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||
| 672 | elsif (/^\s*\/\*/) { | ||||||||||||||||||||||||||||||||||||||||||
| 673 | # the beginning of a C-comment ("/*"), from now on ignore everything. | ||||||||||||||||||||||||||||||||||||||||||
| 674 | 15 | ▶ | if (/\*\/\s*$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 675 | # C-comment end is already there, so just ignore this line! | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | $c_comment = 0; | |||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||
| 678 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 679 | 15 | $c_comment = 1; | |||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||
| 682 | elsif (/\*\//) { | ||||||||||||||||||||||||||||||||||||||||||
| 683 | 15 | ▶ | if (!$c_comment) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | warn "invalid syntax: found end of C-comment without previous start!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 686 | 15 | $c_comment = 0; # the current C-comment ends here, go on | |||||||||||||||||||||||||||||||||||||||||
| 687 | 15 | s/^.*\*\///; # if there is still stuff, it will be read | |||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||
| 689 | 742 | ▶ | next if($c_comment); # ignore EVERYTHING from now on, IF it IS a C-Comment | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | # Remove comments and empty lines | ||||||||||||||||||||||||||||||||||||||||||
| 693 | 590 | s/(?<!\\)#.*$//; # .+ => .* bugfix rt.cpan.org#44600 | |||||||||||||||||||||||||||||||||||||||||
| 694 | 590 | ▶ | next if /^\s*#/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | # look for multiline option, indicated by a trailing backslash | ||||||||||||||||||||||||||||||||||||||||||
| 697 | 590 | ▶ | if (/(?<!\\)\\$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 698 | 9 | chop; # remove trailing backslash | |||||||||||||||||||||||||||||||||||||||||
| 699 | 9 | s/^\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 700 | 9 | $longline .= $_; | |||||||||||||||||||||||||||||||||||||||||
| 701 | 9 | next; | |||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | # transform explicit-empty blocks to conforming blocks | ||||||||||||||||||||||||||||||||||||||||||
| 705 | # rt.cpan.org#80006 added \s* before $/ | ||||||||||||||||||||||||||||||||||||||||||
| 706 | 581 | ▶ | if (!$this->{ApacheCompatible} && /\s*<([^\/]+?.*?)\/>\s*$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $this->{"ApacheCompatible"} and m[\s*<([^/]+?.*?)/>\s*$]
MC/DC50%1/2
not $this->{"ApacheCompatible"} and m[\s*<([^/]+?.*?)/>\s*$]
not $this->{"ApacheCompatible"}
m[\s*<([^/]+?.*?)/>\s*$]
Truth table66%2/3
not(A) and B
A= not $this->{"ApacheCompatible"}B= m[\s*<([^/]+?.*?)/>\s*$]
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | 3 | my $block = $1; | |||||||||||||||||||||||||||||||||||||||||
| 708 | 3 | ▶ | if ($block !~ /\"/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | 3 | ▶ | if ($block !~ /\s[^\s]/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | # fix of bug 7957, add quotation to pure slash at the | ||||||||||||||||||||||||||||||||||||||||||
| 711 | # end of a block so that it will be considered as directory | ||||||||||||||||||||||||||||||||||||||||||
| 712 | # unless the block is already quoted or contains whitespaces | ||||||||||||||||||||||||||||||||||||||||||
| 713 | # and no quotes. | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 3 | ▶ | if ($this->{SlashIsDirectory}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 715 | 3 | push @{$this->{content}}, '<' . $block . '"/">'; | |||||||||||||||||||||||||||||||||||||||||
| 716 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | my $orig = $_; | |||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | $orig =~ s/\/>$/>/; | |||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | $block =~ s/\s\s*.*$//; | |||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | push @{$this->{content}}, $orig, "</${block}>"; | |||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | # look for here-doc identifier | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 578 | ▶ | if ($this->{SplitPolicy} eq 'guess') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 730 | 508 | ▶ | if (/^\s*([^=]+?)\s*=\s*<<\s*(.+?)\s*$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 731 | # try equal sign (fix bug rt#36607) | ||||||||||||||||||||||||||||||||||||||||||
| 732 | 2 | $hier = $1; # the actual here-doc variable name | |||||||||||||||||||||||||||||||||||||||||
| 733 | 2 | $hierend = $2; # the here-doc identifier, i.e. "EOF" | |||||||||||||||||||||||||||||||||||||||||
| 734 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | elsif (/^\s*(\S+?)\s+<<\s*(.+?)\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 737 | # try whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 738 | 5 | $hier = $1; # the actual here-doc variable name | |||||||||||||||||||||||||||||||||||||||||
| 739 | 5 | $hierend = $2; # the here-doc identifier, i.e. "EOF" | |||||||||||||||||||||||||||||||||||||||||
| 740 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||
| 743 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 744 | # no guess, use one of the configured strict split policies | ||||||||||||||||||||||||||||||||||||||||||
| 745 | 70 | ▶ | if (/^\s*(.+?)($this->{SplitDelimiter})<<\s*(.+?)\s*$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 746 | 1 | $hier = $1; # the actual here-doc variable name | |||||||||||||||||||||||||||||||||||||||||
| 747 | 1 | $hierend = $3; # the here-doc identifier, i.e. "EOF" | |||||||||||||||||||||||||||||||||||||||||
| 748 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | ### | ||||||||||||||||||||||||||||||||||||||||||
| 755 | ### any "normal" config lines from now on | ||||||||||||||||||||||||||||||||||||||||||
| 756 | ### | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | 570 | ▶ | if ($longline) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 759 | # previous stuff was a longline and this is the last line of the longline | ||||||||||||||||||||||||||||||||||||||||||
| 760 | 5 | s/^\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 761 | 5 | $longline .= $_; | |||||||||||||||||||||||||||||||||||||||||
| 762 | 5 | push @{$this->{content}}, $longline; # push it onto the content stack | |||||||||||||||||||||||||||||||||||||||||
| 763 | 5 | undef $longline; | |||||||||||||||||||||||||||||||||||||||||
| 764 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||
| 766 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 767 | # ignore empty lines | ||||||||||||||||||||||||||||||||||||||||||
| 768 | 565 | ▶ | next if /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||
| 770 | # look for include statement(s) | ||||||||||||||||||||||||||||||||||||||||||
| 771 | 434 | my $incl_file; | |||||||||||||||||||||||||||||||||||||||||
| 772 | 434 | my $path = ''; | |||||||||||||||||||||||||||||||||||||||||
| 773 | 434 | ▶ | if ( $this->{IncludeRelative} and defined $this->{CurrentConfigFilePath}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$this->{"IncludeRelative"} and defined $this->{"CurrentConfigFilePath"}
MC/DC50%1/2
$this->{"IncludeRelative"} and defined $this->{"CurrentConfigFilePath"}
$this->{"IncludeRelative"}
defined $this->{"CurrentConfigFilePath"}
Truth table66%2/3
A and B
A= $this->{"IncludeRelative"}B= defined $this->{"CurrentConfigFilePath"}
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | 87 | $path = $this->{CurrentConfigFilePath}; | |||||||||||||||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||||||||||||||||
| 776 | elsif (defined $this->{ConfigPath}) { | ||||||||||||||||||||||||||||||||||||||||||
| 777 | # fetch pathname of base config file, assuming the 1st one is the path of it | ||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | $path = $this->{ConfigPath}->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||
| 780 | |||||||||||||||||||||||||||||||||||||||||||
| 781 | # bugfix rt.cpan.org#38635: support quoted filenames | ||||||||||||||||||||||||||||||||||||||||||
| 782 | 434 | ▶ | if ($this->{UseApacheInclude}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 783 | 16 | my $opt = ''; | |||||||||||||||||||||||||||||||||||||||||
| 784 | 16 | ▶ | if (/^\s*(include|includeoptional)\s*(["'])(.*?)(?<!\\)\2$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 785 | 1 | $incl_file = $3; | |||||||||||||||||||||||||||||||||||||||||
| 786 | 1 | $opt = $1; | |||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||
| 788 | elsif (/^\s*(include|includeoptional)\s+(.+?)\s*$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 789 | 3 | $incl_file = $2; | |||||||||||||||||||||||||||||||||||||||||
| 790 | 3 | $opt = $1; | |||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||
| 792 | 16 | ▶ | if ($incl_file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | 4 | ▶ | if ($this->{IncludeGlob} && $opt =~ /opt/i && $incl_file !~ /[*?\[\{\\]/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$this->{"IncludeGlob"} and $opt =~ /opt/i and not $incl_file =~ /[*?\[\{\\]/
$this->{"IncludeGlob"} and $opt =~ /opt/i
MC/DC33%1/3
$this->{"IncludeGlob"} and $opt =~ /opt/i and not $incl_file =~ /[*?\[\{\\]/
$this->{"IncludeGlob"}
$opt =~ /opt/i
not $incl_file =~ /[*?\[\{\\]/
Truth table50%2/4
A and B and not(C)
A= $this->{"IncludeGlob"}B= $opt =~ /opt/iC= not $incl_file =~ /[*?\[\{\\]/
| |||||||||||||||||||||||||||||||||||||||||||
| 794 | # fix rt#107108 | ||||||||||||||||||||||||||||||||||||||||||
| 795 | # glob enabled && optional include && file is not already a glob: | ||||||||||||||||||||||||||||||||||||||||||
| 796 | # turn it into a singular matching glob, like: | ||||||||||||||||||||||||||||||||||||||||||
| 797 | # "file" => "[f][i][l][e]" and: | ||||||||||||||||||||||||||||||||||||||||||
| 798 | # "dir/file" => "dir/[f][i][l][e]" | ||||||||||||||||||||||||||||||||||||||||||
| 799 | # which IS a glob but only matches that particular file. if it | ||||||||||||||||||||||||||||||||||||||||||
| 800 | # doesn't exist, it will be ignored by _open(), just what | ||||||||||||||||||||||||||||||||||||||||||
| 801 | # we'd like to have when using IncludeOptional. | ||||||||||||||||||||||||||||||||||||||||||
| 802 | 2 | my ($vol,$dirs,$file) = splitpath( $incl_file ); | |||||||||||||||||||||||||||||||||||||||||
| 803 | 2 | $incl_file = catpath($vol, $dirs, join '', map { "[$_]" } split //, $file); | |||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||
| 807 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 808 | 418 | ▶ | if (/^\s*<<include\s+(["'])(.+?)>>\\s*$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 809 | 0 | $incl_file = $2; | |||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||
| 811 | elsif (/^\s*<<include\s+(.+?)>>\s*$/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 812 | 17 | $incl_file = $1; | |||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||
| 814 | } | ||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||
| 816 | 434 | ▶ | if ($incl_file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | 21 | ▶ | if ( $this->{IncludeRelative} && $path && !file_name_is_absolute($incl_file) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$this->{"IncludeRelative"} and $path and not file_name_is_absolute($incl_file)
$this->{"IncludeRelative"} and $path
MC/DC33%1/3
$this->{"IncludeRelative"} and $path and not file_name_is_absolute($incl_file)
$this->{"IncludeRelative"}
$path
not file_name_is_absolute($incl_file)
Truth table50%2/4
A and B and not(C)
A= $this->{"IncludeRelative"}B= $pathC= not file_name_is_absolute($incl_file)
| |||||||||||||||||||||||||||||||||||||||||||
| 818 | # include the file from within location of $this->{configfile} | ||||||||||||||||||||||||||||||||||||||||||
| 819 | 8 | $this->_open( $incl_file, $path ); | |||||||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||||||
| 821 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 822 | # include the file from within pwd, or absolute | ||||||||||||||||||||||||||||||||||||||||||
| 823 | 13 | $this->_open($incl_file); | |||||||||||||||||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||
| 826 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 827 | # standard entry, (option = value) | ||||||||||||||||||||||||||||||||||||||||||
| 828 | 413 | push @{$this->{content}}, $_; | |||||||||||||||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||
| 835 | 82 | ($cont, $this->{content}) = $this->_hook('post_read', $this->{content}); | |||||||||||||||||||||||||||||||||||||||||
| 836 | 82 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||
| 840 | 3 | ▶ | sub _process_apache_ifdefine { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_apache_ifdefine: called CC=9 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 841 | # | ||||||||||||||||||||||||||||||||||||||||||
| 842 | # Loop trough config lines and exclude all those entries | ||||||||||||||||||||||||||||||||||||||||||
| 843 | # for which there's no IFDEF but which reside inside an IFDEF. | ||||||||||||||||||||||||||||||||||||||||||
| 844 | # | ||||||||||||||||||||||||||||||||||||||||||
| 845 | # Called from _read(), if UseApacheIfDefine is enabled, returns | ||||||||||||||||||||||||||||||||||||||||||
| 846 | # the modified array. | ||||||||||||||||||||||||||||||||||||||||||
| 847 | 3 | my($this, $rawlines) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | 3 | my @filtered; | |||||||||||||||||||||||||||||||||||||||||
| 850 | 3 | my @includeFlag = (1); | |||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | 3 | foreach (@{$rawlines}) { | |||||||||||||||||||||||||||||||||||||||||
| 853 | 9 | ▶ | if (/^\s*<\s*IfDefine\s+([!]*)("[^"]+"|\S+)\s*>/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 854 | # new IFDEF block, mark following content to be included if | ||||||||||||||||||||||||||||||||||||||||||
| 855 | # the DEF is known, otherwise skip it til end of IFDEF | ||||||||||||||||||||||||||||||||||||||||||
| 856 | 3 | my ($negate, $define) = ($1 eq '!',$2); | |||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | push(@includeFlag, | ||||||||||||||||||||||||||||||||||||||||||
| 859 | $includeFlag[-1] & | ||||||||||||||||||||||||||||||||||||||||||
| 860 | 3 | ((not $negate) & (exists $this->{Define}{$define})) | |||||||||||||||||||||||||||||||||||||||||
| 861 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||
| 863 | elsif (/^\s*<\s*\/IfDefine\s*>/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 864 | 3 | ▶ | if (scalar(@includeFlag) <= 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | 0 | croak qq(Config::General: </IfDefine> without a <IfDefine>!\n); | |||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||
| 867 | 3 | pop(@includeFlag); | |||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||
| 869 | ▶ | elsif ($includeFlag[-1] && /^\s*Define\s+("[^"]+"|\S+)/i) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$includeFlag[-1] and /^\s*Define\s+("[^"]+"|\S+)/i
MC/DC0%0/2
$includeFlag[-1] and /^\s*Define\s+("[^"]+"|\S+)/i
$includeFlag[-1]
/^\s*Define\s+("[^"]+"|\S+)/i
Truth table33%1/3
A and B
A= $includeFlag[-1]B= /^\s*Define\s+("[^"]+"|\S+)/i
| |||||||||||||||||||||||||||||||||||||||||||
| 870 | # inline Define, add it to our list | ||||||||||||||||||||||||||||||||||||||||||
| 871 | 0 | $this->{Define}{$1} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||||||||||||||||
| 873 | elsif ($includeFlag[-1]) { | ||||||||||||||||||||||||||||||||||||||||||
| 874 | 3 | push @filtered, $_; | |||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||||||||||||
| 877 | |||||||||||||||||||||||||||||||||||||||||||
| 878 | 3 | ▶ | if (scalar(@includeFlag) > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | croak qq(Config::General: Block <IfDefine> has no EndBlock statement!\n); | |||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||
| 882 | 3 | @$rawlines = @filtered; # replace caller array | |||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||
| 886 | 139 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=53 SCAR=44.6
| |||||||||||||||||||||||||||||||||||||||||||
| 887 | # | ||||||||||||||||||||||||||||||||||||||||||
| 888 | # parse the contents of the file | ||||||||||||||||||||||||||||||||||||||||||
| 889 | # | ||||||||||||||||||||||||||||||||||||||||||
| 890 | 139 | my($this, $config, $content) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 891 | 139 | my(@newcontent, $block, $blockname, $chunk,$block_level); | |||||||||||||||||||||||||||||||||||||||||
| 892 | 139 | local $_; | |||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||
| 894 | 139 | foreach (@{$content}) { # loop over content stack | |||||||||||||||||||||||||||||||||||||||||
| 895 | 622 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 896 | 622 | $chunk++; | |||||||||||||||||||||||||||||||||||||||||
| 897 | 622 | $_ =~ s/^\s+//; # strip spaces @ end and begin | |||||||||||||||||||||||||||||||||||||||||
| 898 | 622 | $_ =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||
| 900 | # | ||||||||||||||||||||||||||||||||||||||||||
| 901 | # build option value assignment, split current input | ||||||||||||||||||||||||||||||||||||||||||
| 902 | # using whitespace, equal sign or optionally here-doc | ||||||||||||||||||||||||||||||||||||||||||
| 903 | # separator EOFseparator | ||||||||||||||||||||||||||||||||||||||||||
| 904 | 622 | my ($option,$value); | |||||||||||||||||||||||||||||||||||||||||
| 905 | 622 | ▶ | if (/$this->{EOFseparator}/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 906 | 7 | ($option,$value) = split /\s*$this->{EOFseparator}\s*/, $_, 2; # separated by heredoc-finding in _open() | |||||||||||||||||||||||||||||||||||||||||
| 907 | } | ||||||||||||||||||||||||||||||||||||||||||
| 908 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 909 | 615 | ▶ | if ($this->{SplitPolicy} eq 'guess') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 910 | # again the old regex. use equalsign SplitPolicy to get the | ||||||||||||||||||||||||||||||||||||||||||
| 911 | # 2.00 behavior. the new regexes were too odd. | ||||||||||||||||||||||||||||||||||||||||||
| 912 | 500 | ($option,$value) = split /\s*=\s*|\s+/, $_, 2; | |||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||
| 914 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 915 | # no guess, use one of the configured strict split policies | ||||||||||||||||||||||||||||||||||||||||||
| 916 | 115 | ($option,$value) = split /$this->{SplitDelimiter}/, $_, 2; | |||||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||
| 920 | 622 | ▶ | if($this->{NormalizeOption}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | $option = $this->{NormalizeOption}($option); | |||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||||||||||||
| 924 | 622 | ▶ | if ($value && $value =~ /^"/ && $value =~ /"$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$value and $value =~ /^"/ and $value =~ /"$/
$value and $value =~ /^"/
MC/DC100%3/3
$value and $value =~ /^"/ and $value =~ /"$/
$value
$value =~ /^"/
$value =~ /"$/
Truth table100%4/4
A and B and C
A= $valueB= $value =~ /^"/C= $value =~ /"$/
| |||||||||||||||||||||||||||||||||||||||||||
| 925 | 10 | $value =~ s/^"//; # remove leading and trailing " | |||||||||||||||||||||||||||||||||||||||||
| 926 | 10 | $value =~ s/"$//; | |||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||
| 928 | 622 | ▶ | if (! defined $block) { # not inside a block @ the moment | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 929 | 336 | ▶ | if (/^<([^\/]+?.*?)>$/) { # look if it is a block | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 930 | 86 | $block = $1; # store block name | |||||||||||||||||||||||||||||||||||||||||
| 931 | 86 | ▶ | if ($block =~ /^"([^"]+)"$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 932 | # quoted block, unquote it and do not split | ||||||||||||||||||||||||||||||||||||||||||
| 933 | 1 | $block =~ s/"//g; | |||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||
| 935 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 936 | # If it is a named block store the name separately; allow the block and name to each be quoted | ||||||||||||||||||||||||||||||||||||||||||
| 937 | 85 | ▶ | if ($block =~ /^(?:"([^"]+)"|(\S+))(?:\s+(?:"([^"]+)"|(.*)))?$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 938 | 85 | ▶ | $block = $1 || $2; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$1 || $2
MC/DC0%0/2
$1 || $2
$1
$2
Truth table66%2/3
A || B
A= $1B= $2
| |||||||||||||||||||||||||||||||||||||||||||
| 939 | 85 | ▶ | $blockname = $3 || $4; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$3 || $4
MC/DC100%2/2
$3 || $4
$3
$4
Truth table100%3/3
A || B
A= $3B= $4
| |||||||||||||||||||||||||||||||||||||||||||
| 940 | } | ||||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||
| 942 | 86 | ▶ | if($this->{NormalizeBlock}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | $block = $this->{NormalizeBlock}($block); | |||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | ▶ | if (defined $blockname) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | $blockname = $this->{NormalizeBlock}($blockname); | |||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | ▶ | if($blockname eq "") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 947 | # if, after normalization no blockname is left, remove it | ||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | $blockname = undef; | |||||||||||||||||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||||||||||||||||
| 950 | } | ||||||||||||||||||||||||||||||||||||||||||
| 951 | } | ||||||||||||||||||||||||||||||||||||||||||
| 952 | 86 | ▶ | if ($this->{InterPolateVars}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 953 | # interpolate block(name), add "<" and ">" to the key, because | ||||||||||||||||||||||||||||||||||||||||||
| 954 | # it is sure that such keys does not exist otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 955 | 30 | $block = $this->_interpolate($config, "<$block>", $block); | |||||||||||||||||||||||||||||||||||||||||
| 956 | 30 | ▶ | if (defined $blockname) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 957 | 12 | $blockname = $this->_interpolate($config, "<$blockname>", "$blockname"); | |||||||||||||||||||||||||||||||||||||||||
| 958 | } | ||||||||||||||||||||||||||||||||||||||||||
| 959 | } | ||||||||||||||||||||||||||||||||||||||||||
| 960 | 86 | ▶ | if ($this->{LowerCaseNames}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 961 | 0 | $block = lc $block; # only for blocks lc(), if configured via new() | |||||||||||||||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||||||||||||||||
| 963 | 86 | $this->{level} += 1; | |||||||||||||||||||||||||||||||||||||||||
| 964 | 86 | undef @newcontent; | |||||||||||||||||||||||||||||||||||||||||
| 965 | 86 | next; | |||||||||||||||||||||||||||||||||||||||||
| 966 | } | ||||||||||||||||||||||||||||||||||||||||||
| 967 | elsif (/^<\/(.+?)>$/) { # it is an end block, but we don't have a matching block! | ||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | croak "Config::General: EndBlock \"<\/$1>\" has no StartBlock statement (level: $this->{level}, chunk $chunk)!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 969 | } | ||||||||||||||||||||||||||||||||||||||||||
| 970 | else { # insert key/value pair into actual node | ||||||||||||||||||||||||||||||||||||||||||
| 971 | 250 | ▶ | if ($this->{LowerCaseNames}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | $option = lc $option; | |||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||
| 975 | 250 | ▶ | if (exists $config->{$option}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 976 | 25 | ▶ | if ($this->{MergeDuplicateOptions}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 977 | 5 | $config->{$option} = $this->_parse_value($config, $option, $value); | |||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | # bugfix rt.cpan.org#33216 | ||||||||||||||||||||||||||||||||||||||||||
| 980 | 5 | ▶ | if ($this->{InterPolateVars}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 981 | # save pair on local stack | ||||||||||||||||||||||||||||||||||||||||||
| 982 | 2 | $config->{__stack}->{$option} = $config->{$option}; | |||||||||||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||||||||||||
| 984 | } | ||||||||||||||||||||||||||||||||||||||||||
| 985 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 986 | 20 | ▶ | if (! $this->{AllowMultiOptions} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 987 | # no, duplicates not allowed | ||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | croak "Config::General: Option \"$option\" occurs more than once (level: $this->{level}, chunk $chunk)!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 989 | } | ||||||||||||||||||||||||||||||||||||||||||
| 990 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 991 | # yes, duplicates allowed | ||||||||||||||||||||||||||||||||||||||||||
| 992 | 20 | ▶ | if (ref($config->{$option}) ne 'ARRAY') { # convert scalar to array | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 993 | 13 | my $savevalue = $config->{$option}; | |||||||||||||||||||||||||||||||||||||||||
| 994 | 13 | delete $config->{$option}; | |||||||||||||||||||||||||||||||||||||||||
| 995 | 13 | push @{$config->{$option}}, $savevalue; | |||||||||||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||||||||||
| 997 | 20 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 998 | # check if arrays are supported by the underlying hash | ||||||||||||||||||||||||||||||||||||||||||
| 999 | 20 | my $i = scalar @{$config->{$option}}; | |||||||||||||||||||||||||||||||||||||||||
| 1000 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1001 | 20 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1002 | 0 | $config->{$option} = $this->_parse_value($config, $option, $value); | |||||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1004 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1005 | # it's already an array, just push | ||||||||||||||||||||||||||||||||||||||||||
| 1006 | 20 | push @{$config->{$option}}, $this->_parse_value($config, $option, $value); | |||||||||||||||||||||||||||||||||||||||||
| 1007 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1011 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1012 | 225 | ▶ | if($this->{ForceArray} && defined $value && $value =~ /^\[\s*(.+?)\s*\]$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$this->{"ForceArray"} and defined $value and $value =~ /^\[\s*(.+?)\s*\]$/
$this->{"ForceArray"} and defined $value
MC/DC33%1/3
$this->{"ForceArray"} and defined $value and $value =~ /^\[\s*(.+?)\s*\]$/
$this->{"ForceArray"}
defined $value
$value =~ /^\[\s*(.+?)\s*\]$/
Truth table50%2/4
A and B and C
A= $this->{"ForceArray"}B= defined $valueC= $value =~ /^\[\s*(.+?)\s*\]$/
| |||||||||||||||||||||||||||||||||||||||||||
| 1013 | # force single value array entry | ||||||||||||||||||||||||||||||||||||||||||
| 1014 | 2 | push @{$config->{$option}}, $this->_parse_value($config, $option, $1); | |||||||||||||||||||||||||||||||||||||||||
| 1015 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1016 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1017 | # standard config option, insert key/value pair into node | ||||||||||||||||||||||||||||||||||||||||||
| 1018 | 223 | $config->{$option} = $this->_parse_value($config, $option, $value); | |||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||
| 1020 | 223 | ▶ | if ($this->{InterPolateVars}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1021 | # save pair on local stack | ||||||||||||||||||||||||||||||||||||||||||
| 1022 | 72 | $config->{__stack}->{$option} = $config->{$option}; | |||||||||||||||||||||||||||||||||||||||||
| 1023 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1025 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1028 | elsif (/^<([^\/]+?.*?)>$/) { # found a start block inside a block, don't forget it | ||||||||||||||||||||||||||||||||||||||||||
| 1029 | 21 | $block_level++; # $block_level indicates wether we are still inside a node | |||||||||||||||||||||||||||||||||||||||||
| 1030 | 21 | push @newcontent, $_; # push onto new content stack for later recursive call of _parse() | |||||||||||||||||||||||||||||||||||||||||
| 1031 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1032 | elsif (/^<\/(.+?)>$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 1033 | 107 | ▶ | if ($block_level) { # this endblock is not the one we are searching for, decrement and push | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1034 | 21 | $block_level--; # if it is 0, then the endblock was the one we searched for, see below | |||||||||||||||||||||||||||||||||||||||||
| 1035 | 21 | push @newcontent, $_; # push onto new content stack | |||||||||||||||||||||||||||||||||||||||||
| 1036 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1037 | else { # calling myself recursively, end of $block reached, $block_level is 0 | ||||||||||||||||||||||||||||||||||||||||||
| 1038 | 86 | ▶ | if (defined $blockname) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1039 | # a named block, make it a hashref inside a hash within the current node | ||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||
| 1041 | 42 | ▶ | if (! exists $config->{$block}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1042 | # Make sure that the hash is not created implicitly | ||||||||||||||||||||||||||||||||||||||||||
| 1043 | 30 | $config->{$block} = $this->_hashref(); | |||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||
| 1045 | 30 | ▶ | if ($this->{InterPolateVars}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1046 | # inherit current __stack to new block | ||||||||||||||||||||||||||||||||||||||||||
| 1047 | 9 | $config->{$block}->{__stack} = $this->_copy($config->{__stack}); | |||||||||||||||||||||||||||||||||||||||||
| 1048 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1049 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||
| 1051 | 42 | ▶ | if (ref($config->{$block}) eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1052 | 1 | croak "Config::General: Block <$block> already exists as scalar entry!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1053 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1054 | elsif (ref($config->{$block}) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 1055 | 2 | croak "Config::General: Cannot append named block <$block $blockname> to array of scalars!\n" | |||||||||||||||||||||||||||||||||||||||||
| 1056 | ."Block <$block> or scalar '$block' occurs more than once.\n" | ||||||||||||||||||||||||||||||||||||||||||
| 1057 | ."Turn on -MergeDuplicateBlocks or make sure <$block> occurs only once in the config.\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1058 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1059 | elsif (exists $config->{$block}->{$blockname}) { | ||||||||||||||||||||||||||||||||||||||||||
| 1060 | # the named block already exists, make it an array | ||||||||||||||||||||||||||||||||||||||||||
| 1061 | 0 | ▶ | if ($this->{MergeDuplicateBlocks}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1062 | # just merge the new block with the same name as an existing one into | ||||||||||||||||||||||||||||||||||||||||||
| 1063 | # this one. | ||||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | $config->{$block}->{$blockname} = $this->_parse($config->{$block}->{$blockname}, \@newcontent); | |||||||||||||||||||||||||||||||||||||||||
| 1065 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1066 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1067 | 0 | ▶ | if (! $this->{AllowMultiOptions}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1068 | 0 | croak "Config::General: Named block \"<$block $blockname>\" occurs more than once (level: $this->{level}, chunk $chunk)!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1069 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1070 | else { # preserve existing data | ||||||||||||||||||||||||||||||||||||||||||
| 1071 | 0 | my $savevalue = $config->{$block}->{$blockname}; | |||||||||||||||||||||||||||||||||||||||||
| 1072 | 0 | delete $config->{$block}->{$blockname}; | |||||||||||||||||||||||||||||||||||||||||
| 1073 | 0 | my @ar; | |||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | ▶ | if (ref $savevalue eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | push @ar, @{$savevalue}; # preserve array if any | |||||||||||||||||||||||||||||||||||||||||
| 1076 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1077 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | push @ar, $savevalue; | |||||||||||||||||||||||||||||||||||||||||
| 1079 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1080 | 0 | push @ar, $this->_parse( $this->_hashref(), \@newcontent); # append it | |||||||||||||||||||||||||||||||||||||||||
| 1081 | 0 | $config->{$block}->{$blockname} = \@ar; | |||||||||||||||||||||||||||||||||||||||||
| 1082 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1084 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1085 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | # the first occurrence of this particular named block | ||||||||||||||||||||||||||||||||||||||||||
| 1087 | 39 | my $tmphash = $this->_hashref(); | |||||||||||||||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||||||||||||||||
| 1089 | 39 | ▶ | if ($this->{InterPolateVars}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1090 | # inherit current __stack to new block | ||||||||||||||||||||||||||||||||||||||||||
| 1091 | 12 | $tmphash->{__stack} = $this->_copy($config->{__stack}); | |||||||||||||||||||||||||||||||||||||||||
| 1092 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1093 | |||||||||||||||||||||||||||||||||||||||||||
| 1094 | 39 | $config->{$block}->{$blockname} = $this->_parse($tmphash, \@newcontent); | |||||||||||||||||||||||||||||||||||||||||
| 1095 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1096 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1097 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1098 | # standard block | ||||||||||||||||||||||||||||||||||||||||||
| 1099 | 44 | ▶ | if (exists $config->{$block}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1100 | 5 | ▶ | if (ref($config->{$block}) eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1101 | 1 | croak "Config::General: Cannot create hashref from <$block> because there is\n" | |||||||||||||||||||||||||||||||||||||||||
| 1102 | ."already a scalar option '$block' with value '$config->{$block}'\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1104 | |||||||||||||||||||||||||||||||||||||||||||
| 1105 | # the block already exists, make it an array | ||||||||||||||||||||||||||||||||||||||||||
| 1106 | 4 | ▶ | if ($this->{MergeDuplicateBlocks}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1107 | # just merge the new block with the same name as an existing one into | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | # this one. | ||||||||||||||||||||||||||||||||||||||||||
| 1109 | 2 | $config->{$block} = $this->_parse($config->{$block}, \@newcontent); | |||||||||||||||||||||||||||||||||||||||||
| 1110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1111 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1112 | 2 | ▶ | if (! $this->{AllowMultiOptions}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1113 | 0 | croak "Config::General: Block \"<$block>\" occurs more than once (level: $this->{level}, chunk $chunk)!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1115 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1116 | 2 | my $savevalue = $config->{$block}; | |||||||||||||||||||||||||||||||||||||||||
| 1117 | 2 | delete $config->{$block}; | |||||||||||||||||||||||||||||||||||||||||
| 1118 | 2 | my @ar; | |||||||||||||||||||||||||||||||||||||||||
| 1119 | 2 | ▶ | if (ref $savevalue eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1120 | 0 | push @ar, @{$savevalue}; | |||||||||||||||||||||||||||||||||||||||||
| 1121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1123 | 2 | push @ar, $savevalue; | |||||||||||||||||||||||||||||||||||||||||
| 1124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||||||||||||||||
| 1126 | # fixes rt#31529 | ||||||||||||||||||||||||||||||||||||||||||
| 1127 | 2 | my $tmphash = $this->_hashref(); | |||||||||||||||||||||||||||||||||||||||||
| 1128 | 2 | ▶ | if ($this->{InterPolateVars}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1129 | # inherit current __stack to new block | ||||||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | $tmphash->{__stack} = $this->_copy($config->{__stack}); | |||||||||||||||||||||||||||||||||||||||||
| 1131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||
| 1133 | 2 | push @ar, $this->_parse( $tmphash, \@newcontent); | |||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||
| 1135 | 2 | $config->{$block} = \@ar; | |||||||||||||||||||||||||||||||||||||||||
| 1136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1139 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1140 | # the first occurrence of this particular block | ||||||||||||||||||||||||||||||||||||||||||
| 1141 | 39 | my $tmphash = $this->_hashref(); | |||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||
| 1143 | 39 | ▶ | if ($this->{InterPolateVars}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1144 | # inherit current __stack to new block | ||||||||||||||||||||||||||||||||||||||||||
| 1145 | 16 | $tmphash->{__stack} = $this->_copy($config->{__stack}); | |||||||||||||||||||||||||||||||||||||||||
| 1146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||
| 1148 | 39 | $config->{$block} = $this->_parse($tmphash, \@newcontent); | |||||||||||||||||||||||||||||||||||||||||
| 1149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1151 | 82 | undef $blockname; | |||||||||||||||||||||||||||||||||||||||||
| 1152 | 82 | undef $block; | |||||||||||||||||||||||||||||||||||||||||
| 1153 | 82 | $this->{level} -= 1; | |||||||||||||||||||||||||||||||||||||||||
| 1154 | 82 | next; | |||||||||||||||||||||||||||||||||||||||||
| 1155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1157 | else { # inside $block, just push onto new content stack | ||||||||||||||||||||||||||||||||||||||||||
| 1158 | 158 | push @newcontent, $_; | |||||||||||||||||||||||||||||||||||||||||
| 1159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1161 | 135 | ▶ | if ($block) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1162 | # $block is still defined, which means, that it had | ||||||||||||||||||||||||||||||||||||||||||
| 1163 | # no matching endblock! | ||||||||||||||||||||||||||||||||||||||||||
| 1164 | 0 | croak "Config::General: Block \"<$block>\" has no EndBlock statement (level: $this->{level}, chunk $chunk)!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1166 | 135 | return $config; | |||||||||||||||||||||||||||||||||||||||||
| 1167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||||||||||||||||
| 1169 | |||||||||||||||||||||||||||||||||||||||||||
| 1170 | 39 | ▶ | sub _copy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_copy: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1171 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1172 | # copy the contents of one hash into another | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | # to circumvent invalid references | ||||||||||||||||||||||||||||||||||||||||||
| 1174 | # fixes rt.cpan.org bug #35122 | ||||||||||||||||||||||||||||||||||||||||||
| 1175 | 39 | my($this, $source) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1176 | 39 | my %hash = (); | |||||||||||||||||||||||||||||||||||||||||
| 1177 | 39 | ▶ | while (my ($key, $value) = each %{$source}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1178 | 404 | $hash{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1180 | 39 | return \%hash; | |||||||||||||||||||||||||||||||||||||||||
| 1181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||||||||||||||||
| 1183 | |||||||||||||||||||||||||||||||||||||||||||
| 1184 | 250 | ▶ | sub _parse_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_value: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||
| 1185 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1186 | # parse the value if value parsing is turned on | ||||||||||||||||||||||||||||||||||||||||||
| 1187 | # by either -AutoTrue and/or -FlagBits | ||||||||||||||||||||||||||||||||||||||||||
| 1188 | # otherwise just return the given value unchanged | ||||||||||||||||||||||||||||||||||||||||||
| 1189 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1190 | 250 | my($this, $config, $option, $value) =@_; | |||||||||||||||||||||||||||||||||||||||||
| 1191 | |||||||||||||||||||||||||||||||||||||||||||
| 1192 | 250 | my $cont; | |||||||||||||||||||||||||||||||||||||||||
| 1193 | 250 | ($cont, $option, $value) = $this->_hook('pre_parse_value', $option, $value); | |||||||||||||||||||||||||||||||||||||||||
| 1194 | 250 | ▶ | return $value if(!$cont); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||
| 1196 | # avoid "Use of uninitialized value" | ||||||||||||||||||||||||||||||||||||||||||
| 1197 | 250 | ▶ | if (! defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1198 | # patch fix rt#54583 | ||||||||||||||||||||||||||||||||||||||||||
| 1199 | # Return an input undefined value without trying transformations | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | 4 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 1201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1202 | |||||||||||||||||||||||||||||||||||||||||||
| 1203 | 246 | ▶ | if($this->{NormalizeValue}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1204 | 0 | $value = $this->{NormalizeValue}($value); | |||||||||||||||||||||||||||||||||||||||||
| 1205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1206 | |||||||||||||||||||||||||||||||||||||||||||
| 1207 | 246 | ▶ | if ($this->{InterPolateVars}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1208 | 73 | $value = $this->_interpolate($config, $option, $value); | |||||||||||||||||||||||||||||||||||||||||
| 1209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||||||||||||||||
| 1211 | # make true/false values to 1 or 0 (-AutoTrue) | ||||||||||||||||||||||||||||||||||||||||||
| 1212 | 246 | ▶ | if ($this->{AutoTrue}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1213 | 46 | ▶ | if ($value =~ /$this->{AutoTrueFlags}->{true}/io) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1214 | 7 | $value = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1216 | elsif ($value =~ /$this->{AutoTrueFlags}->{false}/io) { | ||||||||||||||||||||||||||||||||||||||||||
| 1217 | 9 | $value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||||||||||||||||
| 1221 | # assign predefined flags or undef for every flag | flag ... (-FlagBits) | ||||||||||||||||||||||||||||||||||||||||||
| 1222 | 246 | ▶ | if ($this->{FlagBits}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1223 | 35 | ▶ | if (exists $this->{FlagBitsFlags}->{$option}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1224 | 2 | my %__flags = map { $_ => 1 } split /\s*\|\s*/, $value; | |||||||||||||||||||||||||||||||||||||||||
| 1225 | 2 | foreach my $flag (keys %{$this->{FlagBitsFlags}->{$option}}) { | |||||||||||||||||||||||||||||||||||||||||
| 1226 | 6 | ▶ | if (exists $__flags{$flag}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1227 | 5 | $__flags{$flag} = $this->{FlagBitsFlags}->{$option}->{$flag}; | |||||||||||||||||||||||||||||||||||||||||
| 1228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1229 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1230 | 1 | $__flags{$flag} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 1231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1233 | 2 | $value = \%__flags; | |||||||||||||||||||||||||||||||||||||||||
| 1234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1236 | |||||||||||||||||||||||||||||||||||||||||||
| 1237 | 246 | ▶ | if (!$this->{NoEscape}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1238 | # are there any escaped characters left? put them out as is | ||||||||||||||||||||||||||||||||||||||||||
| 1239 | 245 | $value =~ s/\\([\$\\\"#])/$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 1240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1241 | |||||||||||||||||||||||||||||||||||||||||||
| 1242 | 246 | ($cont, $option, $value) = $this->_hook('post_parse_value', $option, $value); | |||||||||||||||||||||||||||||||||||||||||
| 1243 | |||||||||||||||||||||||||||||||||||||||||||
| 1244 | 246 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 1245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1246 | |||||||||||||||||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||||||||||||||||
| 1249 | 733 | ▶ | sub _hook { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hook: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||
| 1250 | 733 | my ($this, $hook, @arguments) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1251 | 733 | ▶ | if(exists $this->{Plug}->{$hook}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1252 | 0 | my $sub = $this->{Plug}->{$hook}; | |||||||||||||||||||||||||||||||||||||||||
| 1253 | 0 | my @hooked = &$sub(@arguments); | |||||||||||||||||||||||||||||||||||||||||
| 1254 | 0 | return @hooked; | |||||||||||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1256 | 733 | return (1, @arguments); | |||||||||||||||||||||||||||||||||||||||||
| 1257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||||||||||||||||
| 1259 | |||||||||||||||||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||||||||||||||||
| 1261 | 0 | ▶ | sub save { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1262 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1263 | # this is the old version of save() whose API interface | ||||||||||||||||||||||||||||||||||||||||||
| 1264 | # has been changed. I'm very sorry 'bout this. | ||||||||||||||||||||||||||||||||||||||||||
| 1265 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1266 | # I'll try to figure out, if it has been called correctly | ||||||||||||||||||||||||||||||||||||||||||
| 1267 | # and if yes, feed the call to Save(), otherwise croak. | ||||||||||||||||||||||||||||||||||||||||||
| 1268 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1269 | 0 | my($this, $one, @two) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1270 | |||||||||||||||||||||||||||||||||||||||||||
| 1271 | 0 | ▶ | if ( (@two && $one) && ( (scalar @two) % 2 == 0) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@two and $one and scalar(@two) % 2 == 0
@two and $one
MC/DC0%0/3
@two and $one and scalar(@two) % 2 == 0
@two
$one
scalar(@two) % 2 == 0
Truth table0%0/4
A and B and C
A= @twoB= $oneC= scalar(@two) % 2 == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 1272 | # @two seems to be a hash | ||||||||||||||||||||||||||||||||||||||||||
| 1273 | 0 | my %h = @two; | |||||||||||||||||||||||||||||||||||||||||
| 1274 | 0 | $this->save_file($one, \%h); | |||||||||||||||||||||||||||||||||||||||||
| 1275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1276 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1277 | 0 | croak q(Config::General: The save() method is deprecated. Use the new save_file() method instead!); | |||||||||||||||||||||||||||||||||||||||||
| 1278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1279 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1281 | |||||||||||||||||||||||||||||||||||||||||||
| 1282 | |||||||||||||||||||||||||||||||||||||||||||
| 1283 | 7 | ▶ | sub save_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_file: called CC=8 SCAR=24.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1284 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1285 | # save the config back to disk | ||||||||||||||||||||||||||||||||||||||||||
| 1286 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1287 | 7 | my($this, $file, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1288 | 7 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 1289 | my $config_string; | ||||||||||||||||||||||||||||||||||||||||||
| 1290 | |||||||||||||||||||||||||||||||||||||||||||
| 1291 | 7 | ▶ | if (!$file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1292 | 0 | croak "Config::General: Filename is required!"; | |||||||||||||||||||||||||||||||||||||||||
| 1293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1294 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1295 | 7 | ▶ | if ($this->{UTF8}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1296 | 0 | $fh = IO::File->new; | |||||||||||||||||||||||||||||||||||||||||
| 1297 | 0 | ▶ | open($fh, ">:utf8", $file) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1298 | or croak "Config::General: Could not open $file in UTF8 mode!($!)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1300 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1301 | 7 | ▶ | $fh = IO::File->new( "$file", 'w') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1302 | or croak "Config::General: Could not open $file!($!)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 1303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1304 | 7 | ▶ | if (!$config) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1305 | 5 | ▶ | if (exists $this->{config}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1306 | 5 | $config_string = $this->_store(0, $this->{config}); | |||||||||||||||||||||||||||||||||||||||||
| 1307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1308 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1309 | 0 | croak "Config::General: No config hash supplied which could be saved to disk!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1312 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1313 | 2 | $config_string = $this->_store(0, $config); | |||||||||||||||||||||||||||||||||||||||||
| 1314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1315 | |||||||||||||||||||||||||||||||||||||||||||
| 1316 | 6 | ▶ | if ($config_string) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1317 | 6 | print {$fh} $config_string; | |||||||||||||||||||||||||||||||||||||||||
| 1318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1319 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1320 | # empty config for whatever reason, I don't care | ||||||||||||||||||||||||||||||||||||||||||
| 1321 | 0 | print {$fh} q(); | |||||||||||||||||||||||||||||||||||||||||
| 1322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1323 | |||||||||||||||||||||||||||||||||||||||||||
| 1324 | 6 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 1325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1326 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||||||||||||||||
| 1329 | |||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||
| 1331 | 2 | ▶ | sub save_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
save_string: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1332 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1333 | # return the saved config as a string | ||||||||||||||||||||||||||||||||||||||||||
| 1334 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1335 | 2 | my($this, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1336 | |||||||||||||||||||||||||||||||||||||||||||
| 1337 | 2 | ▶ | if (!$config || ref($config) ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $config or ref $config ne "HASH"
MC/DC50%1/2
not $config or ref $config ne "HASH"
not $config
ref $config ne "HASH"
Truth table66%2/3
not(A) or B
A= not $configB= ref $config ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 1338 | 1 | ▶ | if (exists $this->{config}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1339 | 1 | return $this->_store(0, $this->{config}); | |||||||||||||||||||||||||||||||||||||||||
| 1340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1341 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1342 | 0 | croak "Config::General: No config hash supplied which could be saved to disk!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1345 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1346 | 1 | return $this->_store(0, $config); | |||||||||||||||||||||||||||||||||||||||||
| 1347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1348 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1350 | |||||||||||||||||||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||||||||||||||||
| 1352 | |||||||||||||||||||||||||||||||||||||||||||
| 1353 | 32 | ▶ | sub _store { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_store: called CC=12 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1354 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1355 | # internal sub for saving a block | ||||||||||||||||||||||||||||||||||||||||||
| 1356 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1357 | 32 | my($this, $level, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1358 | 32 | local $_; | |||||||||||||||||||||||||||||||||||||||||
| 1359 | 32 | my $indent = q( ) x $level; | |||||||||||||||||||||||||||||||||||||||||
| 1360 | |||||||||||||||||||||||||||||||||||||||||||
| 1361 | 32 | my $config_string = q(); | |||||||||||||||||||||||||||||||||||||||||
| 1362 | |||||||||||||||||||||||||||||||||||||||||||
| 1363 | 32 | ▶ | foreach my $entry ( $this->{SaveSorted} ? sort keys %$config : keys %$config ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1364 | # fix rt#104548 | ||||||||||||||||||||||||||||||||||||||||||
| 1365 | 94 | ▶ | if ($entry =~ /[<>\n\r]/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1366 | 1 | croak "Config::General: current key contains invalid characters: $entry!\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1368 | |||||||||||||||||||||||||||||||||||||||||||
| 1369 | 93 | ▶ | if (ref($config->{$entry}) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1370 | 5 | ▶ | if( $this->{ForceArray} && scalar @{$config->{$entry}} == 1 && ! ref($config->{$entry}->[0]) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$this->{"ForceArray"} and scalar @{$config->{$entry};} == 1 and not ref $config->{$entry}[0]
$this->{"ForceArray"} and scalar @{$config->{$entry};} == 1
MC/DC33%1/3
$this->{"ForceArray"} and scalar @{$config->{$entry};} == 1 and not ref $config->{$entry}[0]
$this->{"ForceArray"}
scalar @{$config->{$entry};} == 1
not ref $config->{$entry}[0]
Truth table50%2/4
A and B and not(C)
A= $this->{"ForceArray"}B= scalar @{$config->{$entry};} == 1C= not ref $config->{$entry}[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 1371 | # a single value array forced to stay as array | ||||||||||||||||||||||||||||||||||||||||||
| 1372 | 1 | $config_string .= $this->_write_scalar($level, $entry, '[' . $config->{$entry}->[0] . ']'); | |||||||||||||||||||||||||||||||||||||||||
| 1373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1374 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1375 | 0 | ▶ | foreach my $line ( $this->{SaveSorted} ? sort @{$config->{$entry}} : @{$config->{$entry}} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1376 | 10 | ▶ | if (ref($line) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1377 | 2 | $config_string .= $this->_write_hash($level, $entry, $line); | |||||||||||||||||||||||||||||||||||||||||
| 1378 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1379 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1380 | 8 | $config_string .= $this->_write_scalar($level, $entry, $line); | |||||||||||||||||||||||||||||||||||||||||
| 1381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1385 | elsif (ref($config->{$entry}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 1386 | 21 | $config_string .= $this->_write_hash($level, $entry, $config->{$entry}); | |||||||||||||||||||||||||||||||||||||||||
| 1387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1388 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1389 | 67 | $config_string .= $this->_write_scalar($level, $entry, $config->{$entry}); | |||||||||||||||||||||||||||||||||||||||||
| 1390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1392 | |||||||||||||||||||||||||||||||||||||||||||
| 1393 | 31 | return $config_string; | |||||||||||||||||||||||||||||||||||||||||
| 1394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1395 | |||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||
| 1397 | 76 | ▶ | sub _write_scalar { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_scalar: called CC=11 SCAR=24.3
| |||||||||||||||||||||||||||||||||||||||||||
| 1398 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1399 | # internal sub, which writes a scalar | ||||||||||||||||||||||||||||||||||||||||||
| 1400 | # it returns it, in fact | ||||||||||||||||||||||||||||||||||||||||||
| 1401 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1402 | 76 | my($this, $level, $entry, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1403 | |||||||||||||||||||||||||||||||||||||||||||
| 1404 | 76 | my $indent = q( ) x $level; | |||||||||||||||||||||||||||||||||||||||||
| 1405 | |||||||||||||||||||||||||||||||||||||||||||
| 1406 | 76 | my $config_string; | |||||||||||||||||||||||||||||||||||||||||
| 1407 | |||||||||||||||||||||||||||||||||||||||||||
| 1408 | # patch fix rt#54583 | ||||||||||||||||||||||||||||||||||||||||||
| 1409 | 76 | ▶ | if ( ! defined $line ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1410 | 0 | $config_string .= $indent . $entry . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1412 | ▶ | elsif ($line =~ /\n/ || $line =~ /\\$/) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$line =~ /\n/ or $line =~ /\\$/
MC/DC50%1/2
$line =~ /\n/ or $line =~ /\\$/
$line =~ /\n/
$line =~ /\\$/
Truth table66%2/3
A or B
A= $line =~ /\n/B= $line =~ /\\$/
| |||||||||||||||||||||||||||||||||||||||||||
| 1413 | # it is a here doc | ||||||||||||||||||||||||||||||||||||||||||
| 1414 | 3 | my $delimiter; | |||||||||||||||||||||||||||||||||||||||||
| 1415 | 3 | my $tmplimiter = 'EOF'; | |||||||||||||||||||||||||||||||||||||||||
| 1416 | 3 | ▶ | while (!$delimiter) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1417 | # create a unique here-doc identifier | ||||||||||||||||||||||||||||||||||||||||||
| 1418 | 3 | ▶ | if ($line =~ /$tmplimiter/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1419 | 0 | $tmplimiter .= '%'; | |||||||||||||||||||||||||||||||||||||||||
| 1420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1421 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1422 | 3 | $delimiter = $tmplimiter; | |||||||||||||||||||||||||||||||||||||||||
| 1423 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1424 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1425 | 3 | my @lines = split /\n/, $line; | |||||||||||||||||||||||||||||||||||||||||
| 1426 | 3 | $config_string .= $indent . $entry . $this->{StoreDelimiter} . "<<$delimiter\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1427 | 3 | foreach (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 1428 | 8 | $config_string .= $indent . $_ . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1430 | 3 | $config_string .= $indent . "$delimiter\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1432 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1433 | # a simple stupid scalar entry | ||||||||||||||||||||||||||||||||||||||||||
| 1434 | |||||||||||||||||||||||||||||||||||||||||||
| 1435 | 73 | ▶ | if (!$this->{NoEscape}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1436 | # re-escape contained $ or # or \ chars | ||||||||||||||||||||||||||||||||||||||||||
| 1437 | 73 | $line =~ s/([#\$\\\"])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 1438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1439 | |||||||||||||||||||||||||||||||||||||||||||
| 1440 | 73 | ▶ | if ($line =~ /^\s/ || $line =~ /\s$/ || $this->{AlwaysQuoteOutput}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$line =~ /^\s/ or $line =~ /\s$/ or $this->{"AlwaysQuoteOutput"}
$line =~ /^\s/ or $line =~ /\s$/
MC/DC100%3/3
$line =~ /^\s/ or $line =~ /\s$/ or $this->{"AlwaysQuoteOutput"}
$line =~ /^\s/
$line =~ /\s$/
$this->{"AlwaysQuoteOutput"}
Truth table100%4/4
A or B or C
A= $line =~ /^\s/B= $line =~ /\s$/C= $this->{"AlwaysQuoteOutput"}
| |||||||||||||||||||||||||||||||||||||||||||
| 1441 | # quote lines containing whitespace | ||||||||||||||||||||||||||||||||||||||||||
| 1442 | 3 | $line = "\"$line\""; | |||||||||||||||||||||||||||||||||||||||||
| 1443 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1444 | |||||||||||||||||||||||||||||||||||||||||||
| 1445 | 73 | $config_string .= $indent . $entry . $this->{StoreDelimiter} . $line . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||||||||||||||||
| 1448 | 76 | return $config_string; | |||||||||||||||||||||||||||||||||||||||||
| 1449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1450 | |||||||||||||||||||||||||||||||||||||||||||
| 1451 | 23 | ▶ | sub _write_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_hash: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1452 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1453 | # internal sub, which writes a hash (block) | ||||||||||||||||||||||||||||||||||||||||||
| 1454 | # it returns it, in fact | ||||||||||||||||||||||||||||||||||||||||||
| 1455 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1456 | 23 | my($this, $level, $entry, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1457 | |||||||||||||||||||||||||||||||||||||||||||
| 1458 | 23 | my $indent = q( ) x $level; | |||||||||||||||||||||||||||||||||||||||||
| 1459 | 23 | my $config_string; | |||||||||||||||||||||||||||||||||||||||||
| 1460 | |||||||||||||||||||||||||||||||||||||||||||
| 1461 | 23 | ▶ | if ($entry =~ /\s/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1462 | # quote the entry if it contains whitespaces | ||||||||||||||||||||||||||||||||||||||||||
| 1463 | 0 | $entry = q(") . $entry . q("); | |||||||||||||||||||||||||||||||||||||||||
| 1464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1465 | |||||||||||||||||||||||||||||||||||||||||||
| 1466 | # check if the next level key points to a hash and is the only one | ||||||||||||||||||||||||||||||||||||||||||
| 1467 | # in this case put out a named block | ||||||||||||||||||||||||||||||||||||||||||
| 1468 | # fixes rt.77667 | ||||||||||||||||||||||||||||||||||||||||||
| 1469 | 23 | my $num = scalar keys %{$line}; | |||||||||||||||||||||||||||||||||||||||||
| 1470 | 23 | ▶ | if($num == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1471 | 17 | my $key = (keys %{$line})[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1472 | 17 | ▶ | if(ref($line->{$key}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1473 | 11 | $config_string .= $indent . qq(<$entry $key>\n); | |||||||||||||||||||||||||||||||||||||||||
| 1474 | 11 | $config_string .= $this->_store($level + 1, $line->{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 1475 | 11 | $config_string .= $indent . qq(</) . $entry . ">\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1476 | 11 | return $config_string; | |||||||||||||||||||||||||||||||||||||||||
| 1477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1479 | |||||||||||||||||||||||||||||||||||||||||||
| 1480 | 12 | $config_string .= $indent . q(<) . $entry . ">\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1481 | 12 | $config_string .= $this->_store($level + 1, $line); | |||||||||||||||||||||||||||||||||||||||||
| 1482 | 12 | $config_string .= $indent . q(</) . $entry . ">\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1483 | |||||||||||||||||||||||||||||||||||||||||||
| 1484 | 12 | return $config_string | |||||||||||||||||||||||||||||||||||||||||
| 1485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1486 | |||||||||||||||||||||||||||||||||||||||||||
| 1487 | |||||||||||||||||||||||||||||||||||||||||||
| 1488 | 155 | ▶ | sub _hashref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hashref: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1489 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1490 | # return a probably tied new empty hash ref | ||||||||||||||||||||||||||||||||||||||||||
| 1491 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1492 | 155 | my($this) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1493 | 155 | ▶ | if ($this->{Tie}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1494 | 1 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 1495 | 1 | eval qq{require $this->{Tie}}; | |||||||||||||||||||||||||||||||||||||||||
| 1496 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1497 | 1 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1498 | 0 | croak q(Config::General: Could not create a tied hash of type: ) . $this->{Tie} . q(: ) . $EVAL_ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 1499 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1500 | 1 | my %hash; | |||||||||||||||||||||||||||||||||||||||||
| 1501 | 1 | tie %hash, $this->{Tie}; | |||||||||||||||||||||||||||||||||||||||||
| 1502 | 1 | return \%hash; | |||||||||||||||||||||||||||||||||||||||||
| 1503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1504 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1505 | 154 | return {}; | |||||||||||||||||||||||||||||||||||||||||
| 1506 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1508 | |||||||||||||||||||||||||||||||||||||||||||
| 1509 | 45 | ▶ | sub _validate_input_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_input_hash: called CC=12 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1510 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1511 | # Checks if a given input hash contains invalid keys or values. | ||||||||||||||||||||||||||||||||||||||||||
| 1512 | # Fixes https://codeberg.org/scip/Config-General/issues/9. | ||||||||||||||||||||||||||||||||||||||||||
| 1513 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1514 | 45 | my($this, $hash) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1515 | |||||||||||||||||||||||||||||||||||||||||||
| 1516 | 45 | ▶ | if (ref($hash) eq '') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1517 | 8 | return $this->_validate_input_hash_value($hash); | |||||||||||||||||||||||||||||||||||||||||
| 1518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1519 | elsif (ref($hash) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 1520 | 0 | foreach my $sub (@{$hash}) { | |||||||||||||||||||||||||||||||||||||||||
| 1521 | 0 | return $this->_validate_input_hash($sub); | |||||||||||||||||||||||||||||||||||||||||
| 1522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1524 | |||||||||||||||||||||||||||||||||||||||||||
| 1525 | 37 | foreach my $key (keys %{$hash}) { | |||||||||||||||||||||||||||||||||||||||||
| 1526 | 50 | ▶ | if (! $this->_validate_input_hash_value($key)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1527 | 6 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||||||||||||||||
| 1530 | 44 | ▶ | if (ref($hash->{$key}) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1531 | 3 | foreach my $sub (@{$hash->{$key}}) { | |||||||||||||||||||||||||||||||||||||||||
| 1532 | 7 | ▶ | if (! $this->_validate_input_hash($sub)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1533 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1535 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1537 | elsif(ref($hash->{$key}) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 1538 | 11 | ▶ | if (! $this->_validate_input_hash($hash->{$key})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1539 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1541 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1542 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1543 | 30 | ▶ | if (! $this->_validate_input_hash_value($hash->{$key})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1544 | 7 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1547 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1548 | |||||||||||||||||||||||||||||||||||||||||||
| 1549 | 20 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1550 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1551 | |||||||||||||||||||||||||||||||||||||||||||
| 1552 | 88 | ▶ | sub _validate_input_hash_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_input_hash_value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1553 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1554 | # Checks a given key or value against a deny regex | ||||||||||||||||||||||||||||||||||||||||||
| 1555 | 88 | my ($this, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1556 | |||||||||||||||||||||||||||||||||||||||||||
| 1557 | 88 | ▶ | if ($value =~ /(<<|>>|\*\/|\/\*|#)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1558 | 14 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 1559 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||||||||||||||||
| 1561 | 74 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1563 | |||||||||||||||||||||||||||||||||||||||||||
| 1564 | |||||||||||||||||||||||||||||||||||||||||||
| 1565 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1566 | # Procedural interface | ||||||||||||||||||||||||||||||||||||||||||
| 1567 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1568 | 3 | ▶ | sub ParseConfig { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ParseConfig: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1569 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1570 | # @_ may contain everything which is allowed for new() | ||||||||||||||||||||||||||||||||||||||||||
| 1571 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1572 | 3 | return (new Config::General(@_))->getall(); | |||||||||||||||||||||||||||||||||||||||||
| 1573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1574 | |||||||||||||||||||||||||||||||||||||||||||
| 1575 | 1 | ▶ | sub SaveConfig { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SaveConfig: called CC=4 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1576 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1577 | # 2 parameters are required, filename and hash ref | ||||||||||||||||||||||||||||||||||||||||||
| 1578 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1579 | 1 | my ($file, $hash) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1580 | |||||||||||||||||||||||||||||||||||||||||||
| 1581 | 1 | ▶ | if (!$file || !$hash) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$file && $hash
MC/DC0%0/2
$file && $hash
$file
$hash
Truth table33%1/3
A && B
A= $fileB= $hash
| |||||||||||||||||||||||||||||||||||||||||||
| 1582 | 0 | croak q{Config::General::SaveConfig(): filename and hash argument required.}; | |||||||||||||||||||||||||||||||||||||||||
| 1583 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1584 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1585 | 1 | ▶ | if (ref($hash) ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1586 | 0 | croak q(Config::General::SaveConfig() The second parameter must be a reference to a hash!); | |||||||||||||||||||||||||||||||||||||||||
| 1587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1588 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1589 | 1 | (new Config::General(-ConfigHash => $hash))->save_file($file); | |||||||||||||||||||||||||||||||||||||||||
| 1590 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1591 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1592 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1593 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1594 | |||||||||||||||||||||||||||||||||||||||||||
| 1595 | 0 | ▶ | sub SaveConfigString { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SaveConfigString: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1596 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1597 | # same as SaveConfig, but return the config, | ||||||||||||||||||||||||||||||||||||||||||
| 1598 | # instead of saving it | ||||||||||||||||||||||||||||||||||||||||||
| 1599 | # | ||||||||||||||||||||||||||||||||||||||||||
| 1600 | 0 | my ($hash) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1601 | |||||||||||||||||||||||||||||||||||||||||||
| 1602 | 0 | ▶ | if (!$hash) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1603 | 0 | croak q{Config::General::SaveConfigString(): Hash argument required.}; | |||||||||||||||||||||||||||||||||||||||||
| 1604 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1605 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1606 | 0 | ▶ | if (ref($hash) ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1607 | 0 | croak q(Config::General::SaveConfigString() The parameter must be a reference to a hash!); | |||||||||||||||||||||||||||||||||||||||||
| 1608 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1609 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1610 | 0 | return (new Config::General(-ConfigHash => $hash))->save_string(); | |||||||||||||||||||||||||||||||||||||||||
| 1611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1612 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1613 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1615 | |||||||||||||||||||||||||||||||||||||||||||
| 1616 | |||||||||||||||||||||||||||||||||||||||||||
| 1617 | |||||||||||||||||||||||||||||||||||||||||||
| 1618 | # keep this one | ||||||||||||||||||||||||||||||||||||||||||
| 1619 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1620 | __END__ | ||||||||||||||||||||||||||||||||||||||||||