Yath/Option.pm

filter: Statementstmt 82.2% 231 / 281 Branchbran 63.1% 96 / 152 Conditioncond 44.1% 45 / 102 MC/DCmcdc 14.5% 8 / 55 Subroutinesub 75.0% 33 / 44 Podpod 0.0% 0 / 35 totaltotal 61.7% 413 / 669 CC 130 SCAR 39.4
CC
130
Cov
70%
check_value
174.4
init
108.2
cli_docs
39.3
CRAP 51.4
« Yath/Instance.pm ↑ Summary Yath/Util.pm »
1 package Getopt::Yath::Option;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our @CARP_NOT = (
7 __PACKAGE__,
8 'Getopt::Yath',
9 'Getopt::Yath::Instance',
10 );
11  
12 1 ▶use Getopt::Yath::Util qw/mod2file fqmod/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Getopt::Yath::Term qw/USE_COLOR color/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 our $VERSION = '2.000008';
16  
17 1 use Getopt::Yath::HashBase qw{
18 <title
19 <field <name <short <alt <alt_no
20 <allow_underscore_in_alt
21  
22 <group
23 <prefix
24 <trace
25  
26 <module <no_module
27  
28 <maybe
29  
30 <applicable
31 <default <autofill <initialize <clear
32 <default_text <autofill_text
33 <normalize
34 +trigger
35  
36 <allowed_values
37 <allowed_values_text
38  
39 <from_env_vars
40 <clear_env_vars
41 <set_env_vars
42  
43 <category
44  
45 <description
46 +short_examples
47 +long_examples
48  
49 +forms
50  
51 <mod_adds_options
52  
53 <notes
54 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 0 ▶sub requires_arg { croak "'$_[0]' does not define requires_arg()" }
Subroutine requires_arg: not called CC=1 SCAR=6.9
Pod undocumented
57 0 ▶sub add_value { croak "'$_[0]' does not define add_value()" }
Subroutine add_value: not called CC=1 SCAR=6.9
Pod undocumented
58 0 ▶sub is_populated { croak "'$_[0]' does not define is_populated()" }
Subroutine is_populated: not called CC=1 SCAR=6.9
Pod undocumented
59 0 ▶sub no_arg_value { croak "'$_[0]' does not define no_arg_value()" }
Subroutine no_arg_value: not called CC=1 SCAR=6.9
Pod undocumented
60 0 ▶sub get_env_value { croak "'$_[0]' does not define get_env_value()" }
Subroutine get_env_value: not called CC=1 SCAR=6.9
Pod undocumented
61  
62 80 ▶sub can_set_env { 0 }
Subroutine can_set_env: called CC=1 SCAR=0.0
Pod undocumented
63 0 ▶sub requires_autofill { 0 }
Subroutine requires_autofill: not called CC=1 SCAR=6.9
Pod undocumented
64  
65 25 ▶sub allows_shortval { $_[0]->allows_arg }
Subroutine allows_shortval: called CC=1 SCAR=0.0
Pod undocumented
66 0 ▶sub allows_default { 0 }
Subroutine allows_default: not called CC=1 SCAR=6.9
Pod undocumented
67  
68 16 ▶sub allows_list { 0 }
Subroutine allows_list: called CC=1 SCAR=0.0
Pod undocumented
69  
70 0 ▶sub allows_arg { $_[0]->requires_arg }
Subroutine allows_arg: not called CC=1 SCAR=6.9
Pod undocumented
71 0 ▶sub allows_autofill { $_[0]->requires_autofill }
Subroutine allows_autofill: not called CC=1 SCAR=6.9
Pod undocumented
72  
73 7 ▶sub get_autofill_value { shift->_get___value(AUTOFILL(), @_) }
Subroutine get_autofill_value: called CC=1 SCAR=0.0
Pod undocumented
74 354 ▶sub get_default_value { shift->_get___value(DEFAULT(), @_) }
Subroutine get_default_value: called CC=1 SCAR=0.0
Pod undocumented
75  
76 ▶sub init_settings { }
Subroutine init_settings: called CC=1 SCAR=0.0
Pod undocumented
77 ▶sub finalize_settings { }
Subroutine finalize_settings: called CC=1 SCAR=0.0
Pod undocumented
78  
79 sub create {
80 16 ▶ my $class = shift;
Subroutine create: called CC=3 SCAR=11.2
Pod undocumented
81 16 my %params = @_;
82  
83 16 ▶ croak "create() cannot be called on an option subclass" unless $class eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
unless $class eq __PACKAGE__ 0 16 16
84  
85 16 ▶ my $type = delete $params{type} or croak "No 'type' specified";
Branch: 1 branch
BranchTrueFalseTotal
my $type = delete $params{"type"} or croak("No 'type' specified") 0 16 16
86  
87 16 my $new_class = fqmod($type, __PACKAGE__);
88 16 local $Carp::CarpLevel = $Carp::CarpLevel = 1;
89 16 return $new_class->new(%params);
90 }
91  
92 sub get_initial_value {
93 389 ▶ my $self = shift;
Subroutine get_initial_value: called CC=6 SCAR=17.9
Pod undocumented
94  
95 389 my $env = $self->from_env_vars;
96 389 ▶ for my $name (@{$env || []}) {
Branch: 1 branch
BranchTrueFalseTotal
$env or [] 377 12 389
97 19 my $env = "$name";
98 19 $env =~ s/^(!)//;
99 19 my $neg = $1;
100  
101 19 ▶ next unless exists $ENV{$env};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ENV{$env} 10 9 19
102 9 ▶ return $ENV{$env} unless $neg;
Branch: 1 branch
BranchTrueFalseTotal
unless $neg 7 2 9
103 2 ▶ return $ENV{$env} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{$env} ? : 1 1 2
104 }
105  
106 380 return $self->_get___value(INITIALIZE(), @_);
107 }
108  
109 sub get_clear_value {
110 2 ▶ my $self = shift;
Subroutine get_clear_value: called CC=1 SCAR=0.0
Pod undocumented
111  
112 2 return $self->_get___value(CLEAR(), @_);
113 }
114  
115 sub _get___value {
116 833 ▶ my $self = shift;
Subroutine _get___value: called CC=6 SCAR=18.5
117 833 my ($field, @args) = @_;
118  
119 833 ▶ return undef if $self->{+MAYBE} && $field eq INITIALIZE();
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"maybe"} and $field eq "initialize" 0 833 833
Condition33%1/3
$self->{"maybe"} and $field eq "initialize"
!ll&&!rl&&r
83300
MC/DC0%0/2
$self->{"maybe"} and $field eq "initialize"
$self->{"maybe"} $field eq "initialize"
Truth table33%1/3
A and B
A= $self->{"maybe"}B= $field eq "initialize"
ABresult
0X0
100
111
120  
121 833 ▶ return unless exists $self->{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$field} 539 294 833
122 294 my $val = $self->{$field}; # May be undef, that is fine if specified.
123 294 ▶ return $val unless ref($val);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $val 226 68 294
124 68 ▶ croak "'$field' values must either be simple scalars (not references) or a code ref that returns the '$field' value"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $val eq "CODE" 0 68 68
125 unless ref($val) eq 'CODE';
126 68 return $self->$val(@args);
127 }
128  
129 sub normalize_value {
130 34 ▶ my $self = shift;
Subroutine normalize_value: called CC=2 SCAR=7.6
Pod undocumented
131 34 my (@input) = @_;
132  
133 34 ▶ my $cb = $self->{+NORMALIZE} or return @input;
Branch: 1 branch
BranchTrueFalseTotal
my $cb = $self->{"normalize"} or return @input 34 0 34
134 0 return $cb->(@input);
135 }
136  
137 sub trigger {
138 531 ▶ my $self = shift;
Subroutine trigger: called CC=2 SCAR=6.9
Pod undocumented
139 531 ▶ my $cb = $self->{+TRIGGER} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $cb = $self->{"trigger"} or return 465 66 531
140 66 $self->$cb(@_);
141 }
142  
143 sub clear_field {
144 6 ▶ my $self = shift;
Subroutine clear_field: called CC=1 SCAR=0.0
Pod undocumented
145 6 my ($ref) = @_;
146 6 return $$ref = $self->get_clear_value();
147 }
148  
149 sub is_applicable {
150 503 ▶ my $self = shift;
Subroutine is_applicable: called CC=2 SCAR=7.6
Pod undocumented
151 503 my ($options, $settings) = @_;
152 503 ▶ my $cb = $self->{+APPLICABLE} or return 1;
Branch: 1 branch
BranchTrueFalseTotal
my $cb = $self->{"applicable"} or return 1 503 0 503
153 0 return $self->$cb($options, $settings);
154 }
155  
156 sub long_args {
157 0 ▶ my $self = shift;
Subroutine long_args: not called CC=2 SCAR=17.9
Pod undocumented
158  
159 0 ▶ return ($self->{+NAME}, @{$self->{+ALT} || []});
Branch: 1 branch
BranchTrueFalseTotal
$self->{"alt"} or [] 0 0 0
160 }
161  
162 sub trace_string {
163 0 ▶ my $self = shift;
Subroutine trace_string: not called CC=2 SCAR=17.9
Pod undocumented
164 0 ▶ my $trace = $self->{+TRACE} or return "[UNKNOWN]";
Branch: 1 branch
BranchTrueFalseTotal
my $trace = $self->{"trace"} or return "[UNKNOWN]" 0 0 0
165 0 return "$trace->[1] line $trace->[2]";
166 }
167  
168 sub long_examples {
169 28 ▶ my $self = shift;
Subroutine long_examples: called CC=2 SCAR=7.4
Pod undocumented
170 28 ▶ return @{$self->{+LONG_EXAMPLES}} if $self->{+LONG_EXAMPLES};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"long_examples"} 0 28 28
171 28 return @{$self->default_long_examples(@_)};
172 }
173  
174 sub short_examples {
175 16 ▶ my $self = shift;
Subroutine short_examples: called CC=2 SCAR=7.4
Pod undocumented
176 16 ▶ return @{$self->{+SHORT_EXAMPLES}} if $self->{+SHORT_EXAMPLES};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"short_examples"} 0 16 16
177 16 return @{$self->default_short_examples(@_)};
178 }
179  
180 sub init {
181 16 ▶ my $self = shift;
Subroutine init: called CC=43 SCAR=46.8
Pod undocumented
182  
183 croak "A trace is required"
184 16 ▶ unless $self->{+TRACE};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"trace"} 0 16 16
185  
186 croak "You must provide either 'module' (a module name for dynamic loading) or set 'no_module'"
187 16 ▶ unless $self->{+MODULE} || $self->{+NO_MODULE};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"module"} or $self->{"no_module"} 0 16 16
Condition66%2/3
$self->{"module"} or $self->{"no_module"}
l!l&&r!l&&!r
1150
MC/DC0%0/2
$self->{"module"} or $self->{"no_module"}
$self->{"module"} $self->{"no_module"}
Truth table66%2/3
A or B
A= $self->{"module"}B= $self->{"no_module"}
ABresult
1X1
011
000
188  
189 croak "You must specify 'title' or both 'field' and 'name'"
190 16 ▶ unless $self->{+TITLE} || ($self->{+FIELD} && $self->{+NAME});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"title"} or $self->{"field"} and $self->{"name"} 0 16 16
Condition16%1/6
$self->{"title"} or $self->{"field"} and $self->{"name"}
l!l&&r!l&&!r
1600
$self->{"field"} and $self->{"name"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"title"} or $self->{"field"} and $self->{"name"}
$self->{"title"} $self->{"field"} $self->{"name"}
Truth table25%1/4
A or B and C
A= $self->{"title"}B= $self->{"field"}C= $self->{"name"}
ABCresult
1XX1
0111
00X0
0100
191  
192 croak "The 'group' attribute is required"
193 16 ▶ unless $self->{+GROUP};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"group"} 0 16 16
194  
195 croak "'set_env_vars' is not supported for this option type"
196 16 ▶ if $self->{+SET_ENV_VARS} && !$self->can_set_env;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"set_env_vars"} and not $self->can_set_env 0 16 16
Condition66%2/3
$self->{"set_env_vars"} and not $self->can_set_env
!ll&&!rl&&r
1420
MC/DC0%0/2
$self->{"set_env_vars"} and not $self->can_set_env
$self->{"set_env_vars"} not $self->can_set_env
Truth table66%2/3
A and not(B)
A= $self->{"set_env_vars"}B= not $self->can_set_env
ABresult
0X0
100
111
197  
198 croak "The 'alt' attribute must be an array-ref"
199 16 ▶ if $self->{+ALT} && ref($self->{+ALT}) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"alt"} and ref $self->{"alt"} ne "ARRAY" 0 16 16
Condition66%2/3
$self->{"alt"} and ref $self->{"alt"} ne "ARRAY"
!ll&&!rl&&r
1330
MC/DC0%0/2
$self->{"alt"} and ref $self->{"alt"} ne "ARRAY"
$self->{"alt"} ref $self->{"alt"} ne "ARRAY"
Truth table66%2/3
A and B
A= $self->{"alt"}B= ref $self->{"alt"} ne "ARRAY"
ABresult
0X0
100
111
200  
201 croak "The 'alt_no' attribute must be an array-ref"
202 16 ▶ if $self->{+ALT_NO} && ref($self->{+ALT_NO}) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"alt_no"} and ref $self->{"alt_no"} ne "ARRAY" 0 16 16
Condition33%1/3
$self->{"alt_no"} and ref $self->{"alt_no"} ne "ARRAY"
!ll&&!rl&&r
1600
MC/DC0%0/2
$self->{"alt_no"} and ref $self->{"alt_no"} ne "ARRAY"
$self->{"alt_no"} ref $self->{"alt_no"} ne "ARRAY"
Truth table33%1/3
A and B
A= $self->{"alt_no"}B= ref $self->{"alt_no"} ne "ARRAY"
ABresult
0X0
100
111
203  
204 16 ▶ $self->{+MODULE} //= $self->{+TRACE}->[0] unless $self->{+NO_MODULE};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_module"} 1 15 16
Condition33%1/3
$self->{"module"} //= $self->{"trace"}[0]
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{"module"} //= $self->{"trace"}[0]
$self->{"module"} $self->{"trace"}[0]
Truth table33%1/3
A //= B
A= $self->{"module"}B= $self->{"trace"}[0]
ABresult
1X1
011
000
205  
206 16 ▶ if (my $title = $self->{+TITLE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $title = $self->{"title"}) 16 0 16
207 16 ▶ $self->{+FIELD} //= $title;
Condition33%1/3
$self->{"field"} //= $title
l!l&&r!l&&!r
0160
MC/DC0%0/2
$self->{"field"} //= $title
$self->{"field"} $title
Truth table33%1/3
A //= B
A= $self->{"field"}B= $title
ABresult
1X1
011
000
208 16 ▶ $self->{+NAME} //= $title;
Condition33%1/3
$self->{"name"} //= $title
l!l&&r!l&&!r
0160
MC/DC0%0/2
$self->{"name"} //= $title
$self->{"name"} $title
Truth table33%1/3
A //= B
A= $self->{"name"}B= $title
ABresult
1X1
011
000
209 }
210  
211 16 $self->{+FIELD} =~ s/-/_/g;
212 16 $self->{+NAME} =~ s/_/-/g;
213  
214 16 ▶ unless ($self->allow_underscore_in_alt) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->allow_underscore_in_alt) 16 0 16
215 16 ▶ for my $alt (@{$self->{+ALT} // []}) {
Condition100%2/2
$self->{"alt"} // []
l!l
313
MC/DC100%1/1
$self->{"alt"} // []
$self->{"alt"}
Truth table100%2/2
A
A= $self->{"alt"}
Aresult
11
00
216 3 ▶ next unless $alt =~ m/_/;
Branch: 1 branch
BranchTrueFalseTotal
unless $alt =~ /_/ 3 0 3
217 0 croak "alt option form '$alt' contains an underscore, replace it with a '-' or set 'allow_underscore_in_alt' to true";
218 }
219 }
220  
221 croak "'default' is not allowed (did you mean 'initialize'" . ($self->allows_autofill ? " or 'autofill'" : "") . "?)"
222 16 ▶ if $self->{+DEFAULT} && !$self->allows_default;
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"default"} and not $self->allows_default 0 16 16
$self->allows_autofill ? : 0 0 0
Condition66%2/3
$self->{"default"} and not $self->allows_default
!ll&&!rl&&r
970
MC/DC0%0/2
$self->{"default"} and not $self->allows_default
$self->{"default"} not $self->allows_default
Truth table66%2/3
A and not(B)
A= $self->{"default"}B= not $self->allows_default
ABresult
0X0
100
111
223  
224 16 ▶ croak "'autofill' is required" if $self->requires_autofill && !$self->{+AUTOFILL};
Branch: 1 branch
BranchTrueFalseTotal
if $self->requires_autofill and not $self->{"autofill"} 1 15 16
Condition100%3/3
$self->requires_autofill and not $self->{"autofill"}
!ll&&!rl&&r
1141
MC/DC100%2/2
$self->requires_autofill and not $self->{"autofill"}
$self->requires_autofill not $self->{"autofill"}
Truth table100%3/3
A and not(B)
A= $self->requires_autofillB= not $self->{"autofill"}
ABresult
0X0
100
111
225 15 ▶ croak "'autofill' is not allowed" if $self->{+AUTOFILL} && !$self->allows_autofill;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"autofill"} and not $self->allows_autofill 0 15 15
Condition66%2/3
$self->{"autofill"} and not $self->allows_autofill
!ll&&!rl&&r
1140
MC/DC0%0/2
$self->{"autofill"} and not $self->allows_autofill
$self->{"autofill"} not $self->allows_autofill
Truth table66%2/3
A and not(B)
A= $self->{"autofill"}B= not $self->allows_autofill
ABresult
0X0
100
111
226  
227 15 for my $field (DEFAULT(), AUTOFILL(), INITIALIZE()) {
228 45 ▶ my $val = $self->{$field} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $val = $self->{$field} or next 33 12 45
229 12 ▶ my $ref = ref($val) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $ref = ref $val or next 6 6 12
230 6 ▶ croak "'$field' must be a simple scalar, or a coderef, got a '$ref'" if $ref && $ref ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $ref and $ref ne "CODE" 0 6 6
Condition33%1/3
$ref and $ref ne "CODE"
!ll&&!rl&&r
060
MC/DC0%0/2
$ref and $ref ne "CODE"
$ref $ref ne "CODE"
Truth table33%1/3
A and B
A= $refB= $ref ne "CODE"
ABresult
0X0
100
111
231 }
232  
233 15 for my $field (NORMALIZE(), APPLICABLE(), TRIGGER()) {
234 45 ▶ my $val = $self->{$field} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $val = $self->{$field} or next 44 1 45
235 1 ▶ my $ref = ref($val) || 'not a ref';
Condition50%1/2
ref $val || 'not a ref'
l!l
10
MC/DC0%0/1
ref $val || 'not a ref'
ref $val
Truth table50%1/2
A
A= ref $val
Aresult
11
00
236 1 ▶ next if $ref eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "CODE" 1 0 1
237 0 croak "'$field' must be undef, or a coderef, got '$ref'";
238 }
239  
240 15 ▶ $self->{+CATEGORY} //= 'NO CATEGORY - FIX ME';
Condition50%1/2
$self->{"category"} //= "NO CATEGORY - FIX ME"
l!l
150
MC/DC0%0/1
$self->{"category"} //= "NO CATEGORY - FIX ME"
$self->{"category"}
Truth table50%1/2
A
A= $self->{"category"}
Aresult
11
00
241 15 ▶ $self->{+DESCRIPTION} //= 'NO DESCRIPTION - FIX ME';
Condition100%2/2
$self->{"description"} //= "NO DESCRIPTION - FIX ME"
l!l
114
MC/DC100%1/1
$self->{"description"} //= "NO DESCRIPTION - FIX ME"
$self->{"description"}
Truth table100%2/2
A
A= $self->{"description"}
Aresult
11
00
242  
243 15 for my $key (sort keys %$self) {
244 156 ▶ croak "'$key' is not a valid option attribute" unless $self->can(uc($key));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can(uc $key) 0 156 156
245 }
246  
247 15 return $self;
248 }
249  
250 sub check_value {
251 44 ▶ my $self = shift;
Subroutine check_value: called CC=17 SCAR=51.6
Pod undocumented
252 44 my ($val) = @_;
253  
254 44 ▶ return unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 44 44
255  
256 44 ▶ $val = [$val] unless ref($val) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $val eq "ARRAY" 0 44 44
257  
258 44 ▶ my $av = $self->allowed_values or return;
Branch: 1 branch
BranchTrueFalseTotal
my $av = $self->allowed_values or return 44 0 44
259 0 my $r = ref($av);
260  
261 0 my @bad;
262 0 for my $v (@$val) {
263 0 my $ok = 1;
264 0 ▶ if ($r eq 'CODE') {
Branch: 3 branches
BranchTrueFalseTotal
if ($r eq 'CODE') { } 0 0 0
elsif ($r =~ /Regex/i) { } 0 0 0
elsif ($r eq 'ARRAY') { } 0 0 0
265 0 $ok = $self->$av($v);
266 }
267 elsif ($r =~ /Regex/i) {
268 0 $ok = $v =~ $av;
269 }
270 elsif($r eq 'ARRAY') {
271 0 $ok = 0;
272 0 for my $c (@$av) {
273 0 ▶ next unless defined $c;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 0 0
274 1 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
275 0 ▶ $ok = 1 and last if $c eq $v;
Branch: 1 branch
BranchTrueFalseTotal
if $c eq $v 0 0 0
Condition0%0/5
$c eq $v && (($ok = 1) && (last))
!ll&&!rl&&r
000
$ok = 1 and last
!ll
00
MC/DC0%0/2
$c eq $v && (($ok = 1) && (last))
$c eq $v $ok = 1
Truth table0%0/3
A && B
A= $c eq $vB= $ok = 1
ABresult
0X0
100
111
276 0 ▶ $ok = 1 and last if 0+$c && 0+$v && $c == $v;
Branch: 1 branch
BranchTrueFalseTotal
if 0 + $c and 0 + $v and $c == $v 0 0 0
Condition0%0/11
0 + $c && 0 + $v && $c == $v && (($ok = 1) && (last))
!ll&&!rl&&r
000
0 + $c and 0 + $v and $c == $v
!ll&&!rl&&r
000
0 + $c and 0 + $v
!ll&&!rl&&r
000
$ok = 1 and last
!ll
00
MC/DC0%0/4
0 + $c && 0 + $v && $c == $v && (($ok = 1) && (last))
0 + $c 0 + $v $c == $v $ok = 1
Truth table0%0/5
A and B and C && D
A= 0 + $cB= 0 + $vC= $c == $vD= $ok = 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
277 }
278 }
279 else {
280 0 die "Invalid value check '$av' ($r) defined at " . $self->trace_string . ".\n";
281 }
282 0 ▶ next if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
283  
284 0 push @bad => $v;
285 }
286  
287 0 return @bad;
288 }
289  
290 sub forms {
291 509 ▶ my $self = shift;
Subroutine forms: called CC=11 SCAR=24.2
Pod undocumented
292 509 ▶ return $self->{+FORMS} if $self->{+FORMS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"forms"} 494 15 509
293  
294 15 my $forms = $self->{+FORMS} = {};
295  
296 15 ▶ $forms->{'-' . $self->{+SHORT}} = 1 if $self->{+SHORT};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"short"} 8 7 15
297  
298 15 ▶ my $prefix = $self->prefix // '';
Condition50%1/2
$self->prefix // ""
l!l
015
MC/DC0%0/1
$self->prefix // ""
$self->prefix
Truth table50%1/2
A
A= $self->prefix
Aresult
11
00
299 15 ▶ $prefix .= '-' if length $prefix;
Branch: 1 branch
BranchTrueFalseTotal
if length $prefix 0 15 15
300  
301 15 ▶ $forms->{$_} = 1 for map { "--${prefix}$_" } @{$self->{+ALT} // []};
Condition100%2/2
$self->{"alt"} // []
l!l
312
MC/DC100%1/1
$self->{"alt"} // []
$self->{"alt"}
Truth table100%2/2
A
A= $self->{"alt"}
Aresult
11
00
302 15 ▶ $forms->{$_} = -1 for map { "--no-${prefix}$_" } @{$self->{+ALT} // []};
Condition100%2/2
$self->{"alt"} // []
l!l
312
MC/DC100%1/1
$self->{"alt"} // []
$self->{"alt"}
Truth table100%2/2
A
A= $self->{"alt"}
Aresult
11
00
303 15 ▶ $forms->{$_} = -1 for map { "--${prefix}$_" } @{$self->{+ALT_NO} // []};
Condition50%1/2
$self->{"alt_no"} // []
l!l
015
MC/DC0%0/1
$self->{"alt_no"} // []
$self->{"alt_no"}
Truth table50%1/2
A
A= $self->{"alt_no"}
Aresult
11
00
304  
305 15 my $name = $self->name;
306 15 $forms->{"--${prefix}${name}"} = 1;
307 15 $forms->{"--no-${prefix}${name}"} = -1;
308  
309 15 return $forms;
310 }
311  
312 sub _example_append {
313 24 ▶ my $self = shift;
Subroutine _example_append: called CC=5 SCAR=16.1
314 24 my ($params, @prefixes) = @_;
315  
316 24 ▶ return unless $self->allows_list;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->allows_list 16 8 24
317  
318 8 ▶ my $groups = $params->{groups} // {};
Condition100%2/2
$params->{"groups"} // {}
l!l
44
MC/DC100%1/1
$params->{"groups"} // {}
$params->{"groups"}
Truth table100%2/2
A
A= $params->{"groups"}
Aresult
11
00
319  
320 8 my @out;
321  
322 8 for my $prefix (@prefixes) {
323 12 for my $group (sort keys %$groups) {
324 6 push @out => "${prefix}${group} ARG1 ARG2 ... $groups->{$group}";
325 }
326 }
327  
328 8 return @out;
329 }
330  
331 sub default_long_examples {
332 26 ▶ my $self = shift;
Subroutine default_long_examples: called CC=3 SCAR=11.0
Pod undocumented
333 26 my %params = @_;
334  
335 26 ▶ return [''] unless $self->allows_arg;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->allows_arg 6 20 26
336  
337 20 ▶ if ($self->requires_arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->requires_arg) 12 8 20
338 12 return [' ARG', '=ARG', $self->_example_append(\%params, ' ', '=')];
339 }
340  
341 8 return ['', '=ARG', $self->_example_append(\%params, '=')];
342 }
343  
344 sub default_short_examples {
345 6 ▶ my $self = shift;
Subroutine default_short_examples: called CC=5 SCAR=16.8
Pod undocumented
346 6 my %params = @_;
347  
348 6 ▶ return [''] unless $self->allows_arg;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->allows_arg 2 4 6
349  
350 4 ▶ if ($self->requires_arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->requires_arg) 2 2 4
351 2 ▶ return ['ARG', ' ARG', '=ARG', $self->_example_append(\%params, '', ' ', '=')] if $self->allows_shortval;
Branch: 1 branch
BranchTrueFalseTotal
if $self->allows_shortval 2 0 2
352 0 return [' ARG', '=ARG', $self->_example_append(\%params, ' ', '=')];
353 }
354  
355 2 ▶ return ['', 'ARG', '=ARG', $self->_example_append(\%params, '', '=')] if $self->allows_shortval;
Branch: 1 branch
BranchTrueFalseTotal
if $self->allows_shortval 2 0 2
356 0 return ['', '=ARG', $self->_example_append(\%params, '=')];
357 }
358  
359 sub doc_forms {
360 28 ▶ my $self = shift;
Subroutine doc_forms: called CC=9 SCAR=22.1
Pod undocumented
361 28 my %params = @_;
362  
363 28 my $name = $self->{+NAME};
364 28 ▶ my $prefix = $self->{+PREFIX} ? "$self->{+PREFIX}-" : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'prefix'} ? : 0 28 28
365  
366 28 my @long_examples = $self->long_examples(%params);
367 28 my @forms = (map { "--${prefix}${name}${_}" } @long_examples );
368  
369 28 ▶ for my $alt (@{$self->{+ALT} || []}) {
Branch: 1 branch
BranchTrueFalseTotal
$self->{"alt"} or [] 22 6 28
370 6 push @forms => (map { "--${prefix}${alt}${_}" } @long_examples);
371 }
372  
373 28 ▶ if (my $short = $self->{+SHORT}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $short = $self->{"short"}) 16 12 28
374 16 my @short_examples = $self->short_examples(%params);
375 16 push @forms => map { "-${short}${_}" } @short_examples;
376 }
377  
378 @forms = sort {
379 28 $a =~ m/^(-+)/;
380 195 ▶ my $al = length($1 // '');
Condition50%1/2
$1 // ""
l!l
1950
MC/DC0%0/1
$1 // ""
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
381 195 $b =~ m/^(-+)/;
382 195 ▶ my $bl = length($1 // '');
Condition50%1/2
$1 // ""
l!l
1950
MC/DC0%0/1
$1 // ""
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
383 195 ▶ $al <=> $bl || length($a) <=> length($b);
Branch: 1 branch
BranchTrueFalseTotal
$al <=> $bl or length $a <=> length $b 136 59 195
384 } @forms;
385  
386 28 my @no_forms;
387 28 push @no_forms => "--no-${prefix}${name}";
388 28 ▶ push @no_forms => map { "--$_" } @{$self->{+ALT_NO} // []};
Condition50%1/2
$self->{"alt_no"} // []
l!l
028
MC/DC0%0/1
$self->{"alt_no"} // []
$self->{"alt_no"}
Truth table50%1/2
A
A= $self->{"alt_no"}
Aresult
11
00
389  
390 28 return \@forms, \@no_forms;
391 }
392  
393 sub cli_docs {
394 14 ▶ my $self = shift;
Subroutine cli_docs: called CC=21 SCAR=36.7
Pod undocumented
395 14 my %params = @_;
396  
397 14 ▶ $params{color} //= USE_COLOR && -t STDOUT;
Condition33%1/3
$params{"color"} //= -t STDOUT
l!l&&r!l&&!r
1400
MC/DC0%0/2
$params{"color"} //= -t STDOUT
$params{"color"} -t STDOUT
Truth table33%1/3
A //= B
A= $params{"color"}B= -t STDOUT
ABresult
1X1
011
000
398  
399 14 my ($forms, $no_forms, $other_forms) = $self->doc_forms(%params);
400  
401 14 my @out;
402 14 ▶ if ($params{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'color'}) { } 0 14 14
403 @out = (
404 color('underline white') . $self->{+NAME} . color('reset'),
405 0 ▶ (map { color('green') . $_ . color('reset') } @{$forms // []}),
Condition0%0/2
$forms // []
l!l
00
MC/DC0%0/1
$forms // []
$forms
Truth table0%0/2
A
A= $forms
Aresult
11
00
406 0 ▶ (map { color('yellow') . $_ . color('reset') } @{$no_forms // []}),
Condition0%0/2
$no_forms // []
l!l
00
MC/DC0%0/1
$no_forms // []
$no_forms
Truth table0%0/2
A
A= $no_forms
Aresult
11
00
407 0 ▶ (map { color('cyan') . $_ . color('reset') } @{$other_forms // []}),
Condition0%0/2
$other_forms // []
l!l
00
MC/DC0%0/1
$other_forms // []
$other_forms
Truth table0%0/2
A
A= $other_forms
Aresult
11
00
408 );
409 }
410 else {
411 @out = (
412 "[$self->{+NAME}]",
413 14 ▶ @{$forms // []},
Condition50%1/2
$forms // []
l!l
140
MC/DC0%0/1
$forms // []
$forms
Truth table50%1/2
A
A= $forms
Aresult
11
00
414 14 ▶ @{$no_forms // []},
Condition50%1/2
$no_forms // []
l!l
140
MC/DC0%0/1
$no_forms // []
$no_forms
Truth table50%1/2
A
A= $no_forms
Aresult
11
00
415 14 ▶ @{$other_forms // []},
Condition50%1/2
$other_forms // []
l!l
014
MC/DC0%0/1
$other_forms // []
$other_forms
Truth table50%1/2
A
A= $other_forms
Aresult
11
00
416 );
417 }
418  
419 14 push @out => Getopt::Yath::Term::fit_to_width(" ", $self->{+DESCRIPTION}, prefix => " ");
420  
421 14 ▶ push @out => "\n" . Getopt::Yath::Term::fit_to_width(" ", "Can also be set with the following environment variables: " . join(", ", @{$self->{+FROM_ENV_VARS}}), prefix => " ") if $self->{+FROM_ENV_VARS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"from_env_vars"} 2 12 14
422 14 ▶ push @out => "\n" . Getopt::Yath::Term::fit_to_width(" ", "The following environment variables will be cleared after arguments are processed: " . join(", ", @{$self->{+CLEAR_ENV_VARS}}), prefix => " ") if $self->{+CLEAR_ENV_VARS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"clear_env_vars"} 2 12 14
423 14 ▶ push @out => "\n" . Getopt::Yath::Term::fit_to_width(" ", "The following environment variables will be set after arguments are processed: " . join(", ", @{$self->{+SET_ENV_VARS}}), prefix => " ") if $self->{+SET_ENV_VARS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"set_env_vars"} 2 12 14
424  
425 14 ▶ if (my @notes = $self->notes) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@notes) = $self->notes) 14 0 14
426 14 my %seen;
427 14 ▶ push @out => map { "\n" . Getopt::Yath::Term::fit_to_width(" ", "Note: $_", prefix => " ") } grep { $_ && !$seen{$_}++ } @notes;
Branch: 1 branch
BranchTrueFalseTotal
$_ and not $seen{$_}++ 5 14 19
428 }
429  
430 14 for my $field (qw/default autofill/) {
431 28 my $t = "${field}_text";
432 28 ▶ my $val = $self->$t || $self->$field // next;
Condition80%4/5
($self->$t || $self->$field) // (next)
l!l
1216
$self->$t or $self->$field
l!l&&r!l&&!r
01216
MC/DC50%1/2
($self->$t || $self->$field) // (next)
$self->$t $self->$field
Truth table66%2/3
A or B
A= $self->$tB= $self->$field
ABresult
1X1
011
000
433 12 ▶ next if ref($val);
Branch: 1 branch
BranchTrueFalseTotal
if ref $val 6 6 12
434 6 push @out => "\n" . Getopt::Yath::Term::fit_to_width(" ", "$field: $val", prefix => " ");
435 }
436  
437 14 ▶ if (my $avt = $self->allowed_values_text) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $avt = $self->allowed_values_text) { } 0 14 14
elsif (my $vals = $self->allowed_values) { } 0 14 14
438 0 push @out => "\n" . Getopt::Yath::Term::fit_to_width(" ", "Allowed Values: $avt", prefix => " ");
439 }
440 elsif (my $vals = $self->allowed_values) {
441 0 ▶ push @out => "\n" . Getopt::Yath::Term::fit_to_width(" ", "Allowed Values: " . join(", " => @$vals), prefix => " ") if @$vals;
Branch: 1 branch
BranchTrueFalseTotal
if @$vals 0 0 0
442 }
443  
444 14 return join "\n" => @out;
445 }
446  
447 sub pod_docs {
448 14 ▶ my $self = shift;
Subroutine pod_docs: called CC=5 SCAR=16.1
Pod undocumented
449 14 my %params = @_;
450  
451 14 my ($forms, $no_forms, $other_forms) = $self->doc_forms(%params);
452  
453 14 my @out = map { "=item $_" } grep { $_ } @$forms, @$no_forms, @$other_forms;
454  
455 14 push @out => $self->description;
456  
457 14 ▶ push @out => "Can also be set with the following environment variables: " . join(", ", map { "C<$_>" } @{$self->{+FROM_ENV_VARS}}) if $self->{+FROM_ENV_VARS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"from_env_vars"} 2 12 14
458 14 ▶ push @out => "The following environment variables will be cleared after arguments are processed: " . join(", ", map { "C<$_>" } @{$self->{+CLEAR_ENV_VARS}}) if $self->{+CLEAR_ENV_VARS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"clear_env_vars"} 2 12 14
459 14 ▶ push @out => "The following environment variables will be set after arguments are processed: " . join(", ", map { "C<$_>" } @{$self->{+SET_ENV_VARS}}) if $self->{+SET_ENV_VARS};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"set_env_vars"} 2 12 14
460  
461 14 my %seen;
462 14 ▶ push @out => map { "Note: $_" } grep { $_ && !$seen{$_}++ } $self->notes;
Branch: 1 branch
BranchTrueFalseTotal
$_ and not $seen{$_}++ 5 14 19
463  
464 14 return join("\n\n" => @out) . "\n";
465 }
466  
467 1 1;
468  
469 __END__
« Yath/Instance.pm ↑ Summary Yath/Util.pm »