inc/ExtUtils/AutoInstall.pm

filter: Statementstmt 31.6% 98 / 310 Branchbran 16.0% 34 / 212 Conditioncond 12.3% 17 / 138 MC/DCmcdc 1.3% 1 / 72 Subroutinesub 53.8% 14 / 26 Podpod 20.0% 1 / 5 totaltotal 21.6% 165 / 763 SCAR 93.8
CC
159
Cov
23%
import
2051.3
_install_cpanplus
380.0
_check_lock
90.0
CRAP 11892.4
↑ Summary blib/lib/OpenThought.pm »
1 package ExtUtils::AutoInstall;
2 $ExtUtils::AutoInstall::VERSION = '0.63';
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use ExtUtils::MakeMaker ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 ExtUtils::AutoInstall - Automatic install of dependencies via CPAN
11  
12 =head1 VERSION
13  
14 This document describes version 0.63 of B<ExtUtils::AutoInstall>,
15 released September 12, 2005.
16  
17 =head1 SYNOPSIS
18  
19 In F<Makefile.PL>, with L<Module::Install> available on the author's system:
20  
21 use inc::Module::Install;
22  
23 name ('Joe-Hacker');
24 abstract ('Perl Interface to Joe Hacker');
25 author ('Joe Hacker <joe@hacker.org>');
26 include ('ExtUtils::AutoInstall');
27  
28 requires ('Module0'); # mandatory modules
29 features (
30 -config => {
31 make_args => '--hello', # option(s) for CPAN::Config
32 force => 1, # pseudo-option to force install
33 do_once => 1, # skip previously failed modules
34 },
35 'Feature1' => [
36 'Module2' => '0.1',
37 ],
38 'Feature2' => [
39 'Module3' => '1.0',
40 ],
41 );
42 auto_install();
43 &WriteAll;
44  
45 Invoking the resulting F<Makefile.PL>:
46  
47 % perl Makefile.PL # interactive behaviour
48 % perl Makefile.PL --defaultdeps # accept default value on prompts
49 % perl Makefile.PL --checkdeps # check only, no Makefile produced
50 % perl Makefile.PL --skipdeps # ignores all dependencies
51 % perl Makefile.PL --testonly # don't write installation targets
52  
53 Note that the trailing 'deps' of arguments may be omitted, too.
54  
55 Using C<--defaultdeps> will make F<Makefile.PL> behave similarly to a regular
56 Makefile.PL file with C<PREREQ_PM> dependencies.
57  
58 One can use environment variables (see "ENVIRONMENT") below to set a default
59 behavior instead of specifying it in the command line for every invocation
60 of F<Makefile.PL>.
61  
62 Using F<make> (or F<nmake>):
63  
64 % make [all|test|install] # install dependencies first
65 % make checkdeps # same as the --checkdeps above
66 % make installdeps # install dependencies only
67  
68 =head1 DESCRIPTION
69  
70 B<ExtUtils::AutoInstall> lets module writers to specify a more
71 sophisticated form of dependency information than the C<PREREQ_PM>
72 option offered by B<ExtUtils::MakeMaker>.
73  
74 This module works best with the B<Module::Install> framework,
75 a drop-in replacement for MakeMaker. However, this module also
76 supports F<Makefile.PL> files based on MakeMaker; see L</EXAMPLES>
77 for instructions.
78  
79 =head2 Prerequisites and Features
80  
81 Prerequisites are grouped into B<features>, and the user could choose
82 yes/no on each one's dependencies; the module writer may also supply a
83 boolean value via C<-default> to specify the default choice.
84  
85 The B<Core Features> marked by the name C<-core> will double-check with
86 the user, if the user chooses not to install the mandatory modules.
87 This differs from the pre-0.26 'silent install' behaviour.
88  
89 Starting from version 0.27, if C<-core> is set to the string C<all>
90 (case-insensitive), every feature will be considered mandatory.
91  
92 The dependencies are expressed as pairs of C<Module> => C<version>
93 inside an array reference. If the order does not matter, and there
94 are no C<-default>, C<-tests> or C<-skiptests> directives for that
95 feature, you may also use a hash reference.
96  
97 =head2 The Installation Process
98  
99 Once B<ExtUtils::AutoInstall> has determined which module(s) are needed,
100 it checks whether it's running under the B<CPAN> shell and should
101 therefore let B<CPAN> handle the dependency.
102  
103 Finally, the C<WriteMakefile()> is overridden to perform some additional
104 checks, as well as skips tests associated with disabled features by the
105 C<-tests> option.
106  
107 The actual installation happens at the end of the C<make config> target;
108 both C<make test> and C<make install> will trigger the installation of
109 required modules.
110  
111 If it's not running under B<CPAN>, the installer will probe for an
112 active connection by trying to resolve the domain C<cpan.org>, and check
113 for the user's permission to use B<CPAN>. If all went well, a separate
114 B<CPAN> instance is created to install the required modules.
115  
116 If you have the B<CPANPLUS> package installed in your system, it is
117 preferred by default over B<CPAN>; it also accepts some extra options
118 (e.g. C<-target =E<gt> 'skiptest', -skiptest =E<gt> 1> to skip testing).
119  
120 All modules scheduled to be installed will be deleted from C<%INC>
121 first, so B<ExtUtils::MakeMaker> will check the newly installed modules.
122  
123 Additionally, you could use the C<make installdeps> target to install
124 the modules, and the C<make checkdeps> target to check dependencies
125 without actually installing them; the C<perl Makefile.PL --checkdeps>
126 command has an equivalent effect.
127  
128 If the F<Makefile.PL> itself needs to use an independent module (e.g.
129 B<Acme::KillarApp>, v1.21 or greater), then use something like below:
130  
131 BEGIN {
132 require ExtUtils::AutoInstall;
133 # the first argument is an arrayref of the -config flags
134 ExtUtils::AutoInstall->install([], 'Acme::KillerApp' => 1.21);
135 }
136 use Acme::KillerApp 1.21;
137  
138 ExtUtils::AutoInstall->import(
139 # ... arguments as usual ...
140 );
141  
142 Note the version test in the use clause; if you are so close to the
143 cutting edge that B<Acme::KillerApp> 1.20 is the latest version on CPAN,
144 this will prevent your module from going awry.
145  
146 =head2 User-Defined Hooks
147  
148 User-defined I<pre-installation> and I<post-installation> hooks are
149 available via C<MY::preinstall> and C<MY::postinstall> subroutines,
150 as shown below:
151  
152 # pre-install handler; takes $module_name and $version
153 sub MY::preinstall { return 1; } # return false to skip install
154  
155 # post-install handler; takes $module_name, $version, $success
156 sub MY::postinstall { return; } # the return value doesn't matter
157  
158 Note that since B<ExtUtils::AutoInstall> performs installation at the
159 time of C<use> (i.e. before perl parses the remainder of
160 F<Makefile.PL>), you have to declare those two handlers I<before> the
161 C<use> statement for them to take effect.
162  
163 If the user did not choose to install a module or it already exists on
164 the system, neither of the handlers is invoked. Both handlers are invoked
165 exactly once for each module when installation is attempted.
166  
167 C<MY::preinstall> takes two arguments, C<$module_name> and C<$version>;
168 if it returns a false value, installation for that module will be
169 skipped, and C<MY::postinstall> won't be called at all.
170  
171 C<MY::postinstall> takes three arguments, C<$module_name>, C<$version>
172 and C<$success>. The last one denotes whether the installation
173 succeeded or not: C<1> means installation completed successfully, C<0>
174 means failure during install, and C<undef> means that the installation
175 was not attempted at all, possibly due to connection problems, or that
176 module does not exist on CPAN at all.
177  
178 =head2 Customized C<MY::postamble>
179  
180 Starting from version 0.43, B<ExtUtils::AutoInstall> supports modules
181 that require a C<MY::postamble> subroutine in their F<Makefile.PL>.
182 The user-defined C<MY::postamble>, if present, is responsible for
183 calling C<ExtUtils::AutoInstall::postamble> and include the output in
184 its return value.
185  
186 For example, the B<DBD::*> (database driver) modules for the Perl DBI
187 are required to include the postamble generated by the function
188 C<dbd_postamble>, so their F<Makefile.PL> may contain lines like this:
189  
190 sub MY::postamble {
191 return &ExtUtils::AutoInstall::postamble . &dbd_postamble;
192 }
193  
194 Note that the B<ExtUtils::AutoInstall> module does not export the
195 C<postamble> function, so the name should always be fully qualified.
196  
197 =head1 CAVEATS
198  
199 B<ExtUtils::AutoInstall> will add C<UNINST=1> to your B<make install>
200 flags if your effective uid is 0 (root), unless you explicitly disable
201 it by setting B<CPAN>'s C<make_install_arg> configuration option (or the
202 C<makeflags> option of B<CPANPLUS>) to include C<UNINST=0>. This I<may>
203 cause dependency problems if you are using a fine-tuned directory
204 structure for your site. Please consult L<CPAN/FAQ> for an explanation
205 in detail.
206  
207 If either B<version> or B<Sort::Versions> is available, they will be
208 used to compare the required version with the existing module's version
209 and the CPAN module's. Otherwise it silently falls back to use I<cmp>.
210 This may cause inconsistent behaviours in pathetic situations.
211  
212 =head1 NOTES
213  
214 Since this module is needed before writing F<Makefile>, it makes little
215 use as a CPAN module; hence each distribution must include it in full.
216 The only alternative I'm aware of, namely prompting in F<Makefile.PL> to
217 force user install it (cf. the B<Template Toolkit>'s dependency on
218 B<AppConfig>) is not very desirable either.
219  
220 The current compromise is to add the bootstrap code listed in the
221 L</SYNOPSIS> before every script, but that does not look pretty, and
222 will not work without an Internet connection.
223  
224 Since we do not want all future options of B<ExtUtils::AutoInstall> to
225 be painfully detected manually like above, this module provides a
226 I<bootstrapping> mechanism via the C<-version> flag. If a newer version
227 is needed by the F<Makefile.PL>, it will go ahead to fetch a new
228 version, reload it into memory, and pass the arguments forward.
229  
230 If you have any suggestions, please let me know. Thanks.
231  
232 =head1 ENVIRONMENT
233  
234 B<ExtUtils::AutoInstall> uses a single environment variable,
235 C<PERL_EXTUTILS_AUTOINSTALL>. It is taken as the command line argument
236 passed to F<Makefile.PL>; you could set it to either C<--defaultdeps> or
237 C<--skipdeps> to avoid interactive behaviour.
238  
239 =head1 EXAMPLES
240  
241 =head2 Using MakeMaker with AutoInstall
242  
243 To use this module with L<ExtUtils::MakeMaker>, first make a
244 F<inc/ExtUtils/> subdirectory in the directory containing your
245 L<Makefile.PL>, and put a copy this module under it as
246 F<inc/ExtUtils/AutoInstall.pm>. You can find out where this module
247 has been installed by typing C<perldoc -l ExtUtils::AutoInstall>
248 in the command line.
249  
250 Your F<Makefile.PL> should look like this:
251  
252 # pull in ExtUtils/AutoInstall.pm from 'inc'
253 use lib 'inc';
254 use ExtUtils::AutoInstall (
255 -core => [ # mandatory modules
256 'Module0' => '', # any version would suffice
257 ],
258 'Feature1' => [
259 # do we want to install this feature by default?
260 -default => ( system('feature1 --version') == 0 ),
261 Module1 => '0.01',
262 ],
263 'Feature2' => [
264 # associate tests to be disabled if this feature is missing
265 -tests => [ <t/feature2*.t> ],
266 # associate tests to be disabled if this feature is present
267 -skiptests => [ <t/nofeature2*.t> ],
268 Module2 => '0.02',
269 ],
270 'Feature3' => { # hash reference works, too
271 # force installation even if tests fail
272 Module2 => '0.03',
273 }
274 );
275  
276 WriteMakefile(
277 AUTHOR => 'Joe Hacker <joe@hacker.org>',
278 ABSTRACT => 'Perl Interface to Joe Hacker',
279 NAME => 'Joe::Hacker',
280 VERSION_FROM => 'Hacker.pm',
281 DISTNAME => 'Joe-Hacker',
282 );
283  
284 =head2 Self-Download Code
285  
286 If you do not wish to put a copy of L<ExtUtils::AutoInstall> under
287 F<inc/>, and are confident that users will have internet access, you
288 may replace the C<use lib 'inc';> line with this block of code:
289  
290 # ExtUtils::AutoInstall Bootstrap Code, version 7.
291 BEGIN{my$p='ExtUtils::AutoInstall';my$v=0.45;$p->VERSION||0>=$v
292 or+eval"use $p $v;1"or+do{my$e=$ENV{PERL_EXTUTILS_AUTOINSTALL};
293 (!defined($e)||$e!~m/--(?:default|skip|testonly)/and-t STDIN or
294 eval"use ExtUtils::MakeMaker;WriteMakefile(PREREQ_PM=>{'$p',$v}
295 );1"and exit)and print"==> $p $v required. Install it from CP".
296 "AN? [Y/n] "and<STDIN>!~/^n/i and print"*** Installing $p\n"and
297 do{if (eval '$>' and lc(`sudo -V`) =~ /version/){system('sudo',
298 $^X,"-MCPANPLUS","-e","CPANPLUS::install $p");eval"use $p $v;1"
299 ||system('sudo', $^X, "-MCPAN", "-e", "CPAN::install $p")}eval{
300 require CPANPLUS;CPANPLUS::install$p};eval"use $p $v;1"or eval{
301 require CPAN;CPAN::install$p};eval"use $p $v;1"||die"*** Please
302 manually install $p $v from cpan.org first...\n"}}}
303  
304 If the user did not have L<ExtUtils::AutoInstall> installed, the
305 block of code above will automatically download and install it.
306  
307 However, due to its space-compressed (and obfuscated) nature, you
308 should think twice before employing this block of code; it is usually
309 much more desirable to just use L<Module::Install> instead.
310  
311 =cut
312  
313 # special map on pre-defined feature sets
314 my %FeatureMap = (
315 '' => 'Core Features', # XXX: deprecated
316 '-core' => 'Core Features',
317 );
318  
319 # various lexical flags
320 my (@Missing, @Existing, %DisabledTests, $UnderCPAN, $HasCPANPLUS);
321 my ($Config, $CheckOnly, $SkipInstall, $AcceptDefault, $TestOnly);
322 my ($PostambleActions, $PostambleUsed);
323  
324 _accept_default(!-t STDIN); # see if it's a non-interactive session
325 _init();
326  
327 sub _accept_default {
328 1 ▶ $AcceptDefault = shift;
Subroutine _accept_default: called CC=1 SCAR=0.0
329 }
330  
331 sub missing_modules {
332 0 ▶ return @Missing;
Subroutine missing_modules: not called CC=1 SCAR=6.9
Pod undocumented
333 }
334  
335 sub do_install {
336 __PACKAGE__->install(
337 0 ▶ [ UNIVERSAL::isa($Config, 'HASH') ? %{$Config} : @{$Config}],
Subroutine do_install: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($Config, 'HASH') ? : 0 0 0
338 @Missing,
339 );
340 }
341  
342 # initialize various flags, and/or perform install
343 sub _init {
344 1 ▶ foreach my $arg (@ARGV, split(/[\s\t]+/, $ENV{PERL_EXTUTILS_AUTOINSTALL} || '')) {
Subroutine _init: called CC=9 SCAR=33.1
Condition50%1/2
$ENV{'PERL_EXTUTILS_AUTOINSTALL'} || ''
l!l
01
MC/DC0%0/1
$ENV{'PERL_EXTUTILS_AUTOINSTALL'} || ''
$ENV{'PERL_EXTUTILS_AUTOINSTALL'}
Truth table50%1/2
A
A= $ENV{'PERL_EXTUTILS_AUTOINSTALL'}
Aresult
11
00
345 2 ▶ if ($arg =~ /^--config=(.*)$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($arg =~ /^--config=(.*)$/) { } 1 1 2
elsif ($arg =~ /^--installdeps=(.*)$/) { } 1 0 1
elsif ($arg =~ /^--default(?:deps)?$/) { } 0 0 0
elsif ($arg =~ /^--check(?:deps)?$/) { } 0 0 0
elsif ($arg =~ /^--skip(?:deps)?$/) { } 0 0 0
elsif ($arg =~ /^--test(?:only)?$/) { } 0 0 0
346 1 $Config = [ split(',', $1) ];
347 }
348 elsif ($arg =~ /^--installdeps=(.*)$/) {
349 1 __PACKAGE__->install($Config, @Missing = split(/,/, $1));
350 1 exit 0;
351 }
352 elsif ($arg =~ /^--default(?:deps)?$/) {
353 0 $AcceptDefault = 1;
354 }
355 elsif ($arg =~ /^--check(?:deps)?$/) {
356 0 $CheckOnly = 1;
357 }
358 elsif ($arg =~ /^--skip(?:deps)?$/) {
359 0 $SkipInstall = 1;
360 }
361 elsif ($arg =~ /^--test(?:only)?$/) {
362 0 $TestOnly = 1;
363 }
364 }
365 }
366  
367 # overrides MakeMaker's prompt() to automatically accept the default choice
368 sub _prompt {
369 0 ▶ goto &ExtUtils::MakeMaker::prompt unless $AcceptDefault;
Subroutine _prompt: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
unless $AcceptDefault 0 0 0
370  
371 0 my ($prompt, $default) = @_;
372 0 my $y = ($default =~ /^[Yy]/);
373  
374 0 ▶ print $prompt, ' [', ($y ? 'Y' : 'y'), '/', ($y ? 'n' : 'N'), '] ';
Branch: 2 branches
BranchTrueFalseTotal
$y ? : 0 0 0
$y ? : 0 0 0
375 0 print "$default\n";
376 0 return $default;
377 }
378  
379 # the workhorse
380 sub import {
381 0 ▶ my $class = shift;
Subroutine import: not called CC=46 SCAR=76.3
382 0 ▶ my @args = @_ or return;
Branch: 1 branch
BranchTrueFalseTotal
my(@args) = or return 0 0 0
383 0 my $core_all;
384  
385 0 print "*** $class version ".$class->VERSION."\n";
386 0 print "*** Checking for dependencies...\n";
387  
388 0 my $cwd = Cwd::cwd();
389  
390 0 $Config = [];
391  
392 0 my $maxlen = length((sort { length($b) <=> length($a) }
393 0 grep { /^[^\-]/ }
394 0 ▶ map { ref($_) ? keys %{ref($_) eq 'HASH' ? $_ : +{@{$_}}} : '' }
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 0 0 0
ref $_ eq 'HASH' ? : 0 0 0
395 0 map { +{@args}->{$_} }
396 0 ▶ grep { /^[^\-]/ or /^-core$/i } keys %{+{@args}})[0]);
Branch: 1 branch
BranchTrueFalseTotal
/^[^\-]/ or /^-core$/i 0 0 0
397  
398 0 ▶ while (my ($feature, $modules) = splice(@args, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@args, 0, 2)) 0 0 0
399 0 my (@required, @tests, @skiptests);
400 0 my $default = 1;
401 0 my $conflict = 0;
402  
403 0 ▶ if ($feature =~ m/^-(\w+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($feature =~ /^-(\w+)$/) 0 0 0
404 0 my $option = lc($1);
405  
406 # check for a newer version of myself
407 0 ▶ _update_to($modules, @_) and return if $option eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if $option eq "version" 0 0 0
Condition0%0/5
$option eq 'version' && (_update_to($modules, @_) && (return))
!ll&&!rl&&r
000
_update_to($modules, @_) and return
!ll
00
MC/DC0%0/2
$option eq 'version' && (_update_to($modules, @_) && (return))
$option eq 'version' _update_to($modules, @_)
Truth table0%0/3
A && B
A= $option eq 'version'B= _update_to($modules, @_)
ABresult
0X0
100
111
408  
409 # sets CPAN configuration options
410 0 ▶ $Config = $modules if $option eq 'config';
Branch: 1 branch
BranchTrueFalseTotal
if $option eq "config" 0 0 0
411  
412 # promote every features to core status
413 0 ▶ $core_all = ($modules =~ /^all$/i) and next
Branch: 1 branch
BranchTrueFalseTotal
if $option eq "core" 0 0 0
Condition0%0/5
$option eq 'core' && (($core_all = $modules =~ /^all$/i) && (next))
!ll&&!rl&&r
000
$core_all = $modules =~ /^all$/i and next
!ll
00
MC/DC0%0/2
$option eq 'core' && (($core_all = $modules =~ /^all$/i) && (next))
$option eq 'core' $core_all = $modules =~ /^all$/i
Truth table0%0/3
A && B
A= $option eq 'core'B= $core_all = $modules =~ /^all$/i
ABresult
0X0
100
111
414 if $option eq 'core';
415  
416 0 ▶ next unless $option eq 'core';
Branch: 1 branch
BranchTrueFalseTotal
unless $option eq "core" 0 0 0
417 }
418  
419 0 ▶ print "[".($FeatureMap{lc($feature)} || $feature)."]\n";
Condition0%0/3
$FeatureMap{lc $feature} || $feature
l!l&&r!l&&!r
000
MC/DC0%0/2
$FeatureMap{lc $feature} || $feature
$FeatureMap{lc $feature} $feature
Truth table0%0/3
A || B
A= $FeatureMap{lc $feature}B= $feature
ABresult
1X1
011
000
420  
421 0 ▶ $modules = [ %{$modules} ] if UNIVERSAL::isa($modules, 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($modules, "HASH") 0 0 0
422  
423 0 ▶ unshift @$modules, -default => &{shift(@$modules)}
Branch: 1 branch
BranchTrueFalseTotal
if ref $modules->[0] eq "CODE" 0 0 0
424 if (ref($modules->[0]) eq 'CODE'); # XXX: bugward combatability
425  
426 0 ▶ while (my ($mod, $arg) = splice(@$modules, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@$modules, 0, 2)) 0 0 0
427 0 ▶ if ($mod =~ m/^-(\w+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod =~ /^-(\w+)$/) 0 0 0
428 0 my $option = lc($1);
429  
430 0 ▶ $default = $arg if ($option eq 'default');
Branch: 1 branch
BranchTrueFalseTotal
if $option eq "default" 0 0 0
431 0 ▶ $conflict = $arg if ($option eq 'conflict');
Branch: 1 branch
BranchTrueFalseTotal
if $option eq "conflict" 0 0 0
432 0 ▶ @tests = @{$arg} if ($option eq 'tests');
Branch: 1 branch
BranchTrueFalseTotal
if $option eq "tests" 0 0 0
433 0 ▶ @skiptests = @{$arg} if ($option eq 'skiptests');
Branch: 1 branch
BranchTrueFalseTotal
if $option eq "skiptests" 0 0 0
434  
435 0 next;
436 }
437  
438 0 printf("- %-${maxlen}s ...", $mod);
439  
440 # XXX: check for conflicts and uninstalls(!) them.
441 0 ▶ if (defined(my $cur = _version_check(_load($mod), $arg ||= 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $cur = _version_check(_load($mod), scalar($arg ||= 0)))) { } 0 0 0
Condition0%0/2
$arg ||= 0
l!l
00
MC/DC0%0/1
$arg ||= 0
$arg
Truth table0%0/2
A
A= $arg
Aresult
11
00
442 0 ▶ print "loaded. ($cur".($arg ? " >= $arg" : '').")\n";
Branch: 1 branch
BranchTrueFalseTotal
$arg ? : 0 0 0
443 0 push @Existing, $mod => $arg;
444 0 $DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
445 }
446 else {
447 0 ▶ print "missing." . ($arg ? " (would need $arg)" : '') . "\n";
Branch: 1 branch
BranchTrueFalseTotal
$arg ? : 0 0 0
448 0 push @required, $mod => $arg;
449 }
450 }
451  
452 0 ▶ next unless @required;
Branch: 1 branch
BranchTrueFalseTotal
unless @required 0 0 0
453  
454 0 ▶ my $mandatory = ($feature eq '-core' or $core_all);
Condition0%0/3
$feature eq '-core' || $core_all
l!l&&r!l&&!r
000
MC/DC0%0/2
$feature eq '-core' || $core_all
$feature eq '-core' $core_all
Truth table0%0/3
A || B
A= $feature eq '-core'B= $core_all
ABresult
1X1
011
000
455  
456 0 ▶ if (!$SkipInstall and ($CheckOnly or _prompt(
Branch: 4 branches
BranchTrueFalseTotal
if (not $SkipInstall and $CheckOnly || _prompt('==> Auto-install the ' . @required / 2 . ($mandatory ? ' mandatory' : ' optional') . ' module(s) from CPAN?', $default ? 'y' : 'n') =~ /^[Yy]/) { } 0 0 0
elsif (not $SkipInstall and $default and $mandatory and _prompt('==> The module(s) are mandatory! Really skip?', 'n') =~ /^[Nn]/) { } 0 0 0
$mandatory ? : 0 0 0
$default ? : 0 0 0
Condition0%0/6
not $SkipInstall and $CheckOnly || _prompt('==> Auto-install the ' . @required / 2 . ($mandatory ? " mandatory" : " optional") . ' module(s) from CPAN?', $default ? "y" : "n") =~ /^[Yy]/
!ll&&!rl&&r
000
$CheckOnly or _prompt('==> Auto-install the ' . @required / 2 . ($mandatory ? " mandatory" : " optional") . ' module(s) from CPAN?', $default ? "y" : "n") =~ /^[Yy]/
l!l&&r!l&&!r
000
MC/DC0%0/3
not $SkipInstall and $CheckOnly || _prompt('==> Auto-install the ' . @required / 2 . ($mandatory ? " mandatory" : " optional") . ' module(s) from CPAN?', $default ? "y" : "n") =~ /^[Yy]/
not $SkipInstall $CheckOnly _prompt('==> Auto-install the ' . @required / 2 . ($mandatory ? " mandatory" : " optional") . ' module(s) from CPAN?', $default ? "y" : "n") =~ /^[Yy]/
Truth table0%0/4
not(A) and B or C
A= not $SkipInstallB= $CheckOnlyC= _prompt('==> Auto-install the ' . @required / 2 . ($mandatory ? " mandatory" : " optional") . ' module(s) from CPAN?', $default ? "y" : "n") =~ /^[Yy]/
ABCresult
0XX0
1000
11X1
1011
457 qq{==> Auto-install the }. (@required / 2).
458 ($mandatory ? ' mandatory' : ' optional').
459 qq{ module(s) from CPAN?}, $default ? 'y' : 'n',
460 ) =~ /^[Yy]/)) {
461 0 push (@Missing, @required);
462 0 $DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
463 }
464  
465 ▶ elsif (!$SkipInstall and $default and $mandatory and _prompt(
Condition0%0/9
not $SkipInstall and $default and $mandatory and _prompt("==> The module(s) are mandatory! Really skip?", "n") =~ /^[Nn]/
!ll&&!rl&&r
000
not $SkipInstall and $default and $mandatory
!ll&&!rl&&r
000
not $SkipInstall and $default
!ll&&!rl&&r
000
MC/DC0%0/4
not $SkipInstall and $default and $mandatory and _prompt("==> The module(s) are mandatory! Really skip?", "n") =~ /^[Nn]/
not $SkipInstall $default $mandatory _prompt("==> The module(s) are mandatory! Really skip?", "n") =~ /^[Nn]/
Truth table0%0/5
not(A) and B and C and D
A= not $SkipInstallB= $defaultC= $mandatoryD= _prompt("==> The module(s) are mandatory! Really skip?", "n") =~ /^[Nn]/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
466 qq{==> The module(s) are mandatory! Really skip?}, 'n',
467 ) =~ /^[Nn]/) {
468 0 push (@Missing, @required);
469 0 $DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
470 }
471  
472 else {
473 0 $DisabledTests{$_} = 1 for map { glob($_) } @tests;
474 }
475 }
476  
477 0 _check_lock(); # check for $UnderCPAN
478  
479 0 ▶ if (@Missing and not ($CheckOnly or $UnderCPAN)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@Missing and not $CheckOnly || $UnderCPAN) 0 0 0
Condition0%0/6
@Missing and not $CheckOnly || $UnderCPAN
!ll&&!rl&&r
000
$CheckOnly || $UnderCPAN
l!l&&r!l&&!r
000
MC/DC0%0/3
@Missing and not $CheckOnly || $UnderCPAN
@Missing $CheckOnly $UnderCPAN
Truth table0%0/4
A and not(B || C)
A= @MissingB= $CheckOnlyC= $UnderCPAN
ABCresult
0XX0
11X0
1010
1001
480 0 require Config;
481 0 print "*** Dependencies will be installed the next time you type '$Config::Config{make}'.\n";
482 # make an educated guess of whether we'll need root permission.
483 0 ▶ print " (You may need to do that as the 'root' user.)\n" if eval '$>';
Branch: 1 branch
BranchTrueFalseTotal
if eval "\$>" 0 0 0
484 }
485 0 print "*** $class configuration finished.\n";
486  
487 0 chdir $cwd;
488  
489 # import to main::
490 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
491 0 ▶ *{'main::WriteMakefile'} = \&Write if caller(0) eq 'main';
Branch: 1 branch
BranchTrueFalseTotal
if caller 0 eq "main" 0 0 0
492 }
493  
494 # CPAN.pm is non-reentrant, so check if we're under it and have no CPANPLUS
495 sub _check_lock {
496 0 ▶ return unless @Missing;
Subroutine _check_lock: not called CC=9 SCAR=45.0
Branch: 1 branch
BranchTrueFalseTotal
unless @Missing 0 0 0
497 0 ▶ return if _has_cpanplus();
Branch: 1 branch
BranchTrueFalseTotal
if _has_cpanplus() 0 0 0
498  
499 0 require CPAN; CPAN::Config->load;
500 0 my $lock = MM->catfile($CPAN::Config->{cpan_home}, ".lock");
501  
502 0 ▶ if (-f $lock and open(LOCK, $lock)
Branch: 2 branches
BranchTrueFalseTotal
if (-f $lock and open LOCK, $lock and $^O eq "MSWin32" ? _under_cpan() : readline LOCK == getppid and ($CPAN::Config->{"prerequisites_policy"} || "") ne "ignore") 0 0 0
$^O eq 'MSWin32' ? : 0 0 0
Condition0%0/11
-f $lock and open LOCK, $lock and $^O eq "MSWin32" ? _under_cpan() : readline LOCK == getppid and ($CPAN::Config->{"prerequisites_policy"} || "") ne "ignore"
!ll&&!rl&&r
000
-f $lock and open LOCK, $lock and $^O eq "MSWin32" ? _under_cpan() : readline LOCK == getppid
!ll&&!rl&&r
000
-f $lock and open LOCK, $lock
!ll&&!rl&&r
000
$CPAN::Config->{'prerequisites_policy'} || ''
l!l
00
MC/DC0%0/4
-f $lock and open LOCK, $lock and $^O eq "MSWin32" ? _under_cpan() : readline LOCK == getppid and ($CPAN::Config->{"prerequisites_policy"} || "") ne "ignore"
-f $lock open LOCK, $lock $^O eq "MSWin32" ? _under_cpan() : readline LOCK == getppid $CPAN::Config->{'prerequisites_policy'}
Truth table0%0/5
A and B and C and D
A= -f $lockB= open LOCK, $lockC= $^O eq "MSWin32" ? _under_cpan() : readline LOCK == getppidD= $CPAN::Config->{'prerequisites_policy'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
503 and ($^O eq 'MSWin32' ? _under_cpan() : <LOCK> == getppid())
504 and ($CPAN::Config->{prerequisites_policy} || '') ne 'ignore'
505 ) {
506 0 print << '.';
507  
508 *** Since we're running under CPAN, I'll just let it take care
509 of the dependency's installation later.
510 .
511 0 $UnderCPAN = 1;
512 }
513  
514 0 close LOCK;
515 }
516  
517 sub install {
518 1 ▶ my $class = shift;
Subroutine install: called CC=17 SCAR=38.0
Pod undocumented
519  
520 1 my $i; # used below to strip leading '-' from config keys
521 1 ▶ my @config = (map { s/^-// if ++$i; $_ } @{+shift});
Branch: 1 branch
BranchTrueFalseTotal
if ++$i 0 0 0
522  
523 1 my (@modules, @installed);
524 1 ▶ while (my ($pkg, $ver) = splice(@_, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 2 1 3
525 # grep out those already installed
526 2 ▶ if (defined(_version_check(_load($pkg), $ver))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined _version_check(_load($pkg), $ver)) { } 1 1 2
527 1 push @installed, $pkg;
528 }
529 else {
530 1 push @modules, $pkg, $ver;
531 }
532 }
533  
534 1 ▶ return @installed unless @modules; # nothing to do
Branch: 1 branch
BranchTrueFalseTotal
unless @modules 0 1 1
535  
536 1 print "*** Installing dependencies...\n";
537  
538 1 ▶ return unless _connected_to('cpan.org');
Branch: 1 branch
BranchTrueFalseTotal
unless _connected_to("cpan.org") 0 1 1
539  
540 1 my %args = @config;
541 1 my %failed;
542 1 local *FAILED;
543 1 ▶ if ($args{do_once} and open(FAILED, '.#autoinstall.failed')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"do_once"} and open FAILED, ".#autoinstall.failed") 0 1 1
Condition33%1/3
$args{"do_once"} and open FAILED, ".#autoinstall.failed"
!ll&&!rl&&r
100
MC/DC0%0/2
$args{"do_once"} and open FAILED, ".#autoinstall.failed"
$args{"do_once"} open FAILED, ".#autoinstall.failed"
Truth table33%1/3
A and B
A= $args{"do_once"}B= open FAILED, ".#autoinstall.failed"
ABresult
0X0
100
111
544 0 ▶ while (<FAILED>) { chomp; $failed{$_}++ }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FAILED)) 0 0 0
545 0 close FAILED;
546  
547 0 my @newmod;
548 0 ▶ while (my ($k, $v) = splice(@modules, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@modules, 0, 2)) 0 0 0
549 0 ▶ push @newmod, ($k => $v) unless $failed{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $failed{$k} 0 0 0
550 }
551 0 @modules = @newmod;
552 }
553  
554 1 ▶ if (_has_cpanplus()) {
Branch: 1 branch
BranchTrueFalseTotal
if (_has_cpanplus()) { } 0 1 1
555 0 _install_cpanplus(\@modules, \@config);
556 }
557 else {
558 1 _install_cpan(\@modules, \@config);
559 }
560  
561 1 print "*** $class installation finished.\n";
562  
563 # see if we have successfully installed them
564 1 ▶ while (my ($pkg, $ver) = splice(@modules, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@modules, 0, 2)) 1 1 2
565 1 ▶ if (defined(_version_check(_load($pkg), $ver))) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined _version_check(_load($pkg), $ver)) { } 0 1 1
elsif ($args{'do_once'} and open FAILED, '>> .#autoinstall.failed') { } 0 2 2
566 0 push @installed, $pkg;
567 }
568 ▶ elsif ($args{do_once} and open(FAILED, '>> .#autoinstall.failed')) {
Condition33%1/3
$args{"do_once"} and open FAILED, ">> .#autoinstall.failed"
!ll&&!rl&&r
100
MC/DC0%0/2
$args{"do_once"} and open FAILED, ">> .#autoinstall.failed"
$args{"do_once"} open FAILED, ">> .#autoinstall.failed"
Truth table33%1/3
A and B
A= $args{"do_once"}B= open FAILED, ">> .#autoinstall.failed"
ABresult
0X0
100
111
569 0 print FAILED "$pkg\n";
570 }
571 }
572  
573 1 ▶ close FAILED if $args{do_once};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"do_once"} 0 1 1
574  
575 1 return @installed;
576 }
577  
578 sub _install_cpanplus {
579 0 ▶ my @modules = @{+shift};
Subroutine _install_cpanplus: not called CC=19 SCAR=59.4
580 0 my @config = @{+shift};
581 0 my $installed = 0;
582  
583 0 require CPANPLUS::Backend;
584 0 my $cp = CPANPLUS::Backend->new;
585 0 my $conf = $cp->configure_object;
586  
587 0 ▶ return unless _can_write(
Branch: 2 branches
BranchTrueFalseTotal
unless _can_write($conf->can("conf") ? $conf->get_conf("base") : $conf->_get_build("base")) 0 0 0
$conf->can('conf') ? : 0 0 0
588 $conf->can('conf')
589 ? $conf->get_conf('base') # 0.05x+
590 : $conf->_get_build('base') # 0.04x
591 );
592  
593 # if we're root, set UNINST=1 to avoid trouble unless user asked for it.
594 0 ▶ my $makeflags = $conf->get_conf('makeflags') || '';
Condition0%0/2
$conf->get_conf('makeflags') || ''
l!l
00
MC/DC0%0/1
$conf->get_conf('makeflags') || ''
$conf->get_conf('makeflags')
Truth table0%0/2
A
A= $conf->get_conf('makeflags')
Aresult
11
00
595 0 ▶ if (UNIVERSAL::isa($makeflags, 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($makeflags, 'HASH')) { } 0 0 0
596 # 0.03+ uses a hashref here
597 0 ▶ $makeflags->{UNINST} = 1 unless exists $makeflags->{UNINST};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $makeflags->{"UNINST"} 0 0 0
598 }
599 else {
600 # 0.02 and below uses a scalar
601 0 ▶ $makeflags = join(' ', split(' ', $makeflags), 'UNINST=1')
Branch: 1 branch
BranchTrueFalseTotal
if not $makeflags =~ /\bUNINST\b/ and eval " $> eq '0' " 0 0 0
Condition0%0/3
not $makeflags =~ /\bUNINST\b/ and eval " $> eq '0' "
!ll&&!rl&&r
000
MC/DC0%0/2
not $makeflags =~ /\bUNINST\b/ and eval " $> eq '0' "
not $makeflags =~ /\bUNINST\b/ eval " $> eq '0' "
Truth table0%0/3
not(A) and B
A= not $makeflags =~ /\bUNINST\b/B= eval " $> eq '0' "
ABresult
0X0
100
111
602 if ($makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' });
603 }
604 0 $conf->set_conf(makeflags => $makeflags);
605 0 $conf->set_conf(prereqs => 1);
606  
607 0 ▶ while (my ($key, $val) = splice(@config, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@config, 0, 2)) 0 0 0
608 0 eval { $conf->set_conf($key, $val) };
609 }
610  
611 0 my $modtree = $cp->module_tree;
612 0 ▶ while (my ($pkg, $ver) = splice(@modules, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@modules, 0, 2)) 0 0 0
613 0 print "*** Installing $pkg...\n";
614  
615 0 ▶ MY::preinstall($pkg, $ver) or next if defined &MY::preinstall;
Branch: 1 branch
BranchTrueFalseTotal
if defined &MY::preinstall 0 0 0
Condition0%0/5
defined &MY::preinstall && (MY::preinstall($pkg, $ver) || (next))
!ll&&!rl&&r
000
MY::preinstall($pkg, $ver) or next
l!l
00
MC/DC0%0/2
defined &MY::preinstall && (MY::preinstall($pkg, $ver) || (next))
defined &MY::preinstall MY::preinstall($pkg, $ver)
Truth table0%0/3
A && B
A= defined &MY::preinstallB= MY::preinstall($pkg, $ver)
ABresult
0X0
100
111
616  
617 0 my $success;
618 0 my $obj = $modtree->{$pkg};
619  
620 0 ▶ if ($obj and defined(_version_check($obj->{version}, $ver))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj and defined _version_check($obj->{'version'}, $ver)) { } 0 0 0
Condition0%0/3
$obj and defined _version_check($obj->{"version"}, $ver)
!ll&&!rl&&r
000
MC/DC0%0/2
$obj and defined _version_check($obj->{"version"}, $ver)
$obj defined _version_check($obj->{"version"}, $ver)
Truth table0%0/3
A and B
A= $objB= defined _version_check($obj->{"version"}, $ver)
ABresult
0X0
100
111
621 0 my $pathname = $pkg; $pathname =~ s/::/\\W/;
622  
623 0 foreach my $inc (grep { m/$pathname.pm/i } keys(%INC)) {
624 0 delete $INC{$inc};
625 }
626  
627 0 my $rv = $cp->install( modules => [ $obj->{module} ]);
628  
629 0 ▶ if ($rv and ($rv->{$obj->{module}} or $rv->{ok})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv and $$rv{$obj->{'module'}} || $rv->{'ok'}) { } 0 0 0
Condition0%0/6
$rv and $$rv{$obj->{"module"}} || $rv->{"ok"}
!ll&&!rl&&r
000
$$rv{$obj->{"module"}} or $rv->{"ok"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$rv and $$rv{$obj->{"module"}} || $rv->{"ok"}
$rv $$rv{$obj->{"module"}} $rv->{"ok"}
Truth table0%0/4
A and B or C
A= $rvB= $$rv{$obj->{"module"}}C= $rv->{"ok"}
ABCresult
0XX0
1000
11X1
1011
630 0 print "*** $pkg successfully installed.\n";
631 0 $success = 1;
632 }
633 else {
634 0 print "*** $pkg installation cancelled.\n";
635 0 $success = 0;
636 }
637  
638 0 $installed += $success;
639 }
640 else {
641 0 print << ".";
642 *** Could not find a version $ver or above for $pkg; skipping.
643 .
644 }
645  
646 0 ▶ MY::postinstall($pkg, $ver, $success) if defined &MY::postinstall;
Branch: 1 branch
BranchTrueFalseTotal
if defined &MY::postinstall 0 0 0
647 }
648  
649 0 return $installed;
650 }
651  
652 sub _install_cpan {
653 1 ▶ my @modules = @{+shift};
Subroutine _install_cpan: called CC=19 SCAR=35.9
654 1 my @config = @{+shift};
655 1 my $installed = 0;
656 1 my %args;
657  
658 1 require CPAN; CPAN::Config->load;
659 1 require Config;
660  
661 return unless _can_write(MM->catfile($CPAN::Config->{cpan_home}, 'sources'))
662 1 ▶ and _can_write($Config::Config{sitelib});
Branch: 1 branch
BranchTrueFalseTotal
unless _can_write("MM"->catfile($CPAN::Config->{"cpan_home"}, "sources")) and _can_write($Config::Config{"sitelib"}) 0 1 1
Condition33%1/3
_can_write("MM"->catfile($CPAN::Config->{"cpan_home"}, "sources")) and _can_write($Config::Config{"sitelib"})
!ll&&!rl&&r
001
MC/DC0%0/2
_can_write("MM"->catfile($CPAN::Config->{"cpan_home"}, "sources")) and _can_write($Config::Config{"sitelib"})
_can_write("MM"->catfile($CPAN::Config->{"cpan_home"}, "sources")) _can_write($Config::Config{"sitelib"})
Truth table33%1/3
A and B
A= _can_write("MM"->catfile($CPAN::Config->{"cpan_home"}, "sources"))B= _can_write($Config::Config{"sitelib"})
ABresult
0X0
100
111
663  
664 # if we're root, set UNINST=1 to avoid trouble unless user asked for it.
665 1 ▶ my $makeflags = $CPAN::Config->{make_install_arg} || '';
Condition50%1/2
$CPAN::Config->{'make_install_arg'} || ''
l!l
01
MC/DC0%0/1
$CPAN::Config->{'make_install_arg'} || ''
$CPAN::Config->{'make_install_arg'}
Truth table50%1/2
A
A= $CPAN::Config->{'make_install_arg'}
Aresult
11
00
666 1 ▶ $CPAN::Config->{make_install_arg} = join(' ', split(' ', $makeflags), 'UNINST=1')
Branch: 1 branch
BranchTrueFalseTotal
if not $makeflags =~ /\bUNINST\b/ and eval " $> eq '0' " 1 0 1
Condition33%1/3
not $makeflags =~ /\bUNINST\b/ and eval " $> eq '0' "
!ll&&!rl&&r
001
MC/DC0%0/2
not $makeflags =~ /\bUNINST\b/ and eval " $> eq '0' "
not $makeflags =~ /\bUNINST\b/ eval " $> eq '0' "
Truth table33%1/3
not(A) and B
A= not $makeflags =~ /\bUNINST\b/B= eval " $> eq '0' "
ABresult
0X0
100
111
667 if ($makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' });
668  
669 # don't show start-up info
670 1 $CPAN::Config->{inhibit_startup_message} = 1;
671  
672 # set additional options
673 1 ▶ while (my ($opt, $arg) = splice(@config, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@config, 0, 2)) 0 1 1
674 0 ▶ ($args{$opt} = $arg, next)
Branch: 1 branch
BranchTrueFalseTotal
if $opt =~ /^force$/ 0 0 0
675 if $opt =~ /^force$/; # pseudo-option
676 0 $CPAN::Config->{$opt} = $arg;
677 }
678  
679 1 local $CPAN::Config->{prerequisites_policy} = 'follow';
680  
681 1 ▶ while (my ($pkg, $ver) = splice(@modules, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@modules, 0, 2)) 1 1 2
682 1 ▶ MY::preinstall($pkg, $ver) or next if defined &MY::preinstall;
Branch: 1 branch
BranchTrueFalseTotal
if defined &MY::preinstall 0 1 1
Condition25%1/4
defined &MY::preinstall && (MY::preinstall($pkg, $ver) || (next))
!ll
10
MY::preinstall($pkg, $ver) or next
l!l
00
MC/DC0%0/2
defined &MY::preinstall && (MY::preinstall($pkg, $ver) || (next))
defined &MY::preinstall MY::preinstall($pkg, $ver)
Truth table33%1/3
A && B
A= defined &MY::preinstallB= MY::preinstall($pkg, $ver)
ABresult
0X0
100
111
683  
684 1 print "*** Installing $pkg...\n";
685  
686 1 my $obj = CPAN::Shell->expand(Module => $pkg);
687 1 my $success = 0;
688  
689 1 ▶ if ($obj and defined(_version_check($obj->cpan_version, $ver))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj and defined _version_check($obj->cpan_version, $ver)) { } 1 0 1
Condition33%1/3
$obj and defined _version_check($obj->cpan_version, $ver)
!ll&&!rl&&r
001
MC/DC0%0/2
$obj and defined _version_check($obj->cpan_version, $ver)
$obj defined _version_check($obj->cpan_version, $ver)
Truth table33%1/3
A and B
A= $objB= defined _version_check($obj->cpan_version, $ver)
ABresult
0X0
100
111
690 1 my $pathname = $pkg; $pathname =~ s/::/\\W/;
691  
692 1 foreach my $inc (grep { m/$pathname.pm/i } keys(%INC)) {
693 0 delete $INC{$inc};
694 }
695  
696 1 ▶ $obj->force('install') if $args{force};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"force"} 0 1 1
697  
698 1 ▶ my $rv = $obj->install || eval {
Condition33%1/3
$obj->install || eval { do { $CPAN::META->instance('CPAN::Distribution', $obj->cpan_file)->{'install'} if $CPAN::META } }
l!l&&r!l&&!r
001
MC/DC0%0/2
$obj->install || eval { do { $CPAN::META->instance('CPAN::Distribution', $obj->cpan_file)->{'install'} if $CPAN::META } }
$obj->install eval { do { $CPAN::META->instance('CPAN::Distribution', $obj->cpan_file)->{'install'} if $CPAN::META } }
Truth table33%1/3
A || B
A= $obj->installB= eval { do { $CPAN::META->instance('CPAN::Distribution', $obj->cpan_file)->{'install'} if $CPAN::META } }
ABresult
1X1
011
000
699 $CPAN::META->instance(
700 'CPAN::Distribution',
701 $obj->cpan_file,
702 1 ▶ )->{install} if $CPAN::META
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::META 1 0 1
703 };
704  
705 1 ▶ if ($rv eq 'YES') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv eq 'YES') { } 0 1 1
706 0 print "*** $pkg successfully installed.\n";
707 0 $success = 1;
708 }
709 else {
710 1 print "*** $pkg installation failed.\n";
711 1 $success = 0;
712 }
713  
714 1 $installed += $success;
715 }
716 else {
717 0 print << ".";
718 *** Could not find a version $ver or above for $pkg; skipping.
719 .
720 }
721  
722 1 ▶ MY::postinstall($pkg, $ver, $success) if defined &MY::postinstall;
Branch: 1 branch
BranchTrueFalseTotal
if defined &MY::postinstall 0 1 1
723 }
724  
725 1 return $installed;
726 }
727  
728 sub _has_cpanplus {
729 return (
730 $HasCPANPLUS = (
731 1 ▶ $INC{'CPANPLUS/Config.pm'} or
Subroutine _has_cpanplus: called CC=2 SCAR=9.2
Condition33%1/3
$INC{'CPANPLUS/Config.pm'} || _load('CPANPLUS::Shell::Default')
l!l&&r!l&&!r
001
MC/DC0%0/2
$INC{'CPANPLUS/Config.pm'} || _load('CPANPLUS::Shell::Default')
$INC{'CPANPLUS/Config.pm'} _load('CPANPLUS::Shell::Default')
Truth table33%1/3
A || B
A= $INC{'CPANPLUS/Config.pm'}B= _load('CPANPLUS::Shell::Default')
ABresult
1X1
011
000
732 _load('CPANPLUS::Shell::Default')
733 )
734 );
735 }
736  
737 # make guesses on whether we're under the CPAN installation directory
738 sub _under_cpan {
739 0 ▶ require Cwd;
Subroutine _under_cpan: not called CC=1 SCAR=6.9
740 0 require File::Spec;
741  
742 0 my $cwd = File::Spec->canonpath(Cwd::cwd());
743 0 my $cpan = File::Spec->canonpath($CPAN::Config->{cpan_home});
744  
745 0 return (index($cwd, $cpan) > -1);
746 }
747  
748 sub _update_to {
749 0 ▶ my $class = __PACKAGE__;
Subroutine _update_to: not called CC=5 SCAR=34.0
750 0 my $ver = shift;
751  
752 0 ▶ return if defined(_version_check(_load($class), $ver)); # no need to upgrade
Branch: 1 branch
BranchTrueFalseTotal
if defined _version_check(_load($class), $ver) 0 0 0
753  
754 0 ▶ if (_prompt(
Branch: 1 branch
BranchTrueFalseTotal
if (_prompt("==> A newer version of $class ($ver) is required. Install?", "y") =~ /^[Nn]/) 0 0 0
755 "==> A newer version of $class ($ver) is required. Install?", 'y'
756 ) =~ /^[Nn]/) {
757 0 die "*** Please install $class $ver manually.\n";
758 }
759  
760 0 print << ".";
761 *** Trying to fetch it from CPAN...
762 .
763  
764 # install ourselves
765 0 ▶ _load($class) and return $class->import(@_)
Branch: 1 branch
BranchTrueFalseTotal
if $class->install([], $class, $ver) 0 0 0
Condition0%0/5
$class->install([], $class, $ver) && (_load($class) && (return $class->import(@_)))
!ll&&!rl&&r
000
_load($class) and return $class->import(@_)
!ll
00
MC/DC0%0/2
$class->install([], $class, $ver) && (_load($class) && (return $class->import(@_)))
$class->install([], $class, $ver) _load($class)
Truth table0%0/3
A && B
A= $class->install([], $class, $ver)B= _load($class)
ABresult
0X0
100
111
766 if $class->install([], $class, $ver);
767  
768 0 print << '.'; exit 1;
769  
770 *** Cannot bootstrap myself. :-( Installation terminated.
771 .
772 }
773  
774 # check if we're connected to some host, using inet_aton
775 sub _connected_to {
776 1 ▶ my $site = shift;
Subroutine _connected_to: called CC=3 SCAR=14.2
777  
778 return (
779 1 ▶ ( _load('Socket') and Socket::inet_aton($site) ) or _prompt(qq(
Condition33%2/6
_load('Socket') && Socket::inet_aton($site) || _prompt("\n*** Your host cannot resolve the domain name '${site}', which\n probably means the Internet connections are unavailable.\n==> Should we try to install the required module(s) anyway?", 'n') =~ /^[Yy]/
l!l&&r!l&&!r
100
_load("Socket") and Socket::inet_aton($site)
!ll&&!rl&&r
001
MC/DC0%0/3
_load('Socket') && Socket::inet_aton($site) || _prompt("\n*** Your host cannot resolve the domain name '${site}', which\n probably means the Internet connections are unavailable.\n==> Should we try to install the required module(s) anyway?", 'n') =~ /^[Yy]/
_load("Socket") Socket::inet_aton($site) _prompt("\n*** Your host cannot resolve the domain name '${site}', which\n probably means the Internet connections are unavailable.\n==> Should we try to install the required module(s) anyway?", 'n') =~ /^[Yy]/
Truth table20%1/5
A and B || C
A= _load("Socket")B= Socket::inet_aton($site)C= _prompt("\n*** Your host cannot resolve the domain name '${site}', which\n probably means the Internet connections are unavailable.\n==> Should we try to install the required module(s) anyway?", 'n') =~ /^[Yy]/
ABCresult
11X1
0X11
1011
0X00
1000
780 *** Your host cannot resolve the domain name '$site', which
781 probably means the Internet connections are unavailable.
782 ==> Should we try to install the required module(s) anyway?), 'n'
783 ) =~ /^[Yy]/
784 );
785 }
786  
787 # check if a directory is writable; may create it on demand
788 sub _can_write {
789 2 ▶ my $path = shift;
Subroutine _can_write: called CC=9 SCAR=40.4
790 2 ▶ mkdir ($path, 0755) unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 0 2 2
791  
792 2 ▶ return 1 if -w $path;
Branch: 1 branch
BranchTrueFalseTotal
if -w $path 2 0 2
793  
794 0 print << ".";
795 *** You are not allowed to write to the directory '$path';
796 the installation may fail due to insufficient permissions.
797 .
798  
799 0 ▶ if (eval '$>' and lc(`sudo -V`) =~ /version/ and _prompt(qq(
Branch: 1 branch
BranchTrueFalseTotal
if (eval "\$>" and lc(`sudo -V`) =~ /version/ and _prompt("\n==> Should we try to re-execute the autoinstall process with 'sudo'?", "y") =~ /^[Yy]/) 0 0 0
Condition0%0/6
eval "\$>" and lc(`sudo -V`) =~ /version/ and _prompt("\n==> Should we try to re-execute the autoinstall process with 'sudo'?", "y") =~ /^[Yy]/
!ll&&!rl&&r
000
eval "\$>" and lc(`sudo -V`) =~ /version/
!ll&&!rl&&r
000
MC/DC0%0/3
eval "\$>" and lc(`sudo -V`) =~ /version/ and _prompt("\n==> Should we try to re-execute the autoinstall process with 'sudo'?", "y") =~ /^[Yy]/
eval "\$>" lc(`sudo -V`) =~ /version/ _prompt("\n==> Should we try to re-execute the autoinstall process with 'sudo'?", "y") =~ /^[Yy]/
Truth table0%0/4
A and B and C
A= eval "\$>"B= lc(`sudo -V`) =~ /version/C= _prompt("\n==> Should we try to re-execute the autoinstall process with 'sudo'?", "y") =~ /^[Yy]/
ABCresult
0XX0
10X0
1100
1111
800 ==> Should we try to re-execute the autoinstall process with 'sudo'?), 'y'
801 ) =~ /^[Yy]/) {
802 # try to bootstrap ourselves from sudo
803 0 print << ".";
804 *** Trying to re-execute the autoinstall process with 'sudo'...
805 .
806 0 my $missing = join(',', @Missing);
807 my $config = join(',',
808 0 ▶ UNIVERSAL::isa($Config, 'HASH') ? %{$Config} : @{$Config}
Branch: 2 branches
BranchTrueFalseTotal
if $Config 0 0 0
UNIVERSAL::isa($Config, 'HASH') ? : 0 0 0
809 ) if $Config;
810  
811 0 ▶ return unless system('sudo', $^X, $0, "--config=$config", "--installdeps=$missing");
Branch: 1 branch
BranchTrueFalseTotal
unless system "sudo", $^X, $0, "--config=$config", "--installdeps=$missing" 0 0 0
812  
813 0 print << ".";
814 *** The 'sudo' command exited with error! Resuming...
815 .
816 }
817  
818 0 return _prompt(qq(
819 ==> Should we try to install the required module(s) anyway?), 'n'
820 ) =~ /^[Yy]/
821 }
822  
823 # load a module and return the version it reports
824 sub _load {
825 5 ▶ my $mod = pop; # class/instance doesn't matter
Subroutine _load: called CC=3 SCAR=11.1
826 5 my $file = $mod;
827  
828 5 $file =~ s|::|/|g;
829 5 $file .= '.pm';
830  
831 5 local $@;
832 5 ▶ return eval { require $file; $mod->VERSION } || ($@ ? undef : 0);
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 3 0 3
Condition66%2/3
eval { do { require $file; $mod->VERSION } } || ($@ ? undef : 0)
l!l&&r!l&&!r
203
MC/DC50%1/2
eval { do { require $file; $mod->VERSION } } || ($@ ? undef : 0)
eval { do { require $file; $mod->VERSION } } ($@ ? undef : 0)
Truth table66%2/3
A || B
A= eval { do { require $file; $mod->VERSION } }B= ($@ ? undef : 0)
ABresult
1X1
011
000
833 }
834  
835 # compare two versions, either use Sort::Versions or plain comparison
836 sub _version_check {
837 4 ▶ my ($cur, $min) = @_;
Subroutine _version_check: called CC=13 SCAR=41.4
838 4 ▶ return unless defined $cur;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cur 2 2 4
839  
840 2 $cur =~ s/\s+$//;
841  
842 # check for version numbers that are not in decimal format
843 2 ▶ if (ref($cur) or ref($min) or $cur =~ /v|\..*\./ or $min =~ /v|\..*\./) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cur or ref $min or $cur =~ /v|\..*\./ or $min =~ /v|\..*\./) 0 2 2
Condition33%3/9
ref $cur or ref $min or $cur =~ /v|\..*\./ or $min =~ /v|\..*\./
l!l&&r!l&&!r
002
ref $cur or ref $min or $cur =~ /v|\..*\./
l!l&&r!l&&!r
002
ref $cur or ref $min
l!l&&r!l&&!r
002
MC/DC0%0/4
ref $cur or ref $min or $cur =~ /v|\..*\./ or $min =~ /v|\..*\./
ref $cur ref $min $cur =~ /v|\..*\./ $min =~ /v|\..*\./
Truth table20%1/5
A or B or C or D
A= ref $curB= ref $minC= $cur =~ /v|\..*\./D= $min =~ /v|\..*\./
ABCDresult
1XXX1
01XX1
001X1
00011
00000
844 0 ▶ if ($version::VERSION or defined(_load('version'))) {
Branch: 2 branches
BranchTrueFalseTotal
if ($version::VERSION or defined _load('version')) { } 0 0 0
elsif ($Sort::Versions::VERSION or defined _load('Sort::Versions')) { } 0 0 0
Condition0%0/3
$version::VERSION or defined _load("version")
l!l&&r!l&&!r
000
MC/DC0%0/2
$version::VERSION or defined _load("version")
$version::VERSION defined _load("version")
Truth table0%0/3
A or B
A= $version::VERSIONB= defined _load("version")
ABresult
1X1
011
000
845 # use version.pm if it is installed.
846 0 ▶ return ((version->new($cur) >= version->new($min)) ? $cur : undef);
Branch: 1 branch
BranchTrueFalseTotal
'version'->new($cur) >= 'version'->new($min) ? : 0 0 0
847 }
848 ▶ elsif ($Sort::Versions::VERSION or defined(_load('Sort::Versions'))) {
Condition0%0/3
$Sort::Versions::VERSION or defined _load("Sort::Versions")
l!l&&r!l&&!r
000
MC/DC0%0/2
$Sort::Versions::VERSION or defined _load("Sort::Versions")
$Sort::Versions::VERSION defined _load("Sort::Versions")
Truth table0%0/3
A or B
A= $Sort::Versions::VERSIONB= defined _load("Sort::Versions")
ABresult
1X1
011
000
849 # use Sort::Versions as the sorting algorithm for a.b.c versions
850 0 ▶ return ((Sort::Versions::versioncmp($cur, $min) != -1) ? $cur : undef);
Branch: 1 branch
BranchTrueFalseTotal
Sort::Versions::versioncmp($cur, $min) != -1 ? : 0 0 0
851 }
852  
853 0 warn "Cannot reliably compare non-decimal formatted versions.\n".
854 "Please install version.pm or Sort::Versions.\n";
855 }
856  
857 # plain comparison
858 2 local $^W = 0; # shuts off 'not numeric' bugs
859 2 ▶ return ($cur >= $min ? $cur : undef);
Branch: 1 branch
BranchTrueFalseTotal
$cur >= $min ? : 2 0 2
860 }
861  
862 # nothing; this usage is deprecated.
863 0 ▶sub main::PREREQ_PM { return {}; }
Subroutine PREREQ_PM: not called CC=1 SCAR=6.9
864  
865 sub _make_args {
866 0 ▶ my %args = @_;
Subroutine _make_args: not called CC=9 SCAR=45.0
867  
868 0 ▶ $args{PREREQ_PM} = { %{$args{PREREQ_PM} || {} }, @Existing, @Missing }
Branch: 2 branches
BranchTrueFalseTotal
if $UnderCPAN or $TestOnly 0 0 0
$args{"PREREQ_PM"} or {} 0 0 0
Condition0%0/3
$UnderCPAN or $TestOnly
l!l&&r!l&&!r
000
MC/DC0%0/2
$UnderCPAN or $TestOnly
$UnderCPAN $TestOnly
Truth table0%0/3
A or B
A= $UnderCPANB= $TestOnly
ABresult
1X1
011
000
869 if $UnderCPAN or $TestOnly;
870  
871 0 ▶ if ($args{EXE_FILES}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"EXE_FILES"}) 0 0 0
872 0 require ExtUtils::Manifest;
873 0 my $manifest = ExtUtils::Manifest::maniread('MANIFEST');
874  
875 $args{EXE_FILES} = [
876 0 grep { exists $manifest->{$_} } @{$args{EXE_FILES}}
877 ];
878 }
879  
880 0 ▶ $args{test}{TESTS} ||= 't/*.t';
Condition0%0/2
$args{"test"}{"TESTS"} ||= "t/*.t"
l!l
00
MC/DC0%0/1
$args{"test"}{"TESTS"} ||= "t/*.t"
$args{"test"}{"TESTS"}
Truth table0%0/2
A
A= $args{"test"}{"TESTS"}
Aresult
11
00
881 $args{test}{TESTS} = join(' ', grep {
882 0 !exists($DisabledTests{$_})
883 0 } map { glob($_) } split(/\s+/, $args{test}{TESTS}));
884  
885 0 my $missing = join(',', @Missing);
886 my $config = join(',',
887 0 ▶ UNIVERSAL::isa($Config, 'HASH') ? %{$Config} : @{$Config}
Branch: 2 branches
BranchTrueFalseTotal
if $Config 0 0 0
UNIVERSAL::isa($Config, 'HASH') ? : 0 0 0
888 ) if $Config;
889  
890 0 ▶ $PostambleActions = (
Branch: 1 branch
BranchTrueFalseTotal
$missing ? : 0 0 0
891 $missing ? "\$(PERL) $0 --config=$config --installdeps=$missing"
892 : "\@\$(NOOP)"
893 );
894  
895 0 return %args;
896 }
897  
898 # a wrapper to ExtUtils::MakeMaker::WriteMakefile
899 sub Write {
900 0 ▶ require Carp;
Subroutine Write: not called CC=5 SCAR=30.5
Pod undocumented
901 0 ▶ Carp::croak "WriteMakefile: Need even number of args" if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
902  
903 0 ▶ if ($CheckOnly) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CheckOnly) 0 0 0
904 0 print << ".";
905 *** Makefile not written in check-only mode.
906 .
907 0 return;
908 }
909  
910 0 my %args = _make_args(@_);
911  
912 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
913  
914 0 $PostambleUsed = 0;
915 0 ▶ local *MY::postamble = \&postamble unless defined &MY::postamble;
Branch: 1 branch
BranchTrueFalseTotal
unless defined &MY::postamble 0 0 0
916 0 ExtUtils::MakeMaker::WriteMakefile(%args);
917  
918 0 ▶ print << "." unless $PostambleUsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $PostambleUsed 0 0 0
919 *** WARNING: Makefile written with customized MY::postamble() without
920 including contents from ExtUtils::AutoInstall::postamble() --
921 auto installation features disabled. Please contact the author.
922 .
923  
924 0 return 1;
925 }
926  
927 sub postamble {
928 0 ▶ $PostambleUsed = 1;
Subroutine postamble: not called CC=1 SCAR=6.9
Pod documented
929  
930 0 return << ".";
931  
932 config :: installdeps
933 \t\@\$(NOOP)
934  
935 checkdeps ::
936 \t\$(PERL) $0 --checkdeps
937  
938 installdeps ::
939 \t$PostambleActions
940  
941 .
942  
943 }
944  
945 1;
946  
947 __END__
↑ Summary blib/lib/OpenThought.pm »