line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Rad::Help; |
2
|
9
|
|
|
9
|
|
9807
|
use Attribute::Handlers; |
|
9
|
|
|
|
|
52578
|
|
|
9
|
|
|
|
|
60
|
|
3
|
9
|
|
|
9
|
|
354
|
use strict; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
263
|
|
4
|
9
|
|
|
9
|
|
46
|
use warnings; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
3487
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub load { |
9
|
7
|
|
|
7
|
1
|
21
|
my ($self, $c) = @_; |
10
|
7
|
|
|
|
|
42
|
$c->register('help', \&help, 'show syntax and available commands'); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# shows specific help commands |
14
|
|
|
|
|
|
|
# TODO: context specific help, |
15
|
|
|
|
|
|
|
# such as "myapp.pl help command" |
16
|
|
|
|
|
|
|
sub help { |
17
|
0
|
|
|
0
|
1
|
0
|
my $c = shift; |
18
|
0
|
|
|
|
|
0
|
return usage() . "\n\n" . helpstr($c); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub usage { |
22
|
0
|
|
|
0
|
1
|
0
|
return "Usage: $0 command [arguments]"; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub helpstr { |
26
|
0
|
|
|
0
|
1
|
0
|
my $c = shift; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
0
|
my $string = "Available Commands:\n"; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# get length of largest command name |
31
|
0
|
|
|
|
|
0
|
my $len = 0; |
32
|
0
|
|
|
|
|
0
|
foreach ( sort $c->commands() ) { |
33
|
0
|
0
|
|
|
|
0
|
$len = length($_) if (length($_) > $len); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# format help string |
37
|
0
|
|
|
|
|
0
|
foreach ( sort $c->commands() ) { |
38
|
0
|
0
|
|
|
|
0
|
$string .= sprintf " %-*s\t%s\n", $len, $_, |
39
|
|
|
|
|
|
|
defined ($c->{'_commands'}->{$_}->{'help'}) |
40
|
|
|
|
|
|
|
? $c->{'_commands'}->{$_}->{'help'} |
41
|
|
|
|
|
|
|
: '' |
42
|
|
|
|
|
|
|
; |
43
|
|
|
|
|
|
|
; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
0
|
return $string; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
{ |
50
|
|
|
|
|
|
|
my %help_attr = (); |
51
|
|
|
|
|
|
|
sub UNIVERSAL::Help :ATTR(CODE) { |
52
|
0
|
|
|
0
|
0
|
0
|
my ($package, $symbol, $ref, $attr, $data, $phase, $filename, $linenum) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
0
|
if ($package eq 'main') { |
55
|
|
|
|
|
|
|
# If data is a single word, it is received as an array ref. Don't ask. |
56
|
0
|
0
|
|
|
|
0
|
$data = join(' ', @$data) if ref($data) eq 'ARRAY'; |
57
|
0
|
|
|
|
|
0
|
$help_attr{ *{$symbol}{NAME} } = $data; |
|
0
|
|
|
|
|
0
|
|
58
|
|
|
|
|
|
|
} |
59
|
9
|
|
|
9
|
|
51
|
} |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
48
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub register_help { |
62
|
36
|
|
|
36
|
1
|
57
|
my ($self, $c, $cmd, $helptext) = @_; |
63
|
|
|
|
|
|
|
|
64
|
36
|
50
|
66
|
|
|
165
|
if ((not defined $helptext) && (defined $help_attr{$cmd})) { |
65
|
0
|
|
|
|
|
0
|
$helptext = $help_attr{$cmd}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# we do $helptext // undef as it would issue a warning otherwise |
69
|
36
|
100
|
|
|
|
154
|
$c->{'_commands'}->{$cmd}->{'help'} = defined $helptext |
70
|
|
|
|
|
|
|
? $helptext |
71
|
|
|
|
|
|
|
: undef |
72
|
|
|
|
|
|
|
; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
42; |
77
|
|
|
|
|
|
|
__END__ |