line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::Kingpin::Args; |
2
|
31
|
|
|
31
|
|
835
|
use 5.008001; |
|
31
|
|
|
|
|
121
|
|
3
|
31
|
|
|
31
|
|
172
|
use strict; |
|
31
|
|
|
|
|
55
|
|
|
31
|
|
|
|
|
673
|
|
4
|
31
|
|
|
31
|
|
168
|
use warnings; |
|
31
|
|
|
|
|
73
|
|
|
31
|
|
|
|
|
1096
|
|
5
|
31
|
|
|
31
|
|
193
|
use Object::Simple -base; |
|
31
|
|
|
|
|
84
|
|
|
31
|
|
|
|
|
195
|
|
6
|
31
|
|
|
31
|
|
15682
|
use Getopt::Kingpin::Arg; |
|
31
|
|
|
|
|
83
|
|
|
31
|
|
|
|
|
313
|
|
7
|
31
|
|
|
31
|
|
889
|
use Carp; |
|
31
|
|
|
|
|
74
|
|
|
31
|
|
|
|
|
16611
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.10"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has _args => sub { |
12
|
|
|
|
|
|
|
return []; |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has _args_remain => sub { |
16
|
|
|
|
|
|
|
return []; |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub add { |
20
|
123
|
|
|
123
|
1
|
437
|
my $self = shift; |
21
|
123
|
|
|
|
|
335
|
my $hash = {@_}; |
22
|
123
|
|
|
|
|
301
|
my ($name, $description) = ($hash->{name}, $hash->{description}); |
23
|
|
|
|
|
|
|
|
24
|
123
|
|
|
|
|
520
|
my $arg = Getopt::Kingpin::Arg->new( |
25
|
|
|
|
|
|
|
name => $name, |
26
|
|
|
|
|
|
|
description => $description, |
27
|
|
|
|
|
|
|
); |
28
|
123
|
|
|
|
|
764
|
push @{$self->_args}, $arg; |
|
123
|
|
|
|
|
2059
|
|
29
|
|
|
|
|
|
|
|
30
|
123
|
|
|
|
|
593
|
return $arg; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub count { |
34
|
628
|
|
|
628
|
1
|
4177
|
my $self = shift; |
35
|
628
|
|
|
|
|
808
|
return scalar @{$self->_args}; |
|
628
|
|
|
|
|
9619
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get { |
39
|
4
|
|
|
4
|
1
|
965
|
my $self = shift; |
40
|
4
|
|
|
|
|
10
|
my ($name) = @_; |
41
|
|
|
|
|
|
|
|
42
|
4
|
|
|
|
|
11
|
foreach my $arg ($self->get_all) { |
43
|
5
|
100
|
|
|
|
109
|
if ($arg->name eq $name) { |
44
|
3
|
|
|
|
|
30
|
return $arg; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
1
|
|
|
|
|
25
|
croak "get($name) failed"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_by_index { |
51
|
195
|
|
|
195
|
1
|
1583
|
my $self = shift; |
52
|
195
|
|
|
|
|
330
|
my ($index) = @_; |
53
|
|
|
|
|
|
|
|
54
|
195
|
100
|
|
|
|
370
|
if ($self->count <= $index) { |
55
|
1
|
|
|
|
|
15
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
194
|
|
|
|
|
3928
|
return $self->_args->[$index]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get_all { |
62
|
85
|
|
|
85
|
1
|
246
|
my $self = shift; |
63
|
85
|
|
|
|
|
110
|
return @{$self->_args}; |
|
85
|
|
|
|
|
1261
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _help_length { |
67
|
17
|
|
|
17
|
|
33
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
17
|
|
|
|
|
25
|
my $max_length_of_arg = 0; |
70
|
17
|
|
|
|
|
30
|
foreach my $arg ($self->get_all) { |
71
|
30
|
100
|
|
|
|
152
|
if ($max_length_of_arg < length $arg->help_name) { |
72
|
19
|
|
|
|
|
58
|
$max_length_of_arg = length $arg->help_name; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
17
|
|
|
|
|
33
|
return $max_length_of_arg; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub help { |
80
|
17
|
|
|
17
|
1
|
104
|
my $self = shift; |
81
|
17
|
|
|
|
|
32
|
my $ret = ""; |
82
|
|
|
|
|
|
|
|
83
|
17
|
|
|
|
|
32
|
$ret .= "Args:\n"; |
84
|
|
|
|
|
|
|
|
85
|
17
|
|
|
|
|
39
|
my $len = $self->_help_length; |
86
|
17
|
|
|
|
|
85
|
foreach my $arg ($self->get_all) { |
87
|
30
|
|
|
|
|
237
|
$ret .= sprintf " %-${len}s %s\n", |
88
|
|
|
|
|
|
|
$arg->help_name, |
89
|
|
|
|
|
|
|
$arg->description; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
17
|
|
|
|
|
366
|
return $ret; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
__END__ |