line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CLI::Dispatch::Command; |
2
|
|
|
|
|
|
|
|
3
|
12
|
|
|
12
|
|
56816
|
use strict; |
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
269
|
|
4
|
12
|
|
|
12
|
|
105
|
use warnings; |
|
12
|
|
|
|
|
18
|
|
|
12
|
|
|
|
|
5152
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub new { |
7
|
91
|
|
|
91
|
1
|
120
|
my $class = shift; |
8
|
91
|
|
|
|
|
161
|
my $self = bless {}, $class; |
9
|
91
|
50
|
|
|
|
210
|
$self->set_options(@_) if @_; |
10
|
|
|
|
|
|
|
|
11
|
91
|
100
|
|
|
|
457
|
if (!$self->can('log')) { |
12
|
10
|
|
|
|
|
3827
|
require Log::Dump; Log::Dump->import; |
|
10
|
|
|
|
|
13552
|
|
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
91
|
|
|
|
|
2269
|
$self; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub set_options { |
19
|
92
|
|
|
92
|
1
|
118
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
92
|
|
|
|
|
190
|
my %args = @_; |
22
|
92
|
|
|
|
|
227
|
for (keys %args) { |
23
|
131
|
100
|
|
|
|
298
|
die "override $_ by a command argument" if defined $self->{$_}; |
24
|
130
|
|
|
|
|
210
|
$self->{$_} = $args{$_}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
91
|
50
|
|
|
|
429
|
if ($self->can('logger')) { |
28
|
91
|
100
|
66
|
|
|
606
|
$self->logger( $self->{verbose} || $self->{debug} || $self->{logfilter} ? 1 : 0 ); |
29
|
|
|
|
|
|
|
} |
30
|
91
|
50
|
|
|
|
971
|
if ($self->can('logfilter')) { |
31
|
91
|
100
|
|
|
|
195
|
my @filters = $self->{logfilter} ? split ',', $self->{logfilter} : (); |
32
|
91
|
100
|
|
|
|
212
|
push @filters, '!debug' unless $self->{debug}; |
33
|
91
|
|
|
|
|
239
|
$self->logfilter(@filters); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
91
|
|
|
|
|
1436
|
$self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
29
|
|
|
29
|
1
|
75
|
sub options { return () } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub option { |
42
|
139
|
|
|
139
|
1
|
262
|
my ($self, $name) = @_; |
43
|
|
|
|
|
|
|
|
44
|
139
|
100
|
|
|
|
1103
|
defined $self->{$name} ? $self->{$name} : ''; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub run { |
48
|
0
|
|
|
0
|
1
|
0
|
my ($self, @args) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub run_directly { |
54
|
9
|
|
|
9
|
1
|
68736
|
my $self = shift; |
55
|
9
|
|
33
|
|
|
43
|
my $class = ref $self || $self; |
56
|
9
|
|
|
|
|
809
|
require CLI::Dispatch; |
57
|
9
|
|
|
|
|
33
|
CLI::Dispatch->run_directly($class); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub usage { |
61
|
0
|
|
|
0
|
1
|
|
my ($self, $no_print) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $class = ref $self; |
64
|
0
|
|
|
|
|
|
$class =~ s{::}{/}g; |
65
|
0
|
|
|
|
|
|
$class .= '.pm'; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
0
|
|
|
|
my $file = $INC{$class} || $0 or return; |
68
|
0
|
|
|
|
|
|
my $content = do { local $/; open my $fh, '<', $file; <$fh> }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
require CLI::Dispatch::Help; |
71
|
0
|
|
|
|
|
|
my $help = CLI::Dispatch::Help->new(%$self); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $pod = $help->_parse_pod($content); |
74
|
0
|
|
|
|
|
|
$pod = $help->extract_pod_body($pod); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$pod =~ /^(\S+\s+.+?)\n(?=\S)/s; # extract first paragraph |
77
|
0
|
|
0
|
|
|
|
$help->output( $1 || '', $no_print ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |