lib/CLI/Dispatch/Command.pm

filter: Statementstmt 63.8% 30 / 47 Branchbran 72.2% 13 / 18 Conditioncond 50.0% 7 / 14 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 77.7% 7 / 9 Podpod 100% 7 / 7 totaltotal 65.0% 67 / 103 CC 15 SCAR 19.8
CC
15
Cov
63%
usage
20.0
set_options
8.0
new
3.0
CRAP 7.2
« lib/CLI/Dispatch/Help.pm ↑ Summary lib/CLI/Dispatch.pm »
1 package CLI::Dispatch::Command;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 sub new {
7 66 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
8 66 my $self = bless {}, $class;
9 66 ▶ $self->set_options(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 66 66
10  
11 66 ▶ if (!$self->can('log')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->can("log")) 9 57 66
12 9 require Log::Dump; Log::Dump->import;
13 }
14  
15 66 $self;
16 }
17  
18 sub set_options {
19 65 ▶ my $self = shift;
Subroutine set_options: called CC=8 SCAR=20.8
Pod documented
20  
21 65 %{ $self } = @_;
22  
23 65 ▶ if ($self->can('logger')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("logger")) 65 0 65
24 65 ▶ $self->logger( $self->{verbose} || $self->{debug} || $self->{logfilter} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'verbose'} || $self->{'debug'} || $self->{'logfilter'} ? : 3 62 65
Condition100%6/6
$self->{"verbose"} or $self->{"debug"} or $self->{"logfilter"}
l!l&&r!l&&!r
2162
$self->{"verbose"} or $self->{"debug"}
l!l&&r!l&&!r
1163
MC/DC100%3/3
$self->{"verbose"} or $self->{"debug"} or $self->{"logfilter"}
$self->{"verbose"} $self->{"debug"} $self->{"logfilter"}
Truth table100%4/4
A or B or C
A= $self->{"verbose"}B= $self->{"debug"}C= $self->{"logfilter"}
ABCresult
1XX1
01X1
0011
0000
25 }
26 65 ▶ if ($self->can('logfilter')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("logfilter")) 65 0 65
27 65 ▶ my @filters = $self->{logfilter} ? split ',', $self->{logfilter} : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'logfilter'} ? : 1 64 65
28 65 ▶ push @filters, '!debug' unless $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"debug"} 64 1 65
29 65 $self->logfilter(@filters);
30 }
31  
32 65 $self;
33 }
34  
35 ▶sub options {}
Subroutine options: called CC=1 SCAR=0.0
Pod documented
36  
37 sub option {
38 106 ▶ my ($self, $name) = @_;
Subroutine option: called CC=2 SCAR=6.9
Pod documented
39  
40 106 ▶ defined $self->{$name} ? $self->{$name} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{$name} ? : 55 51 106
41 }
42  
43 sub run {
44 0 ▶ my ($self, @args) = @_;
Subroutine run: not called CC=1 SCAR=6.9
Pod documented
45  
46 0 return;
47 }
48  
49 sub run_directly {
50 9 ▶ my $self = shift;
Subroutine run_directly: called CC=2 SCAR=7.4
Pod documented
51 9 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
090
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
52 9 require CLI::Dispatch;
53 9 CLI::Dispatch->run_directly($class);
54 }
55  
56 sub usage {
57 0 ▶ my ($self, $no_print) = @_;
Subroutine usage: not called CC=4 SCAR=30.0
Pod documented
58  
59 0 my $class = ref $self;
60 0 $class =~ s{::}{/}g;
61 0 $class .= '.pm';
62  
63 0 ▶ my $file = $INC{$class} || $0 or return;
Branch: 1 branch
BranchTrueFalseTotal
my $file = $INC{$class} || $0 or return 0 0 0
Condition0%0/3
$INC{$class} || $0
l!l&&r!l&&!r
000
MC/DC0%0/2
$INC{$class} || $0
$INC{$class} $0
Truth table0%0/3
A || B
A= $INC{$class}B= $0
ABresult
1X1
011
000
64 0 my $content = do { local $/; open my $fh, '<', $file; <$fh> };
65  
66 0 require CLI::Dispatch::Help;
67 0 my $help = CLI::Dispatch::Help->new(%$self);
68  
69 0 my $pod = $help->_parse_pod($content);
70 0 $pod = $help->extract_pod_body($pod);
71  
72 0 $pod =~ /^(\S+\s+.+?)\n(?=\S)/s; # extract first paragraph
73 0 ▶ $help->output( $1 || '', $no_print );
Condition0%0/2
$1 || ''
l!l
00
MC/DC0%0/1
$1 || ''
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
74 }
75  
76 10 1;
77  
78 __END__
« lib/CLI/Dispatch/Help.pm ↑ Summary lib/CLI/Dispatch.pm »