better bootstrap
[p5sagit/local-lib.git] / Makefile.PL
index 3c41873..bcfefe7 100644 (file)
@@ -7,6 +7,7 @@ BEGIN {
     $bootstrapping = 1;
     my @args = (defined $1 ? ($1) : ());
 
+    $ENV{PERL_MM_USE_DEFAULT} = 1;
     {
       local @INC = @INC;
       unshift(@INC, 'lib');
@@ -24,6 +25,17 @@ BEGIN {
     my $cpan = $? >> 8;
     my $cpan_command = '';
 
+    system($^X, '-MCPAN', '-e',
+      'CPAN::Config->load;
+       unless (-w $CPAN::Config->{keep_source_where}) {
+         $ENV{PERL_MM_USE_DEFAULT} = 0;
+         my $save = $CPAN::Config->{urllist};
+         delete @{$CPAN::Config}{keys %$CPAN::Config};
+         $CPAN::Config->{urllist} = $save;
+         CPAN::Config->init;
+       }'
+    );
+
     # XXX - remove the force on EUMM once its test suite survive PERL_MM_OPT
 
     if ($eumm) { # non-zero exit
@@ -35,7 +47,9 @@ BEGIN {
     if(length $cpan_command) {
       system($^X, '-MCPAN', '-e', $cpan_command);
     }
-
+    if ($cpan) {
+      system($^X, '-MCPAN', '-e', 'CPAN::Config->load; CPAN::Config->commit;');
+    }
   }
 }
 
@@ -50,6 +64,16 @@ requires 'ExtUtils::ParseXS';
 requires 'Module::Build' => '0.28'; # lib -> lib/perl5 change
 requires 'CPAN' => '1.80'; # sudo support
 
+# No, really. See
+# https://rt.cpan.org/Public/Bug/Display.html?id=23735
+# for why CPAN now sets the CPANPLUS env var.
+# trouble is this means we can't auto_install(_now) CPAN itself
+# without this beautiful hack
+
+my $no_cpanplus_env = !exists $ENV{PERL5_CPANPLUS_IS_RUNNING};
+require CPAN;
+delete $ENV{PERL5_CPANPLUS_IS_RUNNING} if $no_cpanplus_env;
+
 if ($bootstrapping) {
   auto_install_now;
 } else {