| 1 | package App::CLI::Helper; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use File::Basename qw( basename ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | for (qw(commands files prog_name)) { | |||||||||||||||||||||||||||||||||||||||||
| 12 | 12 | *{ $caller . "::$_" } = *$_; | |||||||||||||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head3 commands() | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | List the application commands. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 24 | ▶ | sub commands { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commands: called CC=6 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 24 | my ( $class, $include_alias ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 24 | ▶ | my $dir = ref($class) || $class; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 24 | $dir =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 24 | $dir = $INC{ $dir . '.pm' }; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 24 | $dir =~ s/\.pm$//; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 24 | my @cmds = map { ($_) = m{^\Q$dir\E/(.*)\.pm}; lc($_) } $class->files; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 24 | ▶ | if ( $include_alias and ref $class and $class->can('alias') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$include_alias and ref $class and $class->can("alias")
$include_alias and ref $class
MC/DC0%0/3
$include_alias and ref $class and $class->can("alias")
$include_alias
ref $class
$class->can("alias")
Truth table25%1/4
A and B and C
A= $include_aliasB= ref $classC= $class->can("alias")
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my %aliases = $class->alias; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | push @cmds, $_ foreach keys %aliases; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 24 | my @sorted_cmds = sort @cmds; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 24 | return @sorted_cmds; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | =head3 prog_name() | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | The name of the program running your application. This will default to | ||||||||||||||||||||||||||||||||||||||||||
| 44 | C<basename $0>, but can be overridden from within your application. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | my $default; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | sub prog_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prog_name: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | $default = basename $0 unless $default; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | return $default unless ref $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | return $self->{prog_name} if defined $self->{prog_name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | $self->{prog_name} = basename $0; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | return $self->{prog_name}; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | =head3 files() | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | Return module files of subcommands of first level | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | sub files { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
files: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 28 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 28 | ▶ | $class = ref($class) if ref($class); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 28 | $class =~ s{::}{/}g; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 28 | my $dir = $INC{ $class . '.pm' }; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 28 | $dir =~ s/\.pm$//; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | ▶ | my @sorted_files = sort glob("$dir/*.pm"); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 28 | return @sorted_files; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||