lib/Module/Load.pm

filter: Statementstmt 100% 71 / 71 Branchbran 88.1% 37 / 42 Conditioncond 82.9% 34 / 41 MC/DCmcdc 66.6% 14 / 21 Subroutinesub 100% 14 / 14 Podpod 100% 4 / 4 totaltotal 90.1% 174 / 193 CC 37 SCAR 23.1
CC
37
Cov
92%
import
18.1
_load
10.1
_to_file
7.1
CRAP 10.0
↑ Summary
1 package Module::Load;
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 2 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.36';
8  
9  
10 62 ▶sub import {
Subroutine import: called CC=18 SCAR=29.0
11 62 my $who = _who();
12 62 my $h; shift;
13  
14 2 ▶ { no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 @_ or (
17 21 *{"${who}::load"} = \&load, # compat to prev version
18 62 ▶ *{"${who}::autoload"} = \&autoload,
Branch: 1 branch
BranchTrueFalseTotal
@_ or *{"${who}::load";} = \&Module::Load::load, *{"${who}::autoload";} = \&Module::Load::autoload, return 41 21 62
19 return
20 );
21  
22 41 ▶ map { $h->{$_} = () if defined $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ 52 6 58
23  
24 41 ▶ (exists $h->{none} or exists $h->{''})
Branch: 1 branch
BranchTrueFalseTotal
exists $h->{"none"} || exists $h->{""} and shift(), last 18 23 41
Condition100%3/3
exists $h->{"none"} or exists $h->{""}
l!l&&r!l&&!r
11723
MC/DC100%2/2
exists $h->{"none"} or exists $h->{""}
exists $h->{"none"} exists $h->{""}
Truth table100%3/3
A or B
A= exists $h->{"none"}B= exists $h->{""}
ABresult
1X1
011
000
25 and shift, last;
26  
27 ((exists $h->{autoload} and shift,1) or (exists $h->{all} and shift))
28 23 ▶ and *{"${who}::autoload"} = \&autoload;
Branch: 1 branch
BranchTrueFalseTotal
exists $h->{"autoload"} && (shift(), 1) || exists $h->{"all"} && shift() and *{"${who}::autoload";} = \&Module::Load::autoload 14 9 23
Condition77%7/9
exists $h->{"autoload"} and shift(), 1 or exists $h->{"all"} and shift()
l!l&&r!l&&!r
599
exists $h->{"autoload"} and shift(), 1
!ll&&!rl&&r
1805
exists $h->{"all"} and shift()
!ll&&!rl&&r
909
MC/DC50%2/4
exists $h->{"autoload"} and shift(), 1 or exists $h->{"all"} and shift()
exists $h->{"autoload"} shift(), 1 exists $h->{"all"} shift()
Truth table42%3/7
A and B or C and D
A= exists $h->{"autoload"}B= shift(), 1C= exists $h->{"all"}D= shift()
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
29  
30 ((exists $h->{load} and shift,1) or exists $h->{all})
31 23 ▶ and *{"${who}::load"} = \&load;
Branch: 1 branch
BranchTrueFalseTotal
exists $h->{"load"} && (shift(), 1) || exists $h->{"all"} and *{"${who}::load";} = \&Module::Load::load 14 9 23
Condition83%5/6
exists $h->{"load"} and shift(), 1 or exists $h->{"all"}
l!l&&r!l&&!r
599
exists $h->{"load"} and shift(), 1
!ll&&!rl&&r
1805
MC/DC66%2/3
exists $h->{"load"} and shift(), 1 or exists $h->{"all"}
exists $h->{"load"} shift(), 1 exists $h->{"all"}
Truth table60%3/5
A and B or C
A= exists $h->{"load"}B= shift(), 1C= exists $h->{"all"}
ABCresult
11X1
0X11
1011
0X00
1000
32  
33 ((exists $h->{load_remote} and shift,1) or exists $h->{all})
34 23 ▶ and *{"${who}::load_remote"} = \&load_remote;
Branch: 1 branch
BranchTrueFalseTotal
exists $h->{"load_remote"} && (shift(), 1) || exists $h->{"all"} and *{"${who}::load_remote";} = \&Module::Load::load_remote 11 12 23
Condition83%5/6
exists $h->{"load_remote"} and shift(), 1 or exists $h->{"all"}
l!l&&r!l&&!r
2912
exists $h->{"load_remote"} and shift(), 1
!ll&&!rl&&r
2102
MC/DC66%2/3
exists $h->{"load_remote"} and shift(), 1 or exists $h->{"all"}
exists $h->{"load_remote"} shift(), 1 exists $h->{"all"}
Truth table60%3/5
A and B or C
A= exists $h->{"load_remote"}B= shift(), 1C= exists $h->{"all"}
ABCresult
11X1
0X11
1011
0X00
1000
35  
36 ((exists $h->{autoload_remote} and shift,1) or exists $h->{all})
37 23 ▶ and *{"${who}::autoload_remote"} = \&autoload_remote;
Branch: 1 branch
BranchTrueFalseTotal
exists $h->{"autoload_remote"} && (shift(), 1) || exists $h->{"all"} and *{"${who}::autoload_remote";} = \&Module::Load::autoload_remote 11 12 23
Condition83%5/6
exists $h->{"autoload_remote"} and shift(), 1 or exists $h->{"all"}
l!l&&r!l&&!r
2912
exists $h->{"autoload_remote"} and shift(), 1
!ll&&!rl&&r
2102
MC/DC66%2/3
exists $h->{"autoload_remote"} and shift(), 1 or exists $h->{"all"}
exists $h->{"autoload_remote"} shift(), 1 exists $h->{"all"}
Truth table60%3/5
A and B or C
A= exists $h->{"autoload_remote"}B= shift(), 1C= exists $h->{"all"}
ABCresult
11X1
0X11
1011
0X00
1000
38  
39 }
40  
41 }
42  
43 25 ▶sub load(*;@){
Subroutine load: called CC=1 SCAR=0.0
Pod documented
44 25 goto &_load;
45 }
46  
47 19 ▶sub autoload(*;@){
Subroutine autoload: called CC=1 SCAR=0.0
Pod documented
48 19 unshift @_, 'autoimport';
49 19 goto &_load;
50 }
51  
52 9 ▶sub load_remote($$;@){
Subroutine load_remote: called CC=2 SCAR=6.9
Pod documented
53 9 my ($dst, $src, @exp) = @_;
54  
55 9 eval "package $dst;Module::Load::load('$src', qw/@exp/);";
56 9 ▶ $@ && die "$@";
Branch: 1 branch
BranchTrueFalseTotal
$@ and die "$@" 1 8 9
57 }
58  
59 7 ▶sub autoload_remote($$;@){
Subroutine autoload_remote: called CC=2 SCAR=6.9
Pod documented
60 7 my ($dst, $src, @exp) = @_;
61  
62 7 eval "package $dst;Module::Load::autoload('$src', qw/@exp/);";
63 7 ▶ $@ && die "$@";
Branch: 1 branch
BranchTrueFalseTotal
$@ and die "$@" 1 6 7
64 }
65  
66 44 ▶sub _load{
Subroutine _load: called CC=10 SCAR=23.1
67 44 ▶ my $autoimport = $_[0] eq 'autoimport' and shift;
Branch: 1 branch
BranchTrueFalseTotal
my $autoimport = $_[0] eq "autoimport" and shift() 19 25 44
68 44 ▶ my $mod = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $mod = shift() or return 44 0 44
69 44 my $who = _who();
70  
71 44 ▶ if( _is_file( $mod ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_file($mod)) { } 1 43 44
72 1 require $mod;
73 } else {
74 LOAD: {
75 43 my $err;
76 43 for my $flag ( qw[1 0] ) {
77 48 my $file = _to_file( $mod, $flag);
78 48 eval { require $file };
79 48 ▶ $@ ? $err .= $@ : last LOAD;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 9 39 48
80 }
81 4 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 4 0 4
82 }
83 }
84  
85 ### This addresses #41883: Module::Load cannot import
86 ### non-Exporter module. ->import() routines weren't
87 ### properly called when load() was used.
88  
89 2 ▶ { no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 40 my $import;
91  
92 40 ▶ ((@_ or $autoimport) and (
Branch: 1 branch
BranchTrueFalseTotal
@_ || $autoimport and $import = $mod->can("import") and unshift(@_, $mod), goto \&$import 26 14 40
Condition83%5/6
@_ || $autoimport and $import = $mod->can("import")
!ll&&!rl&&r
14026
@_ or $autoimport
l!l&&r!l&&!r
141214
MC/DC66%2/3
@_ || $autoimport and $import = $mod->can("import")
@_ $autoimport $import = $mod->can("import")
Truth table60%3/5
A or B and C
A= @_B= $autoimportC= $import = $mod->can("import")
ABCresult
00X0
1X00
0100
1X11
0111
93 $import = $mod->can('import')
94 ) and (
95 unshift(@_, $mod),
96 goto &$import
97 )
98 );
99 }
100  
101 }
102  
103 53 ▶sub _to_file{
Subroutine _to_file: called CC=7 SCAR=19.7
104 53 local $_ = shift;
105 53 ▶ my $pm = shift || '';
Condition100%2/2
shift() || ''
l!l
467
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
106  
107 ## trailing blanks ignored by default. [rt #69886]
108 53 my @parts = split /::|'/, $_, -1;
109 ## make sure that we can't hop out of @INC
110 53 ▶ shift @parts if @parts && !$parts[0];
Branch: 1 branch
BranchTrueFalseTotal
if @parts and not $parts[0] 2 51 53
Condition66%2/3
@parts and not $parts[0]
!ll&&!rl&&r
0512
MC/DC50%1/2
@parts and not $parts[0]
@parts not $parts[0]
Truth table66%2/3
A and not(B)
A= @partsB= not $parts[0]
ABresult
0X0
100
111
111  
112 ### because of [perl #19213], see caveats ###
113 53 ▶ my $file = $^O eq 'MSWin32'
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 53 53
114 ? join "/", @parts
115 : File::Spec->catfile( @parts );
116  
117 53 ▶ $file .= '.pm' if $pm;
Branch: 1 branch
BranchTrueFalseTotal
if $pm 46 7 53
118  
119 ### on perl's before 5.10 (5.9.5@31746) if you require
120 ### a file in VMS format, it's stored in %INC in VMS
121 ### format. Therefor, better unixify it first
122 ### Patch in reply to John Malmbergs patch (as mentioned
123 ### above) on p5p Tue 21 Aug 2007 04:55:07
124 53 ▶ $file = VMS::Filespec::unixify($file) if $^O eq 'VMS';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "VMS" 0 53 53
125  
126 53 return $file;
127 }
128  
129 106 ▶sub _who { (caller(1))[0] }
Subroutine _who: called CC=1 SCAR=0.0
130  
131 44 ▶sub _is_file {
Subroutine _is_file: called CC=3 SCAR=11.1
132 44 local $_ = shift;
133 44 ▶ return /^\./ ? 1 :
Branch: 2 branches
BranchTrueFalseTotal
/^\./ ? : 0 44 44
/[^\w:']/ ? : 1 43 44
134 /[^\w:']/ ? 1 :
135 undef
136 #' silly bbedit..
137 }
138  
139  
140 2 1;
141  
142 __END__
↑ Summary