| 1 | 3 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Devel::SearchINC; | ||||||||||||||||||||||||||||
| 6 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | $Devel::SearchINC::VERSION = '2.103460'; | |||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Loading Perl modules from their development directories | ||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use File::Find; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | sub build_cache { | ||||||||||||||||||||||||||
|
Subroutine
build_cache: called CC=3 SCAR=11.9
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 2 | our %cache = (); | |||||||||||||||||||||||||||
| 15 | 2 | our @PATHS; | |||||||||||||||||||||||||||
| 16 | 2 | ▶ | return unless @PATHS; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 2 | our $DEBUG; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Programs run with -T cause a "Insecure dependency in chdir while running | ||||||||||||||||||||||||||||
| 20 | # with -T switch" warning, so untaint directory names. | ||||||||||||||||||||||||||||
| 21 | find( | ||||||||||||||||||||||||||||
| 22 | { untaint => 1, | ||||||||||||||||||||||||||||
| 23 | untaint_pattern => qr|^(.+)$|, # File::Find gets this wrong on OS X | ||||||||||||||||||||||||||||
| 24 | untaint_skip => 1, | ||||||||||||||||||||||||||||
| 25 | follow => 1, | ||||||||||||||||||||||||||||
| 26 | 20 | ▶ | wanted => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=15 SCAR=32.6
| |||||||||||||||||||||||||||||
| 27 | 20 | ▶ | warn "dir [$File::Find::name]\n" if $DEBUG && -d; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$Devel::SearchINC::DEBUG and -d $_
MC/DC100%2/2
$Devel::SearchINC::DEBUG and -d $_
$Devel::SearchINC::DEBUG
-d $_
Truth table100%3/3
A and B
A= $Devel::SearchINC::DEBUGB= -d $_
| |||||||||||||||||||||||||||||
| 28 | 20 | ▶ | if (-d && /^(t|CVS|\.svn|\.git|skel|_build)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-d $_ and /^(t|CVS|\.svn|\.git|skel|_build)$/
MC/DC0%0/2
-d $_ and /^(t|CVS|\.svn|\.git|skel|_build)$/
-d $_
/^(t|CVS|\.svn|\.git|skel|_build)$/
Truth table66%2/3
A and B
A= -d $_B= /^(t|CVS|\.svn|\.git|skel|_build)$/
| |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | warn "$File::Find::name dir will be pruned\n" if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | $File::Find::prune = 1; | |||||||||||||||||||||||||||
| 31 | 0 | return; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 20 | ▶ | if (-d && -e "$File::Find::name/INC.SKIP") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-d $_ and -e "$File::Find::name/INC.SKIP"
MC/DC0%0/2
-d $_ and -e "$File::Find::name/INC.SKIP"
-d $_
-e "$File::Find::name/INC.SKIP"
Truth table66%2/3
A and B
A= -d $_B= -e "$File::Find::name/INC.SKIP"
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | warn "$File::Find::name dir contains INC.SKIP; pruned\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | if $DEBUG; | ||||||||||||||||||||||||||||
| 36 | 0 | $File::Find::prune = 1; | |||||||||||||||||||||||||||
| 37 | 0 | return; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 20 | ▶ | if (-d && $_ eq 'lib') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-d $_ and $_ eq "lib"
MC/DC100%2/2
-d $_ and $_ eq "lib"
-d $_
$_ eq "lib"
Truth table100%3/3
A and B
A= -d $_B= $_ eq "lib"
| |||||||||||||||||||||||||||||
| 40 | 2 | push our @inc => $File::Find::name; | |||||||||||||||||||||||||||
| 41 | 2 | return; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 18 | ▶ | return unless -f && /\.pm$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-f $_ and /\.pm$/
MC/DC50%1/2
-f $_ and /\.pm$/
-f $_
/\.pm$/
Truth table66%2/3
A and B
A= -f $_B= /\.pm$/
| |||||||||||||||||||||||||||||
| 44 | 6 | ▶ | if ($File::Find::name =~ m!.*/(?:lib|blib/(?:lib|arch))/(.*)!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 6 | ▶ | $cache{$1} ||= $File::Find::name; | ||||||||||||||||||||||||||
|
Condition33%1/3
$Devel::SearchINC::cache{$1} ||= $File::Find::name
MC/DC0%0/2
$Devel::SearchINC::cache{$1} ||= $File::Find::name
$Devel::SearchINC::cache{$1}
$File::Find::name
Truth table33%1/3
A ||= B
A= $Devel::SearchINC::cache{$1}B= $File::Find::name
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | }, | ||||||||||||||||||||||||||||
| 49 | @PATHS | ||||||||||||||||||||||||||||
| 50 | 2 | ); | |||||||||||||||||||||||||||
| 51 | 2 | ▶ | warn "cache:\n", Dumper \%cache if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||
| 55 | 44 | ▶ | unshift @INC, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.6
| |||||||||||||||||||||||||||||
| 56 | 44 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 57 | 44 | our %cache; | |||||||||||||||||||||||||||
| 58 | 44 | our $DEBUG; | |||||||||||||||||||||||||||
| 59 | 44 | ▶ | unless (exists $cache{$file}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 41 | ▶ | printf "%s: cache miss <%s>\n", __PACKAGE__, $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | if $DEBUG; | ||||||||||||||||||||||||||||
| 62 | 41 | return; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 3 | ▶ | printf "%s: found <%s>\n", __PACKAGE__, $cache{$file} if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 3 | ▶ | if (open(my $fh, '<', $cache{$file})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 3 | $INC{$file} = $cache{$file}; | |||||||||||||||||||||||||||
| 67 | 3 | return $fh; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | printf "%s: can't open <%s>, declining\n", __PACKAGE__, $cache{$file} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | if $DEBUG; | ||||||||||||||||||||||||||||
| 71 | 0 | return; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 3 | } | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 76 | 2 | shift; # we don't need the package name | |||||||||||||||||||||||||||
| 77 | 2 | our $DEBUG = 0; | |||||||||||||||||||||||||||
| 78 | my @p = | ||||||||||||||||||||||||||||
| 79 | 4 | map { s/^~/$ENV{HOME}/; $_ } | |||||||||||||||||||||||||||
| 80 | 2 | map { split /\s*[,;:]\s*/ } @_; | |||||||||||||||||||||||||||
| 81 | 2 | our @PATHS; | |||||||||||||||||||||||||||
| 82 | 2 | for my $path (@p) { | |||||||||||||||||||||||||||
| 83 | 4 | ▶ | if ($path eq '-debug') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 1 | $DEBUG = 1; | |||||||||||||||||||||||||||
| 85 | 1 | next; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 3 | ▶ | if ($path eq '-clear') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 1 | @PATHS = (); | |||||||||||||||||||||||||||
| 89 | 1 | next; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 2 | push @PATHS => $path; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # Build the module cache anew after each import; this is so that if you | ||||||||||||||||||||||||||||
| 95 | # use PERL5OPT=-MDevel::SearchINC=... and then a program loads it | ||||||||||||||||||||||||||||
| 96 | # separately with "use Devel::SearchINC '...'" paths from both occasions | ||||||||||||||||||||||||||||
| 97 | # get respected. | ||||||||||||||||||||||||||||
| 98 | 2 | build_cache(); | |||||||||||||||||||||||||||
| 99 | 2 | ▶ | warn "paths:\n", Dumper \@PATHS if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 3 | 1; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||