blib/lib/YATT/Lite/Util/CmdLine.pm

filter: Statementstmt 71.8% 46 / 64 Branchbran 58.7% 27 / 46 Conditioncond 48.2% 14 / 29 MC/DCmcdc 47.0% 8 / 17 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 4 totaltotal 60.4% 101 / 167 CC 35 SCAR 41.5
CC
35
Cov
63%
process_result
182.0
parse_opts
12.0
run
7.2
CRAP 63.5
« blib/lib/YATT/Lite/Test/TestFCGI.pm ↑ Summary blib/lib/YATT/Lite/Walker.pm »
1 package YATT::Lite::Util::CmdLine;
2 75 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 75 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 75 ▶BEGIN {require Exporter; *import = \&Exporter::import}
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 75 our @EXPORT = qw(parse_opts parse_params);
8 75 our @EXPORT_OK = (@EXPORT, qw(run process_result));
9  
10 # posix style option.
11 38 ▶sub parse_opts {
Subroutine parse_opts: called CC=12 SCAR=24.9
Pod undocumented
12 38 my ($pack, $list, $result, $alias) = @_;
13 38 my $wantarray = wantarray;
14 38 ▶ unless (defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 37 1 38
15 37 ▶ $result = $wantarray ? [] : {};
Branch: 1 branch
BranchTrueFalseTotal
$wantarray ? : 37 0 37
16 }
17 38 ▶ while (@$list and my ($n, $v) = $list->[0]
Branch: 1 branch
BranchTrueFalseTotal
if (@$list and () = $list->[0] =~ /^--$ | ^(?:--? ([\w:\-\.]+) (?: =(.*))?)$/sx) 21 37 58
Condition100%3/3
@$list and () = $list->[0] =~ /^--$ | ^(?:--? ([\w:\-\.]+) (?: =(.*))?)$/sx
!ll&&!rl&&r
53221
MC/DC100%2/2
@$list and () = $list->[0] =~ /^--$ | ^(?:--? ([\w:\-\.]+) (?: =(.*))?)$/sx
@$list () = $list->[0] =~ /^--$ | ^(?:--? ([\w:\-\.]+) (?: =(.*))?)$/sx
Truth table100%3/3
A and B
A= @$listB= () = $list->[0] =~ /^--$ | ^(?:--? ([\w:\-\.]+) (?: =(.*))?)$/sx
ABresult
0X0
100
111
18 =~ m{^--$ | ^(?:--? ([\w:\-\.]+) (?: =(.*))?)$}xs) {
19 21 shift @$list;
20 21 ▶ last unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 1 20 21
21 20 ▶ $n = $alias->{$n} if $alias and $alias->{$n};
Branch: 1 branch
BranchTrueFalseTotal
if $alias and $alias->{$n} 1 19 20
Condition100%3/3
$alias and $alias->{$n}
!ll&&!rl&&r
1541
MC/DC100%2/2
$alias and $alias->{$n}
$alias $alias->{$n}
Truth table100%3/3
A and B
A= $aliasB= $alias->{$n}
ABresult
0X0
100
111
22 20 ▶ $v = 1 unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 11 9 20
23 20 ▶ if (ref $result eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $result eq 'HASH') { } 3 17 20
24 3 $result->{$n} = $v;
25 } else {
26 17 push @$result, $n, $v;
27 }
28 }
29 38 ▶ $wantarray && ref $result ne 'HASH' ? @$result : $result;
Branch: 1 branch
BranchTrueFalseTotal
$wantarray && ref $result ne 'HASH' ? : 37 1 38
Condition66%2/3
$wantarray and ref $result ne "HASH"
!ll&&!rl&&r
0137
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
30 }
31  
32 # 'Make' style parameter.
33 22 ▶sub parse_params {
Subroutine parse_params: called CC=7 SCAR=19.5
Pod undocumented
34 22 my ($pack, $list, $hash) = @_;
35 22 my $explicit;
36 22 ▶ unless (defined $hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash) { } 19 3 22
37 3 $hash = {}
38 } else {
39 19 $explicit++;
40 }
41 22 ▶ for (; @$list and $list->[0] =~ /^([^=]+)=(.*)/s; shift @$list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$list and $list->[0] =~ /^([^=]+)=(.*)/s) 13 22 35
Condition100%3/3
@$list and $list->[0] =~ /^([^=]+)=(.*)/s
!ll&&!rl&&r
111113
MC/DC100%2/2
@$list and $list->[0] =~ /^([^=]+)=(.*)/s
@$list $list->[0] =~ /^([^=]+)=(.*)/s
Truth table100%3/3
A and B
A= @$listB= $list->[0] =~ /^([^=]+)=(.*)/s
ABresult
0X0
100
111
42 13 $hash->{$1} = $2;
43 }
44 22 ▶ if (not $explicit and wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $explicit and wantarray) { } 3 19 22
Condition66%2/3
not $explicit and wantarray
!ll&&!rl&&r
1903
MC/DC50%1/2
not $explicit and wantarray
not $explicit wantarray
Truth table66%2/3
not(A) and B
A= not $explicitB= wantarray
ABresult
0X0
100
111
45 # return empty list if hash is empty
46 3 ▶ %$hash ? $hash : ();
Branch: 1 branch
BranchTrueFalseTotal
%$hash ? : 2 1 3
47 } else {
48 19 $hash
49 }
50 }
51  
52 3 ▶sub run {
Subroutine run: called CC=6 SCAR=19.7
Pod undocumented
53 3 my ($pack, $list, $alias) = @_;
54  
55 3 my @opts = parse_opts($pack, $list, $alias);
56 3 my $app = do {
57 3 ▶ if (ref $pack) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pack) { } 1 2 3
58 1 $pack->configure(@opts);
59 1 $pack;
60 } else {
61 2 $pack->new(@opts);
62 }
63 };
64 3 ▶ my $cmd = shift @$list || 'help';
Condition50%1/2
shift @$list || 'help'
l!l
30
MC/DC0%0/1
shift @$list || 'help'
shift @$list
Truth table50%1/2
A
A= shift @$list
Aresult
11
00
65 3 $app->configure(parse_opts($pack, \@_, $alias));
66  
67 3 ▶ if (my $sub = $app->can("cmd_$cmd")) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $sub = $app->can("cmd_$cmd")) { } 3 0 3
elsif ($sub = $app->can($cmd)) { } 0 0 0
68 3 $sub->($app, @$list);
69 } elsif ($sub = $app->can($cmd)) {
70 0 process_result($sub->($app, @$list));
71 } else {
72 0 die "$0: Unknown subcommand '$cmd'\n"
73 }
74 3 ▶ if (my $sub = $app->can('DESTROY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $app->can("DESTROY")) 0 3 3
75 0 $sub->($app);
76 }
77 }
78  
79 0 ▶sub process_result {
Subroutine process_result: not called CC=13 SCAR=52.0
Pod undocumented
80 0 my (@res) = @_;
81 0 ▶ if (not @res
Branch: 2 branches
BranchTrueFalseTotal
if (not @res or @res == 1 and not $res[0]) { } 0 0 0
elsif (@res == 1 and defined $res[0] and $res[0] eq 1) { } 0 0 0
Condition0%0/6
not @res or @res == 1 and not $res[0]
l!l&&r!l&&!r
000
@res == 1 and not $res[0]
!ll&&!rl&&r
000
MC/DC0%0/3
not @res or @res == 1 and not $res[0]
not @res @res == 1 not $res[0]
Truth table0%0/4
not(A) or B and not(C)
A= not @resB= @res == 1C= not $res[0]
ABCresult
1XX1
0111
00X0
0100
82 or @res == 1 and not $res[0]) {
83 0 exit 1;
84 ▶ } elsif (@res == 1 and defined $res[0] and $res[0] eq 1) {
Condition0%0/6
@res == 1 and defined $res[0] and $res[0] eq 1
!ll&&!rl&&r
000
@res == 1 and defined $res[0]
!ll&&!rl&&r
000
MC/DC0%0/3
@res == 1 and defined $res[0] and $res[0] eq 1
@res == 1 defined $res[0] $res[0] eq 1
Truth table0%0/4
A and B and C
A= @res == 1B= defined $res[0]C= $res[0] eq 1
ABCresult
0XX0
10X0
1100
1111
85 # nop
86 } else {
87 0 require YATT::Lite::Util;
88 0 foreach my $res (@res) {
89 0 ▶ unless (defined $res) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $res) { } 0 0 0
if (do { not ref $res }) { } 0 0 0
elsif (my $sub = $res->can('get_columns')) { } 0 0 0
90 0 print "(undef)\n";
91 } elsif (not ref $res) {
92 0 print $res, "\n";
93 } elsif (my $sub = $res->can('get_columns')) {
94 0 my @kv = $sub->($res);
95 0 my $cnt;
96 0 ▶ while (my ($k, $v) = splice @kv, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@kv, 0, 2)) 0 0 0
97 0 ▶ print "\t" if $cnt++;
Branch: 1 branch
BranchTrueFalseTotal
if $cnt++ 0 0 0
98 0 print "$k=", YATT::Lite::Util::terse_dump($v);
99 }
100 0 print "\n";
101 } else {
102 0 print YATT::Lite::Util::terse_dump($res), "\n";
103 }
104 }
105 }
106 }
107  
108 75 1;
« blib/lib/YATT/Lite/Test/TestFCGI.pm ↑ Summary blib/lib/YATT/Lite/Walker.pm »