AutoLoader.pm

filter: Statementstmt 83.6% 92 / 110 Branchbran 50.0% 27 / 54 Conditioncond 38.8% 7 / 18 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 2 totaltotal 67.4% 139 / 206 CC 35 SCAR 34.8
CC
35
Cov
69%
find_filename
80.5
import
12.6
autoload_sub
6.0
CRAP 32.3
« AutoSplit.pm ↑ Summary
1 package AutoLoader;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use 5.006_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our($VERSION, $AUTOLOAD);
7  
8 2 my $is_dosish;
9 my $is_epoc;
10 2 my $is_vms;
11 2 my $is_macos;
12  
13 2 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=16.6
14 2 ▶ $is_dosish = $^O eq 'dos' || $^O eq 'os2' || $^O eq 'MSWin32' || $^O eq 'NetWare';
Condition33%3/9
$^O eq 'dos' || $^O eq 'os2' || $^O eq 'MSWin32' || $^O eq 'NetWare'
l!l&&r!l&&!r
002
$^O eq "dos" or $^O eq "os2" or $^O eq "MSWin32"
l!l&&r!l&&!r
002
$^O eq "dos" or $^O eq "os2"
l!l&&r!l&&!r
002
MC/DC0%0/4
$^O eq 'dos' || $^O eq 'os2' || $^O eq 'MSWin32' || $^O eq 'NetWare'
$^O eq "dos" $^O eq "os2" $^O eq "MSWin32" $^O eq 'NetWare'
Truth table20%1/5
A or B or C || D
A= $^O eq "dos"B= $^O eq "os2"C= $^O eq "MSWin32"D= $^O eq 'NetWare'
ABCDresult
1XXX1
01XX1
001X1
00011
00000
15 2 $is_epoc = $^O eq 'epoc';
16 2 $is_vms = $^O eq 'VMS';
17 2 $is_macos = $^O eq 'MacOS';
18 2 $VERSION = '5.74';
19 }
20  
21 25 ▶AUTOLOAD {
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
22 25 my $sub = $AUTOLOAD;
23 25 autoload_sub($sub);
24 21 goto &$sub;
25 }
26  
27 27 ▶sub autoload_sub {
Subroutine autoload_sub: called CC=6 SCAR=17.9
Pod undocumented
28 27 my $sub = shift;
29  
30 27 my $filename = AutoLoader::find_filename( $sub );
31  
32 27 my $save = $@;
33 27 local $!; # Do not munge the value.
34 27 eval { local $SIG{__DIE__}; require $filename };
35 27 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 7 20 27
36 7 ▶ if (substr($sub,-9) eq '::DESTROY') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($sub, -9) eq '::DESTROY') { } 2 5 7
elsif ($@ =~ /^Can't locate/) { } 4 1 5
37 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶ *$sub = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
39 2 $@ = undef;
40 } elsif ($@ =~ /^Can't locate/) {
41 # The load might just have failed because the filename was too
42 # long for some old SVR3 systems which treat long names as errors.
43 # If we can successfully truncate a long name then it's worth a go.
44 # There is a slight risk that we could pick up the wrong file here
45 # but autosplit should have warned about that when splitting.
46 4 ▶ if ($filename =~ s/(\w{12,})\.al$/substr($1,0,11).".al"/e){
Branch: 1 branch
BranchTrueFalseTotal
if ($filename =~ s/(\w{12,})\.al$/substr($1, 0, 11) . '.al';/e) 1 3 4
47 1 eval { local $SIG{__DIE__}; require $filename };
48 }
49 }
50 7 ▶ if ($@){
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 4 3 7
51 4 $@ =~ s/ at .*\n//;
52 4 my $error = $@;
53 4 require Carp;
54 4 Carp::croak($error);
55 }
56 }
57 23 $@ = $save;
58  
59 23 return 1;
60 }
61  
62 27 ▶sub find_filename {
Subroutine find_filename: called CC=16 SCAR=43.9
Pod undocumented
63 27 my $sub = shift;
64 27 my $filename;
65 # Braces used to preserve $1 et al.
66 {
67 # Try to find the autoloaded file from the package-qualified
68 # name of the sub. e.g., if the sub needed is
69 # Getopt::Long::GetOptions(), then $INC{Getopt/Long.pm} is
70 # something like '/usr/lib/perl5/Getopt/Long.pm', and the
71 # autoload file is '/usr/lib/perl5/auto/Getopt/Long/GetOptions.al'.
72 #
73 # However, if @INC is a relative path, this might not work. If,
74 # for example, @INC = ('lib'), then $INC{Getopt/Long.pm} is
75 # 'lib/Getopt/Long.pm', and we want to require
76 # 'auto/Getopt/Long/GetOptions.al' (without the leading 'lib').
77 # In this case, we simple prepend the 'auto/' and let the
78 # C<require> take care of the searching for us.
79  
80 27 my ($pkg,$func) = ($sub =~ /(.*)::([^:]+)$/);
81 27 $pkg =~ s#::#/#g;
82 27 ▶ if (defined($filename = $INC{"$pkg.pm"})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($filename = $INC{"$pkg.pm"})) 2 25 27
83 2 ▶ if ($is_macos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_macos) { } 0 2 2
84 0 $pkg =~ tr#/#:#;
85 0 ▶ $filename = undef
Branch: 1 branch
BranchTrueFalseTotal
unless $filename =~ s/^(.*)$pkg\.pm\z/$1auto:${pkg}:$func.al/s 0 0 0
86 unless $filename =~ s#^(.*)$pkg\.pm\z#$1auto:$pkg:$func.al#s;
87 } else {
88 2 ▶ $filename = undef
Branch: 1 branch
BranchTrueFalseTotal
unless $filename =~ s[^(.*)$pkg\.pm\z][$1auto/$pkg/$func.al]s 2 0 2
89 unless $filename =~ s#^(.*)$pkg\.pm\z#$1auto/$pkg/$func.al#s;
90 }
91  
92 # if the file exists, then make sure that it is a
93 # a fully anchored path (i.e either '/usr/lib/auto/foo/bar.al',
94 # or './lib/auto/foo/bar.al'. This avoids C<require> searching
95 # (and failing) to find the 'lib/auto/foo/bar.al' because it
96 # looked for 'lib/lib/auto/foo/bar.al', given @INC = ('lib').
97  
98 2 ▶ if (defined $filename and -r $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filename and -r $filename) { } 0 2 2
Condition33%1/3
defined $filename and -r $filename
!ll&&!rl&&r
200
MC/DC0%0/2
defined $filename and -r $filename
defined $filename -r $filename
Truth table33%1/3
A and B
A= defined $filenameB= -r $filename
ABresult
0X0
100
111
99 0 ▶ unless ($filename =~ m|^/|s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename =~ m[^/]s) 0 0 0
100 0 ▶ if ($is_dosish) {
Branch: 4 branches
BranchTrueFalseTotal
if ($is_dosish) { } 0 0 0
elsif ($is_epoc) { } 0 0 0
elsif ($is_vms) { } 0 0 0
elsif (not $is_macos) { } 0 0 0
101 0 ▶ unless ($filename =~ m{^([a-z]:)?[\\/]}is) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename =~ m[^([a-z]:)?[\\/]]is) 0 0 0
102 0 ▶ if ($^O ne 'NetWare') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O ne 'NetWare') { } 0 0 0
103 0 $filename = "./$filename";
104 } else {
105 0 $filename = "$filename";
106 }
107 }
108 }
109 elsif ($is_epoc) {
110 0 ▶ unless ($filename =~ m{^([a-z?]:)?[\\/]}is) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename =~ m[^([a-z?]:)?[\\/]]is) 0 0 0
111 0 $filename = "./$filename";
112 }
113 }
114 elsif ($is_vms) {
115 # XXX todo by VMSmiths
116 0 $filename = "./$filename";
117 }
118 elsif (!$is_macos) {
119 0 $filename = "./$filename";
120 }
121 }
122 }
123 else {
124 2 $filename = undef;
125 }
126 }
127 27 ▶ unless (defined $filename) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $filename) 27 0 27
128 # let C<require> do the searching
129 27 $filename = "auto/$sub.al";
130 27 $filename =~ s#::#/#g;
131 }
132 }
133 27 return $filename;
134 }
135  
136 10 ▶sub import {
Subroutine import: called CC=10 SCAR=25.4
137 10 my $pkg = shift;
138 10 my $callpkg = caller;
139  
140 #
141 # Export symbols, but not by accident of inheritance.
142 #
143  
144 10 ▶ if ($pkg eq 'AutoLoader') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg eq "AutoLoader") 10 0 10
145 10 ▶ if ( @_ and $_[0] =~ /^&?AUTOLOAD$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $_[0] =~ /^&?AUTOLOAD$/) 8 2 10
Condition66%2/3
@_ and $_[0] =~ /^&?AUTOLOAD$/
!ll&&!rl&&r
208
MC/DC50%1/2
@_ and $_[0] =~ /^&?AUTOLOAD$/
@_ $_[0] =~ /^&?AUTOLOAD$/
Truth table66%2/3
A and B
A= @_B= $_[0] =~ /^&?AUTOLOAD$/
ABresult
0X0
100
111
146 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
147 8 *{ $callpkg . '::AUTOLOAD' } = \&AUTOLOAD;
148 }
149 }
150  
151 #
152 # Try to find the autosplit index file. Eg., if the call package
153 # is POSIX, then $INC{POSIX.pm} is something like
154 # '/usr/local/lib/perl5/POSIX.pm', and the autosplit index file is in
155 # '/usr/local/lib/perl5/auto/POSIX/autosplit.ix', so we require that.
156 #
157 # However, if @INC is a relative path, this might not work. If,
158 # for example, @INC = ('lib'), then
159 # $INC{POSIX.pm} is 'lib/POSIX.pm', and we want to require
160 # 'auto/POSIX/autosplit.ix' (without the leading 'lib').
161 #
162  
163 10 (my $calldir = $callpkg) =~ s#::#/#g;
164 10 my $path = $INC{$calldir . '.pm'};
165 10 ▶ if (defined($path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path) 1 9 10
166 # Try absolute path name, but only eval it if the
167 # transformation from module path to autosplit.ix path
168 # succeeded!
169 1 my $replaced_okay;
170 1 ▶ if ($is_macos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_macos) { } 0 1 1
171 0 (my $malldir = $calldir) =~ tr#/#:#;
172 0 $replaced_okay = ($path =~ s#^(.*)$malldir\.pm\z#$1auto:$malldir:autosplit.ix#s);
173 } else {
174 1 $replaced_okay = ($path =~ s#^(.*)$calldir\.pm\z#$1auto/$calldir/autosplit.ix#);
175 }
176  
177 0 ▶ eval { require $path; } if $replaced_okay;
Branch: 1 branch
BranchTrueFalseTotal
if $replaced_okay 0 1 1
178 # If that failed, try relative path with normal @INC searching.
179 1 ▶ if (!$replaced_okay or $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $replaced_okay or $@) 1 0 1
Condition33%1/3
not $replaced_okay or $@
l!l&&r!l&&!r
100
MC/DC0%0/2
not $replaced_okay or $@
not $replaced_okay $@
Truth table33%1/3
not(A) or B
A= not $replaced_okayB= $@
ABresult
1X1
011
000
180 1 $path ="auto/$calldir/autosplit.ix";
181 1 eval { require $path; };
182 }
183 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
184 0 my $error = $@;
185 0 require Carp;
186 0 Carp::carp($error);
187 }
188 }
189 }
190  
191 2 ▶sub unimport {
Subroutine unimport: called CC=3 SCAR=11.0
192 2 my $callpkg = caller;
193  
194 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
195  
196 2 for my $exported (qw( AUTOLOAD )) {
197 2 my $symname = $callpkg . '::' . $exported;
198 2 ▶ undef *{ $symname } if \&{ $symname } == \&{ $exported };
Branch: 1 branch
BranchTrueFalseTotal
if \&{$symname;} == \&{$exported;} 1 1 2
199 2 *{ $symname } = \&{ $symname };
200 }
201 }
202  
203 2 1;
204  
205 __END__
« AutoSplit.pm ↑ Summary