lib/Module/Install.pm

filter: Statementstmt 70.6% 166 / 235 Branchbran 35.5% 37 / 104 Conditioncond 41.5% 27 / 65 MC/DCmcdc 11.4% 4 / 35 Subroutinesub 88.8% 24 / 27 Podpod 0.0% 0 / 7 totaltotal 54.5% 258 / 473 CC 92 SCAR 30.0
CC
92
Cov
57%
preload
83.4
load
30.0
_write
30.0
CRAP 20.1
« lib/Module/Install/Inline.pm ↑ Summary lib/Module/Install/Metadata.pm »
1 package Module::Install;
2  
3 # For any maintainers:
4 # The load order for Module::Install is a bit magic.
5 # It goes something like this...
6 #
7 # IF ( host has Module::Install installed, creating author mode ) {
8 # 1. Makefile.PL calls "use inc::Module::Install"
9 # 2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install
10 # 3. The installed version of inc::Module::Install loads
11 # 4. inc::Module::Install calls "require Module::Install"
12 # 5. The ./inc/ version of Module::Install loads
13 # } ELSE {
14 # 1. Makefile.PL calls "use inc::Module::Install"
15 # 2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install
16 # 3. The ./inc/ version of Module::Install loads
17 # }
18  
19 52 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
20 52 ▶use strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
21 52 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
22 52 ▶use File::Find ();
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
23 52 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 52 ▶use vars qw{$VERSION $MAIN};
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
26 52 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
27 # All Module::Install core packages now require synchronised versions.
28 # This will be used to ensure we don't accidentally load old or
29 # different versions of modules.
30 # This is not enforced yet, but will be some time in the next few
31 # releases once we can make sure it won't clash with custom
32 # Module::Install extensions.
33 52 $VERSION = '1.21';
34  
35 # Storage for the pseudo-singleton
36 52 $MAIN = undef;
37  
38 52 *inc::Module::Install::VERSION = *VERSION;
39 52 @inc::Module::Install::ISA = __PACKAGE__;
40  
41 }
42  
43 46 ▶sub import {
Subroutine import: called CC=12 SCAR=28.7
44 46 my $class = shift;
45 46 my $self = $class->new(@_);
46 46 my $who = $self->_caller;
47  
48 #-------------------------------------------------------------
49 # all of the following checks should be included in import(),
50 # to allow "eval 'require Module::Install; 1' to test
51 # installation of Module::Install. (RT #51267)
52 #-------------------------------------------------------------
53  
54 # Whether or not inc::Module::Install is actually loaded, the
55 # $INC{inc/Module/Install.pm} is what will still get set as long as
56 # the caller loaded module this in the documented manner.
57 # If not set, the caller may NOT have loaded the bundled version, and thus
58 # they may not have a MI version that works with the Makefile.PL. This would
59 # result in false errors or unexpected behaviour. And we don't want that.
60 46 my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
61 46 ▶ unless ( $INC{$file} ) { die <<"END_DIE" }
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{$file}) 1 45 46
62  
63 1 Please invoke ${\__PACKAGE__} with:
64  
65 1 use inc::${\__PACKAGE__};
66  
67 not:
68  
69 1 use ${\__PACKAGE__};
70  
71 END_DIE
72  
73 # This reportedly fixes a rare Win32 UTC file time issue, but
74 # as this is a non-cross-platform XS module not in the core,
75 # we shouldn't really depend on it. See RT #24194 for detail.
76 # (Also, this module only supports Perl 5.6 and above).
77 45 ▶ eval "use Win32::UTCFileTime" if $^O eq 'MSWin32' && $] >= 5.006;
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" and $] >= "5.006" 0 45 45
Condition33%1/3
$^O eq "MSWin32" and $] >= "5.006"
!ll&&!rl&&r
4500
MC/DC0%0/2
$^O eq "MSWin32" and $] >= "5.006"
$^O eq "MSWin32" $] >= "5.006"
Truth table33%1/3
A and B
A= $^O eq "MSWin32"B= $] >= "5.006"
ABresult
0X0
100
111
78  
79 # If the script that is loading Module::Install is from the future,
80 # then make will detect this and cause it to re-run over and over
81 # again. This is bad. Rather than taking action to touch it (which
82 # is unreliable on some platforms and requires write permissions)
83 # for now we should catch this and refuse to run.
84 45 ▶ if ( -f $0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $0) 45 0 45
85 45 my $s = (stat($0))[9];
86  
87 # If the modification time is only slightly in the future,
88 # sleep briefly to remove the problem.
89 45 my $a = $s - time;
90 0 ▶ if ( $a > 0 and $a < 5 ) { sleep 5 }
Branch: 1 branch
BranchTrueFalseTotal
if ($a > 0 and $a < 5) 0 45 45
Condition33%1/3
$a > 0 and $a < 5
!ll&&!rl&&r
4500
MC/DC0%0/2
$a > 0 and $a < 5
$a > 0 $a < 5
Truth table33%1/3
A and B
A= $a > 0B= $a < 5
ABresult
0X0
100
111
91  
92 # Too far in the future, throw an error.
93 45 my $t = time;
94 0 ▶ if ( $s > $t ) { die <<"END_DIE" }
Branch: 1 branch
BranchTrueFalseTotal
if ($s > $t) 0 45 45
95  
96 Your installer $0 has a modification time in the future ($s > $t).
97  
98 This is known to create infinite loops in make.
99  
100 Please correct this, then run $0 again.
101  
102 END_DIE
103 }
104  
105  
106 # Build.PL was formerly supported, but no longer is due to excessive
107 # difficulty in implementing every single feature twice.
108 0 ▶ if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" }
Branch: 1 branch
BranchTrueFalseTotal
if ($0 =~ /Build.PL$/i) 0 45 45
109  
110 Module::Install no longer supports Build.PL.
111  
112 It was impossible to maintain duel backends, and has been deprecated.
113  
114 Please remove all Build.PL files and only use the Makefile.PL installer.
115  
116 END_DIE
117  
118 #-------------------------------------------------------------
119  
120 # To save some more typing in Module::Install installers, every...
121 # use inc::Module::Install
122 # ...also acts as an implicit use strict.
123 45 $^H |= strict::bits(qw(refs subs vars));
124  
125 #-------------------------------------------------------------
126  
127 45 ▶ unless ( -f $self->{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $self->{"file"}) 45 0 45
128 45 foreach my $key (keys %INC) {
129 3465 ▶ delete $INC{$key} if $key =~ /Module\/Install/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ m[Module/Install] 90 3375 3465
130 }
131  
132 45 local $^W;
133 45 require "$self->{path}/$self->{dispatch}.pm";
134 45 File::Path::mkpath("$self->{prefix}/$self->{author}");
135 45 $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self );
136 45 $self->{admin}->init;
137 45 @_ = ($class, _self => $self);
138 45 goto &{"$self->{name}::import"};
139 }
140  
141 0 local $^W;
142 0 *{"${who}::AUTOLOAD"} = $self->autoload;
143 0 $self->preload;
144  
145 # Unregister loader and worker packages so subdirs can use them again
146 0 delete $INC{'inc/Module/Install.pm'};
147 0 delete $INC{'Module/Install.pm'};
148  
149 # Save to the singleton
150 0 $MAIN = $self;
151  
152 0 return 1;
153 }
154  
155 0 ▶sub autoload {
Subroutine autoload: not called CC=1 SCAR=4.2
Pod undocumented
156 0 my $self = shift;
157 0 my $who = $self->_caller;
158 0 my $cwd = Cwd::getcwd();
159 0 my $sym = "${who}::AUTOLOAD";
160 0 ▶ $sym->{$cwd} = sub {
Subroutine __ANON__: not called CC=7 SCAR=33.8
161 0 my $pwd = Cwd::getcwd();
162 0 ▶ if ( my $code = $sym->{$pwd} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $sym->{$pwd}) 4 0 4
163 # Delegate back to parent dirs
164 0 ▶ goto &$code unless $cwd eq $pwd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cwd eq $pwd 0 4 4
165 }
166 0 ▶ unless ($$sym =~ s/([^:]+)$//) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$sym =~ s/([^:]+)$//) 0 4 4
167 # XXX: it looks like we can't retrieve the missing function
168 # via $$sym (usually $main::AUTOLOAD) in this case.
169 # I'm still wondering if we should slurp Makefile.PL to
170 # get some context or not ...
171 0 my ($package, $file, $line) = caller;
172 0 die <<"EOT";
173 Unknown function is found at $file line $line.
174 Execution of $file aborted due to runtime errors.
175  
176 If you're a contributor to a project, you may need to install
177 some Module::Install extensions from CPAN (or other repository).
178 If you're a user of a module, please contact the author.
179 EOT
180 }
181 0 my $method = $1;
182 0 ▶ if ( uc($method) eq $method ) {
Branch: 2 branches
BranchTrueFalseTotal
if (uc $method eq $method) { } 0 2 2
elsif ($method =~ /^_/ and $self->can($method)) { } 2 2 4
183 # Do nothing
184 0 return;
185 ▶ } elsif ( $method =~ /^_/ and $self->can($method) ) {
Condition0%0/3
$method =~ /^_/ and $self->can($method)
!ll&&!rl&&r
000
MC/DC0%0/2
$method =~ /^_/ and $self->can($method)
$method =~ /^_/ $self->can($method)
Truth table0%0/3
A and B
A= $method =~ /^_/B= $self->can($method)
ABresult
0X0
100
111
186 # Dispatch to the root M:I class
187 0 return $self->$method(@_);
188 }
189  
190 # Dispatch to the appropriate plugin
191 0 unshift @_, ( $self, $1 );
192 0 goto &{$self->can('call')};
193 0 };
194 }
195  
196 3 ▶sub preload {
Subroutine preload: called CC=9 SCAR=44.2
Pod undocumented
197 0 my $self = shift;
198 0 ▶ unless ( $self->{extensions} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"extensions"}) 0 0 0
199 0 $self->load_extensions(
200 "$self->{prefix}/$self->{path}", $self
201 );
202 }
203  
204 0 my @exts = @{$self->{extensions}};
205 0 ▶ unless ( @exts ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@exts) 0 0 0
206 0 @exts = $self->{admin}->load_all_extensions;
207 }
208  
209 0 my %seen;
210 0 foreach my $obj ( @exts ) {
211 0 ▶ while (my ($method, $glob) = each %{ref($obj) . '::'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{ref($obj) . '::';}) 0 0 0
212 0 ▶ next unless $obj->can($method);
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->can($method) 0 0 0
213 0 ▶ next if $method =~ /^_/;
Branch: 1 branch
BranchTrueFalseTotal
if $method =~ /^_/ 0 0 0
214 0 ▶ next if $method eq uc($method);
Branch: 1 branch
BranchTrueFalseTotal
if $method eq uc $method 0 0 0
215 0 $seen{$method}++;
216 }
217 }
218  
219 0 my $who = $self->_caller;
220 0 foreach my $name ( sort keys %seen ) {
221 0 local $^W;
222 0 ▶ *{"${who}::$name"} = sub {
Subroutine __ANON__: called CC=1 SCAR=4.1
223 0 ${"${who}::AUTOLOAD"} = "${who}::$name";
224 0 goto &{"${who}::AUTOLOAD"};
225 0 };
226 }
227 }
228  
229 46 ▶sub new {
Subroutine new: called CC=14 SCAR=29.5
Subroutine new: called CC=14 SCAR=29.5
Pod undocumented
Pod undocumented
230 46 my ($class, %args) = @_;
231  
232 46 delete $INC{'FindBin.pm'};
233 {
234 # to suppress the redefine warning
235 46 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
236 46 require FindBin;
237 }
238  
239 # ignore the prefix on extension modules built from top level.
240 46 my $base_path = Cwd::abs_path($FindBin::Bin);
241 46 ▶ unless ( Cwd::abs_path(Cwd::getcwd()) eq $base_path ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (Cwd::abs_path(Cwd::getcwd()) eq $base_path) 0 46 46
unless (Cwd::abs_path(Cwd::getcwd()) eq $base_path) 0 45 45
242 0 delete $args{prefix};
243 }
244 46 ▶ return $args{_self} if $args{_self};
Branch: 2 branches
BranchTrueFalseTotal
if $args{"_self"} 0 46 46
if $args{"_self"} 0 45 45
245  
246 46 ▶ $base_path = VMS::Filespec::unixify($base_path) if $^O eq 'VMS';
Branch: 2 branches
BranchTrueFalseTotal
if $^O eq "VMS" 0 46 46
if $^O eq "VMS" 0 45 45
247  
248 46 ▶ $args{dispatch} ||= 'Admin';
Condition50%3/6
$args{"dispatch"} ||= "Admin"
l!l
0460
$args{"dispatch"} ||= "Admin"
l!l
4720
MC/DC0%0/1
$args{"dispatch"} ||= "Admin"
$args{"dispatch"}
MC/DC100%1/1
$args{"dispatch"} ||= "Admin"
$args{"dispatch"}
Truth table50%1/2
A
A= $args{"dispatch"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"dispatch"}
Aresult
11
00
249 46 ▶ $args{prefix} ||= 'inc';
Condition60%3/5
$args{"prefix"} ||= "inc"
l!l
248
$args{"prefix"} ||= "inc"
l!l
4500
MC/DC100%1/1
$args{"prefix"} ||= "inc"
$args{"prefix"}
MC/DC0%0/1
$args{"prefix"} ||= "inc"
$args{"prefix"}
Truth table100%2/2
A
A= $args{"prefix"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"prefix"}
Aresult
11
00
250 46 ▶ $args{author} ||= ($^O eq 'VMS' ? '_author' : '.author');
Branch: 2 branches
BranchTrueFalseTotal
$^O eq 'VMS' ? : 0 46 46
$^O eq 'VMS' ? : 0 0 0
Condition33%2/6
$args{"author"} ||= $^O eq "VMS" ? "_author" : ".author"
l!l&&r!l&&!r
0500
$args{"author"} ||= $^O eq "VMS" ? "_author" : ".author"
l!l&&r!l&&!r
4500
MC/DC0%0/2
$args{"author"} ||= $^O eq "VMS" ? "_author" : ".author"
$args{"author"} $^O eq "VMS" ? "_author" : ".author"
MC/DC0%0/2
$args{"author"} ||= $^O eq "VMS" ? "_author" : ".author"
$args{"author"} $^O eq "VMS" ? "_author" : ".author"
Truth table33%1/3
A ||= B
A= $args{"author"}B= $^O eq "VMS" ? "_author" : ".author"
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $args{"author"}B= $^O eq "VMS" ? "_author" : ".author"
ABresult
1X1
011
000
251 46 ▶ $args{bundle} ||= 'inc/BUNDLES';
Condition50%3/6
$args{"bundle"} ||= "inc/BUNDLES"
l!l
2480
$args{"bundle"} ||= "inc/BUNDLES"
l!l
4500
MC/DC100%1/1
$args{"bundle"} ||= "inc/BUNDLES"
$args{"bundle"}
MC/DC0%0/1
$args{"bundle"} ||= "inc/BUNDLES"
$args{"bundle"}
Truth table100%2/2
A
A= $args{"bundle"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"bundle"}
Aresult
11
00
252 46 ▶ $args{base} ||= $base_path;
Condition50%3/6
$args{"base"} ||= $base_path
l!l&&r!l&&!r
2480
$args{"base"} ||= $base_path
l!l&&r!l&&!r
4500
MC/DC0%0/2
$args{"base"} ||= $base_path
$args{"base"} $base_path
MC/DC0%0/2
$args{"base"} ||= $base_path
$args{"base"} $base_path
Truth table66%2/3
A ||= B
A= $args{"base"}B= $base_path
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $args{"base"}B= $base_path
ABresult
1X1
011
000
253 46 $class =~ s/^\Q$args{prefix}\E:://;
254 46 ▶ $args{name} ||= $class;
Condition66%4/6
$args{"name"} ||= $class
l!l&&r!l&&!r
2480
$args{"name"} ||= $class
l!l&&r!l&&!r
6920
MC/DC0%0/2
$args{"name"} ||= $class
$args{"name"} $class
MC/DC0%0/2
$args{"name"} ||= $class
$args{"name"} $class
Truth table66%2/3
A ||= B
A= $args{"name"}B= $class
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $args{"name"}B= $class
ABresult
1X1
011
000
255 46 ▶ $args{version} ||= $class->VERSION;
Condition66%4/6
$args{"version"} ||= $class->VERSION
l!l&&r!l&&!r
2480
$args{"version"} ||= $class->VERSION
l!l&&r!l&&!r
6920
MC/DC0%0/2
$args{"version"} ||= $class->VERSION
$args{"version"} $class->VERSION
MC/DC0%0/2
$args{"version"} ||= $class->VERSION
$args{"version"} $class->VERSION
Truth table66%2/3
A ||= B
A= $args{"version"}B= $class->VERSION
ABresult
1X1
011
000
Truth table0%0/3
A ||= B
A= $args{"version"}B= $class->VERSION
ABresult
1X1
011
000
256 46 ▶ unless ( $args{path} ) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($args{"path"}) 46 0 46
unless ($args{"path"}) 0 45 45
257 46 $args{path} = $args{name};
258 46 $args{path} =~ s!::!/!g;
259 }
260 50 ▶ $args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm";
Condition50%3/6
$args{"file"} ||= qq[$args{"base"}/$args{"prefix"}/$args{"path"}.pm]
l!l
2480
$args{"file"} ||= qq[$args{"base"}/$args{"prefix"}/$args{"path"}.pm]
l!l
4500
MC/DC100%1/1
$args{"file"} ||= qq[$args{"base"}/$args{"prefix"}/$args{"path"}.pm]
$args{"file"}
MC/DC0%0/1
$args{"file"} ||= qq[$args{"base"}/$args{"prefix"}/$args{"path"}.pm]
$args{"file"}
Truth table100%2/2
A
A= $args{"file"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"file"}
Aresult
11
00
261 50 $args{wrote} = 0;
262  
263 50 bless( \%args, $class );
264 }
265  
266 1 ▶sub call {
Subroutine call: called CC=2 SCAR=17.9
Pod undocumented
267 0 my ($self, $method) = @_;
268 0 ▶ my $obj = $self->load($method) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $obj = $self->load($method) or return 0 0 0
269 0 splice(@_, 0, 2, $obj);
270 0 goto &{$obj->can($method)};
271 }
272  
273 26 ▶sub load {
Subroutine load: called CC=5 SCAR=34.0
Pod undocumented
274 0 my ($self, $method) = @_;
275  
276 $self->load_extensions(
277 "$self->{prefix}/$self->{path}", $self
278 0 ▶ ) unless $self->{extensions};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"extensions"} 0 0 0
279  
280 0 foreach my $obj (@{$self->{extensions}}) {
281 0 ▶ return $obj if $obj->can($method);
Branch: 1 branch
BranchTrueFalseTotal
if $obj->can($method) 0 0 0
282 }
283  
284 0 ▶ my $admin = $self->{admin} or die <<"END_DIE";
Branch: 1 branch
BranchTrueFalseTotal
my $admin = $self->{"admin"} or die qq[The '${method}' method does not exist in the '$self->{"prefix"}' path!\nPlease remove the '$self->{"prefix"}' directory and run $0 again to load it.\n] 0 0 0
285 The '$method' method does not exist in the '$self->{prefix}' path!
286 Please remove the '$self->{prefix}' directory and run $0 again to load it.
287 END_DIE
288  
289 0 my $obj = $admin->load($method, 1);
290 0 push @{$self->{extensions}}, $obj;
291  
292 0 $obj;
293 }
294  
295 3 ▶sub load_extensions {
Subroutine load_extensions: called CC=9 SCAR=26.8
Pod undocumented
296 3 my ($self, $path, $top) = @_;
297  
298 3 my $should_reload = 0;
299 3 ▶ unless ( grep { ! ref $_ and lc $_ eq lc $self->{prefix} } @INC ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {not ref $_ and lc $_ eq lc $self->{"prefix"};} @INC) 0 0 0
Condition0%0/3
!ref($_) && lc $_ eq lc $self->{'prefix'}
!ll&&!rl&&r
000
MC/DC0%0/2
!ref($_) && lc $_ eq lc $self->{'prefix'}
!ref($_) lc $_ eq lc $self->{'prefix'}
Truth table0%0/3
not(A) && B
A= !ref($_)B= lc $_ eq lc $self->{'prefix'}
ABresult
0X0
100
111
300 3 unshift @INC, $self->{prefix};
301 3 $should_reload = 1;
302 }
303  
304 3 foreach my $rv ( $self->find_extensions($path) ) {
305 3 my ($file, $pkg) = @{$rv};
306 1 ▶ next if $self->{pathnames}{$pkg};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pathnames"}{$pkg} 0 0 0
307  
308 1 local $@;
309 1 my $new = eval { local $^W; require $file; $pkg->can('new') };
310 1 ▶ unless ( $new ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new) 0 0 0
311 1 ▶ warn $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
312 1 next;
313 }
314 $self->{pathnames}{$pkg} =
315 1 ▶ $should_reload ? delete $INC{$file} : $INC{$file};
Branch: 1 branch
BranchTrueFalseTotal
$should_reload ? : 0 0 0
316 1 push @{$self->{extensions}}, &{$new}($pkg, _top => $top );
317 }
318  
319 1 ▶ $self->{extensions} ||= [];
Condition0%0/3
$self->{"extensions"} ||= []
l!l
000
MC/DC0%0/1
$self->{"extensions"} ||= []
$self->{"extensions"}
Truth table0%0/2
A
A= $self->{"extensions"}
Aresult
11
00
320 }
321  
322 0 ▶sub find_extensions {
Subroutine find_extensions: not called CC=2 SCAR=8.5
323 1 my ($self, $path) = @_;
324  
325 1 my @found;
326 File::Find::find( {no_chdir => 1, wanted => sub {
327 26 my $file = $File::Find::name;
328 26 ▶ return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ m[^\Q$path\E/(.+)\.pm\Z]is 0 0 0
329 26 my $subpath = $1;
330 8 ▶ return if lc($subpath) eq lc($self->{dispatch});
Branch: 1 branch
BranchTrueFalseTotal
if lc $subpath eq lc $self->{"dispatch"} 0 0 0
331  
332 16 $file = "$self->{path}/$subpath.pm";
333 26 my $pkg = "$self->{name}::$subpath";
334 26 $pkg =~ s!/!::!g;
335  
336 # If we have a mixed-case package name, assume case has been preserved
337 # correctly. Otherwise, root through the file to locate the case-preserved
338 # version of the package name.
339 26 ▶ if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subpath eq lc $subpath or $subpath eq uc $subpath) 0 0 0
Condition0%0/3
$subpath eq lc $subpath or $subpath eq uc $subpath
l!l&&r!l&&!r
000
MC/DC0%0/2
$subpath eq lc $subpath or $subpath eq uc $subpath
$subpath eq lc $subpath $subpath eq uc $subpath
Truth table0%0/3
A or B
A= $subpath eq lc $subpathB= $subpath eq uc $subpath
ABresult
1X1
011
000
340 39 my $content = Module::Install::_read($File::Find::name);
341 26 my $in_pod = 0;
342 26 foreach ( split /\n/, $content ) {
343 3 ▶ $in_pod = 1 if /^=\w/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=\w/ 3 0 3
344 0 ▶ $in_pod = 0 if /^=cut/;
Branch: 1 branch
BranchTrueFalseTotal
if /^=cut/ 3 0 3
345 6 ▶ next if ($in_pod || /^=cut/); # skip pod text
Branch: 1 branch
BranchTrueFalseTotal
if $in_pod or /^=cut/ 0 1 1
346 ▶ next if /^\s*#/; # and comments
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*#/ 1 0 1
347 ▶ if ( m/^\s*package\s+($pkg)\s*;/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*package\s+($pkg)\s*;/i) 1 0 1
348 $pkg = $1;
349 last;
350 }
351 }
352 }
353  
354 push @found, [ $file, $pkg ];
355 1 ▶ }}, $path ) if -d $path;
Branch: 1 branch
BranchTrueFalseTotal
if -d $path 0 0 0
356  
357 1 @found;
358 }
359  
360  
361  
362  
363  
364 #####################################################################
365 # Common Utility Functions
366  
367 46 ▶sub _caller {
Subroutine _caller: called CC=2 SCAR=6.9
368 46 my $depth = 0;
369 46 my $call = caller($depth);
370 46 ▶ while ( $call eq __PACKAGE__ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call eq __PACKAGE__) 46 46 92
371 46 $depth++;
372 46 $call = caller($depth);
373 }
374 46 return $call;
375 }
376  
377 sub _read {
378 local *FH;
379 ▶ open( FH, '<', $_[0] ) or die "open($_[0]): $!";
Branch: 1 branch
BranchTrueFalseTotal
open FH, "<", $_[0] or die "open($_[0]): $!" 1 0 1
380 binmode FH;
381 my $string = do { local $/; <FH> };
382 ▶ close FH or die "close($_[0]): $!";
Branch: 1 branch
BranchTrueFalseTotal
close FH or die "close($_[0]): $!" 8 18 26
383 return $string;
384 }
385  
386 sub _readperl {
387 my $string = Module::Install::_read($_[0]);
388 $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg;
389 $string =~ s/(\n)\n*__(?:DATA|END)__\b.*\z/$1/s;
390 $string =~ s/\n\n=\w+.+?\n\n=cut\b.+?\n+/\n\n/sg;
391 return $string;
392 }
393  
394 sub _readpod {
395 my $string = Module::Install::_read($_[0]);
396 $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg;
397 ▶ return $string if $_[0] =~ /\.pod\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /\.pod\z/ 20 6 26
398 $string =~ s/(^|\n=cut\b.+?\n+)[^=\s].+?\n(\n=\w+|\z)/$1$2/sg;
399 $string =~ s/\n*=pod\b[^\n]*\n+/\n\n/sg;
400 $string =~ s/\n*=cut\b[^\n]*\n+/\n\n/sg;
401 $string =~ s/^\n+//s;
402 return $string;
403 }
404  
405 sub _write {
406 local *FH;
407 ▶ open( FH, '>', $_[0] ) or die "open($_[0]): $!";
Branch: 1 branch
BranchTrueFalseTotal
open FH, ">", $_[0] or die "open($_[0]): $!" 0 0 0
408 binmode FH;
409 foreach ( 1 .. $#_ ) {
410 print FH $_[$_] or die "print($_[0]): $!";
411 }
412 close FH or die "close($_[0]): $!";
413 }
414  
415 # _version is for processing module versions (eg, 1.03_05) not
416 # Perl versions (eg, 5.8.1).
417 sub _version {
418 my $s = shift || 0;
419 my $d =()= $s =~ /(\.)/g;
420 if ( $d >= 2 ) {
421 # Normalise multipart versions
422 $s =~ s/(\.)(\d{1,3})/sprintf("$1%03d",$2)/eg;
423 }
424 $s =~ s/^(\d+)\.?//;
425 my $l = $1 || 0;
426 my @v = map {
427 $_ . '0' x (3 - length $_)
428 } $s =~ /(\d{1,3})\D?/g;
429 $l = $l . '.' . join '', @v if @v;
430 return $l + 0;
431 }
432  
433 sub _cmp {
434 _version($_[1]) <=> _version($_[2]);
435 }
436  
437 # Cloned from Params::Util::_CLASS
438 sub _CLASS {
439 (
440 defined $_[0]
441 and
442 ! ref $_[0]
443 and
444 $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s
445 ) ? $_[0] : undef;
446 }
447  
448 45 1;
449  
450 # Copyright 2008 - 2012 Adam Kennedy.
« lib/Module/Install/Inline.pm ↑ Summary lib/Module/Install/Metadata.pm »