line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::optargs; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
4
|
use OptArgs; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
5
|
1
|
|
|
1
|
|
147
|
use lib 'lib'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.1.17_1'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$OptArgs::COLOUR = 1; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
arg class => ( |
11
|
|
|
|
|
|
|
isa => 'Str', |
12
|
|
|
|
|
|
|
required => 1, |
13
|
|
|
|
|
|
|
comment => 'OptArgs-based module to load', |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
arg name => ( |
17
|
|
|
|
|
|
|
isa => 'Str', |
18
|
|
|
|
|
|
|
comment => 'Name of the command', |
19
|
|
|
|
|
|
|
default => sub { '' } |
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
|
7
|
my $opts = shift; |
44
|
|
|
|
|
|
|
|
45
|
4
|
50
|
|
|
|
240
|
die $@ unless eval "require $opts->{class};"; |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
38
|
my $initial = do { my @tmp = split( /::/, $opts->{class} ) }; |
|
4
|
|
|
|
|
15
|
|
48
|
4
|
|
|
|
|
10
|
my $indent = $opts->{spacer} x $opts->{indent}; |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
1
|
|
6
|
binmode( STDOUT, ':encoding(utf8)' ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
49
|
|
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
1460
|
foreach my $cmd ( OptArgs::_cmdlist() ) { |
53
|
32
|
|
|
|
|
54
|
my $length = do { my @tmp = split( /::/, $cmd ) } |
|
32
|
|
|
|
|
123
|
|
54
|
|
|
|
|
|
|
- $initial; |
55
|
32
|
|
|
|
|
58
|
my $space = $indent x $length; |
56
|
|
|
|
|
|
|
|
57
|
32
|
50
|
|
|
|
70
|
unless ( $opts->{full} ) { |
58
|
32
|
|
|
|
|
87
|
my $usage = OptArgs::_synopsis($cmd); |
59
|
32
|
|
|
|
|
154
|
$usage =~ s/^usage: \S+/$space$opts->{name}/; |
60
|
32
|
|
|
|
|
594
|
print $usage; |
61
|
32
|
|
|
|
|
86
|
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__ |