line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::Kingpin::Commands; |
2
|
28
|
|
|
28
|
|
442
|
use 5.008001; |
|
28
|
|
|
|
|
99
|
|
3
|
28
|
|
|
28
|
|
150
|
use strict; |
|
28
|
|
|
|
|
51
|
|
|
28
|
|
|
|
|
622
|
|
4
|
28
|
|
|
28
|
|
140
|
use warnings; |
|
28
|
|
|
|
|
57
|
|
|
28
|
|
|
|
|
976
|
|
5
|
28
|
|
|
28
|
|
168
|
use Object::Simple -base; |
|
28
|
|
|
|
|
55
|
|
|
28
|
|
|
|
|
177
|
|
6
|
28
|
|
|
28
|
|
13116
|
use Getopt::Kingpin::Command; |
|
28
|
|
|
|
|
67
|
|
|
28
|
|
|
|
|
231
|
|
7
|
28
|
|
|
28
|
|
777
|
use Carp; |
|
28
|
|
|
|
|
46
|
|
|
28
|
|
|
|
|
12702
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.09"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has _commands => sub { |
12
|
|
|
|
|
|
|
return []; |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub add { |
16
|
86
|
|
|
86
|
1
|
539
|
my $self = shift; |
17
|
86
|
|
|
|
|
233
|
my $hash = {@_}; |
18
|
86
|
|
|
|
|
214
|
my ($name, $description, $parent) = ($hash->{name}, $hash->{description}, $hash->{parent}); |
19
|
|
|
|
|
|
|
|
20
|
86
|
|
|
|
|
274
|
my $command = Getopt::Kingpin::Command->new(name => $name, description => $description, parent => $parent); |
21
|
86
|
|
|
|
|
123
|
push @{$self->_commands}, $command; |
|
86
|
|
|
|
|
1438
|
|
22
|
|
|
|
|
|
|
|
23
|
86
|
|
|
|
|
624
|
return $command; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub count { |
27
|
159
|
|
|
159
|
1
|
665
|
my $self = shift; |
28
|
159
|
|
|
|
|
206
|
return scalar @{$self->_commands}; |
|
159
|
|
|
|
|
2559
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get { |
32
|
67
|
|
|
67
|
1
|
309
|
my $self = shift; |
33
|
67
|
|
|
|
|
140
|
my ($name) = @_; |
34
|
67
|
|
|
|
|
101
|
foreach my $cmd (@{$self->_commands}) { |
|
67
|
|
|
|
|
1093
|
|
35
|
60
|
100
|
|
|
|
1254
|
if ($cmd->name eq $name) { |
36
|
31
|
|
|
|
|
231
|
return $cmd; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
36
|
|
|
|
|
112
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_all { |
43
|
15
|
|
|
15
|
1
|
67
|
my $self = shift; |
44
|
15
|
|
|
|
|
26
|
return @{$self->_commands}; |
|
15
|
|
|
|
|
235
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub help { |
48
|
6
|
|
|
6
|
1
|
39
|
my $self = shift; |
49
|
6
|
|
|
|
|
11
|
my $ret = ""; |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
27
|
$ret .= "Commands:\n"; |
52
|
|
|
|
|
|
|
|
53
|
6
|
|
|
|
|
15
|
foreach my $cmd ($self->get_all) { |
54
|
17
|
100
|
|
|
|
303
|
if ($cmd->commands->count > 1) { |
55
|
2
|
|
|
|
|
43
|
foreach my $sub ($cmd->commands->get_all) { |
56
|
5
|
100
|
|
|
|
112
|
next if $sub->name eq "help"; |
57
|
3
|
|
|
|
|
65
|
$ret .= sprintf " %s %s\n", $cmd->name, $sub->name; |
58
|
3
|
|
|
|
|
75
|
$ret .= sprintf " %s\n", $sub->description; |
59
|
3
|
|
|
|
|
25
|
$ret .= sprintf "\n"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} else { |
62
|
15
|
|
|
|
|
46
|
$ret .= sprintf " %s\n", $cmd->help_short; |
63
|
15
|
|
|
|
|
268
|
$ret .= sprintf " %s\n", $cmd->description; |
64
|
15
|
|
|
|
|
128
|
$ret .= sprintf "\n"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
6
|
|
|
|
|
121
|
return $ret; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
__END__ |