| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 66 | ▶ | if (!$self->can('log')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 65 | ▶ | $self->logger( $self->{verbose} || $self->{debug} || $self->{logfilter} ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->{"verbose"} or $self->{"debug"} or $self->{"logfilter"}
$self->{"verbose"} or $self->{"debug"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 65 | ▶ | if ($self->can('logfilter')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 65 | ▶ | my @filters = $self->{logfilter} ? split ',', $self->{logfilter} : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 65 | ▶ | push @filters, '!debug' unless $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 65 | $self->logfilter(@filters); | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 65 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 16 | ▶ | sub options { return () } | ||||||||||||||||||||||||||||||||||||||||
|
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$INC{$class} || $0
MC/DC0%0/2
$INC{$class} || $0
$INC{$class}
$0
Truth table0%0/3
A || B
A= $INC{$class}B= $0
| |||||||||||||||||||||||||||||||||||||||||||
| 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 || ''
MC/DC0%0/1
$1 || ''
$1
Truth table0%0/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | __END__ | ||||||||||||||||||||||||||||||||||||||||||