web/cgi-bin/yatt.lib/YATT/Util/CmdLine.pm

filter: Statementstmt 100% 33 / 33 Branchbran 95.4% 21 / 22 Conditioncond 83.3% 10 / 12 MC/DCmcdc 75.0% 6 / 8 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 91.4% 75 / 82 CC 16 SCAR 20.3
CC
16
Cov
96%
parse_opts
10.0
parse_params
7.0
BEGIN
1.0
CRAP 7.6
« web/cgi-bin/yatt.lib/YATT/Fields.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/Test.pm »
1 package YATT::Util::CmdLine;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶BEGIN {require Exporter; *import = \&Exporter::import}
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our @EXPORT_OK = qw(parse_opts parse_params);
8 3 our @EXPORT = @EXPORT_OK;
9  
10 # posix style option.
11 4 ▶sub parse_opts {
Subroutine parse_opts: called CC=10 SCAR=23.0
Pod undocumented
12 4 my ($pack, $list, $result) = @_;
13 4 my $wantarray = wantarray;
14 4 ▶ unless (defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 2 2 4
15 2 ▶ $result = $wantarray ? [] : {};
Branch: 1 branch
BranchTrueFalseTotal
$wantarray ? : 1 1 2
16 }
17 4 ▶ while (@$list
Branch: 1 branch
BranchTrueFalseTotal
if (@$list and () = $list->[0] =~ /^--(?:([\w\.\-]+)(?:=(.*))?)?/) 10 2 12
Condition100%3/3
@$list and () = $list->[0] =~ /^--(?:([\w\.\-]+)(?:=(.*))?)?/
!ll&&!rl&&r
1110
MC/DC100%2/2
@$list and () = $list->[0] =~ /^--(?:([\w\.\-]+)(?:=(.*))?)?/
@$list () = $list->[0] =~ /^--(?:([\w\.\-]+)(?:=(.*))?)?/
Truth table100%3/3
A and B
A= @$listB= () = $list->[0] =~ /^--(?:([\w\.\-]+)(?:=(.*))?)?/
ABresult
0X0
100
111
18 and my ($n, $v) = $list->[0] =~ /^--(?:([\w\.\-]+)(?:=(.*))?)?/) {
19 10 shift @$list;
20 10 ▶ last unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 2 8 10
21 8 ▶ $v = 1 unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 4 4 8
22 8 ▶ if (ref $result eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $result eq 'HASH') { } 2 6 8
23 2 $result->{$n} = $v;
24 } else {
25 6 push @$result, $n, $v;
26 }
27 }
28 4 ▶ $wantarray && ref $result ne 'HASH' ? @$result : $result;
Branch: 1 branch
BranchTrueFalseTotal
$wantarray && ref $result ne 'HASH' ? : 1 3 4
Condition66%2/3
$wantarray and ref $result ne "HASH"
!ll&&!rl&&r
301
MC/DC50%1/2
$wantarray and ref $result ne "HASH"
$wantarray ref $result ne "HASH"
Truth table66%2/3
A and B
A= $wantarrayB= ref $result ne "HASH"
ABresult
0X0
100
111
29 }
30  
31 # 'Make' style parameter.
32 3 ▶sub parse_params {
Subroutine parse_params: called CC=7 SCAR=19.5
Pod undocumented
33 3 my ($pack, $list, $hash) = @_;
34 3 my $explicit;
35 3 ▶ unless (defined $hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash) { } 1 2 3
36 2 $hash = {}
37 } else {
38 1 $explicit++;
39 }
40 3 ▶ for (; @$list and $list->[0] =~ /^([^=]+)=(.*)/; shift @$list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$list and $list->[0] =~ /^([^=]+)=(.*)/) 2 3 5
Condition66%2/3
@$list and $list->[0] =~ /^([^=]+)=(.*)/
!ll&&!rl&&r
032
MC/DC50%1/2
@$list and $list->[0] =~ /^([^=]+)=(.*)/
@$list $list->[0] =~ /^([^=]+)=(.*)/
Truth table66%2/3
A and B
A= @$listB= $list->[0] =~ /^([^=]+)=(.*)/
ABresult
0X0
100
111
41 2 $hash->{$1} = $2;
42 }
43 3 ▶ if (not $explicit and wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $explicit and wantarray) { } 1 2 3
Condition100%3/3
not $explicit and wantarray
!ll&&!rl&&r
111
MC/DC100%2/2
not $explicit and wantarray
not $explicit wantarray
Truth table100%3/3
not(A) and B
A= not $explicitB= wantarray
ABresult
0X0
100
111
44 # return empty list if hash is empty
45 1 ▶ %$hash ? $hash : ();
Branch: 1 branch
BranchTrueFalseTotal
%$hash ? : 0 1 1
46 } else {
47 2 $hash
48 }
49 }
50  
51 3 1;
« web/cgi-bin/yatt.lib/YATT/Fields.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/Test.pm »