File Coverage

example/bin/cool
Criterion Covered Total %
statement 15 15 100.0
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod n/a
total 20 21 95.2


line stmt bran cond sub pod time code
1             #!/usr/bin/env perl
2             package Test::Cool;
3 2     2   3113 use Getopt::App -complete;
  2         4  
  2         19  
4 2     2   12 use File::Spec::Functions qw(catdir catfile rel2abs updir);
  2         4  
  2         139  
5 2     2   13 use File::Basename qw(dirname);
  2         4  
  2         699  
6              
7             # getopt_subcommands() is called by Getopt::App
8             sub getopt_subcommands {
9 18     18   28 my $app = shift;
10              
11             # Can also use File::Share or $INC{'My/Module.pm'} to locate commands
12 18         784 my $dir = catdir dirname(__FILE__), updir, qw(lib Test Cool commands);
13              
14 18 50       824 opendir(my ($DH), $dir) or die $!;
15 90         1233 return [map { [s!\.pl$!!r, rel2abs(catfile $dir, $_), "Try $_"] }
16 18         453 sort grep {/\.pl$/} readdir $DH];
  126         399  
17             }
18              
19             run(
20             'h # Print help',
21             'completion-script # Print autocomplete script',
22             sub {
23             my ($app, @args) = @_;
24             return print generate_completion_script() if $app->{'completion-script'};
25             return print extract_usage() if $app->{h};
26             say __FILE__;
27             return 10;
28             }
29             );