| 1 | package Plient::Util; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use File::Spec::Functions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | our @EXPORT = 'which'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use constant WIN32 => $^O eq 'MSWin32'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | my $bin_quote = WIN32 ? q{"} : q{'}; | |||||||||||||||||||||||||||
| 14 | 5 | my $bin_ext = $Config{_exe}; | |||||||||||||||||||||||||||
| 15 | 5 | my %cache; | |||||||||||||||||||||||||||
| 16 | 3 | ▶ | sub which { | ||||||||||||||||||||||||||
|
Subroutine
which: called CC=7 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 3 | my $name = shift; | |||||||||||||||||||||||||||
| 18 | 3 | ▶ | return $cache{$name} if $cache{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | my $path; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | LINE: | ||||||||||||||||||||||||||||
| 23 | 3 | for my $dir ( path() ) { | |||||||||||||||||||||||||||
| 24 | 30 | my $p = catfile( $dir, $name ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # XXX any other names need to try? | ||||||||||||||||||||||||||||
| 27 | 30 | my @try = grep { -x } ( $p, $p . $bin_ext ); | |||||||||||||||||||||||||||
| 28 | 30 | for my $try (@try) { | |||||||||||||||||||||||||||
| 29 | 0 | $path = $try; | |||||||||||||||||||||||||||
| 30 | 0 | last LINE; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | return unless $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ( $path =~ /\s/ && $path !~ /^$bin_quote/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$path =~ /\s/ and not $path =~ /^$bin_quote/
MC/DC0%0/2
$path =~ /\s/ and not $path =~ /^$bin_quote/
$path =~ /\s/
not $path =~ /^$bin_quote/
Truth table0%0/3
A and not(B)
A= $path =~ /\s/B= not $path =~ /^$bin_quote/
| |||||||||||||||||||||||||||||
| 36 | 0 | $path = $bin_quote . $path . $bin_quote; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | return $cache{$name} = $path; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 5 | 1; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | __END__ | ||||||||||||||||||||||||||||