Skip to content

Commit

Permalink
update M::I
Browse files Browse the repository at this point in the history
  • Loading branch information
ruz committed Feb 7, 2013
1 parent bb3fee1 commit 937bf2a
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 139 deletions.
150 changes: 130 additions & 20 deletions inc/Module/AutoInstall.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package Module::AutoInstall;


use strict; use strict;
use Cwd (); use Cwd ();
use File::Spec ();
use ExtUtils::MakeMaker (); use ExtUtils::MakeMaker ();


use vars qw{$VERSION}; use vars qw{$VERSION};
BEGIN { BEGIN {
$VERSION = '1.03'; $VERSION = '1.06';
} }


# special map on pre-defined feature sets # special map on pre-defined feature sets
Expand All @@ -17,11 +18,14 @@ my %FeatureMap = (
); );


# various lexical flags # various lexical flags
my ( @Missing, @Existing, %DisabledTests, $UnderCPAN, $HasCPANPLUS ); my ( @Missing, @Existing, %DisabledTests, $UnderCPAN, $InstallDepsTarget, $HasCPANPLUS );
my ( my (
$Config, $CheckOnly, $SkipInstall, $AcceptDefault, $TestOnly, $AllDeps $Config, $CheckOnly, $SkipInstall, $AcceptDefault, $TestOnly, $AllDeps,
$UpgradeDeps
); );
my ( $PostambleActions, $PostambleUsed ); my ( $PostambleActions, $PostambleActionsNoTest, $PostambleActionsUpgradeDeps,
$PostambleActionsUpgradeDepsNoTest, $PostambleActionsListDeps,
$PostambleActionsListAllDeps, $PostambleUsed, $NoTest);


# See if it's a testing or non-interactive session # See if it's a testing or non-interactive session
_accept_default( $ENV{AUTOMATED_TESTING} or ! -t STDIN ); _accept_default( $ENV{AUTOMATED_TESTING} or ! -t STDIN );
Expand All @@ -31,6 +35,10 @@ sub _accept_default {
$AcceptDefault = shift; $AcceptDefault = shift;
} }


sub _installdeps_target {
$InstallDepsTarget = shift;
}

sub missing_modules { sub missing_modules {
return @Missing; return @Missing;
} }
Expand Down Expand Up @@ -63,6 +71,11 @@ sub _init {
__PACKAGE__->install( $Config, @Missing = split( /,/, $1 ) ); __PACKAGE__->install( $Config, @Missing = split( /,/, $1 ) );
exit 0; exit 0;
} }
elsif ( $arg =~ /^--upgradedeps=(.*)$/ ) {
$UpgradeDeps = 1;
__PACKAGE__->install( $Config, @Missing = split( /,/, $1 ) );
exit 0;
}
elsif ( $arg =~ /^--default(?:deps)?$/ ) { elsif ( $arg =~ /^--default(?:deps)?$/ ) {
$AcceptDefault = 1; $AcceptDefault = 1;
} }
Expand Down Expand Up @@ -125,7 +138,7 @@ sub import {
# check entirely since we don't want to have to load (and configure) # check entirely since we don't want to have to load (and configure)
# an old CPAN just for a cosmetic message # an old CPAN just for a cosmetic message


$UnderCPAN = _check_lock(1) unless $SkipInstall; $UnderCPAN = _check_lock(1) unless $SkipInstall || $InstallDepsTarget;


while ( my ( $feature, $modules ) = splice( @args, 0, 2 ) ) { while ( my ( $feature, $modules ) = splice( @args, 0, 2 ) ) {
my ( @required, @tests, @skiptests ); my ( @required, @tests, @skiptests );
Expand Down Expand Up @@ -175,7 +188,7 @@ sub import {
} }


# XXX: check for conflicts and uninstalls(!) them. # XXX: check for conflicts and uninstalls(!) them.
my $cur = _load($mod); my $cur = _version_of($mod);
if (_version_cmp ($cur, $arg) >= 0) if (_version_cmp ($cur, $arg) >= 0)
{ {
print "loaded. ($cur" . ( $arg ? " >= $arg" : '' ) . ")\n"; print "loaded. ($cur" . ( $arg ? " >= $arg" : '' ) . ")\n";
Expand Down Expand Up @@ -207,6 +220,7 @@ sub import {
$CheckOnly $CheckOnly
or ($mandatory and $UnderCPAN) or ($mandatory and $UnderCPAN)
or $AllDeps or $AllDeps
or $InstallDepsTarget
or _prompt( or _prompt(
qq{==> Auto-install the } qq{==> Auto-install the }
. ( @required / 2 ) . ( @required / 2 )
Expand Down Expand Up @@ -237,10 +251,17 @@ sub import {
} }
} }


if ( @Missing and not( $CheckOnly or $UnderCPAN ) ) { if ( @Missing and not( $CheckOnly or $UnderCPAN) ) {
require Config; require Config;
print my $make = $Config::Config{make};
"*** Dependencies will be installed the next time you type '$Config::Config{make}'.\n"; if ($InstallDepsTarget) {
print
"*** To install dependencies type '$make installdeps' or '$make installdeps_notest'.\n";
}
else {
print
"*** Dependencies will be installed the next time you type '$make'.\n";
}


# make an educated guess of whether we'll need root permission. # make an educated guess of whether we'll need root permission.
print " (You may need to do that as the 'root' user.)\n" print " (You may need to do that as the 'root' user.)\n"
Expand Down Expand Up @@ -271,6 +292,10 @@ END_MESSAGE
sub _check_lock { sub _check_lock {
return unless @Missing or @_; return unless @Missing or @_;


if ($ENV{PERL5_CPANM_IS_RUNNING}) {
return _running_under('cpanminus');
}

my $cpan_env = $ENV{PERL5_CPAN_IS_RUNNING}; my $cpan_env = $ENV{PERL5_CPAN_IS_RUNNING};


if ($ENV{PERL5_CPANPLUS_IS_RUNNING}) { if ($ENV{PERL5_CPANPLUS_IS_RUNNING}) {
Expand Down Expand Up @@ -324,14 +349,19 @@ sub install {
while ( my ( $pkg, $ver ) = splice( @_, 0, 2 ) ) { while ( my ( $pkg, $ver ) = splice( @_, 0, 2 ) ) {


# grep out those already installed # grep out those already installed
if ( _version_cmp( _load($pkg), $ver ) >= 0 ) { if ( _version_cmp( _version_of($pkg), $ver ) >= 0 ) {
push @installed, $pkg; push @installed, $pkg;
} }
else { else {
push @modules, $pkg, $ver; push @modules, $pkg, $ver;
} }
} }


if ($UpgradeDeps) {
push @modules, @installed;
@installed = ();
}

return @installed unless @modules; # nothing to do return @installed unless @modules; # nothing to do
return @installed if _check_lock(); # defer to the CPAN shell return @installed if _check_lock(); # defer to the CPAN shell


Expand Down Expand Up @@ -363,7 +393,7 @@ sub install {


# see if we have successfully installed them # see if we have successfully installed them
while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) { while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) {
if ( _version_cmp( _load($pkg), $ver ) >= 0 ) { if ( _version_cmp( _version_of($pkg), $ver ) >= 0 ) {
push @installed, $pkg; push @installed, $pkg;
} }
elsif ( $args{do_once} and open( FAILED, '>> .#autoinstall.failed' ) ) { elsif ( $args{do_once} and open( FAILED, '>> .#autoinstall.failed' ) ) {
Expand Down Expand Up @@ -463,6 +493,11 @@ sub _cpanplus_config {
} else { } else {
die "*** Cannot convert option $key = '$value' to CPANPLUS version.\n"; die "*** Cannot convert option $key = '$value' to CPANPLUS version.\n";
} }
push @config, 'prereqs', $value;
} elsif ( $key eq 'force' ) {
push @config, $key, $value;
} elsif ( $key eq 'notest' ) {
push @config, 'skiptest', $value;
} else { } else {
die "*** Cannot convert option $key to CPANPLUS version.\n"; die "*** Cannot convert option $key to CPANPLUS version.\n";
} }
Expand Down Expand Up @@ -497,10 +532,14 @@ sub _install_cpan {
# set additional options # set additional options
while ( my ( $opt, $arg ) = splice( @config, 0, 2 ) ) { while ( my ( $opt, $arg ) = splice( @config, 0, 2 ) ) {
( $args{$opt} = $arg, next ) ( $args{$opt} = $arg, next )
if $opt =~ /^force$/; # pseudo-option if $opt =~ /^(?:force|notest)$/; # pseudo-option
$CPAN::Config->{$opt} = $arg; $CPAN::Config->{$opt} = $arg;
} }


if ($args{notest} && (not CPAN::Shell->can('notest'))) {
die "Your version of CPAN is too old to support the 'notest' pragma";
}

local $CPAN::Config->{prerequisites_policy} = 'follow'; local $CPAN::Config->{prerequisites_policy} = 'follow';


while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) { while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) {
Expand All @@ -519,8 +558,16 @@ sub _install_cpan {
delete $INC{$inc}; delete $INC{$inc};
} }


my $rv = $args{force} ? CPAN::Shell->force( install => $pkg ) my $rv = do {
: CPAN::Shell->install($pkg); if ($args{force}) {
CPAN::Shell->force( install => $pkg )
} elsif ($args{notest}) {
CPAN::Shell->notest( install => $pkg )
} else {
CPAN::Shell->install($pkg)
}
};

$rv ||= eval { $rv ||= eval {
$CPAN::META->instance( 'CPAN::Distribution', $obj->cpan_file, ) $CPAN::META->instance( 'CPAN::Distribution', $obj->cpan_file, )
->{install} ->{install}
Expand Down Expand Up @@ -575,7 +622,7 @@ sub _update_to {
my $ver = shift; my $ver = shift;


return return
if _version_cmp( _load($class), $ver ) >= 0; # no need to upgrade if _version_cmp( _version_of($class), $ver ) >= 0; # no need to upgrade


if ( if (
_prompt( "==> A newer version of $class ($ver) is required. Install?", _prompt( "==> A newer version of $class ($ver) is required. Install?",
Expand Down Expand Up @@ -660,16 +707,30 @@ sub _can_write {


# load a module and return the version it reports # load a module and return the version it reports
sub _load { sub _load {
my $mod = pop; # class/instance doesn't matter my $mod = pop; # method/function doesn't matter
my $file = $mod; my $file = $mod;

$file =~ s|::|/|g; $file =~ s|::|/|g;
$file .= '.pm'; $file .= '.pm';

local $@; local $@;
return eval { require $file; $mod->VERSION } || ( $@ ? undef: 0 ); return eval { require $file; $mod->VERSION } || ( $@ ? undef: 0 );
} }


# report version without loading a module
sub _version_of {
my $mod = pop; # method/function doesn't matter
my $file = $mod;
$file =~ s|::|/|g;
$file .= '.pm';
foreach my $dir ( @INC ) {
next if ref $dir;
my $path = File::Spec->catfile($dir, $file);
next unless -e $path;
require ExtUtils::MM_Unix;
return ExtUtils::MM_Unix->parse_version($path);
}
return undef;
}

# Load CPAN.pm and it's configuration # Load CPAN.pm and it's configuration
sub _load_cpan { sub _load_cpan {
return if $CPAN::VERSION and $CPAN::Config and not @_; return if $CPAN::VERSION and $CPAN::Config and not @_;
Expand Down Expand Up @@ -763,6 +824,35 @@ sub _make_args {
: "\$(NOECHO) \$(NOOP)" : "\$(NOECHO) \$(NOOP)"
); );


my $deps_list = join( ',', @Missing, @Existing );

$PostambleActionsUpgradeDeps =
"\$(PERL) $0 --config=$config --upgradedeps=$deps_list";

my $config_notest =
join( ',', (UNIVERSAL::isa( $Config, 'HASH' ) ? %{$Config} : @{$Config}),
'notest', 1 )
if $Config;

$PostambleActionsNoTest = (
($missing and not $UnderCPAN)
? "\$(PERL) $0 --config=$config_notest --installdeps=$missing"
: "\$(NOECHO) \$(NOOP)"
);

$PostambleActionsUpgradeDepsNoTest =
"\$(PERL) $0 --config=$config_notest --upgradedeps=$deps_list";

$PostambleActionsListDeps =
'@$(PERL) -le "print for @ARGV" '
. join(' ', map $Missing[$_], grep $_ % 2 == 0, 0..$#Missing);

my @all = (@Missing, @Existing);

$PostambleActionsListAllDeps =
'@$(PERL) -le "print for @ARGV" '
. join(' ', map $all[$_], grep $_ % 2 == 0, 0..$#all);

return %args; return %args;
} }


Expand Down Expand Up @@ -797,24 +887,44 @@ sub Write {


sub postamble { sub postamble {
$PostambleUsed = 1; $PostambleUsed = 1;
my $fragment;


return <<"END_MAKE"; $fragment .= <<"AUTO_INSTALL" if !$InstallDepsTarget;
config :: installdeps config :: installdeps
\t\$(NOECHO) \$(NOOP) \t\$(NOECHO) \$(NOOP)
AUTO_INSTALL

$fragment .= <<"END_MAKE";
checkdeps :: checkdeps ::
\t\$(PERL) $0 --checkdeps \t\$(PERL) $0 --checkdeps
installdeps :: installdeps ::
\t$PostambleActions \t$PostambleActions
installdeps_notest ::
\t$PostambleActionsNoTest
upgradedeps ::
\t$PostambleActionsUpgradeDeps
upgradedeps_notest ::
\t$PostambleActionsUpgradeDepsNoTest
listdeps ::
\t$PostambleActionsListDeps
listalldeps ::
\t$PostambleActionsListAllDeps
END_MAKE END_MAKE


return $fragment;
} }


1; 1;


__END__ __END__
#line 1071 #line 1193
6 changes: 3 additions & 3 deletions inc/Module/Install.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BEGIN {
# This is not enforced yet, but will be some time in the next few # This is not enforced yet, but will be some time in the next few
# releases once we can make sure it won't clash with custom # releases once we can make sure it won't clash with custom
# Module::Install extensions. # Module::Install extensions.
$VERSION = '1.01'; $VERSION = '1.06';


# Storage for the pseudo-singleton # Storage for the pseudo-singleton
$MAIN = undef; $MAIN = undef;
Expand Down Expand Up @@ -451,7 +451,7 @@ sub _version ($) {
} }


sub _cmp ($$) { sub _cmp ($$) {
_version($_[0]) <=> _version($_[1]); _version($_[1]) <=> _version($_[2]);
} }


# Cloned from Params::Util::_CLASS # Cloned from Params::Util::_CLASS
Expand All @@ -467,4 +467,4 @@ sub _CLASS ($) {


1; 1;


# Copyright 2008 - 2011 Adam Kennedy. # Copyright 2008 - 2012 Adam Kennedy.
59 changes: 0 additions & 59 deletions inc/Module/Install/AuthorTests.pm

This file was deleted.

Loading

0 comments on commit 937bf2a

Please sign in to comment.