lib/Module/Load.pm

filter: Statementstmt 100% 71 / 71 Branchbran 88.1% 37 / 42 Conditioncond 82.9% 34 / 41 MC/DCmcdc 57.1% 12 / 21 Subroutinesub 100% 14 / 14 Podpod 100% 4 / 4 totaltotal 89.1% 172 / 193 SCAR 36.3
CC
37
Cov
92%
import
18.1
_load
10.1
_to_file
7.1
CRAP 37.6
« blib/lib/Module/Load.pm ↑ Summary
1 package Module::Load;
2  
3 2 $VERSION = '0.32';
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub import {
10 62 ▶ my $who = _who();
Subroutine import: called CC=18 SCAR=29.0
11 62 my $h; shift;
12  
13 2 ▶ { no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 @_ or (
16 21 *{"${who}::load"} = \&load, # compat to prev version
17 62 ▶ *{"${who}::autoload"} = \&autoload,
Branch: 1 branch
BranchTrueFalseTotal
@_ or *{"${who}::load";} = \&Module::Load::load, *{"${who}::autoload";} = \&Module::Load::autoload, return 21 41 62
18 return
19 );
20  
21 41 ▶ map { $h->{$_} = () if defined $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ 52 6 58
22  
23 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
24 and shift, last;
25  
26 ((exists $h->{autoload} and shift,1) or (exists $h->{all} and shift))
27 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
5171
exists $h->{"autoload"} and shift(), 1
!ll&&!rl&&r
1805
exists $h->{"all"} and shift()
!ll&&!rl&&r
909
MC/DC0%0/4
exists $h->{"autoload"} and shift(), 1 or exists $h->{"all"} and shift()
exists $h->{"autoload"} shift(), 1 exists $h->{"all"} shift()
Truth table28%2/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
28  
29 ((exists $h->{load} and shift,1) or exists $h->{all})
30 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
31  
32 ((exists $h->{load_remote} and shift,1) or exists $h->{all})
33 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
34  
35 ((exists $h->{autoload_remote} and shift,1) or exists $h->{all})
36 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
37  
38 }
39  
40 }
41  
42 sub load(*;@){
43 25 ▶ goto &_load;
Subroutine load: called CC=1 SCAR=0.0
Pod documented
44 }
45  
46 sub autoload(*;@){
47 19 ▶ unshift @_, 'autoimport';
Subroutine autoload: called CC=1 SCAR=0.0
Pod documented
48 19 goto &_load;
49 }
50  
51 sub load_remote($$;@){
52 9 ▶ my ($dst, $src, @exp) = @_;
Subroutine load_remote: called CC=2 SCAR=6.9
Pod documented
53  
54 9 eval "package $dst;Module::Load::load('$src', qw/@exp/);";
55 9 ▶ $@ && die "$@";
Branch: 1 branch
BranchTrueFalseTotal
$@ and die "$@" 1 8 9
56 }
57  
58 sub autoload_remote($$;@){
59 7 ▶ my ($dst, $src, @exp) = @_;
Subroutine autoload_remote: called CC=2 SCAR=6.9
Pod documented
60  
61 7 eval "package $dst;Module::Load::autoload('$src', qw/@exp/);";
62 7 ▶ $@ && die "$@";
Branch: 1 branch
BranchTrueFalseTotal
$@ and die "$@" 1 6 7
63 }
64  
65 sub _load{
66 44 ▶ my $autoimport = $_[0] eq 'autoimport' and shift;
Subroutine _load: called CC=10 SCAR=23.1
Branch: 1 branch
BranchTrueFalseTotal
my $autoimport = $_[0] eq "autoimport" and shift() 19 25 44
67 44 ▶ my $mod = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $mod = shift() or return 0 44 44
68 44 my $who = _who();
69  
70 44 ▶ if( _is_file( $mod ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_file($mod)) { } 1 43 44
71 1 require $mod;
72 } else {
73 LOAD: {
74 43 my $err;
75 43 for my $flag ( qw[1 0] ) {
76 48 my $file = _to_file( $mod, $flag);
77 48 eval { require $file };
78 48 ▶ $@ ? $err .= $@ : last LOAD;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 9 39 48
79 }
80 4 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 4 0 4
81 }
82 }
83  
84 ### This addresses #41883: Module::Load cannot import
85 ### non-Exporter module. ->import() routines weren't
86 ### properly called when load() was used.
87  
88 2 ▶ { no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
89 40 my $import;
90  
91 40 ▶ ((@_ or $autoimport) and (
Branch: 1 branch
BranchTrueFalseTotal
@_ || $autoimport and $import = $mod->can("import") and unshift(@_, $mod), goto \&$import, return 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
92 $import = $mod->can('import')
93 ) and (
94 unshift(@_, $mod),
95 goto &$import,
96 return
97 )
98 );
99 }
100  
101 }
102  
103 sub _to_file{
104 53 ▶ local $_ = shift;
Subroutine _to_file: called CC=7 SCAR=19.7
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 sub _is_file {
132 44 ▶ local $_ = shift;
Subroutine _is_file: called CC=3 SCAR=11.1
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__
« blib/lib/Module/Load.pm ↑ Summary