line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::Kingpin::Args; |
2
|
31
|
|
|
31
|
|
702
|
use 5.008001; |
|
31
|
|
|
|
|
107
|
|
3
|
31
|
|
|
31
|
|
167
|
use strict; |
|
31
|
|
|
|
|
90
|
|
|
31
|
|
|
|
|
676
|
|
4
|
31
|
|
|
31
|
|
175
|
use warnings; |
|
31
|
|
|
|
|
66
|
|
|
31
|
|
|
|
|
1221
|
|
5
|
31
|
|
|
31
|
|
200
|
use Object::Simple -base; |
|
31
|
|
|
|
|
84
|
|
|
31
|
|
|
|
|
219
|
|
6
|
31
|
|
|
31
|
|
16387
|
use Getopt::Kingpin::Arg; |
|
31
|
|
|
|
|
87
|
|
|
31
|
|
|
|
|
331
|
|
7
|
31
|
|
|
31
|
|
938
|
use Carp; |
|
31
|
|
|
|
|
65
|
|
|
31
|
|
|
|
|
18020
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.11"; |
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
|
446
|
my $self = shift; |
21
|
123
|
|
|
|
|
330
|
my $hash = {@_}; |
22
|
123
|
|
|
|
|
313
|
my ($name, $description) = ($hash->{name}, $hash->{description}); |
23
|
|
|
|
|
|
|
|
24
|
123
|
|
|
|
|
451
|
my $arg = Getopt::Kingpin::Arg->new( |
25
|
|
|
|
|
|
|
name => $name, |
26
|
|
|
|
|
|
|
description => $description, |
27
|
|
|
|
|
|
|
); |
28
|
123
|
|
|
|
|
775
|
push @{$self->_args}, $arg; |
|
123
|
|
|
|
|
2207
|
|
29
|
|
|
|
|
|
|
|
30
|
123
|
|
|
|
|
565
|
return $arg; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub count { |
34
|
628
|
|
|
628
|
1
|
4703
|
my $self = shift; |
35
|
628
|
|
|
|
|
814
|
return scalar @{$self->_args}; |
|
628
|
|
|
|
|
9961
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get { |
39
|
4
|
|
|
4
|
1
|
1136
|
my $self = shift; |
40
|
4
|
|
|
|
|
9
|
my ($name) = @_; |
41
|
|
|
|
|
|
|
|
42
|
4
|
|
|
|
|
11
|
foreach my $arg ($self->get_all) { |
43
|
5
|
100
|
|
|
|
120
|
if ($arg->name eq $name) { |
44
|
3
|
|
|
|
|
31
|
return $arg; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
1
|
|
|
|
|
27
|
croak "get($name) failed"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_by_index { |
51
|
195
|
|
|
195
|
1
|
1729
|
my $self = shift; |
52
|
195
|
|
|
|
|
345
|
my ($index) = @_; |
53
|
|
|
|
|
|
|
|
54
|
195
|
100
|
|
|
|
339
|
if ($self->count <= $index) { |
55
|
1
|
|
|
|
|
12
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
194
|
|
|
|
|
4129
|
return $self->_args->[$index]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get_all { |
62
|
85
|
|
|
85
|
1
|
315
|
my $self = shift; |
63
|
85
|
|
|
|
|
122
|
return @{$self->_args}; |
|
85
|
|
|
|
|
1398
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _help_length { |
67
|
17
|
|
|
17
|
|
30
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
17
|
|
|
|
|
26
|
my $max_length_of_arg = 0; |
70
|
17
|
|
|
|
|
34
|
foreach my $arg ($self->get_all) { |
71
|
30
|
100
|
|
|
|
184
|
if ($max_length_of_arg < length $arg->help_name) { |
72
|
19
|
|
|
|
|
49
|
$max_length_of_arg = length $arg->help_name; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
17
|
|
|
|
|
35
|
return $max_length_of_arg; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub help { |
80
|
17
|
|
|
17
|
1
|
120
|
my $self = shift; |
81
|
17
|
|
|
|
|
26
|
my $ret = ""; |
82
|
|
|
|
|
|
|
|
83
|
17
|
|
|
|
|
73
|
$ret .= "Args:\n"; |
84
|
|
|
|
|
|
|
|
85
|
17
|
|
|
|
|
65
|
my $len = $self->_help_length; |
86
|
17
|
|
|
|
|
40
|
foreach my $arg ($self->get_all) { |
87
|
30
|
|
|
|
|
267
|
$ret .= sprintf " %-${len}s %s\n", |
88
|
|
|
|
|
|
|
$arg->help_name, |
89
|
|
|
|
|
|
|
$arg->description; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
17
|
|
|
|
|
442
|
return $ret; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
__END__ |