line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::optargs; |
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
3
|
use OptArgs; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
5
|
1
|
|
|
1
|
|
117
|
use lib 'lib'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.1.15_1'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$OptArgs::COLOUR = 1; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
arg class => ( |
11
|
|
|
|
|
|
|
isa => 'Str', |
12
|
|
|
|
|
|
|
required => 1, |
13
|
|
|
|
|
|
|
comment => 'OptArgs-based module to map', |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
arg name => ( |
17
|
|
|
|
|
|
|
isa => 'Str', |
18
|
|
|
|
|
|
|
comment => 'Name of the command', |
19
|
|
|
|
|
|
|
default => sub { ( my $x = shift->{class} ) =~ s/.*://; $x; } |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
opt indent => ( |
23
|
|
|
|
|
|
|
isa => 'Int', |
24
|
|
|
|
|
|
|
comment => 'Number of spaces to indent sub-commands', |
25
|
|
|
|
|
|
|
alias => 'i', |
26
|
|
|
|
|
|
|
default => 4, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
opt spacer => ( |
30
|
|
|
|
|
|
|
isa => 'Str', |
31
|
|
|
|
|
|
|
comment => 'Character to use for indent spaces', |
32
|
|
|
|
|
|
|
default => ' ', |
33
|
|
|
|
|
|
|
alias => 's', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
opt full => ( |
37
|
|
|
|
|
|
|
isa => 'Bool', |
38
|
|
|
|
|
|
|
comment => 'Print the full usage messages', |
39
|
|
|
|
|
|
|
alias => 'f', |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub run { |
43
|
4
|
|
|
4
|
1
|
4
|
my $opts = shift; |
44
|
|
|
|
|
|
|
|
45
|
4
|
50
|
|
|
|
150
|
die $@ unless eval "require $opts->{class};"; |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
29
|
my $initial = do { my @tmp = split( /::/, $opts->{class} ) }; |
|
4
|
|
|
|
|
16
|
|
48
|
4
|
|
|
|
|
9
|
my $indent = $opts->{spacer} x $opts->{indent}; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
5
|
binmode( STDOUT, ':encoding(utf8)' ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
48
|
|
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
996
|
foreach my $cmd ( OptArgs::_cmdlist( $opts->{class} ) ) { |
53
|
32
|
|
|
|
|
27
|
my $length = do { my @tmp = split( /::/, $cmd ) } |
|
32
|
|
|
|
|
120
|
|
54
|
|
|
|
|
|
|
- $initial; |
55
|
32
|
|
|
|
|
43
|
my $space = $indent x $length; |
56
|
|
|
|
|
|
|
|
57
|
32
|
50
|
|
|
|
55
|
unless ( $opts->{full} ) { |
58
|
32
|
|
|
|
|
60
|
my $usage = OptArgs::_synopsis($cmd); |
59
|
32
|
|
|
|
|
115
|
$usage =~ s/^usage: \S+/$space$opts->{name}/; |
60
|
32
|
|
|
|
|
468
|
print $usage; |
61
|
32
|
|
|
|
|
62
|
next; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $usage = OptArgs::_usage($cmd); |
65
|
0
|
|
|
|
|
|
$usage =~ s/^usage: \S+/usage: $opts->{name}/; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $n = 79 - length $space; |
68
|
0
|
|
|
|
|
|
print $space, '#' x $n, "\n"; |
69
|
0
|
|
|
|
|
|
print $space, "# $cmd\n"; |
70
|
0
|
|
|
|
|
|
print $space, '#' x $n, "\n"; |
71
|
0
|
|
|
|
|
|
$usage =~ s/^/$space/gm; |
72
|
0
|
|
|
|
|
|
print $usage; |
73
|
0
|
|
|
|
|
|
print $space . "\n"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |