| 1 | package App::VTide::Command::Help; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # Created on: 2016-02-05 10:11:54 | ||||||||||||||||||||
| 4 | # Create by: Ivan Wills | ||||||||||||||||||||
| 5 | # $Id$ | ||||||||||||||||||||
| 6 | # $Revision$, $HeadURL$, $Date$ | ||||||||||||||||||||
| 7 | # $Revision$, $Source$, $Date$ | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use version; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 1 | ▶ | use English qw/ -no_match_vars /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | ▶ | use Pod::Usage; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | extends 'App::VTide::Command::Run'; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | our $VERSION = version->new('1.0.6'); | |||||||||||||||||||
| 19 | 1 | our $NAME = 'help'; | |||||||||||||||||||
| 20 | 1 | our $OPTIONS = [ 'test|T!', 'verbose|v+', ]; | |||||||||||||||||||
| 21 | 0 | ▶ | sub details_sub { return ( $NAME, $OPTIONS ) } | ||||||||||||||||||
|
Subroutine
details_sub: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | sub run { | ||||||||||||||||||
|
Subroutine
run: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||
| 24 | 0 | my ($self) = @_; | |||||||||||||||||||
| 25 | 0 | my $command = shift @ARGV; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 0 | my $sub = $self->vtide->_sub_commands; | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | ▶ | if ($command) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 0 | my $module = $self->cmd2module($command); | |||||||||||||||||||
| 31 | 0 | ▶ | if ( !$INC{$module} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 0 | require "$module"; ## no critic | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | pod2usage( | ||||||||||||||||||||
| 36 | -verbose => 1, | ||||||||||||||||||||
| 37 | 0 | -input => $INC{$module}, | |||||||||||||||||||
| 38 | ); | ||||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||
| 41 | 0 | my $max = 0; | |||||||||||||||||||
| 42 | 0 | for my $cmd ( keys %$sub ) { | |||||||||||||||||||
| 43 | 0 | my $file = $self->cmd2module($cmd); | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 0 | ▶ | if ( !$INC{$file} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | require "$file"; ## no critic | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | 0 | ▶ | if ( length $cmd > $max ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | $max = length $cmd; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | 0 | my $module = $file; | |||||||||||||||||||
| 52 | 0 | $module =~ s{/}{::}g; | |||||||||||||||||||
| 53 | 0 | $module =~ s{[.]pm$}{}; | |||||||||||||||||||
| 54 | 0 | my ( $name, $options, $local ) = $module->details_sub(); | |||||||||||||||||||
| 55 | 0 | ▶ | $sub->{$cmd} = { | ||||||||||||||||||
|
Condition0%0/2
$local || 0
MC/DC0%0/1
$local || 0
$local
Truth table0%0/2
A
A= $local
| |||||||||||||||||||||
| 56 | module => $file, | ||||||||||||||||||||
| 57 | local => $local || 0, | ||||||||||||||||||||
| 58 | }; | ||||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | my $last = -1; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | # show the list of commands and their descriptions | ||||||||||||||||||||
| 64 | 0 | for my $cmd ( | |||||||||||||||||||
| 65 | 0 | ▶ | sort { $sub->{$a}{local} <=> $sub->{$b}{local} || $a cmp $b } | ||||||||||||||||||
|
Condition0%0/3
$sub->{$a}{'local'} <=> $sub->{$b}{'local'} || $a cmp $b
MC/DC0%0/2
$sub->{$a}{'local'} <=> $sub->{$b}{'local'} || $a cmp $b
$sub->{$a}{'local'} <=> $sub->{$b}{'local'}
$a cmp $b
Truth table0%0/3
A || B
A= $sub->{$a}{'local'} <=> $sub->{$b}{'local'}B= $a cmp $b
| |||||||||||||||||||||
| 66 | keys %$sub | ||||||||||||||||||||
| 67 | ) { | ||||||||||||||||||||
| 68 | 0 | require Tie::Handle::Scalar; | |||||||||||||||||||
| 69 | 0 | my $out = ''; | |||||||||||||||||||
| 70 | 0 | tie *FH, 'Tie::Handle::Scalar', \$out; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | pod2usage( | ||||||||||||||||||||
| 73 | -verbose => 99, | ||||||||||||||||||||
| 74 | -input => $INC{ $sub->{$cmd}{module} }, | ||||||||||||||||||||
| 75 | 0 | -exitval => 'NOEXIT', | |||||||||||||||||||
| 76 | -output => \*FH, | ||||||||||||||||||||
| 77 | -sections => [qw/ NAME /], | ||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | ▶ | if ( $sub->{$cmd}{local} ne $last ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 0 | ▶ | print +( $sub->{$cmd}{local} ? "\nLocal" : 'Global' ), "\n"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | 0 | $last = $sub->{$cmd}{local}; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | $out =~ s/\s\s+/ /gxms; | |||||||||||||||||||
| 86 | 0 | $out | |||||||||||||||||||
| 87 | 0 | =~ s/Name:\s+App::VTide::Command::\w+/sprintf "%-${max}s", $cmd/exms; | |||||||||||||||||||
| 88 | 0 | print "$out\n"; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | return; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | ▶ | sub cmd2module { | ||||||||||||||||||
|
Subroutine
cmd2module: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 96 | 0 | my ( $self, $cmd ) = @_; | |||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | my $title = join '', map { ucfirst $_ } split /-/, $cmd; | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 0 | return 'App/VTide/Command/' . $title . '.pm'; | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | ▶ | sub auto_complete { | ||||||||||||||||||
|
Subroutine
auto_complete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 104 | 0 | my ($self) = @_; | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | my $env = $self->options->files->[-1]; | |||||||||||||||||||
| 107 | 0 | my $sub = $self->vtide->_sub_commands; | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | print join ' ', grep { $env ne 'help' ? /^$env/xms : 1 } sort keys %$sub; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 0 | return; | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 1 | 1; | |||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||