Param.pm

filter: Statementstmt 81.1% 940 / 1159 Branchbran 64.0% 521 / 814 Conditioncond 59.9% 160 / 267 MC/DCmcdc 37.1% 55 / 148 Subroutinesub 94.6% 53 / 56 Podpod 51.1% 22 / 43 totaltotal 70.4% 1751 / 2487 CC 530 SCAR 57.3
CC
530
Cov
72%
help
1937.2
parse_file
100.6
INT_param_help_posix
72.0
CRAP 308.7
↑ Summary Param/FileWorker.pm »
1 # This has been a simple routine for command line and config file parsing.
2 # Now it deals with differing styles (grades of laziness) of command line parameters,
3 # has funky operators on them, and is a tool box to work with other program's config files.
4  
5 # It also carries a badge with the inscript "NIH syndrome".
6 # On the backside, you can read "But still better than anything that came before!".
7  
8 # current modus operandi:
9 # 1. parse command line args into temporary storage
10 # 2. parse config files (that may have been set on command line)
11 # 3. merge settings (overwrite config file settings)
12 # 4. finalize with help/error message
13  
14 # TODO: I got sections now. A next step could be sub-commands, presented as sections
15 # in help output and also defined like/with those. Needs some namespacing, though.
16 # Maybe just sub-instances of Config::Param.
17  
18 # TODO: I should restructure the the internal data. It's too many hashes now
19 # with the same key. Nested hash or better array with named indices (to avoid typos and
20 # less wasteful storage)?
21  
22 # TODO: --config with append mode, by config option
23  
24 package Config::Param;
25  
26 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 12 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 # major.minor.bugfix, the latter two with 3 digits each
32 # or major.minor_alpha
33 12 our $VERSION = '4.000006';
34 12 $VERSION = eval $VERSION;
35 12 our %features = qw(array 1 hash 1);
36  
37 12 our $verbose = 0; # overriding config
38  
39 # parameter flags
40 12 our $count = 1;
41 12 our $arg = 2;
42 12 our $switch = 4;
43 12 our $append = 8;
44 12 our $nonempty = 16;
45  
46 # using exit values from sysexists.h which make sense
47 # for configuration parsing
48 12 my $ex_usage = 64;
49 12 my $ex_config = 78;
50 12 my $ex_software = 70;
51  
52 12 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 12 ▶use FindBin qw($Bin);
Subroutine BEGIN: called CC=1 SCAR=0.0
54 12 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 12 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 # The official API for simple use:
58  
59 # This is the procedural interface: Just call get() with your setup and get the pars.
60 sub get #(config, params)
61 67 ▶{
Subroutine get: called CC=9 SCAR=22.0
Pod documented
62 # Handling of the differing API variants
63 # 1. just plain list of parameter definitions
64 # 2. config hash first, then parameter definitions
65 # 3. config hash, then array ref for definitions
66 # ... in that case, optional ref to argument array to parse
67 67 ▶ my $config = ref $_[0] eq 'HASH' ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 65 2 67
68 67 my $pardef;
69 67 my $args = \@ARGV;
70 67 my $give_error;
71 67 ▶ if(ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 66 1 67
72 {
73 66 $pardef = shift;
74 66 ▶ if(ref $_[0] eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "ARRAY") 64 2 66
75 {
76 64 $args = shift;
77 64 $give_error = 1;
78 }
79 }
80 1 else{ $pardef = \@_; }
81  
82 67 my $pars = Config::Param->new($config, $pardef);
83 # Aborting on bad specification. Not sensible to continue.
84 # Match this with documentation in POD.
85 67 ▶ my $bad = not (
Condition100%12/12
$pars->good && $pars->parse_args($args) && $pars->use_config_files && $pars->apply_args && $pars->INT_value_check
!ll&&!rl&&r
7357
$pars->good and $pars->parse_args($args) and $pars->use_config_files and $pars->apply_args
!ll&&!rl&&r
6160
$pars->good and $pars->parse_args($args) and $pars->use_config_files
!ll&&!rl&&r
5161
$pars->good and $pars->parse_args($args)
!ll&&!rl&&r
2362
MC/DC100%5/5
$pars->good && $pars->parse_args($args) && $pars->use_config_files && $pars->apply_args && $pars->INT_value_check
$pars->good $pars->parse_args($args) $pars->use_config_files $pars->apply_args $pars->INT_value_check
Truth table100%6/6
A and B and C and D && E
A= $pars->goodB= $pars->parse_args($args)C= $pars->use_config_filesD= $pars->apply_argsE= $pars->INT_value_check
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
86 $pars->good()
87 and $pars->parse_args($args)
88 and $pars->use_config_files()
89 and $pars->apply_args()
90 and $pars->INT_value_check()
91 );
92 67 $pars->final_action($bad);
93  
94 67 ▶ $_[0] = $pars->{errors} if $give_error;
Branch: 1 branch
BranchTrueFalseTotal
if $give_error 64 3 67
95 67 return $pars->{param};
96 }
97  
98 # Now the meat.
99  
100 # Codes for types of parameters. It's deliberate that simple scalars are false and others are true.
101 12 my $scalar = 0; # Undefined also counts as scalar.
102 12 my $array = 1;
103 12 my $hash = 2;
104 12 my @initval = (undef, [], {});
105 #This needs to be changed. Also for a hash, --hash is equivalent to --hash=1, which
106 #results in 1=>undef, not truth=>1
107 12 my @trueval = (1, [1], {truth=>1});
108 12 my @falseval = (0, [0], {truth=>0});
109 12 my @typename = ('scalar', 'array', 'hash');
110 12 my %typemap = (''=>$scalar, scalar=>$scalar, array=>$array, hash=>$hash);
111  
112 # A name is allowed to contain just about everything but "=", but shall not end with something that will be mistaken for an operator.
113 # The checks for valid names besides the generic regexes are stricter and should be employed in addition.
114  
115 # Parser regex elements.
116 # Generally, it's optinal operators before "=" or just operators for short parameters.
117 # The addition with /./ is for choosing an arbitrary array separator for the value.
118 # Since long names are not allowed to end with an operator, using "/" that way is
119 # no additional restriction.
120 # Context is needed to decide for /,/ and // with special function for arrays and hashes.
121 # The grammar is not context-free anymore. Meh.
122 # Well, treating it this way: // is a special operator for long names,
123 # // is parsed as /=/, then interpreted accordingly for arrays as //.
124 12 my $ops = '.+\-*\/'; # There's also <<endtext as special thing in config file.
125 12 my $sopex = '['.$ops.']?=|['.$ops.']=?';
126 12 my $lopex = '\/.\/['.$ops.']?=|['.$ops.']?=|\/\/|\/.\/';
127 12 my $noop = '[^+\-=.*\/\s<>]'; # a non-whitespace character that is unspecial
128 12 my $parname = $noop.'[^\s=\/<>]*'.$noop;
129  
130 # Regular expressions for parameter parsing.
131 # The two variants are crafted to yield matching back-references.
132 # -x -x=bla -xyz -xyz=bla
133 12 our $shortex_strict = qr/^(([-+])($noop+|($noop+)($sopex)(.*)))$/;
134 # -x -x=bla -xyz x x=bla xyz
135 12 our $shortex_lazy = qr/^(([-+]?)($noop+|($noop)($sopex)(.*)))$/;
136 # -xbla with x possibly arg-requiring option and bla an argument
137 12 our $shortarg = qr/^[-+]($noop)($sopex|)(.+)$/;
138 # --long --long=bla
139 12 our $longex_strict = qr/^(([-+]{2})($parname)(($lopex)(.*)|))$/;
140 # --long --long=bla -long=bla long=bla
141 12 our $longex_lazy = qr/^(([-+]{0,2})($parname)()($lopex)(.*)|(--|\+\+)($parname))$/;
142  
143 12 my %example =
144 (
145 'lazy' => '[-]s [-]xyz [-]s=value --long [-[-]]long=value - [files/stuff]'
146 ,'normal' => '-s -xyz -s=value --long --long=value [--] [files/stuff]'
147 );
148 12 my $lazyinfo = "The [ ] notation means that the enclosed - is optional, saving typing time for really lazy people. Note that \"xyz\" as well as \"-xyz\" mention three short options, opposed to the long option \"--long\". In trade for the shortage of \"-\", the separator for additional unnamed parameters is mandatory (supply as many \"-\" grouped together as you like;-).";
149  
150 12 my @morehelp =
151 (
152 'You mention the options to change parameters in any order or even multiple times.'
153 , ' They are processed in the oder given, later operations overriding/extending earlier settings.'
154 , ' Using the separator "--" stops option parsing'."\n"
155 ,'An only mentioned short/long name (no "=value") means setting to 1, which is true in the logical sense. Also, prepending + instead of the usual - negates this, setting the value to 0 (false).'."\n"
156 ,'Specifying "-s" and "--long" is the same as "-s=1" and "--long=1", while "+s" and "++long" is the sames as "-s=0" and "--long=0".'."\n"
157 ,"\n"
158 ,'There are also different operators than just "=" available, notably ".=", "+=", "-=", "*=" and "/=" for concatenation / appending array/hash elements and scalar arithmetic operations on the value. Arrays are appended to via "array.=element", hash elements are set via "hash.=name=value". You can also set more array/hash elements by specifying a separator after the long parameter line like this for comma separation:'."\n\n"
159 ,"\t--array/,/=1,2,3 --hash/,/=name=val,name2=val2"
160 );
161  
162 # check if long/short name is valid before use
163 sub valid_name
164 657 ▶{
Subroutine valid_name: called CC=5 SCAR=17.2
Pod documented
165 657 my ($long, $short) = @_;
166 return
167 (
168 657 ▶ (not defined $short or $short eq '' or $short =~ /^$noop$/o)
Condition66%8/12
(!defined($short) || $short eq '' || $short =~ /^$noop$/o) && defined $long && $long =~ /^$parname/o
!ll&&!rl&&r
01656
!defined($short) || $short eq "" || $short =~ /^$noop$/o and defined $long
!ll&&!rl&&r
00657
not defined $short or $short eq "" or $short =~ /^$noop$/o
l!l&&r!l&&!r
1005570
not defined $short or $short eq ""
l!l&&r!l&&!r
892557
MC/DC20%1/5
(!defined($short) || $short eq '' || $short =~ /^$noop$/o) && defined $long && $long =~ /^$parname/o
not defined $short $short eq "" $short =~ /^$noop$/o defined $long $long =~ /^$parname/o
Truth table40%4/10
not(A) or B or C and D && E
A= not defined $shortB= $short eq ""C= $short =~ /^$noop$/oD= defined $longE= $long =~ /^$parname/o
ABCDEresult
000XX0
1XX0X0
01X0X0
0010X0
1XX100
01X100
001100
1XX111
01X111
001111
169 and defined $long
170 and $long =~ /^$parname/o
171 );
172 }
173  
174 sub valid_type
175 657 ▶{
Subroutine valid_type: called CC=1 SCAR=0.0
Pod documented
176 657 my $type = lc(ref $_[0]);
177 657 return $typemap{$type}; # undefined if invalid
178 }
179  
180 # A valid definition also means that the default value type
181 # must match a possibly specified type.
182 sub valid_def
183 657 ▶{
Subroutine valid_def: called CC=10 SCAR=27.4
Pod documented
184 657 my $def = shift;
185 $_[0] = (defined $def->{type} and not defined $def->{value})
186 ? $def->{type}
187 657 ▶ : valid_type($def->{value});
Branch: 1 branch
BranchTrueFalseTotal
defined $def->{'type'} && !defined($def->{'value'}) ? : 0 657 657
Condition33%1/3
defined $def->{"type"} and not defined $def->{"value"}
!ll&&!rl&&r
65700
MC/DC0%0/2
defined $def->{"type"} and not defined $def->{"value"}
defined $def->{"type"} not defined $def->{"value"}
Truth table33%1/3
A and not(B)
A= defined $def->{"type"}B= not defined $def->{"value"}
ABresult
0X0
100
111
188 return
189 (
190 valid_name($def->{long}, $def->{short}) and defined $_[0]
191 and ( not defined $def->{type} or ($def->{type} ne $_[0]) )
192 and ( not defined $def->{regex} or ref $def->{regex} eq 'Regexp')
193 657 ▶ and ( not defined $def->{call} or ref $def->{call} eq 'CODE' )
Condition61%13/21
valid_name($def->{'long'}, $def->{'short'}) && defined $_[0] && (!defined($def->{'type'}) || $def->{'type'} ne $_[0]) && (!defined($def->{'regex'}) || ref $def->{'regex'} eq 'Regexp') && (!defined($def->{'call'}) || ref $def->{'call'} eq 'CODE')
!ll&&!rl&&r
10656
valid_name($def->{"long"}, $def->{"short"}) and defined $_[0] and !defined($def->{"type"}) || $def->{"type"} ne $_[0] and !defined($def->{"regex"}) || ref $def->{"regex"} eq "Regexp"
!ll&&!rl&&r
10656
valid_name($def->{"long"}, $def->{"short"}) and defined $_[0] and !defined($def->{"type"}) || $def->{"type"} ne $_[0]
!ll&&!rl&&r
10656
valid_name($def->{"long"}, $def->{"short"}) and defined $_[0]
!ll&&!rl&&r
10656
not defined $def->{"type"} or $def->{"type"} ne $_[0]
l!l&&r!l&&!r
65600
not defined $def->{"regex"} or ref $def->{"regex"} eq "Regexp"
l!l&&r!l&&!r
4761800
not defined $def->{"call"} or ref $def->{"call"} eq "CODE"
l!l&&r!l&&!r
562940
MC/DC12%1/8
valid_name($def->{'long'}, $def->{'short'}) && defined $_[0] && (!defined($def->{'type'}) || $def->{'type'} ne $_[0]) && (!defined($def->{'regex'}) || ref $def->{'regex'} eq 'Regexp') && (!defined($def->{'call'}) || ref $def->{'call'} eq 'CODE')
valid_name($def->{"long"}, $def->{"short"}) defined $_[0] not defined $def->{"type"} $def->{"type"} ne $_[0] not defined $def->{"regex"} ref $def->{"regex"} eq "Regexp" not defined $def->{"call"} ref $def->{"call"} eq "CODE"
Truth table29%5/17
A and B and not(C) or D and not(E) or F && not(G) or H
A= valid_name($def->{"long"}, $def->{"short"})B= defined $_[0]C= not defined $def->{"type"}D= $def->{"type"} ne $_[0]E= not defined $def->{"regex"}F= ref $def->{"regex"} eq "Regexp"G= not defined $def->{"call"}H= ref $def->{"call"} eq "CODE"
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
1100XXXX0
111X00XX0
110100XX0
111X1X000
111X01000
11011X000
110101000
111X1X1X1
111X1X011
111X011X1
111X01011
11011X1X1
11011X011
1101011X1
110101011
194 );
195 }
196  
197 sub hashdef
198 234 ▶{
Subroutine hashdef: called CC=3 SCAR=11.0
Pod documented
199 234 my %h = ( long=>shift, value=>shift, short=>shift
200 , help=>shift, arg=>shift, flags=>shift
201 , addflags=>shift, level=>shift
202 , regex=>shift, call=>shift );
203 234 ▶ $h{short} = '' unless defined $h{short};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h{"short"} 0 234 234
204 234 ▶ $h{flags} = 0 unless defined $h{flags};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h{"flags"} 178 56 234
205 234 return \%h;
206 }
207  
208 sub builtins
209 79 ▶{
Subroutine builtins: called CC=3 SCAR=12.0
Pod documented
210 79 my $config = shift;
211 79 my %bldi = (help=>1, h=>1, I=>1, config=>1);
212 79 ▶ $bldi{version} = 1 if(defined $config and defined $config->{version});
Branch: 1 branch
BranchTrueFalseTotal
if defined $config and defined $config->{"version"} 0 79 79
Condition33%1/3
defined $config and defined $config->{"version"}
!ll&&!rl&&r
0790
MC/DC0%0/2
defined $config and defined $config->{"version"}
defined $config defined $config->{"version"}
Truth table33%1/3
A and B
A= defined $configB= defined $config->{"version"}
ABresult
0X0
100
111
213 79 return \%bldi;
214 }
215  
216 # helper for below
217 sub INT_defchecker
218 259 ▶{
Subroutine INT_defchecker: called CC=10 SCAR=23.6
Pod undocumented
219 259 my $def = shift;
220 259 my $name_there = shift;
221 259 ▶ my $short = defined $def->{short} ? $def->{short} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $def->{'short'} ? : 251 8 259
222  
223 return ''
224 259 ▶ if defined $def->{section};
Branch: 1 branch
BranchTrueFalseTotal
if defined $def->{"section"} 0 259 259
225 259 ▶ return "'".(defined $def->{long} ? $def->{long} : '')."' definition is not good"
Branch: 2 branches
BranchTrueFalseTotal
unless valid_def($def) 1 258 259
defined $def->{'long'} ? : 1 0 1
226 unless valid_def($def);
227 return "'$def->{long}' ".(defined $def->{short} ? "/ $def->{short}" : '')." name already taken"
228 258 ▶ if($name_there->{$def->{long}} or $name_there->{$short});
Branch: 2 branches
BranchTrueFalseTotal
if $$name_there{$def->{"long"}} or $name_there->{$short} 1 257 258
defined $def->{'short'} ? : 1 0 1
Condition66%2/3
$$name_there{$def->{"long"}} or $name_there->{$short}
l!l&&r!l&&!r
01257
MC/DC50%1/2
$$name_there{$def->{"long"}} or $name_there->{$short}
$$name_there{$def->{"long"}} $name_there->{$short}
Truth table66%2/3
A or B
A= $$name_there{$def->{"long"}}B= $name_there->{$short}
ABresult
1X1
011
000
229 $name_there->{$def->{long}} = 1
230 257 ▶ if defined $def->{long};
Branch: 1 branch
BranchTrueFalseTotal
if defined $def->{"long"} 257 0 257
231 257 ▶ $name_there->{$short} = 1 if $short ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $short ne "" 209 48 257
232  
233 257 return ''; # no problem
234 }
235  
236 # check if whole definition array is proper,
237 # modifying the argument to sanitize to canonical form
238 # That form is an array of definition hashes.
239 sub sane_pardef
240 70 ▶{
Subroutine sane_pardef: called CC=12 SCAR=25.0
Pod documented
241 70 my $config = shift;
242 70 my $name_there = builtins($config);
243 70 my $indef = $_[0];
244 70 $_[0] = []; # If an error comes, nothing is sane.
245 70 ▶ if(@{$indef})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$indef;}) 69 1 70
246 {
247 69 ▶ if(ref $indef->[0] ne '')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $indef->[0] ne '') { } 33 36 69
248 {
249 # each element is a ref, check them all
250 33 for my $d (@{$indef})
251 {
252 86 my $t = ref $d;
253 86 ▶ return 'mix of array/hash and other stuff'
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "" 0 86 86
254 if($t eq '');
255 86 ▶ return 'strange refs, neither hash nor array'
Branch: 1 branch
BranchTrueFalseTotal
if $t ne "ARRAY" and $t ne "HASH" 0 86 86
Condition66%2/3
$t ne "ARRAY" and $t ne "HASH"
!ll&&!rl&&r
61250
MC/DC0%0/2
$t ne "ARRAY" and $t ne "HASH"
$t ne "ARRAY" $t ne "HASH"
Truth table66%2/3
A and B
A= $t ne "ARRAY"B= $t ne "HASH"
ABresult
0X0
100
111
256 if($t ne 'ARRAY' and $t ne 'HASH');
257  
258 86 ▶ my $def = $t eq 'ARRAY' ? hashdef(@{$d}) : $d;
Branch: 1 branch
BranchTrueFalseTotal
$t eq 'ARRAY' ? : 61 25 86
259 86 my $problem = INT_defchecker($def, $name_there);
260 86 $d = $def;
261 86 ▶ return $problem if $problem;
Branch: 1 branch
BranchTrueFalseTotal
if $problem 0 86 86
262 }
263 }
264 else
265 {
266 36 ▶ return 'plain member count not multiple of 4' if(@{$indef} % 4);
Branch: 1 branch
BranchTrueFalseTotal
if @{$indef;} % 4 0 36 36
267  
268 36 my @spars = ();
269 36 ▶ while(@{$indef})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$indef;}) 173 34 207
270 {
271 173 my $sdef;
272 173 my $def = hashdef(splice(@{$indef}, 0, 4));
273 173 my $problem = INT_defchecker($def, $name_there);
274 173 ▶ return $problem if $problem;
Branch: 1 branch
BranchTrueFalseTotal
if $problem 2 171 173
275 171 push(@spars, $def);
276 }
277 34 $indef = \@spars;
278 }
279 }
280 68 $_[0] = $indef; # only after full success
281 68 return '';
282 }
283  
284 sub escape_pod
285 143 ▶{
Subroutine escape_pod: called CC=4 SCAR=13.9
Pod documented
286 143 ▶ return undef unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 2 141 143
287 141 my @text = split("\n", shift, -1);
288 141 for(@text)
289 {
290 173 ▶ next if m/^\s/; # indented stuff is verbatim
Branch: 1 branch
BranchTrueFalseTotal
if /^\s/ 16 157 173
291 157 s/^=(\w)/=Z<>$1/;
292 157 s/([A-Z])</$1Z<></g;
293 }
294 141 return join("\n", @text);
295 }
296  
297 # Following: The OO API for detailed work.
298  
299 sub new # strictly (\%config, \@pardef)
300 70 ▶{
Subroutine new: called CC=17 SCAR=28.7
Pod documented
301 70 my $class = shift;
302 70 my $self = {};
303 70 bless $self, $class;
304  
305 70 $self->{config} = shift;
306 70 ▶ $self->{config} = {} unless defined $self->{config};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"config"} 1 69 70
307 70 my $pars = shift;
308 70 ▶ $pars = [] unless defined $pars;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pars 1 69 70
309 70 $self->{files} = [];
310 70 $self->{errors} = [];
311  
312 70 ▶ $self->{config}{program} = basename($0) unless defined $self->{config}{program};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"config"}{"program"} 40 30 70
313 70 ▶ $self->{config}{shortdefaults} = 1 unless exists $self->{config}{shortdefaults};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"config"}{"shortdefaults"} 40 30 70
314 70 $self->{printconfig} = 0;
315 70 my $hh = 'Show the help message. Value 1..9: help level, par:'
316 . ' help for paramter par (long name) only.';
317 70 $self->{extrahelp} = 'Additional fun with negative values, optionally'
318 . ' followed by comma-separated list of parameter names:'."\n"
319 . '-1: list par names, -2: list one line per name,'
320 . ' -3: -2 without builtins, -10: dump values (Perl style),'
321 . ' -11: dump values (lines), -100: print POD.';
322 70 my $ih = 'Which configfile(s) to use (overriding automatic search'
323 . ' in likely paths);'."\n"
324 . 'special: just -I or --config causes printing a current config'
325 . ' file to STDOUT';
326  
327 70 ▶ if($self->{config}{lazy} and $self->{config}{posixhelp})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"lazy"} and $self->{"config"}{"posixhelp"}) 0 70 70
Condition66%2/3
$self->{"config"}{"lazy"} and $self->{"config"}{"posixhelp"}
!ll&&!rl&&r
55150
MC/DC0%0/2
$self->{"config"}{"lazy"} and $self->{"config"}{"posixhelp"}
$self->{"config"}{"lazy"} $self->{"config"}{"posixhelp"}
Truth table66%2/3
A and B
A= $self->{"config"}{"lazy"}B= $self->{"config"}{"posixhelp"}
ABresult
0X0
100
111
328 {
329 0 $self->INT_error("POSIX-style help texts and lazy parameter syntax are incompatible.");
330 0 $self->{config}{posixhelp} = 0;
331 }
332 # Put -- in front of long names in communication, in POSIX mode.
333 70 ▶ $self->{longprefix} = $self->{config}{posixhelp} ? '--' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'config'}{'posixhelp'} ? : 0 70 70
334 # Same for - and short names.
335 70 ▶ $self->{shortprefix} = $self->{config}{posixhelp} ? '-' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'config'}{'posixhelp'} ? : 0 70 70
336 # An array of sections, with {name=>foo, member=>[$long1, $long2, ...]}.
337 # If I opted for
338 70 $self->{section} = [];
339 # Start the default, nameless section. Maybe a name should be generated if there
340 # are other sections.
341 $self->define({ section=>'', level=>1, flags=>$self->{config}{flags}
342 70 , regex=>$self->{config}{regex}, call=>$self->{config}{call} });
343  
344 # Choosing kindof distributed storage of parmeter properties, for direct
345 # access. With more and more properties, the count of global hashes
346 # increases uncomfortably.
347 70 $self->{param} = {}; # parameter values
348 70 $self->{help} = {}; # help texts
349 70 $self->{long} = {}; # map short to long names
350 70 $self->{short} = {}; # map long to short names
351 70 $self->{arg} = {}; # argument name
352 70 $self->{type} = {}; # type code
353 # store default values, for even more detailed documentation
354 70 $self->{default} = {}; # default value
355 70 $self->{level} = {}; # parameter level for help output
356 70 $self->{length} = 0; # max length of long names
357 70 $self->{arglength} = 0; # max length of name=arg or name[=arg]
358 # Chain of config files being parsed, to be able to check for inclusion loops.
359 70 $self->{parse_chain} = [];
360 # TODO set from config hash
361 70 ▶ $self->define({ long=>'help', short=>$self->{config}{shortdefaults} ? 'h' : '', value=>0
Branch: 1 branch
BranchTrueFalseTotal
$self->{'config'}{'shortdefaults'} ? : 69 1 70
362 , help=>\$hh, flags=>0, regex=>qr/./ });
363 $self->define(
364 {
365 long=>'config', short=>$self->{config}{shortdefaults} ? 'I' : '', value=>[]
366 , help=>\$ih, flags=>0, regex=>qr/./
367 , call=> sub
368 1 ▶ { # --config increments printconfig and does not add a config file.
Subroutine __ANON__: called CC=2 SCAR=7.0
369 1 ▶ unless(defined $_[2])
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[2]) 1 0 1
370 {
371 1 $self->{printconfig} += 1;
372 1 undef $_[0]; # Skip this operation.
373 }
374 1 return 0;
375 }
376 70 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
$self->{'config'}{'shortdefaults'} ? : 69 1 70
377 $self->define({ long=>'version', value=>0, short=>''
378 , help=>\'print out the program version', arg=>''
379 , flags=>0, regex=>qr/./ })
380 70 ▶ if(defined $self->{config}{version});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{"version"} 0 70 70
381  
382 # deprecated v2 API
383 $self->INT_error("Update your program: ignorehelp is gone in favour of nofinals!")
384 70 ▶ if exists $self->{config}{ignorehelp};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"config"}{"ignorehelp"} 0 70 70
385 $self->INT_error("Update your program: eval option not supported anymore.")
386 70 ▶ if exists $self->{config}{eval};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"config"}{"eval"} 0 70 70
387  
388 70 my $problem = sane_pardef($self->{config}, $pars);
389 70 ▶ if($problem)
Branch: 1 branch
BranchTrueFalseTotal
if ($problem) { } 2 68 70
390 {
391 2 $self->INT_error("bad parameter specification: $problem");
392 } else
393 {
394 68 my $di = 0;
395 68 for my $def (@{$pars})
396 {
397 252 ++$di;
398 # definition failure here is an error in the module
399 252 ▶ $self->INT_error("Very unexpected failure to evaluate parameter definition $di.")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->define($def) 0 252 252
400 unless($self->define($def));
401 }
402 68 $self->find_config_files();
403 }
404 70 return $self;
405 }
406  
407 sub good
408 67 ▶{
Subroutine good: called CC=1 SCAR=0.0
Pod documented
409 67 my $self = shift;
410 67 return @{$self->{errors}} == 0;
411 }
412  
413 # name[=arg] and variants
414 sub INT_namearg
415 398 ▶{
Subroutine INT_namearg: called CC=4 SCAR=13.9
Pod undocumented
416 398 my $self = shift;
417 398 my $name = shift;
418 398 my $flags = $self->{flags}{$name};
419 398 my $val= $self->{arg}{$name};
420 398 ▶ $val = 'val' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 342 56 398
421 398 ▶ return $flags & $arg
Branch: 2 branches
BranchTrueFalseTotal
$flags & $arg ? : 56 342 398
$val eq '' ? : 0 342 342
422 ? $name.'='.$val # mandatory argument
423 : ( $val eq ''
424 ? $name # silent optional argument
425 : $name.'[='.$val.']' ) # named optional argument
426 }
427  
428 sub define
429 468 ▶{
Subroutine define: called CC=28 SCAR=35.2
Pod documented
430 468 my $self = shift;
431 468 my $pd = shift;
432  
433 my $helpref = defined $pd->{help}
434 ? ( ref $pd->{help} ? $pd->{help} : \$pd->{help} )
435 468 ▶ : \"";
Branch: 2 branches
BranchTrueFalseTotal
defined $pd->{'help'} ? : 397 71 468
ref $pd->{'help'} ? : 140 257 397
436 # The section keyword defines a section instead of a parameter.
437 468 ▶ if(exists $pd->{section})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pd->{"section"}) 70 398 468
438 {
439 # Silence runs with perl -W. Actually, I'm annoyed that 0+undef isn't
440 # doing this already. Still doing 0+ to catch idle strings, which are
441 # evildoing by the user program.
442 70 ▶ my $flags = defined $pd->{flags} ? 0+$pd->{flags} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $pd->{'flags'} ? : 0 70 70
443 70 ▶ my $level = defined $pd->{level} ? 0+$pd->{level} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $pd->{'level'} ? : 70 0 70
444 # The first section is the default one, any further sections mean
445 # that you care about parameter order.
446 $self->{config}{ordered} = 1
447 70 ▶ if @{$self->{section}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"section"};} 0 70 70
448 70 push(@{$self->{section}}, { section=>$pd->{section}
449 , help=>$helpref, level=>$level
450 , minlevel=>10 # will be lowered when parameters are added to it
451 70 , flags=>$flags, regex=>$pd->{regex}, call=>$pd->{call} });
452 70 return 1;
453 }
454  
455 398 ▶ unless(@{$self->{section}})
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{"section"};}) 0 398 398
456 {
457 0 $self->INT_error("Define the default section first!");
458 0 return 1;
459 }
460  
461 398 my $section = $self->{section}[$#{$self->{section}}];
462 398 my $name = $pd->{long};
463  
464 398 ▶ $pd->{help} = \'' unless defined $pd->{help};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pd->{"help"} 1 397 398
465 398 ▶ $pd->{short} = '' unless defined $pd->{short};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pd->{"short"} 8 390 398
466 398 my $type; # valid_def sets that
467 398 ▶ unless(valid_def($pd, $type))
Branch: 1 branch
BranchTrueFalseTotal
unless (valid_def($pd, $type)) 0 398 398
468 {
469 0 $self->INT_error("Invalid definition for $name / $pd->{short}");
470 0 return 0;
471 }
472 my $flags = defined $pd->{flags}
473 ? $pd->{flags}
474 398 ▶ : $section->{flags};
Branch: 1 branch
BranchTrueFalseTotal
defined $pd->{'flags'} ? : 387 11 398
475 $flags |= $pd->{addflags}
476 398 ▶ if defined $pd->{addflags};
Branch: 1 branch
BranchTrueFalseTotal
if defined $pd->{"addflags"} 0 398 398
477 my $regex = defined $pd->{regex}
478 ? $pd->{regex}
479 398 ▶ : $section->{regex};
Branch: 1 branch
BranchTrueFalseTotal
defined $pd->{'regex'} ? : 160 238 398
480 my $call = defined $pd->{call}
481 ? $pd->{call}
482 398 ▶ : $section->{call};
Branch: 1 branch
BranchTrueFalseTotal
defined $pd->{'call'} ? : 82 316 398
483 398 ▶ if($flags & $switch and $flags & $arg)
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & $switch and $flags & $arg) 0 398 398
Condition33%1/3
$flags & $switch and $flags & $arg
!ll&&!rl&&r
39800
MC/DC0%0/2
$flags & $switch and $flags & $arg
$flags & $switch $flags & $arg
Truth table33%1/3
A and B
A= $flags & $switchB= $flags & $arg
ABresult
0X0
100
111
484 {
485 0 $self->INT_error("Invalid flags (switch requiring argument) for $name / $pd->{short}");
486 0 return 0;
487 }
488 398 ▶ unless(defined $self->{param}{$name} or defined $self->{long}{$pd->{short}})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'param'}{$name} or defined $self->{'long'}{$pd->{'short'}}) { } 0 398 398
Condition33%1/3
defined $self->{"param"}{$name} or defined $self->{"long"}{$pd->{"short"}}
l!l&&r!l&&!r
00398
MC/DC0%0/2
defined $self->{"param"}{$name} or defined $self->{"long"}{$pd->{"short"}}
defined $self->{"param"}{$name} defined $self->{"long"}{$pd->{"short"}}
Truth table33%1/3
A or B
A= defined $self->{"param"}{$name}B= defined $self->{"long"}{$pd->{"short"}}
ABresult
1X1
011
000
489 {
490 398 $self->{type}{$name} = $type;
491 # If the definition value is a reference, make a deep copy of it
492 # instead of copying the reference. This keeps the definition
493 # and default value unchanged, for reproducible multiple runs of
494 # the parser.
495 398 ▶ if(ref $pd->{value})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pd->{'value'}) { } 212 186 398
496 {
497 212 require Storable; # Only require it if there is really the need.
498 212 $self->{param}{$name} = Storable::dclone($pd->{value});
499 212 $self->{default}{$name} = Storable::dclone($pd->{value});
500 }
501 else
502 {
503 186 $self->{param}{$name} = $pd->{value};
504 186 $self->{default}{$name} = $pd->{value};
505 }
506 $self->{long}{$pd->{short}} = $name
507 398 ▶ if $pd->{short} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $pd->{"short"} ne "" 346 52 398
508 398 $self->{short}{$name} = $pd->{short};
509 398 $self->{help}{$name} = $helpref;
510 398 $self->{arg}{$name} = $pd->{arg};
511 my $lev = $self->{level}{$name} = 0+( defined $pd->{level}
512 ? $pd->{level}
513 398 ▶ : $section->{level} );
Branch: 1 branch
BranchTrueFalseTotal
defined $pd->{'level'} ? : 0 398 398
514 # Store the minimum level needed to display at least one section member.
515 $section->{minlevel} = $lev
516 398 ▶ if $lev < $section->{minlevel};
Branch: 1 branch
BranchTrueFalseTotal
if $lev < $section->{"minlevel"} 70 328 398
517 398 $self->{flags}{$name} = $flags;
518 $self->{arg}{$name} = ''
519 398 ▶ if $self->{flags}{$name} & $switch;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"flags"}{$name} & $switch 0 398 398
520 398 push(@{$section->{member}}, $name);
521 398 $self->INT_verb_msg("define $name / $pd->{short} of type $typename[$type] flags $self->{flags}{$name}\n");
522 # Call INT_namearg after settling flags!
523 $self->{length} = length($name)
524 398 ▶ if length($name) > $self->{length};
Branch: 1 branch
BranchTrueFalseTotal
if length $name > $self->{"length"} 144 254 398
525 398 my $arglen = length($self->INT_namearg($name));
526 $self->{arglength} = $arglen
527 398 ▶ if $arglen > $self->{arglength};
Branch: 1 branch
BranchTrueFalseTotal
if $arglen > $self->{"arglength"} 144 254 398
528 398 ▶ $self->{regex}{$name} = $regex
Branch: 1 branch
BranchTrueFalseTotal
if defined $regex 160 238 398
529 if defined $regex;
530 398 ▶ $self->{call}{$name} = $call
Branch: 1 branch
BranchTrueFalseTotal
if defined $call 82 316 398
531 if defined $call;
532 }
533 else
534 {
535 0 $self->INT_error("Tried to redefine an option ($pd->{long} / $pd->{short}! Programmer: please check this!");
536 0 return 0;
537 }
538 398 return 1;
539 }
540  
541 sub find_config_files
542 68 ▶{
Subroutine find_config_files: called CC=9 SCAR=23.5
Pod documented
543 68 my $self = shift;
544  
545 68 ▶ if(defined $self->{config}{file})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"file"}) 0 68 68
546 {
547 0 @{$self->{param}{config}} = ref $self->{config}{file} eq 'ARRAY'
548 0 ? @{$self->{config}{file}}
549 0 ▶ : ($self->{config}{file});
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'config'}{'file'} eq 'ARRAY' ? : 0 0 0
550 }
551 #means: nofile[false,true], file[string], info, verbose[bool],
552 #config confusion
553 # as long as I was told not to use a config file or it has been already given
554 68 ▶ unless($self->{config}{nofile} or @{$self->{param}{config}})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}{"nofile"} or @{$self->{"param"}{"config"};}) 42 26 68
Condition66%2/3
$self->{"config"}{"nofile"} or @{$self->{"param"}{"config"};}
l!l&&r!l&&!r
26042
MC/DC50%1/2
$self->{"config"}{"nofile"} or @{$self->{"param"}{"config"};}
$self->{"config"}{"nofile"} @{$self->{"param"}{"config"};}
Truth table66%2/3
A or B
A= $self->{"config"}{"nofile"}B= @{$self->{"param"}{"config"};}
ABresult
1X1
011
000
555 {
556 # Default to reading program.conf and/or program.host.conf if found.
557 42 my $pconf = $self->INT_find_config($self->{config}{program}.'.conf');
558 42 my $hconf = $self->INT_find_config($self->{config}{program}.'.'.hostname().'.conf');
559 42 my @l;
560 42 ▶ push(@l, $pconf) if defined $pconf;
Branch: 1 branch
BranchTrueFalseTotal
if defined $pconf 11 31 42
561 42 ▶ push(@l, $hconf) if defined $hconf;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hconf 0 42 42
562 # That list can be empty if none existing.
563 42 $self->INT_verb_msg("possible config files: @l\n");
564 # The last entry in the list has precedence.
565 42 ▶ unless($self->{config}{multi})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}{"multi"}) 42 0 42
566 {
567 42 ▶ @l = ($l[$#l]) if @l; # Only the last element, if any, prevails.
Branch: 1 branch
BranchTrueFalseTotal
if @l 11 31 42
568 }
569 42 @{$self->{param}{config}} = @l;
570 }
571 }
572  
573 # Parse abcd to the list of corresponding long names.
574 sub INT_long_names
575 65 ▶{
Subroutine INT_long_names: called CC=6 SCAR=27.7
Pod undocumented
576 65 my $self = shift;
577 65 my $sname = shift;
578 65 my @names;
579 65 for my $s (split(//,$sname))
580 {
581 69 ▶ if(defined (my $name = $self->{long}{$s}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = $self->{'long'}{$s})) { } 69 0 69
582 {
583 69 push(@names, $name);
584 }
585 else
586 {
587 0 ▶ if($self->{config}{fuzzy})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'config'}{'fuzzy'}) { } 0 0 0
588 {
589 0 $self->INT_verb_msg("Unknown short option $s, assuming that this is data instead.\n");
590 0 @names = ();
591 0 last;
592 }
593 else
594 {
595 0 ▶ unless($self->{config}{ignore_unknown} and $self->{config}{ignore_unknown} > 1)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}{"ignore_unknown"} and $self->{"config"}{"ignore_unknown"} > 1) 0 0 0
Condition0%0/3
$self->{"config"}{"ignore_unknown"} and $self->{"config"}{"ignore_unknown"} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"config"}{"ignore_unknown"} and $self->{"config"}{"ignore_unknown"} > 1
$self->{"config"}{"ignore_unknown"} $self->{"config"}{"ignore_unknown"} > 1
Truth table0%0/3
A and B
A= $self->{"config"}{"ignore_unknown"}B= $self->{"config"}{"ignore_unknown"} > 1
ABresult
0X0
100
111
596 {
597 #$self->{param}{help} = 1;
598 0 $self->INT_error("unknown short parameter \"$s\" not in (".join('', sort keys %{$self->{long}}).")");
599 }
600 }
601 }
602 }
603 65 return \@names;
604 }
605  
606 # Works directly on last arguments to avoid passing things back and forth.
607 sub INT_settle_op # (lastoption, sign, name, op, val, args)
608 206 ▶{
Subroutine INT_settle_op: called CC=31 SCAR=36.5
Pod undocumented
609 206 my $self = shift;
610 206 my $lastoption = shift;
611 206 my $sign = shift;
612 206 my $name = shift;
613 # op:$_[0] val:$_[1] args:$_[2]
614 206 my $flags = $self->{flags}{$name};
615 my $arrhash = defined $self->{type}{$name}
616 206 ▶ and grep {$_==$self->{type}{$name}} ($array, $hash);
Branch: 1 branch
BranchTrueFalseTotal
my $arrhash = defined $self->{"type"}{$name} and grep {$_ == $self->{"type"}{$name};} $array, $hash 205 1 206
617  
618 # First settle a possibly enforced argument that has to follow.
619 # Then call the custom callback that could change things
620  
621 206 ▶ if(defined $_[0] and $arrhash)
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_[0] and $arrhash) { } 158 48 206
elsif (not defined $_[0] and $flags & $arg) { } 16 33 49
Condition100%3/3
defined $_[0] and $arrhash
!ll&&!rl&&r
471158
MC/DC100%2/2
defined $_[0] and $arrhash
defined $_[0] $arrhash
Truth table100%3/3
A and B
A= defined $_[0]B= $arrhash
ABresult
0X0
100
111
622 {
623 # -a/,/=bla and -a/,/bla are equivalent, as is -a/,/ bla
624 158 ▶ if($_[0] eq '/' and $_[1] =~ m:(./)(=?)(.*):)
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] eq "/" and $_[1] =~ m[(./)(=?)(.*)]) 16 142 158
Condition100%3/3
$_[0] eq "/" and $_[1] =~ m[(./)(=?)(.*)]
!ll&&!rl&&r
139316
MC/DC100%2/2
$_[0] eq "/" and $_[1] =~ m[(./)(=?)(.*)]
$_[0] eq "/" $_[1] =~ m[(./)(=?)(.*)]
Truth table100%3/3
A and B
A= $_[0] eq "/"B= $_[1] =~ m[(./)(=?)(.*)]
ABresult
0X0
100
111
625 {
626 16 $_[0] .= $1.$2;
627 16 ▶ $_[1] = ($3 eq '' and $2 eq '') ? undef : $3;
Branch: 1 branch
BranchTrueFalseTotal
$3 eq '' && $2 eq '' ? : 4 12 16
Condition66%2/3
$3 eq "" and $2 eq ""
!ll&&!rl&&r
1204
MC/DC50%1/2
$3 eq "" and $2 eq ""
$3 eq "" $2 eq ""
Truth table66%2/3
A and B
A= $3 eq ""B= $2 eq ""
ABresult
0X0
100
111
628 16 ▶ $_[0] .= '='
Branch: 1 branch
BranchTrueFalseTotal
if $2 eq "" and defined $_[1] 4 12 16
Condition100%3/3
$2 eq "" and defined $_[1]
!ll&&!rl&&r
844
MC/DC100%2/2
$2 eq "" and defined $_[1]
$2 eq "" defined $_[1]
Truth table100%3/3
A and B
A= $2 eq ""B= defined $_[1]
ABresult
0X0
100
111
629 if($2 eq '' and defined $_[1]);
630 }
631 158 ▶ if($_[0] =~ m:^/./$: and $flags & $arg)
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ m[^/./$] and $flags & $arg) 8 150 158
Condition66%2/3
$_[0] =~ m[^/./$] and $flags & $arg
!ll&&!rl&&r
15008
MC/DC50%1/2
$_[0] =~ m[^/./$] and $flags & $arg
$_[0] =~ m[^/./$] $flags & $arg
Truth table66%2/3
A and B
A= $_[0] =~ m[^/./$]B= $flags & $arg
ABresult
0X0
100
111
632 {
633 8 ▶ unless(@{$_[2]})
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$_[2];}) 0 8 8
634 {
635 $self->INT_error( "Array/hash missing explicit argument: $self->{longprefix}$name"
636 0 ▶ . ($self->{short}{$name} ne '' ? " ($self->{shortprefix}$self->{short}{$name})" : '') );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'short'}{$name} ne '' ? : 0 0 0
637 0 return;
638 }
639 8 $_[0] .= '=';
640 8 $_[1] = shift @{$_[2]};
641 }
642 ▶ } elsif(not defined $_[0] and $flags & $arg)
Condition100%3/3
not defined $_[0] and $flags & $arg
!ll&&!rl&&r
13116
MC/DC100%2/2
not defined $_[0] and $flags & $arg
not defined $_[0] $flags & $arg
Truth table100%3/3
not(A) and B
A= not defined $_[0]B= $flags & $arg
ABresult
0X0
100
111
643 {
644 16 ▶ unless($lastoption and @{$_[2]})
Branch: 1 branch
BranchTrueFalseTotal
unless ($lastoption and @{$_[2];}) 0 16 16
Condition33%1/3
$lastoption and @{$_[2];}
!ll&&!rl&&r
0016
MC/DC0%0/2
$lastoption and @{$_[2];}
$lastoption @{$_[2];}
Truth table33%1/3
A and B
A= $lastoptionB= @{$_[2];}
ABresult
0X0
100
111
645 {
646 $self->INT_error( "Parameter missing explicit argument: $self->{longprefix}$name"
647 0 ▶ . ($self->{short}{$name} ne '' ? " ($self->{shortprefix}$self->{short}{$name})" : '') );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'short'}{$name} ne '' ? : 0 0 0
648 0 return;
649 }
650 16 $_[0] = '=';
651 16 $_[1] = shift @{$_[2]};
652 }
653  
654 # Defined empty value with undefined operator is just confusing to the callback.
655 206 ▶ undef $_[1]
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 31 175 206
656 unless defined $_[0];
657  
658 # The callback that could modify things.
659  
660 206 ▶ if(defined $self->{call}{$name})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"call"}{$name}) 6 200 206
661 {
662 6 my $nname = $name;
663 6 my $ret = $self->{call}{$name}->($nname, $sign, $_[0], $_[1]);
664 6 ▶ if($ret or (not defined $nname or $nname ne $name))
Branch: 1 branch
BranchTrueFalseTotal
if ($ret or (not defined $nname or $nname ne $name)) 1 5 6
Condition66%4/6
$ret or (not defined $nname or $nname ne $name)
l!l&&r!l&&!r
015
not defined $nname or $nname ne $name
l!l&&r!l&&!r
105
MC/DC33%1/3
$ret or (not defined $nname or $nname ne $name)
$ret not defined $nname $nname ne $name
Truth table50%2/4
A or not(B) or C
A= $retB= not defined $nnameC= $nname ne $name
ABCresult
1XX1
01X1
0011
0000
665 {
666 1 ▶ $self->INT_error("Callback for $name returned an error: $ret")
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 1 1
667 if $ret; # otherwise intentional drop
668 1 undef $_[0];
669 1 return;
670 }
671 }
672  
673 # Final translation of operator.
674  
675 205 ▶ unless(defined $_[0])
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0]) 30 175 205
676 {
677 30 ▶ if($flags & $count)
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & $count) { } 0 30 30
678 {
679 0 ▶ ($_[0], $_[1]) = $sign =~ /^-/ ? ('+=', 1) : ('=', 0);
Branch: 1 branch
BranchTrueFalseTotal
$sign =~ /^-/ ? : 0 0 0
680 }
681 else
682 {
683 30 $_[0] = '=';
684 30 ▶ $_[1] = $sign =~ /^-/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$sign =~ /^-/ ? : 30 0 30
685 }
686 }
687 205 ▶ if($arrhash)
Branch: 1 branch
BranchTrueFalseTotal
if ($arrhash) 204 1 205
688 {
689 $_[0] =~ s:(^|[^\.])=$:$1.=:
690 204 ▶ if $self->{flags}{$name} & $append;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"flags"}{$name} & $append 61 143 204
691 }
692 }
693  
694 # Record a operator and operand for given parameter.
695 # It is not checked if the operation makes sense.
696 sub INT_add_op
697 206 ▶{
Subroutine INT_add_op: called CC=4 SCAR=13.9
Pod undocumented
698 206 my $self = shift;
699 206 my ($name, $op, $val) = (shift, shift, shift);
700 $self->{ops}{$name} = []
701 206 ▶ unless defined $self->{ops}{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ops"}{$name} 149 57 206
702 return # undefined ops are intentionally dropped
703 206 ▶ unless defined $op;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $op 1 205 206
704 205 $self->INT_verb_msg("name: $name op: $op (val: $val)\n");
705 205 ▶ push(@{$self->{ops}{$name}}, ($op =~ /=$/ ? $op : $op.'='), $val);
Branch: 1 branch
BranchTrueFalseTotal
$op =~ /=$/ ? : 199 6 205
706 }
707  
708 # Step 1: parse command line
709 sub parse_args
710 66 ▶{
Subroutine parse_args: called CC=34 SCAR=36.5
Pod documented
711 66 my $self = shift;
712 66 my $args = shift;
713  
714 66 my $olderrs = @{$self->{errors}};
715 66 $self->{ops} = {};
716 66 $self->{printconfig} = 0;
717  
718 0 ▶ $self->{param}{help} = 1 if($self->{config}{gimme} and not @{$args}); #giving help when no arguments
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"config"}{"gimme"} and not @{$args;} 0 66 66
Condition33%1/3
$self->{"config"}{"gimme"} and not @{$args;}
!ll&&!rl&&r
6600
MC/DC0%0/2
$self->{"config"}{"gimme"} and not @{$args;}
$self->{"config"}{"gimme"} not @{$args;}
Truth table33%1/3
A and not(B)
A= $self->{"config"}{"gimme"}B= not @{$args;}
ABresult
0X0
100
111
719  
720 #regexes for option parsing
721 66 my $shorts = $shortex_strict;
722 66 my $longex = $longex_strict;
723 66 my $separator = '^--$'; #exactly this string means "Stop the parsing!"
724  
725 66 ▶ if($self->{config}{lazy})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"lazy"}) 15 51 66
726 {
727 15 $shorts = $shortex_lazy;
728 15 $longex = $longex_lazy;
729 15 $separator = '^-+$'; # Lazy about separators, too ... Any number of consecutive "-".
730 }
731  
732 # The argument parser, long/short parameter evaluation is similar, but separate.
733 66 ▶ while(@{$args})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$args;}) 208 65 273
734 {
735 208 $self->INT_verb_msg("parsing $args->[0]\n");
736 208 my $e = index($args->[0], "\n");
737 208 my $begin;
738 208 my $end = "";
739 208 my $name;
740 208 ▶ if($e >=0)
Branch: 1 branch
BranchTrueFalseTotal
if ($e >= 0) { } 0 208 208
741 {
742 0 $begin = substr($args->[0],0,$e);
743 0 $end = substr($args->[0],$e);
744 }
745 else
746 {
747 208 $begin = $args->[0];
748 }
749 208 ▶ if($begin =~ /$separator/o)
Branch: 4 branches
BranchTrueFalseTotal
if ($begin =~ /$separator/o) { } 0 208 208
elsif ($begin =~ /$shortarg/ and defined($name = $self->{'long'}{$1}) and $self->{'flags'}{$name} & $arg) { } 46 162 208
elsif ($begin =~ /$shorts/o) { } 65 97 162
elsif ($begin =~ /$longex/) { } 96 1 97
750 {
751 0 $self->INT_verb_msg("separator\n");
752 0 shift(@{$args});
753 0 last;
754 }
755 ▶ elsif( $begin =~ $shortarg
Condition83%5/6
$begin =~ /$shortarg/ and defined($name = $self->{"long"}{$1}) and $self->{"flags"}{$name} & $arg
!ll&&!rl&&r
1342846
$begin =~ /$shortarg/ and defined($name = $self->{"long"}{$1})
!ll&&!rl&&r
134074
MC/DC66%2/3
$begin =~ /$shortarg/ and defined($name = $self->{"long"}{$1}) and $self->{"flags"}{$name} & $arg
$begin =~ /$shortarg/ defined($name = $self->{"long"}{$1}) $self->{"flags"}{$name} & $arg
Truth table75%3/4
A and B and C
A= $begin =~ /$shortarg/B= defined($name = $self->{"long"}{$1})C= $self->{"flags"}{$name} & $arg
ABCresult
0XX0
10X0
1100
1111
756 and defined ($name = $self->{long}{$1})
757 and $self->{flags}{$name} & $arg )
758 {
759 46 $self->INT_verb_msg("short with value\n");
760 46 ▶ my $op = $2 ne '' ? $2 : '=';
Branch: 1 branch
BranchTrueFalseTotal
$2 ne '' ? : 38 8 46
761 46 my $val = $3.$end;
762 46 shift @{$args};
763 46 $self->INT_settle_op(1, '-', $name, $op, $val, $args);
764 46 $self->INT_add_op($name, $op, $val);
765 }
766 elsif($begin =~ /$shorts/o)
767 {
768 65 my $sign = $2;
769 65 ▶ $sign = '-' if $sign eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "" 7 58 65
770 65 my $op = $5;
771 65 ▶ my $sname = defined $op ? $4 : $3;
Branch: 1 branch
BranchTrueFalseTotal
defined $op ? : 30 35 65
772 65 ▶ my $val = (defined $6 ? $6 : '').$end;
Branch: 1 branch
BranchTrueFalseTotal
defined $6 ? : 30 35 65
773 65 $self->INT_verb_msg("a (set of) short one(s)\n");
774 # First settle which parameters are mentioned.
775 # This returns an empty list if one invalid option is present.
776 # Also, the case of a single argument-requiring short option leading
777 # a value is handled by redefining the value and operator
778 65 my $names = $self->INT_long_names($sname, $op, $val);
779 65 ▶ last unless @{$names};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$names;} 0 65 65
780 65 shift @{$args}; # It is settled now that this is options.
781  
782 65 ▶ while(@{$names})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$names;}) 69 65 134
783 {
784 69 my $olderr = @{$self->{errors}};
785 69 my $name = shift @{$names};
786 69 my $lastoption = not @{$names};
787 # Only the last one gets the specified operation.
788 69 ▶ my $kop = $lastoption ? $op : undef;
Branch: 1 branch
BranchTrueFalseTotal
$lastoption ? : 65 4 69
789 69 ▶ my $kval = $lastoption ? $val : undef;
Branch: 1 branch
BranchTrueFalseTotal
$lastoption ? : 65 4 69
790 69 $self->INT_settle_op($lastoption, $sign, $name, $kop, $kval, $args);
791 $self->INT_add_op($name, $kop, $kval)
792 69 ▶ if(@{$self->{errors}} == $olderr);
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"errors"};} == $olderr 69 0 69
793 }
794 }
795 elsif($begin =~ $longex)
796 {
797 #yeah, long option
798 96 my $olderr = @{$self->{errors}};
799 96 ▶ my $sign = defined $7 ? $7 : $2;
Branch: 1 branch
BranchTrueFalseTotal
defined $7 ? : 0 96 96
800 96 ▶ $sign = '--' if $sign eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "" 2 94 96
801 96 ▶ my $name = defined $8 ? $8 : $3;
Branch: 1 branch
BranchTrueFalseTotal
defined $8 ? : 0 96 96
802 96 $self->INT_verb_msg("param $name\n");
803 96 my $op = $5;
804 96 ▶ my $val = (defined $6 ? $6 : '').$end;
Branch: 1 branch
BranchTrueFalseTotal
defined $6 ? : 86 10 96
805 96 ▶ unless(exists $self->{param}{$name} or $self->{config}{accept_unknown})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"param"}{$name} or $self->{"config"}{"accept_unknown"}) 6 90 96
Condition66%2/3
exists $self->{"param"}{$name} or $self->{"config"}{"accept_unknown"}
l!l&&r!l&&!r
9006
MC/DC50%1/2
exists $self->{"param"}{$name} or $self->{"config"}{"accept_unknown"}
exists $self->{"param"}{$name} $self->{"config"}{"accept_unknown"}
Truth table66%2/3
A or B
A= exists $self->{"param"}{$name}B= $self->{"config"}{"accept_unknown"}
ABresult
1X1
011
000
806 {
807 6 ▶ if($self->{config}{fuzzy})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'config'}{'fuzzy'}) { } 0 6 6
808 {
809 0 $self->INT_verb_msg("Stopping option parsing at unkown one: $name");
810 0 last;
811 }
812 else
813 {
814 6 ▶ unless($self->{config}{ignore_unknown} and $self->{config}{ignore_unknown} > 1)
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}{"ignore_unknown"} and $self->{"config"}{"ignore_unknown"} > 1) 5 1 6
Condition100%3/3
$self->{"config"}{"ignore_unknown"} and $self->{"config"}{"ignore_unknown"} > 1
!ll&&!rl&&r
411
MC/DC100%2/2
$self->{"config"}{"ignore_unknown"} and $self->{"config"}{"ignore_unknown"} > 1
$self->{"config"}{"ignore_unknown"} $self->{"config"}{"ignore_unknown"} > 1
Truth table100%3/3
A and B
A= $self->{"config"}{"ignore_unknown"}B= $self->{"config"}{"ignore_unknown"} > 1
ABresult
0X0
100
111
815 {
816 5 $self->INT_error("Unknown parameter (long option): $name");
817 }
818 }
819 }
820 96 shift @{$args};
821 # hack for operators, regex may swallow the . in .=
822 96 ▶ unless($name =~ /$noop$/o)
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ /$noop$/o) 0 96 96
823 {
824 0 $op = substr($name,-1,1).$op;
825 0 $name = substr($name,0,length($name)-1);
826 }
827 # On any error, keep parsing for giving the user a full list of errors,
828 # but do not process anything erroneous.
829 $self->INT_settle_op(1, $sign, $name, $op, $val, $args)
830 96 ▶ if(@{$self->{errors}} == $olderr);
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"errors"};} == $olderr 91 5 96
831 $self->INT_add_op($name, $op, $val)
832 96 ▶ if(@{$self->{errors}} == $olderr);
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"errors"};} == $olderr 91 5 96
833 }
834 else
835 {
836 1 $self->INT_verb_msg("No parameter, end.\n");
837 1 last;
838 } #was no option... consider the switch part over
839 }
840 66 $self->{bad_command_line} = not (@{$self->{errors}} == $olderrs)
841 66 ▶ unless $self->{bad_command_line};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"bad_command_line"} 66 0 66
842 66 return not $self->{bad_command_line};
843 }
844  
845 # Step 2: Read in configuration files.
846 sub use_config_files
847 63 ▶{
Subroutine use_config_files: called CC=2 SCAR=7.2
Pod documented
848 63 my $self = shift;
849 63 my $olderr = @{$self->{errors}};
850 # Do operations on config file parameter first.
851 63 $self->INT_apply_ops('config');
852 63 my $newerr = @{$self->{errors}};
853 63 ▶ if($olderr != $newerr)
Branch: 1 branch
BranchTrueFalseTotal
if ($olderr != $newerr) 0 63 63
854 {
855 0 $self->{bad_command_line} = 1;
856 0 return 0;
857 }
858 # Now parse config file(s).
859 63 return $self->INT_parse_files();
860 }
861  
862 # Step 3: Apply command line parameters.
863 # This is complicated by accept_unknown > 2.
864 # I need to wait until config files had the chance to define something properly.
865 sub apply_args
866 62 ▶{
Subroutine apply_args: called CC=8 SCAR=22.7
Pod documented
867 62 my $self = shift;
868 62 my $olderrs = @{$self->{errors}};
869 62 for my $key (keys %{$self->{ops}})
870 {
871 144 ▶ if( not exists $self->{param}{$key}
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{"param"}{$key} and defined $self->{"config"}{"accept_unknown"} and $self->{"config"}{"accept_unknown"} > 1) 0 144 144
Condition50%3/6
not exists $self->{"param"}{$key} and defined $self->{"config"}{"accept_unknown"} and $self->{"config"}{"accept_unknown"} > 1
!ll&&!rl&&r
14400
not exists $self->{"param"}{$key} and defined $self->{"config"}{"accept_unknown"}
!ll&&!rl&&r
14310
MC/DC0%0/3
not exists $self->{"param"}{$key} and defined $self->{"config"}{"accept_unknown"} and $self->{"config"}{"accept_unknown"} > 1
not exists $self->{"param"}{$key} defined $self->{"config"}{"accept_unknown"} $self->{"config"}{"accept_unknown"} > 1
Truth table50%2/4
not(A) and B and C
A= not exists $self->{"param"}{$key}B= defined $self->{"config"}{"accept_unknown"}C= $self->{"config"}{"accept_unknown"} > 1
ABCresult
0XX0
10X0
1100
1111
872 and defined $self->{config}{accept_unknown}
873 and $self->{config}{accept_unknown} > 1 )
874 {
875 0 $self->define({long=>$key});
876 }
877 144 ▶ if(exists $self->{param}{$key})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'param'}{$key}) { } 143 1 144
elsif (not $self->{'config'}{'ignore_unknown'}) { } 0 1 1
878 {
879 143 $self->INT_apply_ops($key);
880 }
881 elsif(not $self->{config}{ignore_unknown})
882 {
883 0 $self->INT_error("Unknown long parameter \"$self->{longprefix}$key\"");
884 }
885 }
886 62 $self->{bad_command_line} = not (@{$self->{errors}} == $olderrs)
887 62 ▶ unless $self->{bad_command_line};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"bad_command_line"} 62 0 62
888 62 return not $self->{bad_command_line};
889 }
890  
891 # Step 4: Take final action.
892 sub final_action
893 67 ▶{
Subroutine final_action: called CC=16 SCAR=37.5
Pod documented
894 67 my $self = shift;
895 67 my $end = shift;
896 67 ▶ return if($self->{config}{nofinals});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"config"}{"nofinals"} 40 27 67
897  
898 27 my $handle = $self->{config}{output};
899 27 ▶ $handle = \*STDOUT
Branch: 1 branch
BranchTrueFalseTotal
unless defined $handle 11 16 27
900 unless defined $handle;
901 27 ▶ my $exitcode = @{$self->{errors}}
Branch: 2 branches
BranchTrueFalseTotal
$self->{'bad_command_line'} ? : 0 0 0
$self->{'bad_config_file'} ? : 0 0 0
902 ? ( $self->{bad_command_line}
903 ? $ex_usage
904 27 ▶ : ($self->{bad_config_file} ? $ex_config : $ex_software)
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{'errors'};} ? : 0 27 27
905 )
906 : 0;
907  
908 27 ▶ if($end)
Branch: 1 branch
BranchTrueFalseTotal
if ($end) 0 27 27
909 {
910 0 ▶ if(@{$self->{errors}})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"errors"};}) 0 0 0
911 {
912 0 $self->INT_error("There have been errors in parameter parsing. You should seek --help.");
913 }
914 exit($exitcode)
915 0 ▶ unless $self->{config}{noexit};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"config"}{"noexit"} 0 0 0
916 0 return;
917 }
918  
919 #give the help (info text + option help) and exit when -h or --help was given
920 27 ▶ if($self->{param}{help})
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'param'}{'help'}) { } 15 12 27
elsif (defined $self->{'config'}{'version'} and $self->{'param'}{'version'}) { } 0 12 12
elsif ($self->{'printconfig'}) { } 1 11 12
921 {
922 15 $self->help();
923 exit($exitcode)
924 15 ▶ unless $self->{config}{noexit};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"config"}{"noexit"} 0 15 15
925 }
926 ▶ elsif(defined $self->{config}{version} and $self->{param}{version})
Condition33%1/3
defined $self->{"config"}{"version"} and $self->{"param"}{"version"}
!ll&&!rl&&r
1200
MC/DC0%0/2
defined $self->{"config"}{"version"} and $self->{"param"}{"version"}
defined $self->{"config"}{"version"} $self->{"param"}{"version"}
Truth table33%1/3
A and B
A= defined $self->{"config"}{"version"}B= $self->{"param"}{"version"}
ABresult
0X0
100
111
927 {
928 0 print $handle "$self->{config}{program} $self->{config}{version}\n";
929 exit($exitcode)
930 0 ▶ unless $self->{config}{noexit};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"config"}{"noexit"} 0 0 0
931 }
932 elsif($self->{printconfig})
933 {
934 1 $self->print_file($handle, ($self->{printconfig} > 1));
935 exit($exitcode)
936 1 ▶ unless $self->{config}{noexit};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"config"}{"noexit"} 0 1 1
937 }
938 }
939  
940 # Helper functions...
941  
942 # Produce a string showing the value of a parameter, for the help.
943 sub par_content
944 71 ▶{
Subroutine par_content: called CC=12 SCAR=25.4
Pod documented
945 71 my $self = shift;
946 71 my $k = shift; # The parameter name.
947 71 my $format = shift; # formatting choice
948 71 my $indent = shift; # indent value for dumper
949 71 my $mk = shift; # value selector: 'param' or 'default', usually
950 71 ▶ $mk = 'param'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mk 71 0 71
951 unless defined $mk;
952 71 ▶ if(not defined $format or $format eq 'dump')
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $format or $format eq 'dump') { } 68 3 71
elsif ($format eq 'lines') { } 3 0 3
Condition66%2/3
not defined $format or $format eq "dump"
l!l&&r!l&&!r
0683
MC/DC50%1/2
not defined $format or $format eq "dump"
not defined $format $format eq "dump"
Truth table66%2/3
not(A) or B
A= not defined $formatB= $format eq "dump"
ABresult
1X1
011
000
953 {
954 68 ▶ if(eval { require Data::Dumper })
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Data::Dumper } }) { } 68 0 68
955 {
956 12 ▶ no warnings 'once'; # triggers when embedding the module
Subroutine BEGIN: called CC=1 SCAR=0.0
957 68 local $Data::Dumper::Terse = 1;
958 68 local $Data::Dumper::Deepcopy = 1;
959 68 local $Data::Dumper::Indent = $indent;
960 68 ▶ $Data::Dumper::Indent = 0 unless defined $Data::Dumper::Indent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Data::Dumper::Indent 0 68 68
961 68 local $Data::Dumper::Sortkeys = 1;
962 68 local $Data::Dumper::Quotekeys = 0;
963 68 return Data::Dumper->Dump([$self->{$mk}{$k}]);
964 }
965 0 else{ return "$self->{$mk}{$k}"; }
966 }
967 elsif($format eq 'lines')
968 {
969 3 ▶ return "\n" unless(defined $self->{$mk}{$k});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$mk}{$k} 0 3 3
970 3 ▶ if($self->{type}{$k} == $array)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'type'}{$k} == $array) { } 1 2 3
elsif ($self->{'type'}{$k} == $hash) { } 1 1 2
971 {
972 1 ▶ return "" unless @{$self->{$mk}{$k}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{$mk}{$k};} 0 1 1
973 1 return join("\n", @{$self->{$mk}{$k}})."\n";
974 }
975 elsif($self->{type}{$k} == $hash)
976 {
977 1 my $ret = '';
978 1 for my $sk (sort keys %{$self->{$mk}{$k}})
979 {
980 2 $ret .= "$sk=$self->{$mk}{$k}{$sk}\n";
981 }
982 1 return $ret;
983 }
984 1 else{ return "$self->{$mk}{$k}\n"; }
985 0 } else{ $self->INT_error("unknown par_content format: $format"); }
986 }
987  
988 # Fill up with given symbol for pretty indent.
989 sub INT_indent_string
990 48 ▶{
Subroutine INT_indent_string: called CC=5 SCAR=16.3
Pod undocumented
991 48 my ($indent, $prefill, $filler) = @_;
992 48 ▶ $filler = '.'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filler 48 0 48
993 unless defined $filler;
994 48 ▶ return ($indent > $prefill)
Branch: 2 branches
BranchTrueFalseTotal
$indent > $prefill ? : 42 6 48
$prefill && $indent - $prefill > 2 ? : 36 6 42
Condition66%2/3
$prefill and $indent - $prefill > 2
!ll&&!rl&&r
0636
MC/DC50%1/2
$prefill and $indent - $prefill > 2
$prefill $indent - $prefill > 2
Truth table66%2/3
A and B
A= $prefillB= $indent - $prefill > 2
ABresult
0X0
100
111
995 ? ( ($prefill and ($indent-$prefill>2)) ? $filler : ' ')
996 x ($indent - $prefill - 1) . ' '
997 : '';
998 }
999  
1000 # simple formatting of some lines (breaking up with initial and subsequent indendation)
1001 sub INT_wrap_print
1002 87 ▶{
Subroutine INT_wrap_print: called CC=22 SCAR=31.9
Pod undocumented
1003 87 my ($handle, $itab, $stab, $length) = (shift, shift, shift, shift);
1004 87 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 87 87
1005 # Wrap if given line length can possibly hold the input.
1006  
1007 # Probably I will make this more efficient in future, probably also
1008 # dropping Text::Wrap instead of fighting it. Or use some POD formatting?
1009 87 my @paragraphs = split("\n", join("", @_), -1);
1010 # Drop trailing empty lines. We do not wrap what.
1011 87 ▶ while(@paragraphs and $paragraphs[$#paragraphs] eq '')
Branch: 1 branch
BranchTrueFalseTotal
if (@paragraphs and $paragraphs[$#paragraphs] eq "") 6 87 93
Condition66%2/3
@paragraphs and $paragraphs[$#paragraphs] eq ""
!ll&&!rl&&r
0876
MC/DC50%1/2
@paragraphs and $paragraphs[$#paragraphs] eq ""
@paragraphs $paragraphs[$#paragraphs] eq ""
Truth table66%2/3
A and B
A= @paragraphsB= $paragraphs[$#paragraphs] eq ""
ABresult
0X0
100
111
1012 {
1013 6 pop @paragraphs;
1014 }
1015 87 my $first = 1;
1016 87 print $handle $itab;
1017 87 ▶ print $handle "\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @paragraphs 0 87 87
1018 unless @paragraphs;
1019 87 my $line = undef;
1020 87 my $llen = length($itab);
1021 87 my $slen = length($stab);
1022 87 ▶ my $can_wrap = $length > $llen && $length > $slen;
Condition33%1/3
$length > $llen && $length > $slen
!ll&&!rl&&r
0087
MC/DC0%0/2
$length > $llen && $length > $slen
$length > $llen $length > $slen
Truth table33%1/3
A && B
A= $length > $llenB= $length > $slen
ABresult
0X0
100
111
1023 87 ▶ while(@paragraphs)
Branch: 1 branch
BranchTrueFalseTotal
if (@paragraphs) 131 87 218
1024 {
1025 131 my $p = shift(@paragraphs);
1026 # Try to handle command line/code blocks by not messing with them.
1027 131 ▶ if($p =~ /^\t/)
Branch: 3 branches
BranchTrueFalseTotal
if ($p =~ /^\t/) { } 3 128 131
elsif ($p eq '') { } 33 95 128
elsif ($can_wrap) { } 95 0 95
1028 {
1029 3 ▶ print $handle (defined $line ? $line : '')."\n"
Branch: 2 branches
BranchTrueFalseTotal
if $llen 0 3 3
defined $line ? : 0 0 0
1030 if $llen;
1031 3 print $handle $stab.$p."\n";
1032 3 $line = '';
1033 3 $llen = 0;
1034 }
1035 elsif($p eq '')
1036 {
1037 33 ▶ print $handle (defined $line ? $line : '')."\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $line ? : 6 27 33
1038 33 $line = '';
1039 33 $llen = 0;
1040 }
1041 elsif($can_wrap)
1042 {
1043 95 my @words = split(/\s+/, $p);
1044 95 ▶ while($llen>$slen or @words)
Branch: 1 branch
BranchTrueFalseTotal
if ($llen > $slen or @words) 1326 95 1421
Condition100%3/3
$llen > $slen or @words
l!l&&r!l&&!r
12319595
MC/DC100%2/2
$llen > $slen or @words
$llen > $slen @words
Truth table100%3/3
A or B
A= $llen > $slenB= @words
ABresult
1X1
011
000
1045 {
1046 1326 my $w = shift(@words);
1047 1326 my $l = length($w);
1048 1326 ▶ if(not $l or $l+$llen >= $length)
Branch: 1 branch
BranchTrueFalseTotal
if (not $l or $l + $llen >= $length) 220 1106 1326
Condition100%3/3
not $l or $l + $llen >= $length
l!l&&r!l&&!r
951251106
MC/DC100%2/2
not $l or $l + $llen >= $length
not $l $l + $llen >= $length
Truth table100%3/3
not(A) or B
A= not $lB= $l + $llen >= $length
ABresult
1X1
011
000
1049 {
1050 220 ▶ print $handle (defined $line ? $line : '')."\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $line ? : 220 0 220
1051 220 $llen = 0;
1052 220 $line = '';
1053 220 $first = 0;
1054 }
1055 1326 ▶ if($l)
Branch: 1 branch
BranchTrueFalseTotal
if ($l) 1231 95 1326
1056 {
1057 1231 ▶ unless(defined $line)
Branch: 2 branches
BranchTrueFalseTotal
if (defined $line) { } 1171 60 1231
if (do { $llen }) { } 1011 160 1171
1058 {
1059 60 $line = '';
1060 }
1061 elsif($llen)
1062 {
1063 1011 $line .= ' ';
1064 1011 $llen += 1;
1065 }
1066 else
1067 {
1068 160 $line = $stab;
1069 160 $llen = $slen;
1070 }
1071 1231 $line .= $w;
1072 1231 $llen += $l;
1073 }
1074 }
1075 95 $line = '';
1076 95 $llen = 0;
1077 }
1078 else # wrapping makes no sense
1079 {
1080 0 ▶ print $handle (defined $line ? $line : '').$p."\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $line ? : 0 0 0
1081 0 $line = '';
1082 0 $llen = 0;
1083 }
1084 }
1085 }
1086  
1087 # Produce wrapped text from POD.
1088 sub INT_pod_print
1089 0 ▶{
Subroutine INT_pod_print: not called CC=1 SCAR=6.9
Pod undocumented
1090 0 my ($handle, $length) = (shift, shift);
1091 0 require Pod::Text;
1092 0 my $pod = Pod::Text->new(width=>$length);
1093 0 $pod->output_fh($handle);
1094 0 $pod->parse_string_document($_[0]);
1095 }
1096  
1097 # Produce POD output from text.
1098 sub print_pod
1099 4 ▶{
Subroutine print_pod: called CC=38 SCAR=37.7
Pod documented
1100 4 my $self = shift;
1101 4 my $handle = $self->{config}{output};
1102 4 ▶ $handle = \*STDOUT unless defined $handle;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $handle 0 4 4
1103  
1104 4 my $prog = escape_pod($self->{config}{program});
1105 4 my $tagline = escape_pod($self->{config}{tagline});
1106 # usage line is unescaped
1107 4 my $usage = $self->{config}{usage};
1108 4 my @desc = (); # usage might come from here
1109 @desc = split("\n", $self->{config}{info}, -1)
1110 4 ▶ if(defined $self->{config}{info});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{"info"} 2 2 4
1111  
1112 4 ▶ $tagline = escape_pod(shift @desc)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tagline or not defined $prog 2 2 4
Condition66%2/3
defined $tagline or not defined $prog
l!l&&r!l&&!r
202
MC/DC50%1/2
defined $tagline or not defined $prog
defined $tagline not defined $prog
Truth table66%2/3
A or not(B)
A= defined $taglineB= not defined $prog
ABresult
1X1
011
000
1113 unless(defined $tagline or not defined $prog);
1114  
1115 4 ▶ while(@desc and $desc[0] =~ /^\s*$/){ shift @desc; }
Branch: 1 branch
BranchTrueFalseTotal
if (@desc and $desc[0] =~ /^\s*$/) 1 4 5
Condition100%3/3
@desc and $desc[0] =~ /^\s*$/
!ll&&!rl&&r
311
MC/DC100%2/2
@desc and $desc[0] =~ /^\s*$/
@desc $desc[0] =~ /^\s*$/
Truth table100%3/3
A and B
A= @descB= $desc[0] =~ /^\s*$/
ABresult
0X0
100
111
1116  
1117 4 ▶ unless(defined $usage or not @desc)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $usage or not @desc) 1 3 4
Condition100%3/3
defined $usage or not @desc
l!l&&r!l&&!r
121
MC/DC100%2/2
defined $usage or not @desc
defined $usage not @desc
Truth table100%3/3
A or not(B)
A= defined $usageB= not @desc
ABresult
1X1
011
000
1118 {
1119 1 ▶ if(lc($desc[0]) =~ /^\s*usage:\s*(.*\S?)\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if (lc($desc[0]) =~ /^\s*usage:\s*(.*\S?)\s*$/) 1 0 1
1120 {
1121 1 ▶ $usage = $1 if $1 ne '';
Branch: 1 branch
BranchTrueFalseTotal
if $1 ne "" 0 1 1
1122 1 shift(@desc);
1123 0 ▶ while(@desc and $desc[0] =~ /^\s*$/){ shift @desc; }
Branch: 1 branch
BranchTrueFalseTotal
if (@desc and $desc[0] =~ /^\s*$/) 0 1 1
Condition33%1/3
@desc and $desc[0] =~ /^\s*$/
!ll&&!rl&&r
010
MC/DC0%0/2
@desc and $desc[0] =~ /^\s*$/
@desc $desc[0] =~ /^\s*$/
Truth table33%1/3
A and B
A= @descB= $desc[0] =~ /^\s*$/
ABresult
0X0
100
111
1124  
1125 # if the real deal follows on a later line
1126 1 ▶ if(not defined $usage and @desc)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $usage and @desc) 1 0 1
Condition33%1/3
not defined $usage and @desc
!ll&&!rl&&r
001
MC/DC0%0/2
not defined $usage and @desc
not defined $usage @desc
Truth table33%1/3
not(A) and B
A= not defined $usageB= @desc
ABresult
0X0
100
111
1127 {
1128 1 $usage = shift @desc;
1129 1 $usage =~ s/^\s*//;
1130 1 $usage =~ s/\s*$//;
1131 1 ▶ while(@desc and $desc[0] =~ /^\s*$/){ shift @desc; }
Branch: 1 branch
BranchTrueFalseTotal
if (@desc and $desc[0] =~ /^\s*$/) 1 1 2
Condition66%2/3
@desc and $desc[0] =~ /^\s*$/
!ll&&!rl&&r
011
MC/DC50%1/2
@desc and $desc[0] =~ /^\s*$/
@desc $desc[0] =~ /^\s*$/
Truth table66%2/3
A and B
A= @descB= $desc[0] =~ /^\s*$/
ABresult
0X0
100
111
1132 }
1133 }
1134 }
1135 4 ▶ if(defined $prog)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prog) 4 0 4
1136 {
1137 4 print $handle "\n=head1 NAME\n\n$prog";
1138 4 ▶ print $handle " - $tagline" if defined $tagline;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tagline 4 0 4
1139 4 print $handle "\n";
1140 }
1141 4 ▶ if(defined $usage)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $usage) 2 2 4
1142 {
1143 2 print $handle "\n=head1 SYNOPSIS\n\n";
1144 2 print $handle "\t$_\n" for(split("\n", $usage));
1145 }
1146 4 ▶ if(@desc or defined $self->{config}{infopod})
Branch: 1 branch
BranchTrueFalseTotal
if (@desc or defined $self->{"config"}{"infopod"}) 1 3 4
Condition66%2/3
@desc or defined $self->{"config"}{"infopod"}
l!l&&r!l&&!r
103
MC/DC50%1/2
@desc or defined $self->{"config"}{"infopod"}
@desc defined $self->{"config"}{"infopod"}
Truth table66%2/3
A or B
A= @descB= defined $self->{"config"}{"infopod"}
ABresult
1X1
011
000
1147 {
1148 1 print $handle "\n=head1 DESCRIPTION\n\n";
1149 1 ▶ if(defined $self->{config}{infopod})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'config'}{'infopod'}) { } 0 1 1
1150 {
1151 0 print $handle $self->{config}{infopod};
1152 } else
1153 {
1154 1 for(@desc){ print $handle escape_pod($_), "\n"; }
1155 }
1156 }
1157 4 ▶ my $nprog = defined $prog ? $prog : 'some_program';
Branch: 1 branch
BranchTrueFalseTotal
defined $prog ? : 4 0 4
1158  
1159 4 print $handle "\n=head1 PARAMETERS\n\n";
1160 4 print $handle "These are the general rules for specifying parameters to this program:\n";
1161 4 print $handle "\n\t$nprog ";
1162 4 ▶ if($self->{config}{lazy})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'config'}{'lazy'}) { } 4 0 4
1163 {
1164 4 print $handle escape_pod($example{lazy}),"\n\n";
1165 4 print $handle escape_pod($lazyinfo),"\n";
1166 }
1167 else
1168 {
1169 0 print $handle escape_pod($example{normal}),"\n";
1170 }
1171 4 print $handle "\n";
1172 4 for(@morehelp)
1173 {
1174 32 print $handle escape_pod($_);
1175 }
1176 4 print $handle "\n\nThe available parameters are these, default values (in Perl-compatible syntax) at the time of generating this document following the long/short names:\n";
1177 4 print $handle "\n=over 2\n";
1178 4 for my $k (sort keys %{$self->{param}})
1179 {
1180 print $handle "\n=item B<".escape_pod($k).">".
1181 28 ▶ ($self->{short}{$k} ne '' ? ', B<'.escape_pod($self->{short}{$k}).'>' : '').
Branch: 1 branch
BranchTrueFalseTotal
$self->{'short'}{$k} ne '' ? : 24 4 28
1182 " ($typename[$self->{type}{$k}])".
1183 "\n\n";
1184 28 ▶ my @content = $k eq 'help'
Branch: 1 branch
BranchTrueFalseTotal
$k eq 'help' ? : 4 24 28
1185 ? 0
1186 : split("\n", $self->par_content($k, 'dump', 1));
1187 28 print $handle "\t$_\n" for(@content);
1188 28 print $handle "\n".escape_pod(${$self->{help}{$k}})."\n";
1189 28 ▶ print $handle "\n".$self->{extrahelp}."\n" if($k eq 'help');
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "help" 4 24 28
1190 }
1191 4 print $handle "\n=back\n";
1192  
1193 # closing with some simple sections
1194 4 my @podsections;
1195 # user-provided
1196 4 push(@podsections, @{$self->{config}{extrapod}})
1197 4 ▶ if(defined $self->{config}{extrapod});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{"extrapod"} 4 0 4
1198  
1199 # standard
1200 4 for( ['BUGS','bugs'], ['AUTHOR', 'author'], ['LICENSE AND COPYRIGHT', 'copyright'] )
1201 {
1202 push(@podsections, {head=>$_->[0], body=>$self->{config}{$_->[1]}})
1203 12 ▶ if(defined $self->{config}{$_->[1]});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{$_->[1]} 8 4 12
1204 }
1205  
1206 4 for my $ps (@podsections)
1207 {
1208 16 print $handle "\n=head1 $ps->{head}\n";
1209 16 ▶ print $handle "\n",$ps->{verbatim} ? $ps->{body} : escape_pod($ps->{body}),"\n";
Branch: 1 branch
BranchTrueFalseTotal
$ps->{'verbatim'} ? : 4 12 16
1210 }
1211  
1212 4 print $handle "\n=cut\n";
1213 }
1214  
1215 sub _pm
1216 0 ▶{
Subroutine _pm: not called CC=6 SCAR=37.4
1217 0 my $self = shift;
1218 0 my $k = shift;
1219 return ( ($self->{type}{$k} == $scalar
1220 and ( $self->{flags}{$k} & $switch
1221 or (defined $self->{arg}{$k} and $self->{arg}{$k} eq '') ))
1222 0 ▶ and ($self->{default}{$k}) ) ? '+' : '-';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'type'}{$k} == $scalar && ($self->{'flags'}{$k} & $switch || defined $self->{'arg'}{$k} && $self->{'arg'}{$k} eq '') && $self->{'default'}{$k} ? : 0 0 0
Condition0%0/12
$self->{"type"}{$k} == $scalar and $self->{"flags"}{$k} & $switch || defined $self->{"arg"}{$k} && $self->{"arg"}{$k} eq "" and $self->{"default"}{$k}
!ll&&!rl&&r
000
$self->{"type"}{$k} == $scalar and $self->{"flags"}{$k} & $switch || defined $self->{"arg"}{$k} && $self->{"arg"}{$k} eq ""
!ll&&!rl&&r
000
$self->{"flags"}{$k} & $switch or defined $self->{"arg"}{$k} and $self->{"arg"}{$k} eq ""
l!l&&r!l&&!r
000
defined $self->{"arg"}{$k} and $self->{"arg"}{$k} eq ""
!ll&&!rl&&r
000
MC/DC0%0/5
$self->{"type"}{$k} == $scalar and $self->{"flags"}{$k} & $switch || defined $self->{"arg"}{$k} && $self->{"arg"}{$k} eq "" and $self->{"default"}{$k}
$self->{"type"}{$k} == $scalar $self->{"flags"}{$k} & $switch defined $self->{"arg"}{$k} $self->{"arg"}{$k} eq "" $self->{"default"}{$k}
Truth table0%0/7
A and B or C and D and E
A= $self->{"type"}{$k} == $scalarB= $self->{"flags"}{$k} & $switchC= defined $self->{"arg"}{$k}D= $self->{"arg"}{$k} eq ""E= $self->{"default"}{$k}
ABCDEresult
0XXXX0
100XX0
1010X0
11XX00
101100
11XX11
101111
1223 }
1224  
1225 # Well, _the_ help.
1226 sub help
1227 15 ▶{
Subroutine help: called CC=85 SCAR=75.7
Pod documented
1228 15 my $self = shift;
1229 15 my $handle = $self->{config}{output};
1230 15 ▶ $handle = \*STDOUT unless defined $handle;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $handle 0 15 15
1231 my $indent = $self->{config}{posixhelp}
1232 ? $self->{arglength} + 7 # -s, --name[=arg]
1233 15 ▶ : $self->{length} + 4; # longest long name + ", s " (s being the short name)
Branch: 1 branch
BranchTrueFalseTotal
$self->{'config'}{'posixhelp'} ? : 0 15 15
1234  
1235 # Trying to format it fitting the screen to ease eye navigation in large parameter lists.
1236 15 my $linewidth = 0;
1237 15 ▶ if(defined $self->{config}{linewidth})
Branch: 3 branches
BranchTrueFalseTotal
if (defined $self->{'config'}{'linewidth'}) { } 15 0 15
elsif (eval { do { require Term::ReadKey } }) { } 0 0 0
elsif (eval { do { require IPC::Run } }) { } 0 0 0
1238 {
1239 15 $linewidth = $self->{config}{linewidth};
1240 }
1241 0 elsif(eval { require Term::ReadKey })
1242 {
1243 # This can die on me! So run it in eval.
1244 0 my @s = eval { Term::ReadKey::GetTerminalSize(); };
1245 0 ▶ $linewidth = $s[0] if @s;
Branch: 1 branch
BranchTrueFalseTotal
if @s 0 0 0
1246 }
1247 0 elsif(eval { require IPC::Run })
1248 {
1249 0 my ($in, $err);
1250 0 ▶ if(eval { IPC::Run::run([qw(tput cols)], \$in, \$linewidth, \$err) })
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { IPC::Run::run(["tput", "cols"], \$in, \$linewidth, \$err) } }) 0 0 0
1251 {
1252 0 chomp($linewidth);
1253 0 $linewidth += 0; # ensure a number;
1254 }
1255 }
1256 15 ▶ my $prosewidth = $linewidth > 80 ? 80 : $linewidth;
Branch: 1 branch
BranchTrueFalseTotal
$linewidth > 80 ? : 0 15 15
1257  
1258 15 ▶ if($self->{param}{help} =~ /^(-\d+),?(.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"param"}{"help"} =~ /^(-\d+),?(.*)$/) 9 6 15
1259 {
1260 9 my $code = $1;
1261 9 my @keys = split(',', $2);
1262 9 my $badkeys;
1263 9 for(@keys)
1264 {
1265 5 ▶ unless(exists $self->{param}{$_})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"param"}{$_}) 0 5 5
1266 {
1267 0 ++$badkeys;
1268 0 $self->INT_error("Parameter $_ is not defined!");
1269 }
1270 }
1271 return
1272 9 ▶ if $badkeys;
Branch: 1 branch
BranchTrueFalseTotal
if $badkeys 0 9 9
1273  
1274 9 ▶ if($code == -1)
Branch: 6 branches
BranchTrueFalseTotal
if ($code == -1) { } 1 8 9
elsif ($code == -2) { } 1 7 8
elsif ($code == -3) { } 1 6 7
elsif ($code == -10) { } 1 5 6
elsif ($code == -11) { } 1 4 5
elsif ($code == -100) { } 4 0 4
1275 { # param list, wrapped to screen
1276 INT_wrap_print( $handle, '', "\t", $linewidth, "List of parameters: "
1277 1 , join(' ', sort keys %{$self->{param}}) );
1278 }
1279 elsif($code == -2)
1280 { # param list, one one each line
1281 1 print $handle join("\n", sort keys %{$self->{param}})."\n";
1282 }
1283 elsif($code == -3)
1284 { # param list, one one each line, without builtins
1285 1 my $builtin = builtins($self->{config});
1286 1 my @pars = sort grep {not $builtin->{$_}} keys %{$self->{param}};
1287 1 ▶ print $handle join("\n", @pars)."\n" if @pars;
Branch: 1 branch
BranchTrueFalseTotal
if @pars 1 0 1
1288 }
1289 elsif($code == -10)
1290 { # dump values, suitable to eval to a big array
1291 1 my $first = 1;
1292 1 for(@keys)
1293 {
1294 2 ▶ if($first){ $first=0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($first) { } 1 1 2
1295 1 else{ print $handle ", "; }
1296 2 print $handle $self->par_content($_, 'dump', 1);
1297 }
1298 }
1299 elsif($code == -11)
1300 { # line values
1301 1 for(@keys){ print $handle $self->par_content($_, 'lines'); }
1302 }
1303 elsif($code == -100)
1304 {
1305 4 $self->print_pod();
1306 }
1307 else
1308 {
1309 0 $self->INT_error("bogus help code $code");
1310 0 INT_wrap_print(\*STDERR, '', '', $linewidth, "\nHelp for help:\n", ${$self->{help}{help}});
1311 0 INT_wrap_print(\*STDERR, '','', $linewidth, $self->{extrahelp});
1312 }
1313 9 return;
1314 }
1315  
1316 # Anything with at least two characters could be a parameter name.
1317 6 ▶ if($self->{param}{help} =~ /../)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"param"}{"help"} =~ /../) 0 6 6
1318 {
1319 0 my $k = $self->{param}{help};
1320 0 ▶ if(exists $self->{param}{$k})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'param'}{$k}) { } 0 0 0
1321 {
1322 0 my $val = $self->{arg}{$k};
1323 0 my $s = $self->{short}{$k};
1324 0 my $type = $self->{type}{$k};
1325 0 my $flags = $self->{flags}{$k};
1326 0 my $pm = $self->_pm($k);
1327 0 ▶ $val = 'val' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
1328 print $handle $self->{config}{posixhelp}
1329 0 ▶ ? "Option:\n\t"
Branch: 3 branches
BranchTrueFalseTotal
$self->{'config'}{'posixhelp'} ? : 0 0 0
$s ne '' ? : 0 0 0
$s ne '' ? : 0 0 0
1330 . ($s ne '' ? "$pm$s, " : '')
1331 . $pm.$pm.$k."\n"
1332 : "Parameter:\n\t$k".($s ne '' ? ", $s" : '')."\n";
1333 0 my $c = $self->par_content($k, 'dump', 1);
1334 0 $c =~ s/\n$//;
1335 0 $c =~s/\n/\n\t/g;
1336 0 print $handle "\nValue:\n\t$c\n";
1337 0 my $dc = $self->par_content($k, 'dump', 1, 'default');
1338 0 $dc =~ s/\n$//;
1339 0 $dc =~s/\n/\n\t/g;
1340 0 ▶ print $handle "\nDefault value: "
Branch: 1 branch
BranchTrueFalseTotal
$c eq $dc ? : 0 0 0
1341 . ($c eq $dc ? "same" : "\n\t$dc")
1342 . "\n";
1343 0 print $handle "\nSyntax notes:\n";
1344 0 my $notes = '';
1345 0 ▶ if($type eq $scalar)
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq $scalar) { } 0 0 0
elsif (grep {$_ == $type;} $array, $hash) { } 0 0 0
1346 {
1347 0 my @switchcount;
1348 0 ▶ push(@switchcount, "switch")
Branch: 1 branch
BranchTrueFalseTotal
if $flags & $switch or not $flags & $count 0 0 0
Condition0%0/3
$flags & $switch or not $flags & $count
l!l&&r!l&&!r
000
MC/DC0%0/2
$flags & $switch or not $flags & $count
$flags & $switch not $flags & $count
Truth table0%0/3
A or not(B)
A= $flags & $switchB= not $flags & $count
ABresult
1X1
011
000
1349 if($flags & $switch or not $flags & $count);
1350 0 ▶ push(@switchcount, "counter")
Branch: 1 branch
BranchTrueFalseTotal
if $flags & $count or not $flags & $switch 0 0 0
Condition0%0/3
$flags & $count or not $flags & $switch
l!l&&r!l&&!r
000
MC/DC0%0/2
$flags & $count or not $flags & $switch
$flags & $count not $flags & $switch
Truth table0%0/3
A or not(B)
A= $flags & $countB= not $flags & $switch
ABresult
1X1
011
000
1351 if($flags & $count or not $flags & $switch);
1352 0 ▶ $notes .= $flags & $arg
Branch: 3 branches
BranchTrueFalseTotal
$flags & $arg ? : 0 0 0
$s ne '' ? : 0 0 0
$val ne '' ? : 0 0 0
1353 ? "This is a scalar parameter that requires an explicit"
1354 . " argument value."
1355 . " You can choose the canonical form --$k=$val or let"
1356 . " the value follow like --$k $val"
1357 . ( $s ne ''
1358 ? " (short option only: both -$s $val and -$s$val are valid)"
1359 : '' )
1360 . '.'
1361 : $val ne ''
1362 ? "This is a scalar parameter with an optional argument"
1363 . " value than can only be provided by attaching it"
1364 . " with an equal sign or another operator,"
1365 . " e.g. --$k=$val."
1366 : "This is a parameter intended as a ".join(" or ", @switchcount)
1367 . ", providing an argument value is not required.";
1368 0 ▶ $notes .= " The value can be built"
Branch: 1 branch
BranchTrueFalseTotal
unless $flags & $switch 0 0 0
1369 . " in multiple steps via operators for appending (--$k.=) or"
1370 . " arithmetic (--$k+= for addition, --$k-=, --$k*=, and --$k/= for"
1371 . " subtraction, multiplication, and division)."
1372 unless $flags & $switch;
1373 0 ▶ $notes .= "\n\nThe above applies to the short -$s, too, with the"
Branch: 1 branch
BranchTrueFalseTotal
if not $flags & $switch and $s ne "" 0 0 0
Condition0%0/3
not $flags & $switch and $s ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
not $flags & $switch and $s ne ""
not $flags & $switch $s ne ""
Truth table0%0/3
not(A) and B
A= not $flags & $switchB= $s ne ""
ABresult
0X0
100
111
1374 . " addition that the equal sign can be dropped for"
1375 . " two-character operators, like -$s+3."
1376 if(not $flags & $switch and $s ne '');
1377 0 ▶ $notes .= $flags & $count
Branch: 6 branches
BranchTrueFalseTotal
unless $flags & $arg 0 0 0
$flags & $count ? : 0 0 0
$s ne '' ? : 0 0 0
$s ne '' ? : 0 0 0
$s ne '' ? : 0 0 0
$s ne '' ? : 0 0 0
1378 ? "\n\nEach appearance of --$k "
1379 . ($s ne '' ? "and -$s " : '')
1380 . "increments the value by 1, while ++$k "
1381 . ($s ne '' ? "and +$s " : '')
1382 . "set it to zero (false)."
1383 : "\n\nJust --$k"
1384 . ($s ne '' ? " or -$s " : '')
1385 . "sets the value to 1 (engages the switch), while ++$k"
1386 . ($s ne '' ? " or +$s " : '')
1387 . "sets the value to 0 (disengages the switch)."
1388 unless($flags & $arg);
1389 0 } elsif(grep {$_ == $type} ($array, $hash))
1390 {
1391 0 ▶ $notes .= $type == $hash
Branch: 1 branch
BranchTrueFalseTotal
$type == $hash ? : 0 0 0
1392 ? 'This is a hash (name-value store) parameter. An option argument'
1393 . ' consists of <key>=<value> to'
1394 . ' store the actual value with for given key.'
1395 : 'This is an array parameter.';
1396 0 ▶ $notes .= ' Assigned values are appended even if the append operator .='
Branch: 1 branch
BranchTrueFalseTotal
if $flags & $append 0 0 0
1397 . ' is not used explicitly.'
1398 if $flags & $append;
1399 0 ▶ $notes .= $flags & $arg
Branch: 1 branch
BranchTrueFalseTotal
$flags & $arg ? : 0 0 0
1400 ? ' An explicit argument to the option is required.'
1401 . " It is equivalent to specify --$k=$val or --$k $val."
1402 . " A value is explcitly appended to the "
1403 . "$typename[$type] via --$k.=$val."
1404 : " An option argument can be given via --$k=$val or --$k.=$val to "
1405 . " explicitly append to the $typename[$self->{type}{$k}].";
1406 0 ▶ $notes .= ' For this parameter, the appending operator .= is implicit.'
Branch: 1 branch
BranchTrueFalseTotal
if $flags & $append 0 0 0
1407 if $flags & $append;
1408 0 ▶ $notes .= "\n\nThe above applies also to the short option -$s"
Branch: 2 branches
BranchTrueFalseTotal
if $s ne "" 0 0 0
$flags & $arg ? : 0 0 0
1409 . ($flags & $arg
1410 ? ", with added possibility of directly attaching the argument via -$s$val."
1411 : ".")
1412 if $s ne '';
1413 0 $notes .= "\n\n";
1414 0 $notes .= "Multiple values can be provided with a single separator character"
1415 . " that is specified between slashes, like --$k/,/=a,b,c.";
1416 } else
1417 {
1418 0 $notes .= 'I do not know what kind of parameter that is.'
1419 }
1420 $notes .= "\n\n"
1421 . 'Lazy option syntax is active: you can drop one or both of the'
1422 . ' leading \'--\', also the \'-\' of the short form. Beware: just'
1423 . ' -'.$k.' is a group of short options, while -'.$k.'=foo would be'
1424 . ' an assignment to '.$k.'.'
1425 0 ▶ if $self->{config}{lazy};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"config"}{"lazy"} 0 0 0
1426 0 INT_wrap_print( $handle, "\t", "\t", $prosewidth, $notes);
1427 0 print $handle "\nHelp:";
1428 0 ▶ if(${$self->{help}{$k}} ne '')
Branch: 1 branch
BranchTrueFalseTotal
if (${$self->{'help'}{$k};} ne '') { } 0 0 0
1429 {
1430 0 print $handle "\n";
1431 0 INT_wrap_print($handle, "\t","\t", $prosewidth, ${$self->{help}{$k}});
1432 } else
1433 {
1434 0 print $handle " none";
1435 }
1436 INT_wrap_print($handle, "\t","\t", $prosewidth, $self->{extrahelp})
1437 0 ▶ if $k eq 'help';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "help" 0 0 0
1438 0 print "\n";
1439 } else
1440 {
1441 0 $self->INT_error("Parameter $k is not defined!");
1442 }
1443 0 return;
1444 }
1445  
1446 6 ▶ if($self->{param}{help} =~ /\D/)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"param"}{"help"} =~ /\D/) 0 6 6
1447 {
1448 0 $self->INT_error("You specified an invalid help level (parameter name needs two characters minimum).");
1449 0 return;
1450 }
1451  
1452 6 ▶ my $vst = (defined $self->{config}{version} ? "v$self->{config}{version} " : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'config'}{'version'} ? : 0 6 6
1453 6 ▶ if(defined $self->{config}{tagline})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'config'}{'tagline'}) { } 3 3 6
1454 {
1455 3 INT_wrap_print($handle, '', '', $prosewidth, "\n$self->{config}{program} ${vst}- ",$self->{config}{tagline});
1456 3 ▶ if(defined $self->{config}{usage})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"usage"}) 1 2 3
1457 {
1458 1 print $handle "\nUsage:\n";
1459 1 INT_wrap_print($handle, "\t","\t", $prosewidth, $self->{config}{usage});
1460 }
1461 3 ▶ if(defined $self->{config}{info})
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'config'}{'info'}) { } 1 2 3
elsif (defined $self->{'config'}{'infopod'}) { } 0 2 2
1462 {
1463 1 INT_wrap_print($handle, '', '', $prosewidth, "\n".$self->{config}{info});
1464 } elsif(defined $self->{config}{infopod})
1465 {
1466 0 print {$handle} "\n";
1467 0 INT_pod_print($handle, $prosewidth, $self->{config}{infopod});
1468 }
1469 INT_wrap_print($handle, '', '', $prosewidth, "\n$self->{config}{copyright}")
1470 3 ▶ if defined $self->{config}{copyright};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{"copyright"} 3 0 3
1471 }
1472 else
1473 {
1474 3 ▶ if(defined $self->{config}{info})
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'config'}{'info'}) { } 3 0 3
elsif (defined $self->{'config'}{'infopod'}) { } 0 0 0
1475 {
1476 INT_wrap_print($handle, '', '', $prosewidth, "\n$self->{config}{program} ${vst}- ".$self->{config}{info})
1477 3 } elsif(defined $self->{config}{infopod})
1478 {
1479 0 print {$handle} "\n$self->{config}{program} ${vst}\n";
1480 0 INT_pod_print($handle, $prosewidth, $self->{config}{infopod});
1481 }
1482  
1483 INT_wrap_print($handle, '', '', $prosewidth, "\n$self->{config}{copyright}")
1484 3 ▶ if defined $self->{config}{copyright};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{"copyright"} 3 0 3
1485 }
1486  
1487 6 my $level = 0+$self->{param}{help};
1488 6 my $tablehead = '';
1489  
1490 6 ▶ if($self->{config}{posixhelp})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'config'}{'posixhelp'}) { } 0 6 6
1491 {
1492 0 INT_wrap_print( $handle, '', '', $prosewidth
1493 , "\nShort options can be grouped and non-optional arguments"
1494 . " can follow without equal sign. Force options end with '--'."
1495 . " Switches on with -, off with +."
1496 . " See --help=par for details on possible advanced syntax with option"
1497 . " --par." );
1498 } else
1499 {
1500 6 my $preprint = "NAME, SHORT ";
1501 6 ▶ $indent = length($preprint)
Branch: 1 branch
BranchTrueFalseTotal
if length $preprint > $indent 6 0 6
1502 if length($preprint) > $indent;
1503 6 $tablehead = $preprint
1504 . INT_indent_string($indent, length($preprint))."VALUE [# DESCRIPTION]\n";
1505 6 INT_wrap_print( $handle, '', '', $prosewidth
1506 , "\nGeneric parameter example (list of real parameters follows):\n" );
1507 6 print $handle "\n";
1508 6 ▶ if($self->{config}{lazy})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'config'}{'lazy'}) { } 6 0 6
1509 {
1510 6 print $handle "\t$self->{config}{program} $example{lazy}\n";
1511 6 ▶ if($level > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($level > 1) 2 4 6
1512 {
1513 2 INT_wrap_print($handle, '', '', $prosewidth, "\n", $lazyinfo);
1514 }
1515 }
1516 else
1517 {
1518 0 print $handle "\t$self->{config}{program} $example{normal}\n";
1519 }
1520 6 print $handle "\n";
1521 6 ▶ if($level > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($level > 1) { } 2 4 6
1522 {
1523 2 INT_wrap_print($handle, '', '', $prosewidth, @morehelp)
1524 } else
1525 { # Don't waste so many lines by default.
1526 4 INT_wrap_print($handle, '', '', $prosewidth
1527 , "Just mentioning -s equals -s=1 (true), while +s equals -s=0 (false)."
1528 , " The separator \"--\" stops option parsing."
1529 )
1530 }
1531 6 INT_wrap_print($handle, '', '', $prosewidth, "\nRecognized parameters:");
1532 }
1533 6 my @hidden_nonshort;
1534 my @hidden_level;
1535 6 ▶ if($self->{config}{ordered})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'config'}{'ordered'}) { } 0 6 6
1536 {
1537 0 foreach my $s (@{$self->{section}})
1538 {
1539 0 ▶ if($level >= $s->{minlevel})
Branch: 1 branch
BranchTrueFalseTotal
if ($level >= $s->{"minlevel"}) 0 0 0
1540 {
1541 INT_wrap_print( $handle, '', '', $prosewidth, "\n".$s->{section} )
1542 0 ▶ if($s->{section} ne '');
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"section"} ne "" 0 0 0
1543 0 INT_wrap_print( $handle, '', '', $prosewidth, ${$s->{help}} )
1544 0 ▶ if(${$s->{help}} ne '');
Branch: 1 branch
BranchTrueFalseTotal
if ${$s->{"help"};} ne "" 0 0 0
1545 0 print $handle "\n".$tablehead;
1546 }
1547 # Go through the parameters at least to count the hidden ones.
1548 0 for my $k (@{$s->{member}})
1549 {
1550 0 $self->INT_param_help( $handle, $k, $level, $prosewidth, $indent
1551 , \@hidden_nonshort, \@hidden_level );
1552 }
1553 }
1554 } else
1555 {
1556 6 print $handle "\n".$tablehead;
1557 6 for my $k ( sort keys %{$self->{param}} )
1558 {
1559 42 $self->INT_param_help( $handle, $k, $level, $prosewidth, $indent
1560 , \@hidden_nonshort, \@hidden_level );
1561 }
1562 }
1563 6 ▶ if(@hidden_nonshort)
Branch: 1 branch
BranchTrueFalseTotal
if (@hidden_nonshort) 0 6 6
1564 {
1565 0 print $handle "\n";
1566 0 ▶ if($level> 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($level > 1) { } 0 0 0
1567 {
1568 0 INT_wrap_print( $handle, '', '', $prosewidth,
1569 "Hidden parameters intended primarily for config files:" );
1570 0 INT_wrap_print( $handle, "\t", "\t", $prosewidth, "@hidden_nonshort" );
1571 } else
1572 {
1573 0 ▶ INT_wrap_print( $handle, '', '', $prosewidth, 'There'
Branch: 1 branch
BranchTrueFalseTotal
@hidden_nonshort == 1 ? : 0 0 0
1574 . ( @hidden_nonshort == 1
1575 ? 'is one hidden config file parameter'
1576 : 'are '.(0+@hidden_nonshort).' hidden config file parameters' ) );
1577 }
1578 }
1579 6 ▶ if(@hidden_level)
Branch: 1 branch
BranchTrueFalseTotal
if (@hidden_level) 0 6 6
1580 {
1581 0 print $handle "\n";
1582 0 ▶ if($level > 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($level > 1) { } 0 0 0
1583 {
1584 0 INT_wrap_print( $handle, '', "\t", $prosewidth
1585 , "Parameters explained at higher help levels: @hidden_level" );
1586 } else
1587 {
1588 0 ▶ INT_wrap_print( $handle, '', '', $prosewidth, "There "
Branch: 1 branch
BranchTrueFalseTotal
@hidden_level == 1 ? : 0 0 0
1589 . ( @hidden_level == 1
1590 ? 'is one parameter'
1591 : 'are '.(0+@hidden_level).' parameters' )
1592 . ' explained at higher help levels.' );
1593 }
1594 }
1595 6 print $handle "\n";
1596 }
1597  
1598 sub INT_param_help
1599 42 ▶{
Subroutine INT_param_help: called CC=8 SCAR=29.6
Pod undocumented
1600 42 my $self = shift;
1601 42 my ($handle, $k, $level, $linewidth, $indent, $hidden_nonshort, $hidden_level) = @_;
1602  
1603 # Reasons to hide from current printout.
1604 42 my $hide = 0;
1605 42 ▶ if( $self->{config}{hidenonshort} and $self->{short}{$k} eq ''
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"hidenonshort"} and $self->{"short"}{$k} eq "" and not $k eq "version" && defined $self->{"config"}{"version"}) 0 42 42
Condition22%2/9
$self->{"config"}{"hidenonshort"} and $self->{"short"}{$k} eq "" and not $k eq "version" && defined $self->{"config"}{"version"}
!ll&&!rl&&r
4200
$self->{"config"}{"hidenonshort"} and $self->{"short"}{$k} eq ""
!ll&&!rl&&r
4200
$k eq 'version' && defined $self->{'config'}{'version'}
!ll&&!rl&&r
000
MC/DC0%0/4
$self->{"config"}{"hidenonshort"} and $self->{"short"}{$k} eq "" and not $k eq "version" && defined $self->{"config"}{"version"}
$self->{"config"}{"hidenonshort"} $self->{"short"}{$k} eq "" $k eq 'version' defined $self->{'config'}{'version'}
Truth table20%1/5
A and B and not(C && D)
A= $self->{"config"}{"hidenonshort"}B= $self->{"short"}{$k} eq ""C= $k eq 'version'D= defined $self->{'config'}{'version'}
ABCDresult
0XXX0
10XX0
11110
110X1
11101
1606 and not ($k eq 'version' and defined $self->{config}{version}) )
1607 {
1608 0 ++$hide;
1609 0 push(@{$hidden_nonshort}, $k);
1610 }
1611 42 ▶ if($level < $self->{level}{$k})
Branch: 1 branch
BranchTrueFalseTotal
if ($level < $self->{"level"}{$k}) 0 42 42
1612 {
1613 0 ++$hide;
1614 0 push(@{$hidden_level}, $k);
1615 }
1616 return
1617 42 ▶ if $hide;
Branch: 1 branch
BranchTrueFalseTotal
if $hide 0 42 42
1618  
1619 42 ▶ if($self->{config}{posixhelp})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'config'}{'posixhelp'}) { } 0 42 42
1620 {
1621 0 $self->INT_param_help_posix($handle, $k, $linewidth, $indent);
1622 } else
1623 {
1624 42 $self->INT_param_help_table($handle, $k, $linewidth, $indent);
1625 }
1626 }
1627  
1628 sub INT_param_help_table
1629 42 ▶{
Subroutine INT_param_help_table: called CC=9 SCAR=22.1
Pod undocumented
1630 42 my $self = shift;
1631 42 my ($handle, $k, $linewidth, $indent) = @_;
1632
1633 # This format will change, I presume.
1634 # This is the parameter syntax-agnostic print, where that
1635 # information is shown elsewhere. People are used to
1636 # -s, --long=<value> Blablabla [default]
1637 # Let's go there.
1638 # long, s
1639 42 my $prefix = $k;
1640 42 ▶ $prefix .= ", $self->{short}{$k}" if($self->{short}{$k} ne '');
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"short"}{$k} ne "" 36 6 42
1641 42 $prefix .= ' ';
1642 42 my $content = $self->par_content($k, 'dump', 0);
1643 42 my $stab = ' ' x $indent;
1644 42 my @help = split("\n", ${$self->{help}{$k}});
1645 push(@help, split("\n", $self->{extrahelp}))
1646 if( $k eq 'help' and $self->{param}{help} > 1
1647 42 ▶ and defined $self->{extrahelp} );
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "help" and $self->{"param"}{"help"} > 1 and defined $self->{"extrahelp"} 2 40 42
Condition83%5/6
$k eq "help" and $self->{"param"}{"help"} > 1 and defined $self->{"extrahelp"}
!ll&&!rl&&r
4002
$k eq "help" and $self->{"param"}{"help"} > 1
!ll&&!rl&&r
3642
MC/DC66%2/3
$k eq "help" and $self->{"param"}{"help"} > 1 and defined $self->{"extrahelp"}
$k eq "help" $self->{"param"}{"help"} > 1 defined $self->{"extrahelp"}
Truth table75%3/4
A and B and C
A= $k eq "help"B= $self->{"param"}{"help"} > 1C= defined $self->{"extrahelp"}
ABCresult
0XX0
10X0
1100
1111
1648 42 ▶ $help[0] = $content.(@help and $help[0] ne '' ? " # $help[0]" : '');
Branch: 1 branch
BranchTrueFalseTotal
$help[0] ne '' ? : 42 0 42
Condition33%1/3
@help && ($help[0] ne '' ? " # $help[0]" : '')
!ll&&!rl&&r
0042
MC/DC0%0/2
@help && ($help[0] ne '' ? " # $help[0]" : '')
@help ($help[0] ne '' ? " # $help[0]" : '')
Truth table33%1/3
A && B
A= @helpB= ($help[0] ne '' ? " # $help[0]" : '')
ABresult
0X0
100
111
1649 42 ▶ for(my $i=0; $i<@help; ++$i)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @help) 52 42 94
1650 {
1651 52 ▶ INT_wrap_print( $handle, ( $i==0
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 42 10 52
1652 ? $prefix.INT_indent_string($indent, length($prefix))
1653 : $stab ) , $stab, $linewidth, $help[$i] );
1654 }
1655 }
1656  
1657 sub INT_param_help_posix
1658 0 ▶{
Subroutine INT_param_help_posix: not called CC=8 SCAR=42.8
Pod undocumented
1659 0 my $self = shift;
1660 0 my ($handle, $k, $linewidth, $indent) = @_;
1661 0 my $stab = ' ' x $indent;
1662 0 my $prefix = '';
1663 0 my $pm = $self->_pm($k);
1664 0 ▶ $prefix = $self->{short}{$k} ne '' ? "$pm$self->{short}{$k}, " : ' ';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'short'}{$k} ne '' ? : 0 0 0
1665 0 $prefix .= $pm.$pm.$self->INT_namearg($k).' ';
1666 0 my @help = split("\n", ${$self->{help}{$k}});
1667 push(@help, split("\n", $self->{extrahelp}))
1668 0 ▶ if($k eq 'help' and $self->{param}{help} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "help" and $self->{"param"}{"help"} > 1 0 0 0
Condition0%0/3
$k eq "help" and $self->{"param"}{"help"} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
$k eq "help" and $self->{"param"}{"help"} > 1
$k eq "help" $self->{"param"}{"help"} > 1
Truth table0%0/3
A and B
A= $k eq "help"B= $self->{"param"}{"help"} > 1
ABresult
0X0
100
111
1669 # Splitting the empty string does not give an array with one empty string,
1670 # but an empty array instead.
1671 0 ▶ push(@help, '')
Branch: 1 branch
BranchTrueFalseTotal
unless @help 0 0 0
1672 unless @help;
1673 0 ▶ $help[0] = 'disable: '.$help[0]
Branch: 1 branch
BranchTrueFalseTotal
if $pm eq "+" 0 0 0
1674 if $pm eq '+';
1675 0 ▶ for(my $i=0; $i<@help; ++$i)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @help) 0 0 0
1676 {
1677 0 ▶ INT_wrap_print( $handle, ( $i==0
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 0 0 0
1678 ? $prefix.INT_indent_string($indent, length($prefix), ' ')
1679 : $stab ) , $stab, $linewidth, $help[$i] );
1680 }
1681 }
1682  
1683 # Have to cover two use cases:
1684 # 1. Have defined param space, just want values.
1685 # 2. Want to construct param space from file.
1686 # Parse configured config files.
1687 sub INT_parse_files
1688 63 ▶{
Subroutine INT_parse_files: called CC=3 SCAR=11.0
Pod undocumented
1689 63 my $self = shift;
1690 63 my $construct = shift;
1691  
1692 63 for my $file (@{$self->{param}{config}})
1693 {
1694 10 ▶ return 0 unless $self->parse_file($file, $construct);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parse_file($file, $construct) 1 9 10
1695 }
1696 62 return 1;
1697 }
1698  
1699 # check if it's existing and not a directory
1700 # _not_ explicitly checking for files as that would exclude things that otherwise would work as files just fine
1701 sub INT_filelike
1702 1302 ▶{
Subroutine INT_filelike: called CC=2 SCAR=7.2
Pod undocumented
1703 1302 ▶ return (-e $_[0] and not -d $_[0])
Condition66%2/3
-e $_[0] && !(-d $_[0])
!ll&&!rl&&r
1278024
MC/DC50%1/2
-e $_[0] && !(-d $_[0])
-e $_[0] !(-d $_[0])
Truth table66%2/3
A && not(B)
A= -e $_[0]B= !(-d $_[0])
ABresult
0X0
100
111
1704 }
1705  
1706 # Look for given config file name in configured directory or search for it in
1707 # the list of likely places. Appending the ending .conf is also tried.
1708 sub INT_find_config
1709 101 ▶{
Subroutine INT_find_config: called CC=9 SCAR=22.1
Pod undocumented
1710 101 my $self = shift;
1711 101 my $name = shift;
1712  
1713 101 ▶ return $name if File::Spec->file_name_is_absolute($name);
Branch: 1 branch
BranchTrueFalseTotal
if "File::Spec"->file_name_is_absolute($name) 15 86 101
1714  
1715 # Let's special-case the current working directory. Do not want to spell it
1716 # out for the directory search loop.
1717 # But yes, it is a bit of duplication with the .conf addition. Sorry.
1718 86 ▶ return $name if(INT_filelike($name));
Branch: 1 branch
BranchTrueFalseTotal
if INT_filelike($name) 2 84 86
1719 84 ▶ return "$name.conf" if(INT_filelike("$name.conf"));
Branch: 1 branch
BranchTrueFalseTotal
if INT_filelike("$name.conf") 0 84 84
1720  
1721 84 my $path;
1722 my @dirs;
1723 #determine directory to search config files in
1724 84 ▶ if(defined $self->{config}{confdir})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'config'}{'confdir'}) { } 0 84 84
1725 {
1726 0 @dirs = ($self->{config}{confdir});
1727 }
1728 else
1729 {
1730 @dirs = (
1731 File::Spec->catfile($ENV{HOME},'.'.$self->{config}{program})
1732 ,File::Spec->catfile($Bin,'..','etc',$self->{config}{program})
1733 ,File::Spec->catfile($Bin,'..','etc')
1734 ,File::Spec->catfile($Bin,'etc')
1735 ,$Bin
1736 ,File::Spec->catfile($ENV{HOME},'.config',$self->{config}{program})
1737 84 ,File::Spec->catfile($ENV{HOME},'.config')
1738 );
1739 }
1740  
1741 84 for my $d (@dirs)
1742 {
1743 566 my $f = File::Spec->catfile($d, $name);
1744 566 ▶ $f .= '.conf' unless INT_filelike($f);
Branch: 1 branch
BranchTrueFalseTotal
unless INT_filelike($f) 555 11 566
1745 566 ▶ if(INT_filelike($f))
Branch: 1 branch
BranchTrueFalseTotal
if (INT_filelike($f)) 11 555 566
1746 {
1747 11 $path = $f;
1748 11 last;
1749 }
1750 }
1751  
1752 84 ▶ $self->INT_verb_msg("Found config: $path\n") if defined $path;
Branch: 1 branch
BranchTrueFalseTotal
if defined $path 11 73 84
1753 84 return $path
1754 }
1755  
1756 # Parse one given file.
1757 sub parse_file
1758 17 ▶{
Subroutine parse_file: called CC=46 SCAR=46.1
Pod documented
1759 17 my $self = shift;
1760  
1761 17 my $confname = shift;
1762 17 my $construct = shift;
1763  
1764 17 my $lend = '(\012\015|\012|\015)';
1765 17 my $nlend = '[^\012\015]';
1766 17 my $olderrs = @{$self->{errors}};
1767 17 require IO::File;
1768  
1769 # TODO: Support loading multiple occurences in order.
1770 17 my $file = $self->INT_find_config($confname);
1771 17 my $cdat = new IO::File;
1772 17 ▶ if(not defined $file)
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $file) { } 0 17 17
elsif (grep {$_ eq $file;} @{$$self{'parse_chain'};}) { } 0 17 17
elsif ($cdat->open($file, '<')) { } 17 0 17
1773 {
1774 0 ▶ $self->INT_error("Couldn't find config file $confname!") unless $self->{config}{nocomplain};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"config"}{"nocomplain"} 0 0 0
1775 }
1776 5 elsif(grep {$_ eq $file} @{$self->{parse_chain}})
1777 {
1778 0 $self->INT_error("Trying to parse config file $file twice in one chain!");
1779 }
1780 elsif($cdat->open($file, '<'))
1781 {
1782 17 push(@{$self->{parse_chain}}, $file);
1783 17 push(@{$self->{files}}, $file);
1784 17 ▶ if(defined $self->{config}{binmode})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"binmode"}) 0 17 17
1785 {
1786 0 binmode($cdat, $self->{config}{binmode});
1787 }
1788 #do we need or want binmode for newlines?
1789 17 my $multiline = '';
1790 17 my $mcollect = 0;
1791 17 my $ender = '';
1792 17 my $mkey ='';
1793 17 my $mop = '';
1794 17 my %curpar;
1795 17 my $ln = 0;
1796 17 ▶ while(<$cdat>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $cdat)) 298 17 315
1797 {
1798 298 ++$ln;
1799 298 ▶ unless($mcollect)
Branch: 1 branch
BranchTrueFalseTotal
if ($mcollect) { } 35 263 298
1800 {
1801 263 ▶ next if ($_ =~ /^\s*#/ or $_ =~ /^\s*#?\s*$lend$/o);
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /^\s*#/ or $_ =~ /^\s*#?\s*$lend$/o 140 123 263
Condition100%3/3
$_ =~ /^\s*#/ or $_ =~ /^\s*#?\s*$lend$/o
l!l&&r!l&&!r
7961123
MC/DC100%2/2
$_ =~ /^\s*#/ or $_ =~ /^\s*#?\s*$lend$/o
$_ =~ /^\s*#/ $_ =~ /^\s*#?\s*$lend$/o
Truth table100%3/3
A or B
A= $_ =~ /^\s*#/B= $_ =~ /^\s*#?\s*$lend$/o
ABresult
1X1
011
000
1802  
1803 123 ▶ if($_ =~ /^=($nlend+)$lend*$/o)
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^=($nlend+)$lend*$/o) { } 39 84 123
1804 {
1805 39 my $meta = $1;
1806 39 ▶ if($construct)
Branch: 1 branch
BranchTrueFalseTotal
if ($construct) 13 26 39
1807 {
1808 13 ▶ if($meta =~ /^param file\s*(\(([^)]*)\)|)\s*for\s*(.+)$/)
Branch: 4 branches
BranchTrueFalseTotal
if ($meta =~ /^param file\s*(\(([^)]*)\)|)\s*for\s*(.+)$/) { } 1 12 13
elsif ($meta =~ /^version\s*(.+)$/) { } 0 12 12
elsif ($meta =~ /^info\s(.*)$/) { } 0 12 12
elsif ($meta =~ /^infopod\s(.*)$/) { } 0 12 12
1809 {
1810 1 $self->{config}{program} = $3;
1811 1 $self->INT_verb_msg("This file is for $self->{config}{program}.\n");
1812 1 ▶ if(defined $2 and $2 =~ /^(.+)$/)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $2 and $2 =~ /^(.+)$/) 0 1 1
Condition33%1/3
defined $2 and $2 =~ /^(.+)$/
!ll&&!rl&&r
100
MC/DC0%0/2
defined $2 and $2 =~ /^(.+)$/
defined $2 $2 =~ /^(.+)$/
Truth table33%1/3
A and B
A= defined $2B= $2 =~ /^(.+)$/
ABresult
0X0
100
111
1813 {
1814 0 for my $s (split(',', $1))
1815 {
1816 0 $self->INT_verb_msg("Activating option $s.\n");
1817 0 ▶ $self->INT_error("$file:$ln: eval option not supported anymore.") if($s eq 'eval');
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "eval" 0 0 0
1818 0 $self->{config}{$s} = 1;
1819 }
1820 }
1821 }
1822 elsif($meta =~ /^version\s*(.+)$/)
1823 {
1824 0 $self->{config}{version} = $1;
1825 }
1826 elsif($meta =~ /^info\s(.*)$/)
1827 {
1828 0 $self->{config}{info} .= $1."\n"; #dos, unix... whatever...
1829 }
1830 elsif($meta =~ /^infopod\s(.*)$/)
1831 {
1832 0 $self->{config}{infopod} .= $1."\n"; #dos, unix... whatever...
1833 }
1834 }
1835 # Groping for parameter description in any case.
1836 39 ▶ if($meta =~ /^(long|key)\s*(\S*)(\s*short\s*(\S)|)(\s*type\s*(\S+)|)/)
Branch: 3 branches
BranchTrueFalseTotal
if ($meta =~ /^(long|key)\s*(\S*)(\s*short\s*(\S)|)(\s*type\s*(\S+)|)/) { } 16 23 39
elsif ($meta =~ /^(help|desc)\s(.*)$/) { } 16 7 23
elsif ($meta =~ /^include\s*(.+)$/) { } 5 2 7
1837 {
1838 16 ▶ %curpar = (long=>$2, short=>defined $4 ? $4 : '', help=>'');
Branch: 1 branch
BranchTrueFalseTotal
defined $4 ? : 8 8 16
1839 16 ▶ my $type = defined $6 ? $6 : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $6 ? : 16 0 16
1840 16 ▶ if(exists $typemap{$type})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $typemap{$type}) { } 16 0 16
1841 {
1842 16 $curpar{value} = $initval[$typemap{$type}];
1843 16 $self->INT_verb_msg("switching to key $curpar{long} / $curpar{short}\n");
1844 }
1845 0 else{ $self->INT_error("$file:$ln: unknown type $type"); %curpar = (); }
1846 }
1847 elsif($meta =~ /^(help|desc)\s(.*)$/)
1848 {
1849 16 ▶ $curpar{help} .= $curpar{help} ne '' ? "\n" : "" . $2;
Branch: 1 branch
BranchTrueFalseTotal
$curpar{'help'} ne '' ? : 0 16 16
1850 }
1851 elsif($meta =~ /^include\s*(.+)$/)
1852 {
1853 5 my $incfile = $1;
1854 # Avoid endless looping by making this path explicit.
1855 # Search for config file vicious if you tell it to load ../config and that also contains ../config ...
1856 5 $self->INT_verb_msg("including $incfile\n");
1857 5 ▶ unless(File::Spec->file_name_is_absolute($incfile))
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($incfile)) 5 0 5
1858 {
1859 5 my $dir = dirname($file);
1860 5 $dir = File::Spec->rel2abs($dir);
1861 5 $incfile = File::Spec->catfile($dir, $incfile);
1862 5 ▶ $incfile .= '.conf'
Branch: 1 branch
BranchTrueFalseTotal
unless -e $incfile 0 5 5
1863 unless -e $incfile;
1864 }
1865 5 $self->parse_file($incfile, $construct);
1866 }
1867 }
1868 else
1869 {
1870 84 ▶ if($_ =~ /^\s*($parname)\s*($lopex)\s*($nlend*)$lend$/)
Branch: 3 branches
BranchTrueFalseTotal
if ($_ =~ /^\s*($parname)\s*($lopex)\s*($nlend*)$lend$/) { } 74 10 84
elsif ($_ =~ /^\s*($parname)\s*$lend$/) { } 0 10 10
elsif ($_ =~ /^\s*($parname)\s*([$ops]?)<<(.*)$/) { } 10 0 10
1871 {
1872 74 my ($par,$op,$val) = ($1,$2,$3);
1873 #remove trailing spaces
1874 74 $val =~ s/\s*$//;
1875 #remove quotes
1876 74 $val =~ s/^"(.*)"$/$1/;
1877 74 $self->INT_definery(\%curpar, $par, $construct);
1878 74 ▶ if(exists $self->{param}{$par})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'param'}{$par}) { } 71 3 74
1879 {
1880 71 $self->INT_verb_msg("Setting $par $op $val\n");
1881 71 $self->INT_apply_op($par, $op, $val, $file);
1882 }
1883 else
1884 {
1885 3 ▶ unless($self->{config}{ignore_unknown})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}{"ignore_unknown"}) 1 2 3
1886 {
1887 1 ▶ $self->{param}{help} = 1 if($self->{config}{nanny});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"config"}{"nanny"} 0 1 1
1888 1 $self->INT_error("$file:$ln: unknown parameter $par");
1889 }
1890 }
1891 }
1892 elsif($_ =~ /^\s*($parname)\s*$lend$/)
1893 {
1894 0 my $par = $1;
1895 0 $self->INT_definery(\%curpar, $par, $construct);
1896 0 ▶ if(exists $self->{param}{$par})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'param'}{$par}) { } 0 0 0
1897 {
1898 0 $self->INT_verb_msg("Setting $par so that it is true.\n");
1899 0 $self->{param}{$par} = $trueval[$self->{type}{$par}];
1900 }
1901 else
1902 {
1903 0 ▶ unless($self->{config}{ignore_unknown})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}{"ignore_unknown"}) 0 0 0
1904 {
1905 0 ▶ $self->{param}{help} = 1 if($self->{config}{nanny});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"config"}{"nanny"} 0 0 0
1906 0 $self->INT_error("$file:$ln: unknown parameter $par");
1907 }
1908 }
1909 }
1910 elsif($_ =~ /^\s*($parname)\s*([$ops]?)<<(.*)$/)
1911 {
1912 10 $ender = $3;
1913 10 ▶ $mop = $2 ne '' ? $2 : '=';
Branch: 1 branch
BranchTrueFalseTotal
$2 ne '' ? : 5 5 10
1914 10 $mkey = $1;
1915 10 $mcollect = 1;
1916 10 ▶ $mop .= '=' unless $mop =~ /=$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mop =~ /=$/ 5 5 10
1917 10 $self->INT_verb_msg("Reading for $mkey...(till $ender)\n");
1918 }
1919 }
1920 }
1921 else
1922 {
1923 35 $self->INT_verb_msg("collect: $_");
1924 35 ▶ unless($_ =~ /^$ender$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^$ender$/) { } 10 25 35
1925 {
1926 25 s/(^|$nlend)$lend$/$1\n/o;
1927 25 $multiline .= $_;
1928 }
1929 else
1930 {
1931 10 $mcollect = 0;
1932 # remove last line end
1933 10 $multiline =~ s/(^|$nlend)$lend$/$1/o;
1934 10 $self->INT_definery(\%curpar, $mkey, $construct);
1935 10 ▶ if(exists $self->{param}{$mkey})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'param'}{$mkey}) { } 10 0 10
1936 {
1937 # apply the config file options first, with eval() when desired
1938 10 $self->INT_apply_op($mkey, $mop, $multiline, $file);
1939 10 $self->INT_verb_msg("set $mkey from $multiline\n");
1940 }
1941 else
1942 {
1943 0 ▶ unless($self->{config}{ignore_unknown})
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}{"ignore_unknown"}) 0 0 0
1944 {
1945 0 ▶ if($self->{config}{nanny}){ $self->{param}{help} = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}{"nanny"}) 0 0 0
1946 0 $self->INT_error("$file:$ln: unknown parameter $mkey!");
1947 }
1948 }
1949  
1950 10 $multiline = '';
1951 }
1952 }
1953 }
1954 17 $cdat->close();
1955 17 $self->INT_verb_msg("... done parsing.\n");
1956 17 pop(@{$self->{parse_chain}});
1957 }
1958 0 ▶ else{ $self->INT_error("Couldn't open config file $file! ($!)") unless $self->{config}{nocomplain}; }
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"config"}{"nocomplain"} 0 0 0
1959  
1960 17 ▶ if(@{$self->{errors}} == $olderrs)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'errors'};} == $olderrs) { } 16 1 17
1961 {
1962 16 return 1
1963 } else
1964 {
1965 1 $self->{bad_config_file} = 1;
1966 1 return 0;
1967 }
1968 }
1969  
1970 # Just helper for the above, not gerneral-purpose.
1971  
1972 # Define a parameter in construction mode or when needed to accept something unknown.
1973 sub INT_definery
1974 84 ▶{
Subroutine INT_definery: called CC=9 SCAR=24.6
Pod undocumented
1975 84 my ($self, $curpar, $par, $construct) = @_;
1976 84 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (defined $curpar->{"long"} and $construct || $self->{"config"}{"accept_unknown"} && !exists $self->{"param"}{$par} && $curpar->{"long"} eq $par) 6 78 84
Condition58%7/12
defined $curpar->{"long"} and $construct || $self->{"config"}{"accept_unknown"} && !exists $self->{"param"}{$par} && $curpar->{"long"} eq $par
!ll&&!rl&&r
68106
$construct or $self->{"config"}{"accept_unknown"} and not exists $self->{"param"}{$par} and $curpar->{"long"} eq $par
l!l&&r!l&&!r
6010
$self->{"config"}{"accept_unknown"} and not exists $self->{"param"}{$par} and $curpar->{"long"} eq $par
!ll&&!rl&&r
1000
$self->{"config"}{"accept_unknown"} and not exists $self->{"param"}{$par}
!ll&&!rl&&r
1000
MC/DC40%2/5
defined $curpar->{"long"} and $construct || $self->{"config"}{"accept_unknown"} && !exists $self->{"param"}{$par} && $curpar->{"long"} eq $par
defined $curpar->{"long"} $construct $self->{"config"}{"accept_unknown"} not exists $self->{"param"}{$par} $curpar->{"long"} eq $par
Truth table50%3/6
A and B or C and not(D) and E
A= defined $curpar->{"long"}B= $constructC= $self->{"config"}{"accept_unknown"}D= not exists $self->{"param"}{$par}E= $curpar->{"long"} eq $par
ABCDEresult
0XXXX0
100XX0
1010X0
101100
11XXX1
101111
1977 defined $curpar->{long}
1978 and (
1979 $construct
1980 or
1981 (
1982 $self->{config}{accept_unknown}
1983 and not exists $self->{param}{$par}
1984 and $curpar->{long} eq $par
1985 ))
1986 6 ){ $self->define($curpar); }
1987  
1988 84 ▶ $self->define({long=>$par}) if(not exists $self->{param}{$par} and ($construct or $self->{config}{accept_unknown}));
Branch: 1 branch
BranchTrueFalseTotal
if not exists $self->{"param"}{$par} and $construct || $self->{"config"}{"accept_unknown"} 0 84 84
Condition50%3/6
not exists $self->{"param"}{$par} and $construct || $self->{"config"}{"accept_unknown"}
!ll&&!rl&&r
8130
$construct or $self->{"config"}{"accept_unknown"}
l!l&&r!l&&!r
003
MC/DC0%0/3
not exists $self->{"param"}{$par} and $construct || $self->{"config"}{"accept_unknown"}
not exists $self->{"param"}{$par} $construct $self->{"config"}{"accept_unknown"}
Truth table50%2/4
not(A) and B or C
A= not exists $self->{"param"}{$par}B= $constructC= $self->{"config"}{"accept_unknown"}
ABCresult
0XX0
1000
11X1
1011
1989 84 %{$curpar} = ();
1990 }
1991  
1992 # Print out a config file.
1993 sub print_file
1994 2 ▶{
Subroutine print_file: called CC=30 SCAR=35.4
Pod documented
1995 2 my ($self, $handle, $bare) = @_;
1996  
1997 2 my @omit = ('config','help');
1998 2 ▶ push(@omit,'version') if defined $self->{config}{version};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{"version"} 0 2 2
1999 0 ▶ push(@omit, @{$self->{config}{notinfile}}) if defined $self->{config}{notinfile};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{"notinfile"} 0 2 2
2000 2 ▶ unless($bare)
Branch: 1 branch
BranchTrueFalseTotal
unless ($bare) 2 0 2
2001 {
2002 2 print $handle <<EOT;
2003 # Configuration file for $self->{config}{program}
2004 #
2005 # Syntax:
2006 #
2007 EOT
2008 2 print $handle <<EOT;
2009 # name = value
2010 # or
2011 # name = "value"
2012 #
2013 # You can provide any number (including 0) of whitespaces before and after name and value. If you really want the whitespace in the value then use the second form and be happy;-)
2014 EOT
2015 2 print $handle <<EOT;
2016 # It is also possible to set multiline strings with
2017 # name <<ENDSTRING
2018 # ...
2019 # ENDSTRING
2020 #
2021 # (just like in Perl but omitting the ;)
2022 # You can use .=, +=, /= and *= instead of = as operators for concatenation of strings or pushing to arrays/hashes, addition, substraction, division and multiplication, respectively.
2023 # The same holds likewise for .<<, +<<, /<< and *<< .
2024 #
2025 # The short names are just provided as a reference; they're only working as real command line parameters, not in this file!
2026 #
2027 # The lines starting with "=" are needed for parsers of the file (other than $self->{config}{program} itself) and are informative to you, too.
2028 # =param file (options) for program
2029 # says for whom the file is and possibly some hints (options)
2030 # =info INFO
2031 # is the general program info (multiple lines, normally)
2032 # =long NAME short S type TYPE
2033 # says that now comes stuff for the parameter NAME and its short form is S. Data TYPE can be scalar, array or hash.
2034 # =help SOME_TEXT
2035 # gives a description for the parameter.
2036 #
2037 # If you don't like/need all this bloated text, the you can strip all "#", "=" - started and empty lines and the result will still be a valid configuration file for $self->{config}{program}.
2038  
2039 EOT
2040 }
2041 2 print $handle '=param file ';
2042 2 my @opt = (); # There are no relevant options currently.
2043 2 ▶ print $handle '('.join(',',@opt).') ' if @opt;
Branch: 1 branch
BranchTrueFalseTotal
if @opt 0 2 2
2044 2 print $handle 'for '.$self->{config}{program}."\n";
2045 2 ▶ print $handle '=version '.$self->{config}{version}."\n" if defined $self->{config}{version};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{"version"} 0 2 2
2046 2 print $handle "\n";
2047 2 ▶ if(defined $self->{config}{info} and !$bare)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"info"} and not $bare) 1 1 2
Condition66%2/3
defined $self->{"config"}{"info"} and not $bare
!ll&&!rl&&r
101
MC/DC50%1/2
defined $self->{"config"}{"info"} and not $bare
defined $self->{"config"}{"info"} not $bare
Truth table66%2/3
A and not(B)
A= defined $self->{"config"}{"info"}B= not $bare
ABresult
0X0
100
111
2048 {
2049 1 my @info = split("\n",$self->{config}{info});
2050 1 for(@info){ print $handle '=info '.$_."\n"; }
2051 }
2052 2 ▶ if(defined $self->{config}{infopod} and !$bare)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"config"}{"infopod"} and not $bare) 0 2 2
Condition33%1/3
defined $self->{"config"}{"infopod"} and not $bare
!ll&&!rl&&r
200
MC/DC0%0/2
defined $self->{"config"}{"infopod"} and not $bare
defined $self->{"config"}{"infopod"} not $bare
Truth table33%1/3
A and not(B)
A= defined $self->{"config"}{"infopod"}B= not $bare
ABresult
0X0
100
111
2053 {
2054 0 my @info = split("\n",$self->{config}{infopod});
2055 0 for(@info){ print $handle '=infopod '.$_."\n"; }
2056 }
2057 2 for my $k (sort keys %{$self->{param}})
2058 {
2059 15 ▶ unless(grep(/^$k$/, @omit))
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$k$/, @omit) 11 4 15
2060 {
2061 #make line ending changeable...
2062 #or use proper system-independent line end
2063 #for now we just use \n - what may even work with active perl
2064 #
2065 11 ▶ unless($bare)
Branch: 1 branch
BranchTrueFalseTotal
unless ($bare) 11 0 11
2066 {
2067 print $handle "\n=long $k"
2068 11 ▶ ,$self->{short}{$k} ne '' ? " short $self->{short}{$k}" : ''
Branch: 1 branch
BranchTrueFalseTotal
$self->{'short'}{$k} ne '' ? : 8 3 11
2069 ," type $typename[$self->{type}{$k}]"
2070 ,"\n";
2071 11 my @help = split("\n",${$self->{help}{$k}});
2072 11 for(@help)
2073 {
2074 11 print $handle "=help $_\n";
2075 }
2076 }
2077 11 ▶ my $values = $self->{type}{$k} ? $self->{param}{$k} : [ $self->{param}{$k} ];
Branch: 1 branch
BranchTrueFalseTotal
$self->{'type'}{$k} ? : 4 7 11
2078 11 ▶ if($self->{type}{$k} == $hash)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"type"}{$k} == $hash) 2 9 11
2079 {
2080 2 my @vals;
2081 2 for my $k (sort keys %{$values})
2082 {
2083 4 ▶ push(@vals, $k.(defined $values->{$k} ? '='.$values->{$k} : ''));
Branch: 1 branch
BranchTrueFalseTotal
defined $values->{$k} ? : 4 0 4
2084 }
2085 2 $values = \@vals;
2086 }
2087 11 ▶ $values = [ undef ] unless defined $values;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $values 0 11 11
2088 11 my $first = 1;
2089 11 ▶ print $handle "\n" unless $bare;
Branch: 1 branch
BranchTrueFalseTotal
unless $bare 11 0 11
2090 11 for my $v (@{$values})
2091 {
2092 my $preop = $self->{type}{$k}
2093 ? ( (not $first)
2094 ? '.'
2095 19 ▶ : ( (@{$values} > 1) ? ' ' : '' ) )
Branch: 3 branches
BranchTrueFalseTotal
$self->{'type'}{$k} ? : 12 7 19
!$first ? : 8 4 12
@{$values;} > 1 ? : 4 0 4
2096 : '';
2097 19 ▶ if(defined $v)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 18 1 19
2098 {
2099 18 ▶ if($v =~ /[\012\015]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /[\012\015]/) { } 1 17 18
2100 {
2101 1 my $end = 'EOT';
2102 1 my $num = '';
2103 1 $v =~ s/[\012\015]*\z/\n/g; # that line end business needs testing
2104 1 ▶ while($v =~ /(^|\n)$end$num(\n|$)/){ ++$num; }
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /(^|\n)$end$num(\n|$)/) 1 1 2
2105 1 print $handle "$k $preop<<$end$num\n$v$end$num\n";
2106 }
2107 17 else{ print $handle "$k $preop= \"$v\"\n"; }
2108 }
2109 1 else{ print $handle "# $k is undefined\n"; }
2110  
2111 19 $first = 0;
2112 }
2113 }
2114 }
2115 }
2116  
2117 sub INT_push_hash
2118 75 ▶{
Subroutine INT_push_hash: called CC=3 SCAR=11.3
Pod undocumented
2119 75 my $self = shift;
2120 75 my $par = shift; for (@_)
2121 {
2122 104 my ($k, $v) = split('=',$_,2);
2123 104 ▶ if(defined $k)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k) { } 104 0 104
2124 {
2125 104 $par->{$k} = $v;
2126 } else
2127 {
2128 0 $self->INT_error("Undefined key for hash $_[0]. Did you mean --$_[0]// to empty it?");
2129 }
2130 }
2131 }
2132  
2133 # The low-level worker for applying one parameter operation.
2134 sub INT_apply_op
2135 280 ▶{
Subroutine INT_apply_op: called CC=29 SCAR=34.8
Pod undocumented
2136 280 my $self = shift; # (par, op, value, file||undef)
2137  
2138 280 ▶ return unless exists $self->{param}{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"param"}{$_[0]} 0 280 280
2139  
2140 280 ▶ if($self->{type}{$_[0]} == $scalar)
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'type'}{$_[0]} == $scalar) { } 101 179 280
elsif ($self->{'type'}{$_[0]} == $array) { } 101 78 179
elsif ($self->{'type'}{$_[0]} == $hash) { } 78 0 78
2141 {
2142 12 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
2143 101 my $par = \$self->{param}{$_[0]}; # scalar ref
2144 101 ▶ if ($_[1] eq '='){ $$par = $_[2]; }
Branch: 6 branches
BranchTrueFalseTotal
if ($_[1] eq '=') { } 69 32 101
elsif ($_[1] eq '.=') { } 6 26 32
elsif ($_[1] eq '+=') { } 10 16 26
elsif ($_[1] eq '-=') { } 11 5 16
elsif ($_[1] eq '*=') { } 5 0 5
elsif ($_[1] eq '/=') { } 0 0 0
2145 6 elsif($_[1] eq '.='){ $$par .= $_[2]; }
2146 10 elsif($_[1] eq '+='){ $$par += $_[2]; }
2147 11 elsif($_[1] eq '-='){ $$par -= $_[2]; }
2148 5 elsif($_[1] eq '*='){ $$par *= $_[2]; }
2149 0 elsif($_[1] eq '/='){ $$par /= $_[2]; }
2150 0 else{ $self->INT_error("Operator '$_[1]' on '$_[0]' is invalid."); $self->{param}{help} = 1; }
2151 }
2152 elsif($self->{type}{$_[0]} == $array)
2153 {
2154 101 my $par = $self->{param}{$_[0]}; # array ref
2155 101 my $bad;
2156 101 ▶ if ($_[1] eq '='){ @{$par} = ( $_[2] ); }
Branch: 4 branches
BranchTrueFalseTotal
if ($_[1] eq '=') { } 18 83 101
elsif ($_[1] eq '.=') { } 54 29 83
elsif ($_[1] eq '//=' or $_[1] eq '/=' and $_[2] eq '/') { } 3 26 29
elsif ($_[1] =~ m[^/(.)/(.*)$]) { } 25 1 26
2157 54 elsif($_[1] eq '.='){ push(@{$par}, $_[2]); }
2158 3 ▶ elsif($_[1] eq '//=' or ($_[1] eq '/=' and $_[2] eq '/')){ @{$par} = (); }
Condition83%5/6
$_[1] eq "//=" or $_[1] eq "/=" and $_[2] eq "/"
l!l&&r!l&&!r
2126
$_[1] eq "/=" and $_[2] eq "/"
!ll&&!rl&&r
2601
MC/DC66%2/3
$_[1] eq "//=" or $_[1] eq "/=" and $_[2] eq "/"
$_[1] eq "//=" $_[1] eq "/=" $_[2] eq "/"
Truth table75%3/4
A or B and C
A= $_[1] eq "//="B= $_[1] eq "/="C= $_[2] eq "/"
ABCresult
1XX1
0111
00X0
0100
2159 elsif($_[1] =~ m:^/(.)/(.*)$:) # operator with specified array separator
2160 {
2161 25 my $sep = $1; # array separator
2162 25 my $op = $2; # actual operator
2163 25 my @values = split(/\Q$sep\E/, $_[2]);
2164 25 ▶ if ($op eq '='){ @{$par} = @values; }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '=') { } 11 14 25
elsif ($op eq '.=') { } 14 0 14
2165 14 elsif($op eq '.='){ push(@{$par}, @values); }
2166 0 else{ $bad = 1; }
2167 }
2168 1 else{ $bad = 1 }
2169 101 ▶ if($bad)
Branch: 1 branch
BranchTrueFalseTotal
if ($bad) 1 100 101
2170 {
2171 1 $self->INT_error("Operator '$_[1]' is invalid for array '$_[0]'!");
2172 #$self->{param}{help} = 1;
2173 }
2174 }
2175 elsif($self->{type}{$_[0]} == $hash)
2176 {
2177 78 my $par = $self->{param}{$_[0]}; # hash ref
2178 78 my $bad;
2179  
2180 78 ▶ if($_[1] =~ m:^/(.)/(.*)$:) # operator with specified array separator
Branch: 2 branches
BranchTrueFalseTotal
if ($_[1] =~ m[^/(.)/(.*)$]) { } 25 53 78
elsif ($_[1] eq '//=' or $_[1] eq '/=' and $_[2] eq '/') { } 3 50 53
2181 {
2182 25 my $sep = $1; # array separator
2183 25 my $op = $2; # actual operator
2184 25 my @values = split(/\Q$sep\E/, $_[2]);
2185 # a sub just to avoid duplicating the name=value splitting and setting
2186 25 ▶ if ($op eq '='){ %{$par} = (); $self->INT_push_hash($par,@values); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '=') { } 11 14 25
elsif ($op eq '.=') { } 14 0 14
2187 14 elsif($op eq '.='){ $self->INT_push_hash($par,@values); }
2188 0 else{ $bad = 1; }
2189 }
2190 ▶ elsif($_[1] eq '//=' or ($_[1] eq '/=' and $_[2] eq '/'))
Condition83%5/6
$_[1] eq "//=" or $_[1] eq "/=" and $_[2] eq "/"
l!l&&r!l&&!r
1250
$_[1] eq "/=" and $_[2] eq "/"
!ll&&!rl&&r
5002
MC/DC66%2/3
$_[1] eq "//=" or $_[1] eq "/=" and $_[2] eq "/"
$_[1] eq "//=" $_[1] eq "/=" $_[2] eq "/"
Truth table75%3/4
A or B and C
A= $_[1] eq "//="B= $_[1] eq "/="C= $_[2] eq "/"
ABCresult
1XX1
0111
00X0
0100
2191 {
2192 3 %{$par} = ();
2193 } else
2194 {
2195 50 ▶ if ($_[1] eq '='){ %{$par} = (); $self->INT_push_hash($par, $_[2]); }
Branch: 2 branches
BranchTrueFalseTotal
if ($_[1] eq '=') { } 12 38 50
elsif ($_[1] eq '.=') { } 38 0 38
2196 38 elsif($_[1] eq '.='){ $self->INT_push_hash($par, $_[2]); }
2197 0 else{ $bad = 1 }
2198 }
2199 78 ▶ if($bad)
Branch: 1 branch
BranchTrueFalseTotal
if ($bad) 0 78 78
2200 {
2201 0 $self->INT_error("Operator '$_[1]' is invalid for hash '$_[0]'!");
2202 0 $self->{param}{help} = 1;
2203 }
2204 }
2205 }
2206  
2207 sub INT_value_check
2208 60 ▶{
Subroutine INT_value_check: called CC=18 SCAR=29.0
Pod undocumented
2209 60 my $self = shift;
2210 60 my $p = $self->{param};
2211 60 my $olderr = @{$self->{errors}};
2212 60 for my $k (keys %{$self->{regex}})
2213 {
2214 140 ▶ if($self->{type}{$k} == $scalar)
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'type'}{$k} == $scalar) { } 64 76 140
elsif ($self->{'type'}{$k} == $array) { } 68 8 76
elsif ($self->{'type'}{$k} == $hash) { } 8 0 8
2215 {
2216 $self->INT_error("Value of $k does not match regex: $p->{$k}")
2217 64 ▶ unless $p->{$k} =~ $self->{regex}{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $p->{$k} =~ /$self->{"regex"}{$k}/ 0 64 64
2218 } elsif($self->{type}{$k} == $array)
2219 {
2220 68 ▶ for(my $i=0; $i<@{$p->{$k}}; ++$i)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$p->{$k};}) 15 68 83
2221 {
2222 $self->INT_error("Element $i of $k does not match regex: $p->{$k}[$i]")
2223 15 ▶ unless $p->{$k}[$i] =~ $self->{regex}{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $p->{$k}[$i] =~ /$self->{"regex"}{$k}/ 2 13 15
2224 }
2225 } elsif($self->{type}{$k} == $hash)
2226 {
2227 8 for my $n (sort keys %{$p->{$k}})
2228 {
2229 $self->INT_error("Element $n of $k does not match regex: $p->{$k}{$n}")
2230 4 ▶ unless $p->{$k}{$n} =~ $self->{regex}{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $p->{$k}{$n} =~ /$self->{"regex"}{$k}/ 0 4 4
2231 }
2232 }
2233 }
2234 60 for my $k (keys %{$p})
2235 {
2236 12 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
2237 next
2238 337 ▶ unless ($self->{flags}{$k} & $nonempty);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"flags"}{$k} & $nonempty 321 16 337
2239 16 ▶ unless(
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"type"}{$k} == $scalar and $p->{$k} ne "" or $self->{"type"}{$k} == $array and @{$p->{$k};} or $self->{"type"}{$k} == $hash and %{$p->{$k};}) 3 13 16
Condition91%11/12
$self->{"type"}{$k} == $scalar and $p->{$k} ne "" or $self->{"type"}{$k} == $array and @{$p->{$k};} or $self->{"type"}{$k} == $hash and %{$p->{$k};}
l!l&&r!l&&!r
1033
$self->{"type"}{$k} == $scalar and $p->{$k} ne "" or $self->{"type"}{$k} == $array and @{$p->{$k};}
l!l&&r!l&&!r
466
$self->{"type"}{$k} == $scalar and $p->{$k} ne ""
!ll&&!rl&&r
1204
$self->{"type"}{$k} == $array and @{$p->{$k};}
!ll&&!rl&&r
426
MC/DC40%2/5
$self->{"type"}{$k} == $scalar and $p->{$k} ne "" or $self->{"type"}{$k} == $array and @{$p->{$k};} or $self->{"type"}{$k} == $hash and %{$p->{$k};}
$self->{"type"}{$k} == $scalar $p->{$k} ne "" $self->{"type"}{$k} == $array @{$p->{$k};} $self->{"type"}{$k} == $hash and %{$p->{$k};}
Truth table36%4/11
A and B or C and D or E
A= $self->{"type"}{$k} == $scalarB= $p->{$k} ne ""C= $self->{"type"}{$k} == $arrayD= @{$p->{$k};}E= $self->{"type"}{$k} == $hash and %{$p->{$k};}
ABCDEresult
11XXX1
0X11X1
1011X1
0X0X11
0X1011
100X11
101011
0X0X00
0X1000
100X00
101000
2240 ( $self->{type}{$k} == $scalar and $p->{$k} ne '' ) or
2241 8 ▶ ( $self->{type}{$k} == $array and @{$p->{$k}} ) or
Condition100%3/3
$self->{"type"}{$k} == $hash and %{$p->{$k};}
!ll&&!rl&&r
213
MC/DC100%2/2
$self->{"type"}{$k} == $hash and %{$p->{$k};}
$self->{"type"}{$k} == $hash %{$p->{$k};}
Truth table100%3/3
A and B
A= $self->{"type"}{$k} == $hashB= %{$p->{$k};}
ABresult
0X0
100
111
2242 4 ( $self->{type}{$k} == $hash and %{$p->{$k}} )
2243 ){
2244 3 $self->INT_error("Parameter $k is empty but should not be.");
2245 }
2246 }
2247 60 return $olderr == @{$self->{errors}};
2248 }
2249  
2250 sub current_setup
2251 3 ▶{
Subroutine current_setup: called CC=4 SCAR=13.9
Pod documented
2252 3 require Storable;
2253 3 my $self = shift;
2254 3 my $config = Storable::dclone($self->{config});
2255 3 my @pardef;
2256 3 my $bin = builtins($self->{config});
2257 3 for my $p (sort keys %{$self->{param}})
2258 {
2259 24 ▶ next if $bin->{$p};
Branch: 1 branch
BranchTrueFalseTotal
if $bin->{$p} 6 18 24
2260 18 ▶ my $val = ref($self->{param}{$p}) ? Storable::dclone($self->{param}{$p}) : $self->{param}{$p};
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'param'}{$p} ? : 6 12 18
2261 18 push(@pardef, $p, $val, $self->{short}{$p}, ${$self->{help}{$p}});
2262 }
2263 3 return ($config, \@pardef);
2264 }
2265  
2266  
2267 # Little hepler for modifying the parameters.
2268 # Apply all collected operations to a specific parameter.
2269 sub INT_apply_ops
2270 206 ▶{
Subroutine INT_apply_ops: called CC=3 SCAR=11.0
Pod undocumented
2271 206 my $self = shift;
2272 206 my $key = shift;
2273 206 ▶ return unless defined $self->{ops}{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ops"}{$key} 62 144 206
2274 144 $self->INT_verb_msg("Param: applying (@{$self->{ops}{$key}}) to $key of type $self->{type}{$key}\n");
2275 144 ▶ while(@{$self->{ops}{$key}})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"ops"}{$key};}) 199 144 343
2276 {
2277 199 my $op = shift(@{$self->{ops}{$key}});
2278 199 my $val = shift(@{$self->{ops}{$key}});
2279 199 $self->INT_apply_op($key, $op, $val);
2280 }
2281 }
2282  
2283 sub INT_verb_msg
2284 1381 ▶{
Subroutine INT_verb_msg: called CC=3 SCAR=14.2
Pod undocumented
2285 1381 my $self = shift;
2286 1381 ▶ return unless ($verbose or $self->{config}{verbose});
Branch: 1 branch
BranchTrueFalseTotal
unless $verbose or $self->{"config"}{"verbose"} 1381 0 1381
Condition33%1/3
$verbose or $self->{"config"}{"verbose"}
l!l&&r!l&&!r
001381
MC/DC0%0/2
$verbose or $self->{"config"}{"verbose"}
$verbose $self->{"config"}{"verbose"}
Truth table33%1/3
A or B
A= $verboseB= $self->{"config"}{"verbose"}
ABresult
1X1
011
000
2287 0 print STDERR "[Config::Param] ", @_;
2288 }
2289  
2290 sub INT_error
2291 14 ▶{
Subroutine INT_error: called CC=2 SCAR=7.0
Pod undocumented
2292 14 my $self = shift;
2293 print STDERR "$self->{config}{program}: [Config::Param] Error: "
2294 14 ▶ , $_[0], "\n" unless $self->{config}{silenterr};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"config"}{"silenterr"} 0 14 14
2295 14 push(@{$self->{errors}}, $_[0]);
2296 14 return 1;
2297 }
2298  
2299 12 1;
2300  
2301 __END__
↑ Summary Param/FileWorker.pm »