Skip to content

Commit

Permalink
Upgrade MI and MIRTx
Browse files Browse the repository at this point in the history
  • Loading branch information
jibsheet committed Sep 30, 2011
1 parent 6d65e85 commit 558d77b
Show file tree
Hide file tree
Showing 13 changed files with 1,034 additions and 409 deletions.
11 changes: 6 additions & 5 deletions META.yml
Expand Up @@ -2,19 +2,20 @@
abstract: 'Display RT API documentation online'
author:
- 'Jesse Vincent <jesse@bestpractical.com>'
build_requires:
ExtUtils::MakeMaker: 6.42
configure_requires:
ExtUtils::MakeMaker: 6.42
distribution_type: module
generated_by: 'Module::Install version 0.770'
license: GPLv2
generated_by: 'Module::Install version 1.01'
license: gplv2
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: RT-OnlineDocs
no_index:
directory:
- etc
- html
- po
- var
- inc
requires:
File::Basename: 0
Expand Down
118 changes: 85 additions & 33 deletions inc/Module/AutoInstall.pm
Expand Up @@ -18,7 +18,9 @@ my %FeatureMap = (

# various lexical flags
my ( @Missing, @Existing, %DisabledTests, $UnderCPAN, $HasCPANPLUS );
my ( $Config, $CheckOnly, $SkipInstall, $AcceptDefault, $TestOnly );
my (
$Config, $CheckOnly, $SkipInstall, $AcceptDefault, $TestOnly, $AllDeps
);
my ( $PostambleActions, $PostambleUsed );

# See if it's a testing or non-interactive session
Expand Down Expand Up @@ -73,6 +75,9 @@ sub _init {
elsif ( $arg =~ /^--test(?:only)?$/ ) {
$TestOnly = 1;
}
elsif ( $arg =~ /^--all(?:deps)?$/ ) {
$AllDeps = 1;
}
}
}

Expand Down Expand Up @@ -115,6 +120,13 @@ sub import {
)[0]
);

# We want to know if we're under CPAN early to avoid prompting, but
# if we aren't going to try and install anything anyway then skip the
# check entirely since we don't want to have to load (and configure)
# an old CPAN just for a cosmetic message

$UnderCPAN = _check_lock(1) unless $SkipInstall;

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

# XXX: check for conflicts and uninstalls(!) them.
if (
defined( my $cur = _version_check( _load($mod), $arg ||= 0 ) ) )
my $cur = _load($mod);
if (_version_cmp ($cur, $arg) >= 0)
{
print "loaded. ($cur" . ( $arg ? " >= $arg" : '' ) . ")\n";
push @Existing, $mod => $arg;
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
}
else {
print "missing." . ( $arg ? " (would need $arg)" : '' ) . "\n";
if (not defined $cur) # indeed missing
{
print "missing." . ( $arg ? " (would need $arg)" : '' ) . "\n";
}
else
{
# no need to check $arg as _version_cmp ($cur, undef) would satisfy >= above
print "too old. ($cur < $arg)\n";
}

push @required, $mod => $arg;
}
}
Expand All @@ -184,6 +205,8 @@ sub import {
!$SkipInstall
and (
$CheckOnly
or ($mandatory and $UnderCPAN)
or $AllDeps
or _prompt(
qq{==> Auto-install the }
. ( @required / 2 )
Expand Down Expand Up @@ -214,8 +237,6 @@ sub import {
}
}

$UnderCPAN = _check_lock(); # check for $UnderCPAN

if ( @Missing and not( $CheckOnly or $UnderCPAN ) ) {
require Config;
print
Expand All @@ -232,23 +253,42 @@ sub import {
# import to main::
no strict 'refs';
*{'main::WriteMakefile'} = \&Write if caller(0) eq 'main';

return (@Existing, @Missing);
}

sub _running_under {
my $thing = shift;
print <<"END_MESSAGE";
*** Since we're running under ${thing}, I'll just let it take care
of the dependency's installation later.
END_MESSAGE
return 1;
}

# Check to see if we are currently running under CPAN.pm and/or CPANPLUS;
# if we are, then we simply let it taking care of our dependencies
sub _check_lock {
return unless @Missing;
return unless @Missing or @_;

my $cpan_env = $ENV{PERL5_CPAN_IS_RUNNING};

if ($ENV{PERL5_CPANPLUS_IS_RUNNING}) {
print <<'END_MESSAGE';
return _running_under($cpan_env ? 'CPAN' : 'CPANPLUS');
}

*** Since we're running under CPANPLUS, I'll just let it take care
of the dependency's installation later.
END_MESSAGE
return 1;
require CPAN;

if ($CPAN::VERSION > '1.89') {
if ($cpan_env) {
return _running_under('CPAN');
}
return; # CPAN.pm new enough, don't need to check further
}

_load_cpan();
# last ditch attempt, this -will- configure CPAN, very sorry

_load_cpan(1); # force initialize even though it's already loaded

# Find the CPAN lock-file
my $lock = MM->catfile( $CPAN::Config->{cpan_home}, ".lock" );
Expand Down Expand Up @@ -284,7 +324,7 @@ sub install {
while ( my ( $pkg, $ver ) = splice( @_, 0, 2 ) ) {

# grep out those already installed
if ( defined( _version_check( _load($pkg), $ver ) ) ) {
if ( _version_cmp( _load($pkg), $ver ) >= 0 ) {
push @installed, $pkg;
}
else {
Expand Down Expand Up @@ -313,7 +353,7 @@ sub install {
@modules = @newmod;
}

if ( _has_cpanplus() ) {
if ( _has_cpanplus() and not $ENV{PERL_AUTOINSTALL_PREFER_CPAN} ) {
_install_cpanplus( \@modules, \@config );
} else {
_install_cpan( \@modules, \@config );
Expand All @@ -323,7 +363,7 @@ sub install {

# see if we have successfully installed them
while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) {
if ( defined( _version_check( _load($pkg), $ver ) ) ) {
if ( _version_cmp( _load($pkg), $ver ) >= 0 ) {
push @installed, $pkg;
}
elsif ( $args{do_once} and open( FAILED, '>> .#autoinstall.failed' ) ) {
Expand Down Expand Up @@ -378,7 +418,7 @@ sub _install_cpanplus {
my $success;
my $obj = $modtree->{$pkg};

if ( $obj and defined( _version_check( $obj->{version}, $ver ) ) ) {
if ( $obj and _version_cmp( $obj->{version}, $ver ) >= 0 ) {
my $pathname = $pkg;
$pathname =~ s/::/\\W/;

Expand Down Expand Up @@ -471,7 +511,7 @@ sub _install_cpan {
my $obj = CPAN::Shell->expand( Module => $pkg );
my $success = 0;

if ( $obj and defined( _version_check( $obj->cpan_version, $ver ) ) ) {
if ( $obj and _version_cmp( $obj->cpan_version, $ver ) >= 0 ) {
my $pathname = $pkg;
$pathname =~ s/::/\\W/;

Expand Down Expand Up @@ -535,7 +575,7 @@ sub _update_to {
my $ver = shift;

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

if (
_prompt( "==> A newer version of $class ($ver) is required. Install?",
Expand Down Expand Up @@ -632,9 +672,22 @@ sub _load {

# Load CPAN.pm and it's configuration
sub _load_cpan {
return if $CPAN::VERSION;
return if $CPAN::VERSION and $CPAN::Config and not @_;
require CPAN;
if ( $CPAN::HandleConfig::VERSION ) {

# CPAN-1.82+ adds CPAN::Config::AUTOLOAD to redirect to
# CPAN::HandleConfig->load. CPAN reports that the redirection
# is deprecated in a warning printed at the user.

# CPAN-1.81 expects CPAN::HandleConfig->load, does not have
# $CPAN::HandleConfig::VERSION but cannot handle
# CPAN::Config->load

# Which "versions expect CPAN::Config->load?

if ( $CPAN::HandleConfig::VERSION
|| CPAN::HandleConfig->can('load')
) {
# Newer versions of CPAN have a HandleConfig module
CPAN::HandleConfig->load;
} else {
Expand All @@ -644,9 +697,11 @@ sub _load_cpan {
}

# compare two versions, either use Sort::Versions or plain comparison
sub _version_check {
# return values same as <=>
sub _version_cmp {
my ( $cur, $min ) = @_;
return unless defined $cur;
return -1 unless defined $cur; # if 0 keep comparing
return 1 unless $min;

$cur =~ s/\s+$//;

Expand All @@ -657,16 +712,13 @@ sub _version_check {
) {

# use version.pm if it is installed.
return (
( version->new($cur) >= version->new($min) ) ? $cur : undef );
return version->new($cur) <=> version->new($min);
}
elsif ( $Sort::Versions::VERSION or defined( _load('Sort::Versions') ) )
{

# use Sort::Versions as the sorting algorithm for a.b.c versions
return ( ( Sort::Versions::versioncmp( $cur, $min ) != -1 )
? $cur
: undef );
return Sort::Versions::versioncmp( $cur, $min );
}

warn "Cannot reliably compare non-decimal formatted versions.\n"
Expand All @@ -675,7 +727,7 @@ sub _version_check {

# plain comparison
local $^W = 0; # shuts off 'not numeric' bugs
return ( $cur >= $min ? $cur : undef );
return $cur <=> $min;
}

# nothing; this usage is deprecated.
Expand Down Expand Up @@ -706,7 +758,7 @@ sub _make_args {
if $Config;

$PostambleActions = (
$missing
($missing and not $UnderCPAN)
? "\$(PERL) $0 --config=$config --installdeps=$missing"
: "\$(NOECHO) \$(NOOP)"
);
Expand Down Expand Up @@ -746,7 +798,7 @@ sub Write {
sub postamble {
$PostambleUsed = 1;

return << ".";
return <<"END_MAKE";
config :: installdeps
\t\$(NOECHO) \$(NOOP)
Expand All @@ -757,12 +809,12 @@ checkdeps ::
installdeps ::
\t$PostambleActions
.
END_MAKE

}

1;

__END__
#line 1003
#line 1071

0 comments on commit 558d77b

Please sign in to comment.