| 1 | package CLI::Dispatch::Help; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use base qw( CLI::Dispatch::Command ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Class::Unload; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Class::Inspector; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Pod::Simple::Text; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use String::CamelCase; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Term::Encoding (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 9 | ▶ | my $term_encoding = eval { | ||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
&find_encoding(scalar Term::Encoding::get_encoding())
}
} || 'utf8'
MC/DC0%0/1
eval {
do {
&find_encoding(scalar Term::Encoding::get_encoding())
}
} || 'utf8'
eval {
do {
&find_encoding(scalar Term::Encoding::get_encoding())
}
}
Truth table50%1/2
A
A= eval {
do {
&find_encoding(scalar Term::Encoding::get_encoding())
}
}
| |||||||||||||||||||||||||||||
| 16 | 9 | find_encoding(Term::Encoding::get_encoding()) | |||||||||||||||||||||||||||
| 17 | } || 'utf8'; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 8 | ▶ | sub options {qw( from|decode=s to|encode=s )} | ||||||||||||||||||||||||||
|
Subroutine
options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | ▶ | sub extra_namespaces {} | |||||||||||||||||||||||||||
|
Subroutine
extra_namespaces: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub run { | ||||||||||||||||||||||||||||
| 25 | 8 | ▶ | my ($self, @args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 8 | my $text; | |||||||||||||||||||||||||||
| 28 | 8 | ▶ | if ( @args ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 8 | $text = $self->extract_pod( @args ); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | else { | ||||||||||||||||||||||||||||
| 32 | 4 | $text = $self->list_commands; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 8 | $self->output( $text ); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub output { | ||||||||||||||||||||||||||||
| 39 | 14 | ▶ | my ($self, $text, $no_print) = @_; | ||||||||||||||||||||||||||
|
Subroutine
output: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 14 | ▶ | unless ( Encode::is_utf8( $text ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 10 | ▶ | $text = decode( $self->option('from') || 'utf8', $text ) | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->option('from') || 'utf8'
MC/DC0%0/1
$self->option('from') || 'utf8'
$self->option('from')
Truth table50%1/2
A
A= $self->option('from')
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 14 | ▶ | $text = encode( $self->option('to') || $term_encoding, $text ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->option('to') || $term_encoding
MC/DC0%0/2
$self->option('to') || $term_encoding
$self->option('to')
$term_encoding
Truth table33%1/3
A || B
A= $self->option('to')B= $term_encoding
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 14 | ▶ | print $text unless $no_print; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 14 | return $text; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub extract_pod { | ||||||||||||||||||||||||||||
| 52 | 8 | ▶ | my ($self, $command) = @_; | ||||||||||||||||||||||||||
|
Subroutine
extract_pod: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 8 | my $content = $self->_lookup( $command ); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 8 | ▶ | unless ( $content ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 4 | ▶ | $self->logger(1) unless $self->logger; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 4 | $self->log( warn => "$command is not found" ); | |||||||||||||||||||||||||||
| 59 | 4 | return $self->list_commands; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 8 | my $pod = $self->_parse_pod($content); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 8 | return $self->extract_pod_body($pod); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub extract_pod_body { | ||||||||||||||||||||||||||||
| 68 | 8 | ▶ | my ($self, $pod) = @_; | ||||||||||||||||||||||||||
|
Subroutine
extract_pod_body: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # remove the first ("NAME") section as the command does not | ||||||||||||||||||||||||||||
| 71 | # always belong to the same namespace as the dispatcher/script. | ||||||||||||||||||||||||||||
| 72 | # (default CLI::Dispatch namespace may be confusing for end users) | ||||||||||||||||||||||||||||
| 73 | 8 | $pod =~ s/^\S+\s+(.+?)\n(?=\S)//s; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 8 | return $pod; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub list_commands { | ||||||||||||||||||||||||||||
| 79 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
list_commands: called CC=19 SCAR=38.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | my @paths = map { s{::}{/}g; $_ } $self->_namespaces; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 4 | my %found; | |||||||||||||||||||||||||||
| 84 | my %classes; | ||||||||||||||||||||||||||||
| 85 | 4 | my $maxlength = 0; | |||||||||||||||||||||||||||
| 86 | 4 | foreach my $inc ( @INC ) { | |||||||||||||||||||||||||||
| 87 | 4 | foreach my $path ( @paths ) { | |||||||||||||||||||||||||||
| 88 | 4 | my $dir = path( $inc, $path ); | |||||||||||||||||||||||||||
| 89 | 4 | ▶ | next unless $dir->exists && $dir->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$dir->exists and $dir->is_dir
MC/DC0%0/2
$dir->exists and $dir->is_dir
$dir->exists
$dir->is_dir
Truth table0%0/3
A and B
A= $dir->existsB= $dir->is_dir
| |||||||||||||||||||||||||||||
| 90 | 4 | my $iter = $dir->iterator({recurse => 1}); | |||||||||||||||||||||||||||
| 91 | 4 | ▶ | while (my $file = $iter->()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 4 | ▶ | next if $file->is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 4 | my $basename = $file->basename; | |||||||||||||||||||||||||||
| 95 | 4 | $basename =~ s/\.(?:pm|pod)$//; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 4 | ▶ | next if defined $found{$basename}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 4 | (my $class = $path) =~ s{/}{::}g; | |||||||||||||||||||||||||||
| 100 | 4 | $class .= '::'.$basename; | |||||||||||||||||||||||||||
| 101 | 4 | $classes{$class} = 1; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # ignore base class | ||||||||||||||||||||||||||||
| 104 | 4 | ▶ | next if $class eq 'CLI::Dispatch::Command'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 4 | my $podfile = $file->parent->child($basename . '.pod'); | |||||||||||||||||||||||||||
| 107 | 4 | my $pmfile = $file->parent->child($basename . '.pm'); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # should always parse .pod file if it exists | ||||||||||||||||||||||||||||
| 110 | 4 | ▶ | my $pod = $self->_parse_pod($podfile->exists ? $podfile->slurp : $file->slurp); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 4 | $basename = $self->convert_command($basename); | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 4 | ▶ | $found{$basename} ||= $self->extract_brief_description($pod, $class); | ||||||||||||||||||||||||||
|
Condition0%0/3
$found{$basename} ||= $self->extract_brief_description($pod, $class)
MC/DC0%0/2
$found{$basename} ||= $self->extract_brief_description($pod, $class)
$found{$basename}
$self->extract_brief_description($pod, $class)
Truth table0%0/3
A ||= B
A= $found{$basename}B= $self->extract_brief_description($pod, $class)
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # check availability | ||||||||||||||||||||||||||||
| 117 | 4 | ▶ | if ( $pmfile->exists ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 4 | my $loaded = Class::Inspector->loaded($class); | |||||||||||||||||||||||||||
| 119 | 4 | ▶ | Class::Unload->unload($class) if $loaded; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 4 | my $error; | |||||||||||||||||||||||||||
| 121 | 4 | ▶ | try { eval "require $class" or die } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=11.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 4 | ▶ | catch { $error = $_ || 'Obscure error' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=9.2
Condition0%0/2
$_ || 'Obscure error'
MC/DC0%0/1
$_ || 'Obscure error'
$_
Truth table0%0/2
A
A= $_
| |||||||||||||||||||||||||||||
| 123 | 4 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 124 | 4 | ▶ | if ($error =~ /^Can't locate /) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | # most probably this is a subcommand of some command | ||||||||||||||||||||||||||||
| 126 | # (ie. in a wrong namespace) | ||||||||||||||||||||||||||||
| 127 | 4 | delete $found{$basename}; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | else { | ||||||||||||||||||||||||||||
| 130 | 4 | $found{$basename} .= " [disabled: compile error]"; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | elsif ( $class->can('check') ) { | ||||||||||||||||||||||||||||
| 134 | 4 | ▶ | try { $class->check } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 135 | catch { | ||||||||||||||||||||||||||||
| 136 | 4 | ▶ | $error = $_ || 'Obscure error'; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
Condition0%0/2
$_ || 'Obscure error'
MC/DC0%0/1
$_ || 'Obscure error'
$_
Truth table0%0/2
A
A= $_
| |||||||||||||||||||||||||||||
| 137 | 4 | $error =~ s/\s+at .+? line \d+\.?\s*$//; | |||||||||||||||||||||||||||
| 138 | 4 | $found{$basename} .= " [disabled: $error]"; | |||||||||||||||||||||||||||
| 139 | 4 | }; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | 4 | ▶ | Class::Unload->unload($class) unless $loaded; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 4 | my $len = length $basename; | |||||||||||||||||||||||||||
| 145 | 4 | ▶ | $maxlength = $len if $maxlength < $len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 4 | my $text = ''; | |||||||||||||||||||||||||||
| 151 | 4 | my $format = "%-${maxlength}s - %s\n"; | |||||||||||||||||||||||||||
| 152 | 4 | foreach my $key ( sort keys %found ) { | |||||||||||||||||||||||||||
| 153 | 4 | $text .= sprintf($format, $key, $found{$key}); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 4 | return $text; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | sub convert_command { | ||||||||||||||||||||||||||||
| 159 | 4 | ▶ | my ($self, $command) = @_; | ||||||||||||||||||||||||||
|
Subroutine
convert_command: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 160 | 4 | String::CamelCase::decamelize( $command ); | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | sub extract_brief_description { | ||||||||||||||||||||||||||||
| 164 | 4 | ▶ | my ($self, $pod, $class) = @_; | ||||||||||||||||||||||||||
|
Subroutine
extract_brief_description: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # "NAME" header may be localized | ||||||||||||||||||||||||||||
| 167 | 4 | my ($brief_desc) = $pod =~ /^\S+\s+$class\s+\-\s+(.+?)\n/s; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 4 | ▶ | return $brief_desc || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$brief_desc || ''
MC/DC0%0/1
$brief_desc || ''
$brief_desc
Truth table0%0/2
A
A= $brief_desc
| |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | sub _parse_pod { | ||||||||||||||||||||||||||||
| 173 | 8 | ▶ | my ($self, $file) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_parse_pod: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 8 | my $parser = Pod::Simple::Text->new; | |||||||||||||||||||||||||||
| 176 | 8 | $parser->output_string( \my $pod ); | |||||||||||||||||||||||||||
| 177 | 8 | $parser->parse_string_document("$file"); | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 8 | return $pod; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | sub _namespaces { | ||||||||||||||||||||||||||||
| 183 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_namespaces: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 7 | my %seen; | |||||||||||||||||||||||||||
| 186 | 10 | return grep { !$seen{$_}++ } ( | |||||||||||||||||||||||||||
| 187 | $self->extra_namespaces, | ||||||||||||||||||||||||||||
| 188 | 7 | ▶ | @{ $self->option('_namespaces') || [] }, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 'CLI::Dispatch' | ||||||||||||||||||||||||||||
| 190 | ); | ||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | sub _lookup { | ||||||||||||||||||||||||||||
| 194 | 8 | ▶ | my ($self, $command) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_lookup: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 8 | my @paths; | |||||||||||||||||||||||||||
| 197 | 8 | ▶ | if ($command =~ s/^\+//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 5 | $command =~ s{::}{/}g; | |||||||||||||||||||||||||||
| 199 | 5 | @paths = $command; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | else { | ||||||||||||||||||||||||||||
| 202 | 7 | @paths = map { s{::}{/}g; "$_/$command" } $self->_namespaces; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 8 | foreach my $inc ( @INC ) { | |||||||||||||||||||||||||||
| 206 | 15 | foreach my $path ( @paths ) { | |||||||||||||||||||||||||||
| 207 | 15 | foreach my $ext (qw( pod pm )) { | |||||||||||||||||||||||||||
| 208 | 22 | my $file = path( $inc, "$path.$ext" ); | |||||||||||||||||||||||||||
| 209 | 22 | ▶ | return $file->slurp if $file->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | # probably it's embedded in the caller... | ||||||||||||||||||||||||||||
| 215 | 1 | my $ct = 0; | |||||||||||||||||||||||||||
| 216 | 1 | my %seen; | |||||||||||||||||||||||||||
| 217 | 1 | ▶ | while (my @caller = caller($ct++)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 5 | ▶ | next if $caller[0] =~ /^CLI::Dispatch(::.+)?$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 1 | ▶ | next if $seen{$caller[0]}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 1 | my $content = path($caller[1])->slurp; | |||||||||||||||||||||||||||
| 221 | 1 | for my $path ( @paths ) { | |||||||||||||||||||||||||||
| 222 | 1 | (my $package = $path) =~ s{/}{::}g; | |||||||||||||||||||||||||||
| 223 | 1 | ▶ | if ($content =~ /=head1\s+\S+\s+$package/s) { # hopefully NAME | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | 1 | return $content; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 0 | return; | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 9 | 1; | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | __END__ | ||||||||||||||||||||||||||||