blib/lib/Devel/SearchINC.pm

filter: Statementstmt 88.0% 59 / 67 Branchbran 69.4% 25 / 36 Conditioncond 72.2% 13 / 18 MC/DCmcdc 41.6% 5 / 12 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 78.6% 114 / 145 CC 26 SCAR 25.8
CC
26
Cov
80%
__ANON__
26.2
__ANON__
6.4
import
5.0
CRAP 13.1
↑ Summary
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
BranchTrueFalseTotal
unless @Devel::SearchINC::PATHS 0 2 2
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
BranchTrueFalseTotal
if $Devel::SearchINC::DEBUG and -d $_ 7 13 20
Condition100%3/3
$Devel::SearchINC::DEBUG and -d $_
!ll&&!rl&&r
1037
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 $_
ABresult
0X0
100
111
28 20 ▶ if (-d && /^(t|CVS|\.svn|\.git|skel|_build)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $_ and /^(t|CVS|\.svn|\.git|skel|_build)$/) 0 20 20
Condition66%2/3
-d $_ and /^(t|CVS|\.svn|\.git|skel|_build)$/
!ll&&!rl&&r
6140
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)$/
ABresult
0X0
100
111
29 0 ▶ warn "$File::Find::name dir will be pruned\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::SearchINC::DEBUG 0 0 0
30 0 $File::Find::prune = 1;
31 0 return;
32 }
33 20 ▶ if (-d && -e "$File::Find::name/INC.SKIP") {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $_ and -e "$File::Find::name/INC.SKIP") 0 20 20
Condition66%2/3
-d $_ and -e "$File::Find::name/INC.SKIP"
!ll&&!rl&&r
6140
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"
ABresult
0X0
100
111
34 0 ▶ warn "$File::Find::name dir contains INC.SKIP; pruned\n"
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::SearchINC::DEBUG 0 0 0
35 if $DEBUG;
36 0 $File::Find::prune = 1;
37 0 return;
38 }
39 20 ▶ if (-d && $_ eq 'lib') {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $_ and $_ eq "lib") 2 18 20
Condition100%3/3
-d $_ and $_ eq "lib"
!ll&&!rl&&r
6122
MC/DC100%2/2
-d $_ and $_ eq "lib"
-d $_ $_ eq "lib"
Truth table100%3/3
A and B
A= -d $_B= $_ eq "lib"
ABresult
0X0
100
111
40 2 push our @inc => $File::Find::name;
41 2 return;
42 }
43 18 ▶ return unless -f && /\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_ and /\.pm$/ 12 6 18
Condition66%2/3
-f $_ and /\.pm$/
!ll&&!rl&&r
1206
MC/DC50%1/2
-f $_ and /\.pm$/
-f $_ /\.pm$/
Truth table66%2/3
A and B
A= -f $_B= /\.pm$/
ABresult
0X0
100
111
44 6 ▶ if ($File::Find::name =~ m!.*/(?:lib|blib/(?:lib|arch))/(.*)!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::name =~ m[.*/(?:lib|blib/(?:lib|arch))/(.*)]) 6 0 6
45 6 ▶ $cache{$1} ||= $File::Find::name;
Condition33%1/3
$Devel::SearchINC::cache{$1} ||= $File::Find::name
l!l&&r!l&&!r
060
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
ABresult
1X1
011
000
46 }
47 }
48 },
49 @PATHS
50 2 );
51 2 ▶ warn "cache:\n", Dumper \%cache if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::SearchINC::DEBUG 1 1 2
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
BranchTrueFalseTotal
unless (exists $Devel::SearchINC::cache{$file}) 41 3 44
60 41 ▶ printf "%s: cache miss <%s>\n", __PACKAGE__, $file
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::SearchINC::DEBUG 19 22 41
61 if $DEBUG;
62 41 return;
63 }
64 3 ▶ printf "%s: found <%s>\n", __PACKAGE__, $cache{$file} if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Devel::SearchINC::DEBUG 1 2 3
65 3 ▶ if (open(my $fh, '<', $cache{$file})) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<", $Devel::SearchINC::cache{$file}) 3 0 3
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
BranchTrueFalseTotal
if $Devel::SearchINC::DEBUG 0 0 0
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
BranchTrueFalseTotal
if ($path eq "-debug") 1 3 4
84 1 $DEBUG = 1;
85 1 next;
86 }
87 3 ▶ if ($path eq '-clear') {
Branch: 1 branch
BranchTrueFalseTotal
if ($path eq "-clear") 1 2 3
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
BranchTrueFalseTotal
if $Devel::SearchINC::DEBUG 1 1 2
100 }
101 3 1;
102  
103  
104 __END__
↑ Summary