line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::Kingpin::Commands; |
2
|
31
|
|
|
31
|
|
553
|
use 5.008001; |
|
31
|
|
|
|
|
108
|
|
3
|
31
|
|
|
31
|
|
180
|
use strict; |
|
31
|
|
|
|
|
68
|
|
|
31
|
|
|
|
|
653
|
|
4
|
31
|
|
|
31
|
|
138
|
use warnings; |
|
31
|
|
|
|
|
61
|
|
|
31
|
|
|
|
|
1154
|
|
5
|
31
|
|
|
31
|
|
183
|
use Object::Simple -base; |
|
31
|
|
|
|
|
80
|
|
|
31
|
|
|
|
|
212
|
|
6
|
31
|
|
|
31
|
|
16445
|
use Getopt::Kingpin::Command; |
|
31
|
|
|
|
|
91
|
|
|
31
|
|
|
|
|
278
|
|
7
|
31
|
|
|
31
|
|
906
|
use Carp; |
|
31
|
|
|
|
|
58
|
|
|
31
|
|
|
|
|
15863
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.11"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has _commands => sub { |
12
|
|
|
|
|
|
|
return []; |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub add { |
16
|
93
|
|
|
93
|
1
|
608
|
my $self = shift; |
17
|
93
|
|
|
|
|
251
|
my $hash = {@_}; |
18
|
93
|
|
|
|
|
260
|
my ($name, $description, $parent) = ($hash->{name}, $hash->{description}, $hash->{parent}); |
19
|
|
|
|
|
|
|
|
20
|
93
|
|
|
|
|
290
|
my $command = Getopt::Kingpin::Command->new(name => $name, description => $description, parent => $parent); |
21
|
93
|
|
|
|
|
146
|
push @{$self->_commands}, $command; |
|
93
|
|
|
|
|
1581
|
|
22
|
|
|
|
|
|
|
|
23
|
93
|
|
|
|
|
747
|
return $command; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub count { |
27
|
173
|
|
|
173
|
1
|
732
|
my $self = shift; |
28
|
173
|
|
|
|
|
248
|
return scalar @{$self->_commands}; |
|
173
|
|
|
|
|
2853
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get { |
32
|
76
|
|
|
76
|
1
|
365
|
my $self = shift; |
33
|
76
|
|
|
|
|
164
|
my ($name) = @_; |
34
|
76
|
|
|
|
|
109
|
foreach my $cmd (@{$self->_commands}) { |
|
76
|
|
|
|
|
1302
|
|
35
|
66
|
100
|
|
|
|
1456
|
if ($cmd->name eq $name) { |
36
|
34
|
|
|
|
|
261
|
return $cmd; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
42
|
|
|
|
|
142
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_all { |
43
|
15
|
|
|
15
|
1
|
68
|
my $self = shift; |
44
|
15
|
|
|
|
|
23
|
return @{$self->_commands}; |
|
15
|
|
|
|
|
266
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub help { |
48
|
6
|
|
|
6
|
1
|
37
|
my $self = shift; |
49
|
6
|
|
|
|
|
9
|
my $ret = ""; |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
13
|
$ret .= "Commands:\n"; |
52
|
|
|
|
|
|
|
|
53
|
6
|
|
|
|
|
15
|
foreach my $cmd ($self->get_all) { |
54
|
17
|
100
|
|
|
|
300
|
if ($cmd->commands->count > 1) { |
55
|
2
|
|
|
|
|
49
|
foreach my $sub ($cmd->commands->get_all) { |
56
|
5
|
100
|
|
|
|
111
|
next if $sub->name eq "help"; |
57
|
3
|
|
|
|
|
62
|
$ret .= sprintf " %s %s\n", $cmd->name, $sub->name; |
58
|
3
|
|
|
|
|
97
|
$ret .= sprintf " %s\n", $sub->description; |
59
|
3
|
|
|
|
|
28
|
$ret .= sprintf "\n"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} else { |
62
|
15
|
|
|
|
|
40
|
$ret .= sprintf " %s\n", $cmd->help_short; |
63
|
15
|
|
|
|
|
689
|
$ret .= sprintf " %s\n", $cmd->description; |
64
|
15
|
|
|
|
|
137
|
$ret .= sprintf "\n"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
6
|
|
|
|
|
124
|
return $ret; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
__END__ |