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

filter: Statementstmt 68.7% 44 / 64 Branchbran 56.5% 26 / 46 Conditioncond 48.2% 14 / 29 MC/DCmcdc 47.0% 8 / 17 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 4 totaltotal 58.6% 98 / 167 CC 35 SCAR 41.6
CC
35
Cov
60%
process_result
182.0
parse_opts
12.0
run
9.1
CRAP 63.8
« blib/lib/YATT/Lite/Test/TestFCGI.pm ↑ Summary blib/lib/YATT/Lite/Inspector.pm »
1 package YATT::Lite::Util::CmdLine;
2 47 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 47 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 47 ▶BEGIN {require Exporter; *import = \&Exporter::import}
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 47 our @EXPORT = qw(parse_opts parse_params);
8 47 our @EXPORT_OK = (@EXPORT, qw(run process_result));
9  
10 # posix style option.
11 25 ▶sub parse_opts {
Subroutine parse_opts: called CC=12 SCAR=24.9
Pod undocumented
12 25 my ($pack, $list, $result, $alias) = @_;
13 25 my $wantarray = wantarray;
14 25 ▶ unless (defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 24 1 25
15 24 ▶ $result = $wantarray ? [] : {};
Branch: 1 branch
BranchTrueFalseTotal
$wantarray ? : 24 0 24
16 }
17 25 ▶ while (@$list and my ($n, $v) = $list->[0]
Branch: 1 branch
BranchTrueFalseTotal
if (@$list and () = $list->[0] =~ /^--$ | ^(?:--? ([\w:\-\.]+) (?: =(.*))?)$/sx) 15 24 39
Condition100%3/3
@$list and () = $list->[0] =~ /^--$ | ^(?:--? ([\w:\-\.]+) (?: =(.*))?)$/sx
!ll&&!rl&&r
32115
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 15 shift @$list;
20 15 ▶ last unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 1 14 15
21 14 ▶ $n = $alias->{$n} if $alias and $alias->{$n};
Branch: 1 branch
BranchTrueFalseTotal
if $alias and $alias->{$n} 1 13 14
Condition100%3/3
$alias and $alias->{$n}
!ll&&!rl&&r
1211
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 14 ▶ $v = 1 unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 7 7 14
23 14 ▶ if (ref $result eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $result eq 'HASH') { } 3 11 14
24 3 $result->{$n} = $v;
25 } else {
26 11 push @$result, $n, $v;
27 }
28 }
29 25 ▶ $wantarray && ref $result ne 'HASH' ? @$result : $result;
Branch: 1 branch
BranchTrueFalseTotal
$wantarray && ref $result ne 'HASH' ? : 24 1 25
Condition66%2/3
$wantarray and ref $result ne "HASH"
!ll&&!rl&&r
0124
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 14 ▶sub parse_params {
Subroutine parse_params: called CC=7 SCAR=19.5
Pod undocumented
34 14 my ($pack, $list, $hash) = @_;
35 14 my $explicit;
36 14 ▶ unless (defined $hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash) { } 11 3 14
37 3 $hash = {}
38 } else {
39 11 $explicit++;
40 }
41 14 ▶ for (; @$list and $list->[0] =~ /^([^=]+)=(.*)/s; shift @$list) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$list and $list->[0] =~ /^([^=]+)=(.*)/s) 9 14 23
Condition100%3/3
@$list and $list->[0] =~ /^([^=]+)=(.*)/s
!ll&&!rl&&r
779
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 9 $hash->{$1} = $2;
43 }
44 14 ▶ if (not $explicit and wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $explicit and wantarray) { } 3 11 14
Condition66%2/3
not $explicit and wantarray
!ll&&!rl&&r
1103
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 11 $hash
49 }
50 }
51  
52 1 ▶sub run {
Subroutine run: called CC=6 SCAR=22.0
Pod undocumented
53 1 my ($pack, $list, $alias) = @_;
54  
55 1 my @opts = parse_opts($pack, $list, $alias);
56 1 my $app = do {
57 1 ▶ if (ref $pack) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pack) { } 0 1 1
58 0 $pack->configure(@opts);
59 0 $pack;
60 } else {
61 1 $pack->new(@opts);
62 }
63 };
64 1 ▶ my $cmd = shift @$list || 'help';
Condition50%1/2
shift @$list || 'help'
l!l
10
MC/DC0%0/1
shift @$list || 'help'
shift @$list
Truth table50%1/2
A
A= shift @$list
Aresult
11
00
65 1 $app->configure(parse_opts($pack, \@_, $alias));
66  
67 1 ▶ if (my $sub = $app->can("cmd_$cmd")) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $sub = $app->can("cmd_$cmd")) { } 1 0 1
elsif ($sub = $app->can($cmd)) { } 0 0 0
68 1 $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 1 ▶ if (my $sub = $app->can('DESTROY')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $app->can("DESTROY")) 0 1 1
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 47 1;
« blib/lib/YATT/Lite/Test/TestFCGI.pm ↑ Summary blib/lib/YATT/Lite/Inspector.pm »