| 1 | package Unix::Whereis; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | $Unix::Whereis::VERSION = '0.1'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | our $sep; | |||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $cache; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | my $caller = caller(); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | *{ $caller . '::whereis' } = \&whereis; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | if ( defined $_[1] && $_[1] eq 'whereis_everyone' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_[1] and $_[1] eq "whereis_everyone"
MC/DC50%1/2
defined $_[1] and $_[1] eq "whereis_everyone"
defined $_[1]
$_[1] eq "whereis_everyone"
Truth table66%2/3
A and B
A= defined $_[1]B= $_[1] eq "whereis_everyone"
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | *{ $caller . '::whereis_everyone' } = \&whereis_everyone; | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 35 | ▶ | sub pathsep { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pathsep: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 35 | ▶ | $sep = $_[0] if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 35 | ▶ | if ( !defined $sep ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # only use %Config::Config if loaded already (keys() is the key!): | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # pkit -e 'd(scalar keys %Config::Config);require Config;d(scalar keys %Config::Config)' | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # pkit -e 'd(scalar keys %Config::Config)' | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # pkit -MConfig -e 'd(scalar keys %Config::Config)' | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | if ( keys %Config::Config && exists $Config::Config{'path_sep'} && length $Config::Config{'path_sep'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
keys %Config::Config and exists $Config::Config{"path_sep"} and length $Config::Config{"path_sep"}
keys %Config::Config and exists $Config::Config{"path_sep"}
MC/DC66%2/3
keys %Config::Config and exists $Config::Config{"path_sep"} and length $Config::Config{"path_sep"}
keys %Config::Config
exists $Config::Config{"path_sep"}
length $Config::Config{"path_sep"}
Truth table75%3/4
A and B and C
A= keys %Config::ConfigB= exists $Config::Config{"path_sep"}C= length $Config::Config{"path_sep"}
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | $sep = $Config::Config{'path_sep'}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | $sep = ':'; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 35 | return $sep; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 11 | ▶ | sub whereis { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
whereis: called CC=16 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 11 | my ( $name, $conf_hr ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 11 | ▶ | return if !defined $name || $name eq ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $name or $name eq ""
MC/DC0%0/2
not defined $name or $name eq ""
not defined $name
$name eq ""
Truth table33%1/3
not(A) or B
A= not defined $nameB= $name eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 11 | ▶ | $conf_hr = {} if !defined $conf_hr || ref $conf_hr ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $conf_hr or ref $conf_hr ne "HASH"
MC/DC50%1/2
not defined $conf_hr or ref $conf_hr ne "HASH"
not defined $conf_hr
ref $conf_hr ne "HASH"
Truth table66%2/3
not(A) or B
A= not defined $conf_hrB= ref $conf_hr ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 11 | ▶ | if ( $conf_hr->{'cache'} && $cache->{'whereis'}{$name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$conf_hr->{"cache"} and $Unix::Whereis::cache->{"whereis"}{$name}
MC/DC100%2/2
$conf_hr->{"cache"} and $Unix::Whereis::cache->{"whereis"}{$name}
$conf_hr->{"cache"}
$Unix::Whereis::cache->{"whereis"}{$name}
Truth table100%3/3
A and B
A= $conf_hr->{"cache"}B= $Unix::Whereis::cache->{"whereis"}{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | ▶ | delete $cache->{'whereis'}{$name} if $conf_hr->{'cache'} eq 'clear'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | return $cache->{'whereis'}{$name} if $conf_hr->{'cache'} && exists $cache->{'whereis'}{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$conf_hr->{"cache"} and exists $Unix::Whereis::cache->{"whereis"}{$name}
MC/DC50%1/2
$conf_hr->{"cache"} and exists $Unix::Whereis::cache->{"whereis"}{$name}
$conf_hr->{"cache"}
exists $Unix::Whereis::cache->{"whereis"}{$name}
Truth table66%2/3
A and B
A= $conf_hr->{"cache"}B= exists $Unix::Whereis::cache->{"whereis"}{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | local $ENV{'PATH'} = _build_env_path($conf_hr); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 10 | for my $PATH ( split( pathsep(), $ENV{'PATH'} ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 57 | 31 | my $bin = File::Spec->catfile( $PATH, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 31 | ▶ | if ( -f $bin && -x _ && -s _ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
-f $bin and -x _ and -s _
-f $bin and -x _
MC/DC100%3/3
-f $bin and -x _ and -s _
-f $bin
-x _
-s _
Truth table100%4/4
A and B and C
A= -f $binB= -x _C= -s _
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | ▶ | $cache->{'whereis'}{$name} = $bin if $conf_hr->{'cache'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | return $bin; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | ▶ | return $name if $conf_hr->{'fallback'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 11 | ▶ | sub whereis_everyone { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
whereis_everyone: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 11 | my ( $name, $conf_hr ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 11 | ▶ | $conf_hr = {} if !defined $conf_hr || ref $conf_hr ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $conf_hr or ref $conf_hr ne "HASH"
MC/DC50%1/2
not defined $conf_hr or ref $conf_hr ne "HASH"
not defined $conf_hr
ref $conf_hr ne "HASH"
Truth table66%2/3
not(A) or B
A= not defined $conf_hrB= ref $conf_hr ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 11 | ▶ | if ( $conf_hr->{'cache'} && $cache->{'whereis_everyone'}{$name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$conf_hr->{"cache"} and $Unix::Whereis::cache->{"whereis_everyone"}{$name}
MC/DC100%2/2
$conf_hr->{"cache"} and $Unix::Whereis::cache->{"whereis_everyone"}{$name}
$conf_hr->{"cache"}
$Unix::Whereis::cache->{"whereis_everyone"}{$name}
Truth table100%3/3
A and B
A= $conf_hr->{"cache"}B= $Unix::Whereis::cache->{"whereis_everyone"}{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | delete $cache->{'whereis_everyone'}{$name} if $conf_hr->{'cache'} eq 'clear'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | return @{ $cache->{'whereis_everyone'}{$name} } if $conf_hr->{'cache'} && exists $cache->{'whereis_everyone'}{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$conf_hr->{"cache"} and exists $Unix::Whereis::cache->{"whereis_everyone"}{$name}
MC/DC50%1/2
$conf_hr->{"cache"} and exists $Unix::Whereis::cache->{"whereis_everyone"}{$name}
$conf_hr->{"cache"}
exists $Unix::Whereis::cache->{"whereis_everyone"}{$name}
Truth table66%2/3
A and B
A= $conf_hr->{"cache"}B= exists $Unix::Whereis::cache->{"whereis_everyone"}{$name}
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 10 | my @found; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 10 | local $ENV{'PATH'} = _build_env_path($conf_hr); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 10 | for my $PATH ( split( pathsep(), $ENV{'PATH'} ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 82 | 37 | my $bin = File::Spec->catfile( $PATH, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 37 | ▶ | push( @found, $bin ) if -f $bin && -x _ && -s _; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
-f $bin and -x _ and -s _
-f $bin and -x _
MC/DC100%3/3
-f $bin and -x _ and -s _
-f $bin
-x _
-s _
Truth table100%4/4
A and B and C
A= -f $binB= -x _C= -s _
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 10 | ▶ | $cache->{'whereis_everyone'}{$name} = \@found if $conf_hr->{'cache'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | return @found; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 73 | ▶ | sub _build_env_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_env_path: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 73 | my ($conf_hr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 73 | ▶ | $sep ||= pathsep(); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$Unix::Whereis::sep ||= pathsep()
MC/DC0%0/2
$Unix::Whereis::sep ||= pathsep()
$Unix::Whereis::sep
pathsep()
Truth table66%2/3
A ||= B
A= $Unix::Whereis::sepB= pathsep()
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 73 | my $path = $ENV{'PATH'}; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 73 | ▶ | $path = $conf_hr->{'mypath'} if exists $conf_hr->{'mypath'} && length $conf_hr->{'mypath'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $conf_hr->{"mypath"} and length $conf_hr->{"mypath"}
MC/DC100%2/2
exists $conf_hr->{"mypath"} and length $conf_hr->{"mypath"}
exists $conf_hr->{"mypath"}
length $conf_hr->{"mypath"}
Truth table100%3/3
A and B
A= exists $conf_hr->{"mypath"}B= length $conf_hr->{"mypath"}
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 73 | $path =~ s/\Q$sep\E+$//; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 73 | $path =~ s/^\Q$sep\E+//; | |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 73 | ▶ | if ( exists $conf_hr->{'prepend'} && length $conf_hr->{'prepend'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $conf_hr->{"prepend"} and length $conf_hr->{"prepend"}
MC/DC100%2/2
exists $conf_hr->{"prepend"} and length $conf_hr->{"prepend"}
exists $conf_hr->{"prepend"}
length $conf_hr->{"prepend"}
Truth table100%3/3
A and B
A= exists $conf_hr->{"prepend"}B= length $conf_hr->{"prepend"}
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 24 | $conf_hr->{'prepend'} =~ s/\Q$sep\E+$//; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 24 | $conf_hr->{'prepend'} =~ s/^\Q$sep\E+//; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 24 | $path = "$conf_hr->{'prepend'}$sep$path"; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 73 | ▶ | if ( exists $conf_hr->{'append'} && length $conf_hr->{'append'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $conf_hr->{"append"} and length $conf_hr->{"append"}
MC/DC100%2/2
exists $conf_hr->{"append"} and length $conf_hr->{"append"}
exists $conf_hr->{"append"}
length $conf_hr->{"append"}
Truth table100%3/3
A and B
A= exists $conf_hr->{"append"}B= length $conf_hr->{"append"}
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 24 | $conf_hr->{'append'} =~ s/\Q$sep\E+$//; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 24 | $conf_hr->{'append'} =~ s/^\Q$sep\E+//; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 24 | $path .= $sep . $conf_hr->{'append'}; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 73 | return $path; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||||||||||||||||