| 1 | #!/usr/bin/env perl | ||||||||||||
| 2 | package Test::Cool; | ||||||||||||
| 3 | 2 | ▶ | use Getopt::App -complete; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use File::Spec::Functions qw(catdir catfile rel2abs updir); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use File::Basename qw(dirname); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | sub command_foo { | ||||||||||||
| 8 | 2 | ▶ | my ($app, @args) = @_; | ||||||||||
|
Subroutine
command_foo: called CC=2 SCAR=6.9
| |||||||||||||
| 9 | 2 | ▶ | printf qq(args=%s foo=%s\n), join(',', @args), $app->{foo} // ''; | ||||||||||
|
Condition100%2/2
$app->{"foo"} // ""
MC/DC100%1/1
$app->{"foo"} // ""
$app->{"foo"}
Truth table100%2/2
A
A= $app->{"foo"}
| |||||||||||||
| 10 | } | ||||||||||||
| 11 | |||||||||||||
| 12 | # getopt_subcommands() is called by Getopt::App | ||||||||||||
| 13 | sub getopt_subcommands { | ||||||||||||
| 14 | 20 | ▶ | my $app = shift; | ||||||||||
|
Subroutine
getopt_subcommands: called CC=2 SCAR=7.0
| |||||||||||||
| 15 | 20 | my $method = ['foo', 'command_foo', 'internal method']; | |||||||||||
| 16 | |||||||||||||
| 17 | # Can also use File::Share or $INC{'My/Module.pm'} to locate commands | ||||||||||||
| 18 | 20 | my $dir = catdir dirname(__FILE__), updir, qw(lib Test Cool commands); | |||||||||||
| 19 | |||||||||||||
| 20 | 20 | ▶ | opendir(my ($DH), $dir) or die $!; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | 20 | return [$method, map { [s!\.pl$!!r, rel2abs(catfile $dir, $_), "Try $_"] } sort grep {/\.pl$/} readdir $DH]; | |||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | run( | ||||||||||||
| 25 | 'foo=s # Argument for foo', | ||||||||||||
| 26 | 'h # Print help', | ||||||||||||
| 27 | 'completion-script # Print autocomplete script', | ||||||||||||
| 28 | sub { | ||||||||||||
| 29 | 2 | ▶ | my ($app, @args) = @_; | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||
| 30 | 2 | ▶ | return print generate_completion_script() if $app->{'completion-script'}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 2 | ▶ | return print extract_usage() if $app->{h}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 1 | say __FILE__; | |||||||||||
| 33 | 1 | return 10; | |||||||||||
| 34 | } | ||||||||||||
| 35 | 2 | ); | |||||||||||