blib/lib/above.pm

filter: Statementstmt 97.5% 78 / 80 Branchbran 69.2% 18 / 26 Conditioncond 58.3% 7 / 12 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 100% 13 / 13 Podpod 0.0% 0 / 1 totaltotal 85.0% 119 / 140 CC 21 SCAR 18.5
CC
21
Cov
87%
use_package
13.1
__ANON__
5.5
BEGIN
4.0
CRAP 6.4
« lib/UR/BoolExpr/Template/PropertyComparison/Like.pm ↑ Summary blib/lib/Command/Test/Echo.pm »
1 package above;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use Cwd qw(getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use File::Spec qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 our $VERSION = '0.03'; # No BumpVersion
10  
11 11 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
12 11 my $package = shift;
13 11 for (@_) {
14 11 use_package($_);
15 }
16 }
17  
18 12 our %used_libs;
19 12 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=13.9
20 12 ▶ %used_libs = ($ENV{PERL_USED_ABOVE} ? (map { $_ => 1 } split(":", $ENV{PERL_USED_ABOVE})) : ());
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PERL_USED_ABOVE'} ? : 2 10 12
21 12 for my $path (keys %used_libs) {
22 2 my $error = do {
23 2 local $@;
24 2 ▶ eval "use lib '$path';";
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 $@;
26 };
27 2 ▶ die "Failed to use library path '$path' from the environment PERL_USED_ABOVE?: $error" if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 2 2
28 }
29 };
30  
31 11 ▶sub _caller_use {
Subroutine _caller_use: called CC=2 SCAR=6.9
32 11 my ($caller, $class) = @_;
33 11 my $error = do {
34 11 local $@;
35 11 ▶ eval "package $caller; use $class";
Subroutine BEGIN: called CC=1 SCAR=0.0
36 11 $@;
37 };
38 11 ▶ die $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 8 3 11
39 }
40  
41 42 ▶sub _dev {
Subroutine _dev: called CC=1 SCAR=0.0
42 42 my $path = shift;
43 42 return (stat($path))[0];
44 }
45  
46 11 ▶sub use_package {
Subroutine use_package: called CC=12 SCAR=25.7
Pod undocumented
47 11 my $class = shift;
48 11 my $caller = (caller(1))[0];
49 11 my $module = File::Spec->join(split(/::/, $class)) . '.pm';
50  
51 ## paths already found in %used_above have
52 ## higher priority than paths based on cwd
53 11 for my $path (keys %used_libs) {
54 2 ▶ if (-e File::Spec->join($path, $module)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "File::Spec"->join($path, $module)) 2 0 2
55 2 _caller_use($caller, $class);
56 2 return;
57 }
58 }
59  
60 9 my $xdev = $ENV{ABOVE_DISCOVERY_ACROSS_FILESYSTEM};
61 9 my $cwd = getcwd();
62 9 ▶ unless ($cwd) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cwd) 0 9 9
63 0 die "cwd failed: $!";
64 }
65 9 my $dev = _dev($cwd);
66 41 ▶ my $abort_crawl = sub {
Subroutine __ANON__: called CC=5 SCAR=17.0
67 41 my @parts = @_;
68 41 ▶ return 1 if (@parts == 0); # nothing left to try
Branch: 1 branch
BranchTrueFalseTotal
if @parts == 0 0 41 41
69 41 ▶ return 1 if (@parts == 1 && $parts[0] eq ''); # hit root dir
Branch: 1 branch
BranchTrueFalseTotal
if @parts == 1 and $parts[0] eq "" 8 33 41
Condition66%2/3
@parts == 1 and $parts[0] eq ""
!ll&&!rl&&r
3308
MC/DC50%1/2
@parts == 1 and $parts[0] eq ""
@parts == 1 $parts[0] eq ""
Truth table66%2/3
A and B
A= @parts == 1B= $parts[0] eq ""
ABresult
0X0
100
111
70 33 my $path = File::Spec->join(@parts);
71 33 ▶ return !($xdev || _dev($path) == $dev); # crossed device
Condition33%1/3
$xdev || _dev($path) == $dev
l!l&&r!l&&!r
0330
MC/DC0%0/2
$xdev || _dev($path) == $dev
$xdev _dev($path) == $dev
Truth table33%1/3
A || B
A= $xdevB= _dev($path) == $dev
ABresult
1X1
011
000
72 9 };
73 51 ▶ my $found_module_at = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
74 51 my $path = shift;
75 51 return (-e File::Spec->join($path, $module));
76 9 };
77  
78 9 my @parts = File::Spec->splitdir($cwd);
79 9 my $path;
80 9 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
(&$found_module_at($path) or &$abort_crawl(@parts)) or do { do { $path = "File::Spec"->join(@parts); pop @parts } } 9 33 42
Condition100%3/3
&$found_module_at($path) or &$abort_crawl(@parts)
l!l&&r!l&&!r
1833
MC/DC100%2/2
&$found_module_at($path) or &$abort_crawl(@parts)
&$found_module_at($path) &$abort_crawl(@parts)
Truth table100%3/3
A or B
A= &$found_module_at($path)B= &$abort_crawl(@parts)
ABresult
1X1
011
000
81 42 $path = File::Spec->join(@parts);
82 42 pop @parts;
83 } until ($found_module_at->($path) || $abort_crawl->(@parts));
84  
85 9 ▶ if ($found_module_at->($path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$found_module_at($path)) 1 8 9
86 0 ▶ while ($path =~ s:/[^/]+/\.\./:/:) { 1 } # simplify
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ s[/[^/]+/\.\./][/]) 0 1 1
87 1 ▶ unless ($used_libs{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($used_libs{$path}) 1 0 1
88 1 ▶ print STDERR "Using libraries at $path\n" unless $ENV{PERL_ABOVE_QUIET} or $ENV{COMP_LINE};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"PERL_ABOVE_QUIET"} or $ENV{"COMP_LINE"} 0 1 1
Condition33%1/3
$ENV{"PERL_ABOVE_QUIET"} or $ENV{"COMP_LINE"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$ENV{"PERL_ABOVE_QUIET"} or $ENV{"COMP_LINE"}
$ENV{"PERL_ABOVE_QUIET"} $ENV{"COMP_LINE"}
Truth table33%1/3
A or B
A= $ENV{"PERL_ABOVE_QUIET"}B= $ENV{"COMP_LINE"}
ABresult
1X1
011
000
89 1 my $error = do {
90 1 local $@;
91 1 eval "use lib '$path';";
92 1 $@;
93 };
94 1 ▶ die $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 1 1
95 1 $used_libs{$path} = 1;
96 1 my $env_value = join(":", sort keys %used_libs);
97 1 $ENV{PERL_USED_ABOVE} = $env_value;
98 }
99 }
100  
101 9 _caller_use($caller, $class);
102 };
103  
104 12 1;
105  
106 =pod
107  
108 =head1 NAME
109  
110 above - auto "use lib" when a module is in the tree of the PWD
111  
112 =head1 SYNOPSIS
113  
114 use above "My::Module";
115  
116 =head1 DESCRIPTION
117  
118 Used by the command-line wrappers for Command modules which are developer tools.
119  
120 Do NOT use this in modules, or user applications.
121  
122 Uses a module as though the cwd and each of its parent directories were at the beginnig of @INC.
123 If found in that path, the parent directory is kept as though by "use lib".
124  
125 Set ABOVE_DISCOVERY_ACROSS_FILESYSTEM shell variable to true value to crawl past device boundaries.
126  
127 =head1 EXAMPLES
128  
129 # given
130 /home/me/perlsrc/My/Module.pm
131  
132 # in
133 /home/me/perlsrc/My/Module/Some/Path/
134  
135 # in myapp.pl:
136 use above "My::Module";
137  
138 # does this ..if run anywhere under /home/me/perlsrc:
139 use lib '/home/me/perlsrc/'
140 use My::Module;
141  
142 =head1 AUTHOR
143  
144 Scott Smith
145 Nathaniel Nutter
146  
147 =cut
« lib/UR/BoolExpr/Template/PropertyComparison/Like.pm ↑ Summary blib/lib/Command/Test/Echo.pm »