line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
|
|
|
|
|
|
package Test::Cool; |
3
|
2
|
|
|
2
|
|
3044
|
use Getopt::App -complete; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
4
|
2
|
|
|
2
|
|
10
|
use File::Spec::Functions qw(catdir catfile rel2abs updir); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
126
|
|
5
|
2
|
|
|
2
|
|
11
|
use File::Basename qw(dirname); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
827
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub command_foo { |
8
|
2
|
|
|
2
|
|
5
|
my ($app, @args) = @_; |
9
|
2
|
|
100
|
|
|
106
|
printf qq(args=%s foo=%s\n), join(',', @args), $app->{foo} // ''; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# getopt_subcommands() is called by Getopt::App |
13
|
|
|
|
|
|
|
sub getopt_subcommands { |
14
|
20
|
|
|
20
|
|
30
|
my $app = shift; |
15
|
20
|
|
|
|
|
41
|
my $method = ['foo', 'command_foo', 'internal method']; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Can also use File::Share or $INC{'My/Module.pm'} to locate commands |
18
|
20
|
|
|
|
|
806
|
my $dir = catdir dirname(__FILE__), updir, qw(lib Test Cool commands); |
19
|
|
|
|
|
|
|
|
20
|
20
|
50
|
|
|
|
815
|
opendir(my ($DH), $dir) or die $!; |
21
|
20
|
|
|
|
|
508
|
return [$method, map { [s!\.pl$!!r, rel2abs(catfile $dir, $_), "Try $_"] } sort grep {/\.pl$/} readdir $DH]; |
|
100
|
|
|
|
|
1347
|
|
|
140
|
|
|
|
|
436
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
run( |
25
|
|
|
|
|
|
|
'foo=s # Argument for foo', |
26
|
|
|
|
|
|
|
'h # Print help', |
27
|
|
|
|
|
|
|
'completion-script # Print autocomplete script', |
28
|
|
|
|
|
|
|
sub { |
29
|
|
|
|
|
|
|
my ($app, @args) = @_; |
30
|
|
|
|
|
|
|
return print generate_completion_script() if $app->{'completion-script'}; |
31
|
|
|
|
|
|
|
return print extract_usage() if $app->{h}; |
32
|
|
|
|
|
|
|
say __FILE__; |
33
|
|
|
|
|
|
|
return 10; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
); |