23
19
my ($Config, $CheckOnly, $SkipInstall, $AcceptDefault, $TestOnly);
24
20
my ($PostambleActions, $PostambleUsed);
26
$AcceptDefault = 1 unless -t STDIN; # non-interactive session
22
_accept_default(!-t STDIN); # see if it's a non-interactive session
26
$AcceptDefault = shift;
29
29
sub missing_modules {
34
34
__PACKAGE__->install(
35
[ UNIVERSAL::isa($Config, 'HASH') ? %{$Config} : @{$Config}],
35
[ UNIVERSAL::isa($Config, 'HASH') ? %{$Config} : @{$Config}],
40
40
# initialize various flags, and/or perform install
42
42
foreach my $arg (@ARGV, split(/[\s\t]+/, $ENV{PERL_EXTUTILS_AUTOINSTALL} || '')) {
43
if ($arg =~ /^--config=(.*)$/) {
44
$Config = [ split(',', $1) ];
46
elsif ($arg =~ /^--installdeps=(.*)$/) {
47
__PACKAGE__->install($Config, @Missing = split(/,/, $1));
50
elsif ($arg =~ /^--default(?:deps)?$/) {
53
elsif ($arg =~ /^--check(?:deps)?$/) {
56
elsif ($arg =~ /^--skip(?:deps)?$/) {
59
elsif ($arg =~ /^--test(?:only)?$/) {
43
if ($arg =~ /^--config=(.*)$/) {
44
$Config = [ split(',', $1) ];
46
elsif ($arg =~ /^--installdeps=(.*)$/) {
47
__PACKAGE__->install($Config, @Missing = split(/,/, $1));
50
elsif ($arg =~ /^--default(?:deps)?$/) {
53
elsif ($arg =~ /^--check(?:deps)?$/) {
56
elsif ($arg =~ /^--skip(?:deps)?$/) {
59
elsif ($arg =~ /^--test(?:only)?$/) {
90
90
my $maxlen = length((sort { length($b) <=> length($a) }
92
92
map { ref($_) ? keys %{ref($_) eq 'HASH' ? $_ : +{@{$_}}} : '' }
93
map { +{@args}->{$_} }
94
grep { /^[^\-]/ or /^-core$/i } keys %{+{@args}})[0]);
93
map { +{@args}->{$_} }
94
grep { /^[^\-]/ or /^-core$/i } keys %{+{@args}})[0]);
96
96
while (my ($feature, $modules) = splice(@args, 0, 2)) {
97
my (@required, @tests, @skiptests);
101
if ($feature =~ m/^-(\w+)$/) {
104
# check for a newer version of myself
105
_update_to($modules, @_) and return if $option eq 'version';
107
# sets CPAN configuration options
108
$Config = $modules if $option eq 'config';
110
# promote every features to core status
111
$core_all = ($modules =~ /^all$/i) and next
112
if $option eq 'core';
114
next unless $option eq 'core';
117
print "[".($FeatureMap{lc($feature)} || $feature)."]\n";
119
$modules = [ %{$modules} ] if UNIVERSAL::isa($modules, 'HASH');
121
unshift @$modules, -default => &{shift(@$modules)}
122
if (ref($modules->[0]) eq 'CODE'); # XXX: bugward combatability
124
while (my ($mod, $arg) = splice(@$modules, 0, 2)) {
125
if ($mod =~ m/^-(\w+)$/) {
128
$default = $arg if ($option eq 'default');
129
$conflict = $arg if ($option eq 'conflict');
130
@tests = @{$arg} if ($option eq 'tests');
131
@skiptests = @{$arg} if ($option eq 'skiptests');
136
printf("- %-${maxlen}s ...", $mod);
138
# XXX: check for conflicts and uninstalls(!) them.
139
if (defined(my $cur = _version_check(_load($mod), $arg ||= 0))) {
140
print "loaded. ($cur".($arg ? " >= $arg" : '').")\n";
141
push @Existing, $mod => $arg;
142
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
145
print "failed! (need".($arg ? "s $arg" : 'ed').")\n";
146
push @required, $mod => $arg;
150
next unless @required;
152
my $mandatory = (($feature eq '-core' or $core_all) and $default);
154
if (!$SkipInstall and ($CheckOnly or _prompt(
155
qq{==> Do you wish to install the }. (@required / 2).
156
($mandatory ? ' mandatory' : ' optional').
157
qq{ module(s)?}, $default ? 'y' : 'n',
159
push (@Missing, @required);
160
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
163
elsif (!$SkipInstall and $mandatory and _prompt(
164
qq{==> The module(s) are mandatory! Really skip?}, 'n',
166
push (@Missing, @required);
167
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
171
$DisabledTests{$_} = 1 for map { glob($_) } @tests;
97
my (@required, @tests, @skiptests);
101
if ($feature =~ m/^-(\w+)$/) {
104
# check for a newer version of myself
105
_update_to($modules, @_) and return if $option eq 'version';
107
# sets CPAN configuration options
108
$Config = $modules if $option eq 'config';
110
# promote every features to core status
111
$core_all = ($modules =~ /^all$/i) and next
112
if $option eq 'core';
114
next unless $option eq 'core';
117
print "[".($FeatureMap{lc($feature)} || $feature)."]\n";
119
$modules = [ %{$modules} ] if UNIVERSAL::isa($modules, 'HASH');
121
unshift @$modules, -default => &{shift(@$modules)}
122
if (ref($modules->[0]) eq 'CODE'); # XXX: bugward combatability
124
while (my ($mod, $arg) = splice(@$modules, 0, 2)) {
125
if ($mod =~ m/^-(\w+)$/) {
128
$default = $arg if ($option eq 'default');
129
$conflict = $arg if ($option eq 'conflict');
130
@tests = @{$arg} if ($option eq 'tests');
131
@skiptests = @{$arg} if ($option eq 'skiptests');
136
printf("- %-${maxlen}s ...", $mod);
138
# XXX: check for conflicts and uninstalls(!) them.
139
if (defined(my $cur = _version_check(_load($mod), $arg ||= 0))) {
140
print "loaded. ($cur".($arg ? " >= $arg" : '').")\n";
141
push @Existing, $mod => $arg;
142
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
145
print "missing." . ($arg ? " (would need $arg)" : '') . "\n";
146
push @required, $mod => $arg;
150
next unless @required;
152
my $mandatory = ($feature eq '-core' or $core_all);
154
if (!$SkipInstall and ($CheckOnly or _prompt(
155
qq{==> Auto-install the }. (@required / 2).
156
($mandatory ? ' mandatory' : ' optional').
157
qq{ module(s) from CPAN?}, $default ? 'y' : 'n',
159
push (@Missing, @required);
160
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
163
elsif (!$SkipInstall and $default and $mandatory and _prompt(
164
qq{==> The module(s) are mandatory! Really skip?}, 'n',
166
push (@Missing, @required);
167
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
171
$DisabledTests{$_} = 1 for map { glob($_) } @tests;
175
175
_check_lock(); # check for $UnderCPAN
177
177
if (@Missing and not ($CheckOnly or $UnderCPAN)) {
179
print "*** Dependencies will be installed the next time you type '$Config::Config{make}'.\n";
180
# make an educated guess of whether we'll need root permission.
181
print " (You may need to do that as the 'root' user.)\n" if eval '$>';
179
print "*** Dependencies will be installed the next time you type '$Config::Config{make}'.\n";
180
# make an educated guess of whether we'll need root permission.
181
print " (You may need to do that as the 'root' user.)\n" if eval '$>';
183
183
print "*** $class configuration finished.\n";
238
238
my %args = @config;
241
if ($args{do_once} and open(FAILED, '.autoinstall.failed')) {
242
while (<FAILED>) { chomp; $failed{$_}++ }
241
if ($args{do_once} and open(FAILED, '.#autoinstall.failed')) {
242
while (<FAILED>) { chomp; $failed{$_}++ }
246
while (my ($k, $v) = splice(@modules, 0, 2)) {
247
push @newmod, ($k => $v) unless $failed{$k};
246
while (my ($k, $v) = splice(@modules, 0, 2)) {
247
push @newmod, ($k => $v) unless $failed{$k};
252
252
if (_has_cpanplus()) {
253
_install_cpanplus(\@modules, \@config);
253
_install_cpanplus(\@modules, \@config);
256
_install_cpan(\@modules, \@config);
256
_install_cpan(\@modules, \@config);
259
259
print "*** $class installation finished.\n";
261
261
# see if we have successfully installed them
262
262
while (my ($pkg, $ver) = splice(@modules, 0, 2)) {
263
if (defined(_version_check(_load($pkg), $ver))) {
264
push @installed, $pkg;
266
elsif ($args{do_once} and open(FAILED, '>> .autoinstall.failed')) {
267
print FAILED "$pkg\n";
263
if (defined(_version_check(_load($pkg), $ver))) {
264
push @installed, $pkg;
266
elsif ($args{do_once} and open(FAILED, '>> .#autoinstall.failed')) {
267
print FAILED "$pkg\n";
271
271
close FAILED if $args{do_once};
282
282
my $cp = CPANPLUS::Backend->new;
283
283
my $conf = $cp->configure_object;
285
return unless _can_write($conf->_get_build('base'));
285
return unless _can_write(
287
? $conf->get_conf('base') # 0.05x+
288
: $conf->_get_build('base') # 0.04x
287
291
# if we're root, set UNINST=1 to avoid trouble unless user asked for it.
288
292
my $makeflags = $conf->get_conf('makeflags') || '';
289
293
if (UNIVERSAL::isa($makeflags, 'HASH')) {
290
# 0.03+ uses a hashref here
291
$makeflags->{UNINST} = 1 unless exists $makeflags->{UNINST};
294
# 0.03+ uses a hashref here
295
$makeflags->{UNINST} = 1 unless exists $makeflags->{UNINST};
294
# 0.02 and below uses a scalar
295
$makeflags = join(' ', split(' ', $makeflags), 'UNINST=1')
296
if ($makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' });
298
# 0.02 and below uses a scalar
299
$makeflags = join(' ', split(' ', $makeflags), 'UNINST=1')
300
if ($makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' });
298
302
$conf->set_conf(makeflags => $makeflags);
303
$conf->set_conf(prereqs => 1);
300
305
while (my ($key, $val) = splice(@config, 0, 2)) {
301
eval { $conf->set_conf($key, $val) };
306
eval { $conf->set_conf($key, $val) };
304
309
my $modtree = $cp->module_tree;
305
310
while (my ($pkg, $ver) = splice(@modules, 0, 2)) {
306
print "*** Installing $pkg...\n";
308
MY::preinstall($pkg, $ver) or next if defined &MY::preinstall;
311
my $obj = $modtree->{$pkg};
313
if ($obj and defined(_version_check($obj->{version}, $ver))) {
314
my $pathname = $pkg; $pathname =~ s/::/\\W/;
316
foreach my $inc (grep { m/$pathname.pm/i } keys(%INC)) {
320
my $rv = $cp->install( modules => [ $obj->{module} ]);
322
if ($rv and ($rv->{$obj->{module}} or $rv->{ok})) {
323
print "*** $pkg successfully installed.\n";
327
print "*** $pkg installation cancelled.\n";
331
$installed += $success;
311
print "*** Installing $pkg...\n";
313
MY::preinstall($pkg, $ver) or next if defined &MY::preinstall;
316
my $obj = $modtree->{$pkg};
318
if ($obj and defined(_version_check($obj->{version}, $ver))) {
319
my $pathname = $pkg; $pathname =~ s/::/\\W/;
321
foreach my $inc (grep { m/$pathname.pm/i } keys(%INC)) {
325
my $rv = $cp->install( modules => [ $obj->{module} ]);
327
if ($rv and ($rv->{$obj->{module}} or $rv->{ok})) {
328
print "*** $pkg successfully installed.\n";
332
print "*** $pkg installation cancelled.\n";
336
$installed += $success;
335
340
*** Could not find a version $ver or above for $pkg; skipping.
339
MY::postinstall($pkg, $ver, $success) if defined &MY::postinstall;
344
MY::postinstall($pkg, $ver, $success) if defined &MY::postinstall;
342
347
return $installed;
355
360
# if we're root, set UNINST=1 to avoid trouble unless user asked for it.
356
361
my $makeflags = $CPAN::Config->{make_install_arg} || '';
357
362
$CPAN::Config->{make_install_arg} = join(' ', split(' ', $makeflags), 'UNINST=1')
358
if ($makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' });
363
if ($makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' });
360
365
# don't show start-up info
361
366
$CPAN::Config->{inhibit_startup_message} = 1;
363
368
# set additional options
364
369
while (my ($opt, $arg) = splice(@config, 0, 2)) {
365
($args{$opt} = $arg, next)
366
if $opt =~ /^force$/; # pseudo-option
367
$CPAN::Config->{$opt} = $arg;
370
($args{$opt} = $arg, next)
371
if $opt =~ /^force$/; # pseudo-option
372
$CPAN::Config->{$opt} = $arg;
375
local $CPAN::Config->{prerequisites_policy} = 'follow';
370
377
while (my ($pkg, $ver) = splice(@modules, 0, 2)) {
371
MY::preinstall($pkg, $ver) or next if defined &MY::preinstall;
373
print "*** Installing $pkg...\n";
375
my $obj = CPAN::Shell->expand(Module => $pkg);
378
if ($obj and defined(_version_check($obj->cpan_version, $ver))) {
379
my $pathname = $pkg; $pathname =~ s/::/\\W/;
381
foreach my $inc (grep { m/$pathname.pm/i } keys(%INC)) {
385
$obj->force('install') if $args{force};
387
if ($obj->install eq 'YES') {
388
print "*** $pkg successfully installed.\n";
392
print "*** $pkg installation failed.\n";
396
$installed += $success;
378
MY::preinstall($pkg, $ver) or next if defined &MY::preinstall;
380
print "*** Installing $pkg...\n";
382
my $obj = CPAN::Shell->expand(Module => $pkg);
385
if ($obj and defined(_version_check($obj->cpan_version, $ver))) {
386
my $pathname = $pkg; $pathname =~ s/::/\\W/;
388
foreach my $inc (grep { m/$pathname.pm/i } keys(%INC)) {
392
$obj->force('install') if $args{force};
394
my $rv = $obj->install || eval {
395
$CPAN::META->instance(
396
'CPAN::Distribution',
398
)->{install} if $CPAN::META
402
print "*** $pkg successfully installed.\n";
406
print "*** $pkg installation failed.\n";
410
$installed += $success;
400
414
*** Could not find a version $ver or above for $pkg; skipping.
404
MY::postinstall($pkg, $ver, $success) if defined &MY::postinstall;
418
MY::postinstall($pkg, $ver, $success) if defined &MY::postinstall;
407
421
return $installed;
525
539
# check for version numbers that are not in decimal format
526
540
if (ref($cur) or ref($min) or $cur =~ /v|\..*\./ or $min =~ /v|\..*\./) {
527
if ($version::VERSION or defined(_load('version'))) {
528
# use version.pm if it is installed.
529
return ((version->new($cur) >= version->new($min)) ? $cur : undef);
531
elsif ($Sort::Versions::VERSION or defined(_load('Sort::Versions'))) {
532
# use Sort::Versions as the sorting algorithm for a.b.c versions
533
return ((Sort::Versions::versioncmp($cur, $min) != -1) ? $cur : undef);
541
if ($version::VERSION or defined(_load('version'))) {
542
# use version.pm if it is installed.
543
return ((version->new($cur) >= version->new($min)) ? $cur : undef);
545
elsif ($Sort::Versions::VERSION or defined(_load('Sort::Versions'))) {
546
# use Sort::Versions as the sorting algorithm for a.b.c versions
547
return ((Sort::Versions::versioncmp($cur, $min) != -1) ? $cur : undef);
536
warn "Cannot reliably compare non-decimal formatted versions.\n".
537
"Please install version.pm or Sort::Versions.\n";
550
warn "Cannot reliably compare non-decimal formatted versions.\n".
551
"Please install version.pm or Sort::Versions.\n";
540
554
# plain comparison
551
565
$args{PREREQ_PM} = { %{$args{PREREQ_PM} || {} }, @Existing, @Missing }
552
if $UnderCPAN or $TestOnly;
566
if $UnderCPAN or $TestOnly;
554
568
if ($args{EXE_FILES}) {
555
require ExtUtils::Manifest;
556
my $manifest = ExtUtils::Manifest::maniread('MANIFEST');
569
require ExtUtils::Manifest;
570
my $manifest = ExtUtils::Manifest::maniread('MANIFEST');
559
grep { exists $manifest->{$_} } @{$args{EXE_FILES}}
573
grep { exists $manifest->{$_} } @{$args{EXE_FILES}}
563
577
$args{test}{TESTS} ||= 't/*.t';
564
578
$args{test}{TESTS} = join(' ', grep {
565
!exists($DisabledTests{$_})
579
!exists($DisabledTests{$_})
566
580
} map { glob($_) } split(/\s+/, $args{test}{TESTS}));
568
582
my $missing = join(',', @Missing);
569
583
my $config = join(',',
570
UNIVERSAL::isa($Config, 'HASH') ? %{$Config} : @{$Config}
584
UNIVERSAL::isa($Config, 'HASH') ? %{$Config} : @{$Config}
573
587
$PostambleActions = (
574
$missing ? "\$(PERL) $0 --config=$config --installdeps=$missing"
588
$missing ? "\$(PERL) $0 --config=$config --installdeps=$missing"