blib/lib/Getopt/Long/Less.pm

filter: Statementstmt 84.5% 159 / 188 Branchbran 74.1% 92 / 124 Conditioncond 69.1% 65 / 94 MC/DCmcdc 53.3% 24 / 45 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 4 totaltotal 74.9% 350 / 467 CC 103 SCAR 36.9
CC
103
Cov
78%
Configure
132.0
GetOptionsFromArray
44.0
__ANON__
34.8
CRAP 39.9
↑ Summary
1 package Getopt::Long::Less;
2  
3 2 our $DATE = '2019-02-02'; # DATE
4 2 our $VERSION = '0.090'; # VERSION
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict 'subs', 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 # IFUNBUILT
9 # use warnings;
10 # END IFUNBUILT
11  
12 2 our @EXPORT = qw(GetOptions);
13 2 our @EXPORT_OK = qw(Configure GetOptionsFromArray);
14  
15 2 my $Opts = {};
16  
17 sub import {
18 1 ▶ my $pkg = shift;
Subroutine import: called CC=4 SCAR=14.2
19 1 my $caller = caller;
20 1 ▶ my @imp = @_ ? @_ : @EXPORT;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
21 1 for my $imp (@imp) {
22 3 ▶ if (grep {$_ eq $imp} (@EXPORT, @EXPORT_OK)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $imp;} @EXPORT, @EXPORT_OK) { } 3 0 3
23 3 *{"$caller\::$imp"} = \&{$imp};
24 } else {
25 0 die "$imp is not exported by ".__PACKAGE__;
26 }
27 }
28 }
29  
30 sub Configure {
31 0 ▶ my $old_opts = {%$Opts};
Subroutine Configure: not called CC=11 SCAR=48.8
Pod undocumented
32  
33 0 ▶ if (ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 0 0 0
34 0 $Opts->{$_} = $_[0]{$_} for keys %{$_[0]};
35 } else {
36 0 for (@_) {
37 0 ▶ if ($_ eq 'no_ignore_case') { next }
Branch: 7 branches
BranchTrueFalseTotal
if ($_ eq 'no_ignore_case') { } 0 0 0
elsif ($_ eq 'bundling') { } 0 0 0
elsif ($_ eq 'auto_abbrev') { } 0 0 0
elsif ($_ eq 'gnu_compat') { } 0 0 0
elsif ($_ eq 'no_getopt_compat') { } 0 0 0
elsif ($_ eq 'permute') { } 0 0 0
elsif (/\Ano_?require_order\z/) { } 0 0 0
38 0 elsif ($_ eq 'bundling') { next }
39 0 elsif ($_ eq 'auto_abbrev') { next }
40 0 elsif ($_ eq 'gnu_compat') { next }
41 0 elsif ($_ eq 'no_getopt_compat') { next }
42 0 elsif ($_ eq 'permute') { next }
43 0 elsif (/\Ano_?require_order\z/) { next }
44 #elsif (/\A(no_?)?pass_through\z/) { $Opts->{pass_through} = $1 ?0:1 }
45 0 else { die "Unknown or erroneous config parameter \"$_\"\n" }
46 }
47 }
48 0 $old_opts;
49 }
50  
51 sub GetOptionsFromArray {
52 39 ▶ my $argv = shift;
Subroutine GetOptionsFromArray: called CC=38 SCAR=37.8
Pod undocumented
53  
54 39 my $vals;
55 my $spec;
56  
57 # if next argument is a hashref, it means user wants to store values in this
58 # hash. and the spec is a list.
59 39 ▶ if (ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 35 4 39
60 35 $vals = shift;
61 35 ▶ $spec = {map { $_ => sub { $vals->{ $_[0]->name } = $_[1] } } @_};
Subroutine __ANON__: called CC=1 SCAR=0.0
62 } else {
63 4 $spec = {@_};
64 }
65  
66 # parse option spec
67 39 my %parsed_spec;
68 39 for my $k (keys %$spec) {
69 55 ▶ my $parsed = parse_getopt_long_opt_spec($k)
Branch: 1 branch
BranchTrueFalseTotal
my $parsed = parse_getopt_long_opt_spec($k) or die "Error in option spec: $k\n" 0 55 55
70 or die "Error in option spec: $k\n";
71 55 ▶ if (defined $parsed->{max_vals}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parsed->{"max_vals"}) 0 55 55
72 0 die "Cannot repeat while bundling: $k\n";
73 }
74 55 $parsed->{_orig} = $k;
75 55 $parsed_spec{$parsed->{opts}[0]} = $parsed;
76 }
77 39 my @parsed_spec_opts = sort keys %parsed_spec;
78  
79 39 my $success = 1;
80  
81 my $code_find_opt = sub {
82 53 ▶ my ($wanted, $short_mode) = @_;
Subroutine __ANON__: called CC=12 SCAR=24.9
83 53 my @candidates;
84 OPT_SPEC:
85 53 for my $opt (@parsed_spec_opts) {
86 81 my $s = $parsed_spec{$opt};
87 81 for my $o0 (@{ $s->{opts} }) {
88 92 ▶ for my $o ($s->{is_neg} && length($o0) > 1 ?
Branch: 1 branch
BranchTrueFalseTotal
$s->{'is_neg'} && length $o0 > 1 ? : 3 89 92
Condition66%2/3
$s->{"is_neg"} and length $o0 > 1
!ll&&!rl&&r
8903
MC/DC50%1/2
$s->{"is_neg"} and length $o0 > 1
$s->{"is_neg"} length $o0 > 1
Truth table66%2/3
A and B
A= $s->{"is_neg"}B= length $o0 > 1
ABresult
0X0
100
111
89 ($o0, "no$o0", "no-$o0") : ($o0)) {
90 95 my $is_neg = $o0 ne $o;
91 95 ▶ next if $short_mode && length($o) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $short_mode and length $o > 1 11 84 95
Condition100%3/3
$short_mode and length $o > 1
!ll&&!rl&&r
731111
MC/DC100%2/2
$short_mode and length $o > 1
$short_mode length $o > 1
Truth table100%3/3
A and B
A= $short_modeB= length $o > 1
ABresult
0X0
100
111
92 84 ▶ if ($o eq $wanted) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o eq $wanted) { } 47 37 84
elsif (index($o, $wanted) == 0) { } 3 34 37
93 # perfect match, we immediately go with this one
94 47 @candidates = ([$opt, $is_neg]);
95 47 last OPT_SPEC;
96 } elsif (index($o, $wanted) == 0) {
97 # prefix match, collect candidates first
98 3 push @candidates, [$opt, $is_neg];
99 3 next OPT_SPEC;
100 }
101 }
102 }
103 }
104 53 ▶ if (!@candidates) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @candidates) { } 4 49 53
elsif (@candidates > 1) { } 1 48 49
105 4 warn "Unknown option: $wanted\n";
106 4 $success = 0;
107 4 return (undef, undef);
108 } elsif (@candidates > 1) {
109 warn "Option $wanted is ambiguous (" .
110 1 join(", ", map {$_->[0]} @candidates) . ")\n";
111 1 $success = 0;
112 1 return (undef, undef, 1);
113 }
114 48 return @{ $candidates[0] };
115 39 };
116  
117 my $code_set_val = sub {
118 46 ▶ my $is_neg = shift;
Subroutine __ANON__: called CC=33 SCAR=35.5
119 46 my $name = shift;
120  
121 46 my $parsed = $parsed_spec{$name};
122 46 my $spec_key = $parsed->{_orig};
123 46 my $destination = $spec->{$spec_key};
124 46 my $ref = ref $destination;
125  
126 46 my $val;
127 46 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 28 18 46
128 28 $val = shift;
129 } else {
130 18 ▶ if ($parsed->{is_inc} && $ref eq 'SCALAR') {
Branch: 5 branches
BranchTrueFalseTotal
if ($parsed->{'is_inc'} and $ref eq 'SCALAR') { } 3 15 18
elsif ($parsed->{'is_inc'} and $vals) { } 1 14 15
elsif ($parsed->{'type'} and $parsed->{'type'} eq 'i' or $parsed->{'opttype'} and $parsed->{'opttype'} eq 'i') { } 2 12 14
elsif ($parsed->{'type'} and $parsed->{'type'} eq 'f' or $parsed->{'opttype'} and $parsed->{'opttype'} eq 'f') { } 1 11 12
elsif ($parsed->{'type'} and $parsed->{'type'} eq 's' or $parsed->{'opttype'} and $parsed->{'opttype'} eq 's') { } 2 9 11
Condition100%3/3
$parsed->{"is_inc"} and $ref eq "SCALAR"
!ll&&!rl&&r
1413
MC/DC100%2/2
$parsed->{"is_inc"} and $ref eq "SCALAR"
$parsed->{"is_inc"} $ref eq "SCALAR"
Truth table100%3/3
A and B
A= $parsed->{"is_inc"}B= $ref eq "SCALAR"
ABresult
0X0
100
111
131 3 ▶ $val = ($$destination // 0) + 1;
Condition50%1/2
$$destination // 0
l!l
30
MC/DC0%0/1
$$destination // 0
$$destination
Truth table50%1/2
A
A= $$destination
Aresult
11
00
132 ▶ } elsif ($parsed->{is_inc} && $vals) {
Condition66%2/3
$parsed->{"is_inc"} and $vals
!ll&&!rl&&r
1401
MC/DC50%1/2
$parsed->{"is_inc"} and $vals
$parsed->{"is_inc"} $vals
Truth table66%2/3
A and B
A= $parsed->{"is_inc"}B= $vals
ABresult
0X0
100
111
133 1 ▶ $val = ($vals->{$name} // 0) + 1;
Condition50%1/2
$vals->{$name} // 0
l!l
01
MC/DC0%0/1
$vals->{$name} // 0
$vals->{$name}
Truth table50%1/2
A
A= $vals->{$name}
Aresult
11
00
134 ▶ } elsif ($parsed->{type} && $parsed->{type} eq 'i' ||
Condition66%6/9
$parsed->{"type"} and $parsed->{"type"} eq "i" or $parsed->{"opttype"} and $parsed->{"opttype"} eq "i"
l!l&&r!l&&!r
0212
$parsed->{"type"} and $parsed->{"type"} eq "i"
!ll&&!rl&&r
1400
$parsed->{"opttype"} and $parsed->{"opttype"} eq "i"
!ll&&!rl&&r
932
MC/DC50%2/4
$parsed->{"type"} and $parsed->{"type"} eq "i" or $parsed->{"opttype"} and $parsed->{"opttype"} eq "i"
$parsed->{"type"} $parsed->{"type"} eq "i" $parsed->{"opttype"} $parsed->{"opttype"} eq "i"
Truth table42%3/7
A and B or C and D
A= $parsed->{"type"}B= $parsed->{"type"} eq "i"C= $parsed->{"opttype"}D= $parsed->{"opttype"} eq "i"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
135 $parsed->{opttype} && $parsed->{opttype} eq 'i') {
136 2 $val = 0;
137 ▶ } elsif ($parsed->{type} && $parsed->{type} eq 'f' ||
Condition66%6/9
$parsed->{"type"} and $parsed->{"type"} eq "f" or $parsed->{"opttype"} and $parsed->{"opttype"} eq "f"
l!l&&r!l&&!r
0111
$parsed->{"type"} and $parsed->{"type"} eq "f"
!ll&&!rl&&r
1200
$parsed->{"opttype"} and $parsed->{"opttype"} eq "f"
!ll&&!rl&&r
921
MC/DC50%2/4
$parsed->{"type"} and $parsed->{"type"} eq "f" or $parsed->{"opttype"} and $parsed->{"opttype"} eq "f"
$parsed->{"type"} $parsed->{"type"} eq "f" $parsed->{"opttype"} $parsed->{"opttype"} eq "f"
Truth table42%3/7
A and B or C and D
A= $parsed->{"type"}B= $parsed->{"type"} eq "f"C= $parsed->{"opttype"}D= $parsed->{"opttype"} eq "f"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
138 $parsed->{opttype} && $parsed->{opttype} eq 'f') {
139 1 $val = 0;
140 ▶ } elsif ($parsed->{type} && $parsed->{type} eq 's' ||
Condition55%5/9
$parsed->{"type"} and $parsed->{"type"} eq "s" or $parsed->{"opttype"} and $parsed->{"opttype"} eq "s"
l!l&&r!l&&!r
029
$parsed->{"type"} and $parsed->{"type"} eq "s"
!ll&&!rl&&r
1100
$parsed->{"opttype"} and $parsed->{"opttype"} eq "s"
!ll&&!rl&&r
902
MC/DC25%1/4
$parsed->{"type"} and $parsed->{"type"} eq "s" or $parsed->{"opttype"} and $parsed->{"opttype"} eq "s"
$parsed->{"type"} $parsed->{"type"} eq "s" $parsed->{"opttype"} $parsed->{"opttype"} eq "s"
Truth table28%2/7
A and B or C and D
A= $parsed->{"type"}B= $parsed->{"type"} eq "s"C= $parsed->{"opttype"}D= $parsed->{"opttype"} eq "s"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
141 $parsed->{opttype} && $parsed->{opttype} eq 's') {
142 2 $val = '';
143 } else {
144 9 ▶ $val = $is_neg ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$is_neg ? : 2 7 9
145 }
146 }
147  
148 # type checking
149 46 ▶ if ($parsed->{type} && $parsed->{type} eq 'i' ||
Branch: 2 branches
BranchTrueFalseTotal
if ($parsed->{'type'} and $parsed->{'type'} eq 'i' or $parsed->{'opttype'} and $parsed->{'opttype'} eq 'i') { } 8 38 46
elsif ($parsed->{'type'} and $parsed->{'type'} eq 'f' or $parsed->{'opttype'} and $parsed->{'opttype'} eq 'f') { } 11 52 63
Condition100%9/9
$parsed->{"type"} and $parsed->{"type"} eq "i" or $parsed->{"opttype"} and $parsed->{"opttype"} eq "i"
l!l&&r!l&&!r
5338
$parsed->{"type"} and $parsed->{"type"} eq "i"
!ll&&!rl&&r
19225
$parsed->{"opttype"} and $parsed->{"opttype"} eq "i"
!ll&&!rl&&r
3533
MC/DC100%4/4
$parsed->{"type"} and $parsed->{"type"} eq "i" or $parsed->{"opttype"} and $parsed->{"opttype"} eq "i"
$parsed->{"type"} $parsed->{"type"} eq "i" $parsed->{"opttype"} $parsed->{"opttype"} eq "i"
Truth table71%5/7
A and B or C and D
A= $parsed->{"type"}B= $parsed->{"type"} eq "i"C= $parsed->{"opttype"}D= $parsed->{"opttype"} eq "i"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
150 $parsed->{opttype} && $parsed->{opttype} eq 'i') {
151 8 ▶ unless ($val =~ /\A[+-]?\d+\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val =~ /\A[+-]?\d+\z/) 3 5 8
152 3 warn qq|Value "$val" invalid for option $name (number expected)\n|;
153 3 return 0;
154 }
155 ▶ } elsif ($parsed->{type} && $parsed->{type} eq 'f' ||
Condition100%9/9
$parsed->{"type"} and $parsed->{"type"} eq "f" or $parsed->{"opttype"} and $parsed->{"opttype"} eq "f"
l!l&&r!l&&!r
10127
$parsed->{"type"} and $parsed->{"type"} eq "f"
!ll&&!rl&&r
161210
$parsed->{"opttype"} and $parsed->{"opttype"} eq "f"
!ll&&!rl&&r
2521
MC/DC100%4/4
$parsed->{"type"} and $parsed->{"type"} eq "f" or $parsed->{"opttype"} and $parsed->{"opttype"} eq "f"
$parsed->{"type"} $parsed->{"type"} eq "f" $parsed->{"opttype"} $parsed->{"opttype"} eq "f"
Truth table71%5/7
A and B or C and D
A= $parsed->{"type"}B= $parsed->{"type"} eq "f"C= $parsed->{"opttype"}D= $parsed->{"opttype"} eq "f"
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
156 $parsed->{opttype} && $parsed->{opttype} eq 'f') {
157 11 ▶ unless ($val =~ /\A[+-]?(\d+(\.\d+)?|\.\d+)([Ee][+-]?\d+)?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val =~ /\A[+-]?(\d+(\.\d+)?|\.\d+)([Ee][+-]?\d+)?\z/) 4 7 11
158 4 warn qq|Value "$val" invalid for option $name (number expected)\n|;
159 4 return 0;
160 }
161 }
162  
163 39 ▶ if ($ref eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'CODE') { } 34 5 39
elsif ($ref eq 'SCALAR') { } 4 1 5
164 34 my $cb = Getopt::Long::Less::Callback->new(
165 name => $name,
166 );
167 34 $destination->($cb, $val);
168 } elsif ($ref eq 'SCALAR') {
169 4 $$destination = $val;
170 } else {
171 # no nothing
172 }
173 39 1;
174 39 };
175  
176 39 my $i = -1;
177 39 my @remaining;
178 ELEM:
179 39 ▶ while (++$i < @$argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i < @$argv) 54 35 89
180 54 ▶ if ($argv->[$i] eq '--') {
Branch: 3 branches
BranchTrueFalseTotal
if ($argv->[$i] eq '--') { } 2 52 54
elsif ($argv->[$i] =~ /\A--(.+?)(?:=(.*))?\z/) { } 46 6 52
elsif ($argv->[$i] =~ /\A-(.*)/) { } 4 2 6
181  
182 2 push @remaining, @{$argv}[$i+1 .. @$argv-1];
183 2 last ELEM;
184  
185 } elsif ($argv->[$i] =~ /\A--(.+?)(?:=(.*))?\z/) {
186  
187 46 my ($used_name, $val_in_opt) = ($1, $2);
188 46 my ($opt, $is_neg, $is_ambig) = $code_find_opt->($used_name);
189 46 ▶ unless (defined $opt) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opt) 5 41 46
190 5 ▶ push @remaining, $argv->[$i] unless $is_ambig;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_ambig 4 1 5
191 5 next ELEM;
192 }
193  
194 41 my $spec = $parsed_spec{$opt};
195 # check whether option requires an argument
196 41 ▶ if ($spec->{type} ||
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{'type'} or $spec->{'opttype'} and defined $val_in_opt && length $val_in_opt || $i + 1 < @$argv && !($$argv[$i + 1] =~ /\A-/)) { } 26 15 41
Condition80%12/15
$spec->{"type"} or $spec->{"opttype"} and defined $val_in_opt && length $val_in_opt || $i + 1 < @$argv && !($$argv[$i + 1] =~ /\A-/)
l!l&&r!l&&!r
25115
$spec->{"opttype"} and defined $val_in_opt && length $val_in_opt || $i + 1 < @$argv && !($$argv[$i + 1] =~ /\A-/)
!ll&&!rl&&r
1051
defined $val_in_opt and length $val_in_opt or $i + 1 < @$argv and not $$argv[$i + 1] =~ /\A-/
l!l&&r!l&&!r
015
defined $val_in_opt and length $val_in_opt
!ll&&!rl&&r
600
$i + 1 < @$argv and not $$argv[$i + 1] =~ /\A-/
!ll&&!rl&&r
411
MC/DC66%4/6
$spec->{"type"} or $spec->{"opttype"} and defined $val_in_opt && length $val_in_opt || $i + 1 < @$argv && !($$argv[$i + 1] =~ /\A-/)
$spec->{"type"} $spec->{"opttype"} defined $val_in_opt length $val_in_opt $i + 1 < @$argv not $$argv[$i + 1] =~ /\A-/
Truth table55%5/9
A or B and C and D or E and not(F)
A= $spec->{"type"}B= $spec->{"opttype"}C= defined $val_in_optD= length $val_in_optE= $i + 1 < @$argvF= not $$argv[$i + 1] =~ /\A-/
ABCDEFresult
1XXXXX1
0111XX1
010X111
0110111
00XXXX0
010X0X0
010X100
01100X0
0110100
197 $spec->{opttype} &&
198 (defined($val_in_opt) && length($val_in_opt) || ($i+1 < @$argv && $argv->[$i+1] !~ /\A-/))) {
199 26 ▶ if (defined($val_in_opt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val_in_opt) { } 2 24 26
200 # argument is taken after =
201 2 ▶ unless ($code_set_val->($is_neg, $opt, $val_in_opt)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$code_set_val($is_neg, $opt, $val_in_opt)) 0 2 2
202 0 $success = 0;
203 0 next ELEM;
204 }
205 } else {
206 24 ▶ if ($i+1 >= @$argv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 >= @$argv) 1 23 24
207 # we are the last element
208 1 warn "Option $used_name requires an argument\n";
209 1 $success = 0;
210 1 last ELEM;
211 }
212 # take the next element as argument
213 23 ▶ if ($spec->{type} || $argv->[$i+1] !~ /\A-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"type"} or not $$argv[$i + 1] =~ /\A-/) 23 0 23
Condition66%2/3
$spec->{"type"} or not $$argv[$i + 1] =~ /\A-/
l!l&&r!l&&!r
2210
MC/DC0%0/2
$spec->{"type"} or not $$argv[$i + 1] =~ /\A-/
$spec->{"type"} not $$argv[$i + 1] =~ /\A-/
Truth table66%2/3
A or not(B)
A= $spec->{"type"}B= not $$argv[$i + 1] =~ /\A-/
ABresult
1X1
011
000
214 23 $i++;
215 23 ▶ unless ($code_set_val->($is_neg, $opt, $argv->[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$code_set_val($is_neg, $opt, $argv->[$i])) 7 16 23
216 7 $success = 0;
217 7 next ELEM;
218 }
219 }
220 }
221 } else {
222 15 ▶ unless ($code_set_val->($is_neg, $opt)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$code_set_val($is_neg, $opt)) 0 15 15
223 0 $success = 0;
224 0 next ELEM;
225 }
226 }
227  
228 } elsif ($argv->[$i] =~ /\A-(.*)/) {
229  
230 4 my $str = $1;
231 SHORT_OPT:
232 4 ▶ while ($str =~ s/(.)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/(.)//) 7 1 8
233 7 my $used_name = $1;
234 7 my ($opt, $is_neg) = $code_find_opt->($1, 'short');
235 7 ▶ next SHORT_OPT unless defined $opt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt 0 7 7
236  
237 7 my $spec = $parsed_spec{$opt};
238 # check whether option requires an argument
239 7 ▶ if ($spec->{type} ||
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{'type'} or $spec->{'opttype'} and length $str || $i + 1 < @$argv && !($$argv[$i + 1] =~ /\A-/)) { } 4 3 7
Condition25%3/12
$spec->{"type"} or $spec->{"opttype"} and length $str || $i + 1 < @$argv && !($$argv[$i + 1] =~ /\A-/)
l!l&&r!l&&!r
403
$spec->{"opttype"} and length $str || $i + 1 < @$argv && !($$argv[$i + 1] =~ /\A-/)
!ll&&!rl&&r
300
length $str or $i + 1 < @$argv and not $$argv[$i + 1] =~ /\A-/
l!l&&r!l&&!r
000
$i + 1 < @$argv and not $$argv[$i + 1] =~ /\A-/
!ll&&!rl&&r
000
MC/DC20%1/5
$spec->{"type"} or $spec->{"opttype"} and length $str || $i + 1 < @$argv && !($$argv[$i + 1] =~ /\A-/)
$spec->{"type"} $spec->{"opttype"} length $str $i + 1 < @$argv not $$argv[$i + 1] =~ /\A-/
Truth table33%2/6
A or B and C or D and not(E)
A= $spec->{"type"}B= $spec->{"opttype"}C= length $strD= $i + 1 < @$argvE= not $$argv[$i + 1] =~ /\A-/
ABCDEresult
1XXXX1
011XX1
010111
00XXX0
0100X0
010100
240 $spec->{opttype} &&
241 (length($str) || ($i+1 < @$argv && $argv->[$i+1] !~ /\A-/))) {
242 4 ▶ if (length $str) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $str) { } 2 2 4
243 # argument is taken from $str
244 2 ▶ if ($code_set_val->($is_neg, $opt, $str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$code_set_val($is_neg, $opt, $str)) { } 2 0 2
245 2 next ELEM;
246 } else {
247 0 $success = 0;
248 0 next SHORT_OPT;
249 }
250 } else {
251 2 ▶ if ($i+1 >= @$argv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 >= @$argv) 1 1 2
252 # we are the last element
253 1 warn "Option $used_name requires an argument\n";
254 1 $success = 0;
255 1 last ELEM;
256 }
257 # take the next element as argument
258 1 ▶ if ($spec->{type} || $argv->[$i+1] !~ /\A-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec->{"type"} or not $$argv[$i + 1] =~ /\A-/) 1 0 1
Condition33%1/3
$spec->{"type"} or not $$argv[$i + 1] =~ /\A-/
l!l&&r!l&&!r
100
MC/DC0%0/2
$spec->{"type"} or not $$argv[$i + 1] =~ /\A-/
$spec->{"type"} not $$argv[$i + 1] =~ /\A-/
Truth table33%1/3
A or not(B)
A= $spec->{"type"}B= not $$argv[$i + 1] =~ /\A-/
ABresult
1X1
011
000
259 1 $i++;
260 1 ▶ unless ($code_set_val->($is_neg, $opt, $argv->[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$code_set_val($is_neg, $opt, $argv->[$i])) 0 1 1
261 0 $success = 0;
262 0 next ELEM;
263 }
264 }
265 }
266 } else {
267 3 ▶ unless ($code_set_val->($is_neg, $opt)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$code_set_val($is_neg, $opt)) 0 3 3
268 0 $success = 0;
269 0 next SHORT_OPT;
270 }
271 }
272 }
273  
274 } else { # argument
275  
276 2 push @remaining, $argv->[$i];
277 2 next;
278  
279 }
280 }
281  
282 RETURN:
283 39 splice @$argv, 0, ~~@$argv, @remaining; # replace with remaining elements
284 39 return $success;
285 }
286  
287 sub GetOptions {
288 0 ▶ GetOptionsFromArray(\@ARGV, @_);
Subroutine GetOptions: not called CC=1 SCAR=6.9
Pod undocumented
289 }
290  
291 # IFBUILT
292 sub parse_getopt_long_opt_spec {
293 55 ▶ my $optspec = shift;
Subroutine parse_getopt_long_opt_spec: called CC=10 SCAR=23.3
Pod undocumented
294 55 ▶ return {is_arg=>1, dash_prefix=>'', opts=>[]}
Branch: 1 branch
BranchTrueFalseTotal
if $optspec eq "<>" 0 55 55
295 if $optspec eq '<>';
296 55 ▶ $optspec =~ qr/\A
Branch: 1 branch
BranchTrueFalseTotal
$optspec =~ qr/\A (?P<dash_prefix>-{0,2}) (?P<name>[A-Za-z0-9_][A-Za-z0-9_-]*) (?P<aliases> (?: \| (?:[^:|!+=:-][^:|!+=:]*) )*)? (?: (?P<is_neg>!) | (?P<is_inc>\+) | (?: = (?P<type>[siof]) (?P<desttype>|[%\@])? (?: \{ (?: (?P<min_vals>\d+), )? (?P<max_vals>\d+) \} )? ) | (?: : (?P<opttype>[siof]) (?P<desttype>|[%\@]) ) | (?: : (?P<optnum>\d+) (?P<desttype>|[%\@]) ) (?: : (?P<optplus>\+) (?P<desttype>|[%\@]) ) )? \z/x or return undef 0 55 55
297 (?P<dash_prefix>-{0,2})
298 (?P<name>[A-Za-z0-9_][A-Za-z0-9_-]*)
299 (?P<aliases> (?: \| (?:[^:|!+=:-][^:|!+=:]*) )*)?
300 (?:
301 (?P<is_neg>!) |
302 (?P<is_inc>\+) |
303 (?:
304 =
305 (?P<type>[siof])
306 (?P<desttype>|[%@])?
307 (?:
308 \{
309 (?: (?P<min_vals>\d+), )?
310 (?P<max_vals>\d+)
311 \}
312 )?
313 ) |
314 (?:
315 :
316 (?P<opttype>[siof])
317 (?P<desttype>|[%@])
318 ) |
319 (?:
320 :
321 (?P<optnum>\d+)
322 (?P<desttype>|[%@])
323 )
324 (?:
325 :
326 (?P<optplus>\+)
327 (?P<desttype>|[%@])
328 )
329 )?
330 \z/x
331 or return undef;
332 55 my %res = %+;
333  
334 55 ▶ if ($res{aliases}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res{'aliases'}) { } 8 47 55
335 8 my @als;
336 8 for my $al (split /\|/, $res{aliases}) {
337 16 ▶ next unless length $al;
Branch: 1 branch
BranchTrueFalseTotal
unless length $al 8 8 16
338 8 ▶ next if $al eq $res{name};
Branch: 1 branch
BranchTrueFalseTotal
if $al eq $res{"name"} 0 8 8
339 8 ▶ next if grep {$_ eq $al} @als;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $al;} @als 0 8 8
340 8 push @als, $al;
341 }
342 8 $res{opts} = [$res{name}, @als];
343 } else {
344 47 $res{opts} = [$res{name}];
345 }
346 55 delete $res{name};
347 55 delete $res{aliases};
348  
349 55 ▶ $res{is_neg} = 1 if $res{is_neg};
Branch: 1 branch
BranchTrueFalseTotal
if $res{"is_neg"} 3 52 55
350 55 ▶ $res{is_inc} = 1 if $res{is_inc};
Branch: 1 branch
BranchTrueFalseTotal
if $res{"is_inc"} 2 53 55
351  
352 55 \%res;
353 }
354  
355 # END IFBUILT
356 # IFUNBUILT
357 # require Getopt::Long::Util; *parse_getopt_long_opt_spec = \&Getopt::Long::Util::parse_getopt_long_opt_spec;
358 # END IFUNBUILT
359  
360 package Getopt::Long::Less::Callback;
361  
362 sub new {
363 34 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
364 34 bless {@_}, $class;
365 }
366  
367 sub name {
368 33 ▶ shift->{name};
Subroutine name: called CC=1 SCAR=0.0
369 }
370  
371 2 1;
372 # ABSTRACT: Like Getopt::Long, but with less features
373  
374 __END__
↑ Summary