File Coverage

example/bin/cool
Criterion Covered Total %
statement 18 18 100.0
branch 1 2 50.0
condition 2 2 100.0
subroutine 5 5 100.0
pod n/a
total 26 27 96.3


line stmt bran cond sub pod time code
1             #!/usr/bin/env perl
2             package Test::Cool;
3 2     2   177177 use Getopt::App -complete;
  2         5  
  2         21  
4 2     2   12 use File::Spec::Functions qw(catdir catfile rel2abs updir);
  2         3  
  2         161  
5 2     2   10 use File::Basename qw(dirname);
  2         3  
  2         1088  
6              
7             sub command_foo {
8 2     2   6 my ($app, @args) = @_;
9 2   100     119 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 22     22   33 my $app = shift;
15 22         60 my $method = ['foo', 'command_foo', 'internal method'];
16              
17             # Can also use File::Share or $INC{'My/Module.pm'} to locate commands
18 22         1236 my $dir = catdir dirname(__FILE__), updir, qw(lib Test Cool commands);
19              
20 22 50       1780 opendir(my ($DH), $dir) or die $!;
21 22         793 return [$method, map { [s!\.pl$!!r, rel2abs(catfile $dir, $_), "Try $_"] } sort grep {/\.pl$/} readdir $DH];
  110         1426  
  154         413  
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 join '|', $Getopt::App::DEPTH, __FILE__;
33             return 10;
34             }
35             );