blib/lib/above.pm

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