line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::Kingpin::Commands; |
2
|
31
|
|
|
31
|
|
540
|
use 5.008001; |
|
31
|
|
|
|
|
132
|
|
3
|
31
|
|
|
31
|
|
158
|
use strict; |
|
31
|
|
|
|
|
58
|
|
|
31
|
|
|
|
|
607
|
|
4
|
31
|
|
|
31
|
|
151
|
use warnings; |
|
31
|
|
|
|
|
75
|
|
|
31
|
|
|
|
|
952
|
|
5
|
31
|
|
|
31
|
|
194
|
use Object::Simple -base; |
|
31
|
|
|
|
|
70
|
|
|
31
|
|
|
|
|
721
|
|
6
|
31
|
|
|
31
|
|
15735
|
use Getopt::Kingpin::Command; |
|
31
|
|
|
|
|
80
|
|
|
31
|
|
|
|
|
280
|
|
7
|
31
|
|
|
31
|
|
961
|
use Carp; |
|
31
|
|
|
|
|
66
|
|
|
31
|
|
|
|
|
15086
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.10"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has _commands => sub { |
12
|
|
|
|
|
|
|
return []; |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub add { |
16
|
93
|
|
|
93
|
1
|
555
|
my $self = shift; |
17
|
93
|
|
|
|
|
204
|
my $hash = {@_}; |
18
|
93
|
|
|
|
|
196
|
my ($name, $description, $parent) = ($hash->{name}, $hash->{description}, $hash->{parent}); |
19
|
|
|
|
|
|
|
|
20
|
93
|
|
|
|
|
272
|
my $command = Getopt::Kingpin::Command->new(name => $name, description => $description, parent => $parent); |
21
|
93
|
|
|
|
|
119
|
push @{$self->_commands}, $command; |
|
93
|
|
|
|
|
1297
|
|
22
|
|
|
|
|
|
|
|
23
|
93
|
|
|
|
|
583
|
return $command; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub count { |
27
|
173
|
|
|
173
|
1
|
684
|
my $self = shift; |
28
|
173
|
|
|
|
|
209
|
return scalar @{$self->_commands}; |
|
173
|
|
|
|
|
2474
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get { |
32
|
76
|
|
|
76
|
1
|
345
|
my $self = shift; |
33
|
76
|
|
|
|
|
135
|
my ($name) = @_; |
34
|
76
|
|
|
|
|
104
|
foreach my $cmd (@{$self->_commands}) { |
|
76
|
|
|
|
|
1202
|
|
35
|
66
|
100
|
|
|
|
1196
|
if ($cmd->name eq $name) { |
36
|
34
|
|
|
|
|
238
|
return $cmd; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
42
|
|
|
|
|
150
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_all { |
43
|
15
|
|
|
15
|
1
|
57
|
my $self = shift; |
44
|
15
|
|
|
|
|
20
|
return @{$self->_commands}; |
|
15
|
|
|
|
|
188
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub help { |
48
|
6
|
|
|
6
|
1
|
32
|
my $self = shift; |
49
|
6
|
|
|
|
|
8
|
my $ret = ""; |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
11
|
$ret .= "Commands:\n"; |
52
|
|
|
|
|
|
|
|
53
|
6
|
|
|
|
|
12
|
foreach my $cmd ($self->get_all) { |
54
|
17
|
100
|
|
|
|
243
|
if ($cmd->commands->count > 1) { |
55
|
2
|
|
|
|
|
34
|
foreach my $sub ($cmd->commands->get_all) { |
56
|
5
|
100
|
|
|
|
85
|
next if $sub->name eq "help"; |
57
|
3
|
|
|
|
|
49
|
$ret .= sprintf " %s %s\n", $cmd->name, $sub->name; |
58
|
3
|
|
|
|
|
62
|
$ret .= sprintf " %s\n", $sub->description; |
59
|
3
|
|
|
|
|
21
|
$ret .= sprintf "\n"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} else { |
62
|
15
|
|
|
|
|
35
|
$ret .= sprintf " %s\n", $cmd->help_short; |
63
|
15
|
|
|
|
|
214
|
$ret .= sprintf " %s\n", $cmd->description; |
64
|
15
|
|
|
|
|
105
|
$ret .= sprintf "\n"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
6
|
|
|
|
|
90
|
return $ret; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
__END__ |