Randy W. Sims <[EMAIL PROTECTED]> wrote:
> > This is a problem with CPAN.pm as well; if you try to do the initial
> >setup with PERL_MM_USE_DEFAULT=1, it loops forever on the "Select a mirror"
> >prompt. :-/ I've been meaning to discuss this more / submit a patch, but my
> >backlog has been insane lately...
> We can:
>
> die "ERROR: This build script not safe for unattended installs. Please
> notify @{[$self->dist_author]} that they wrote a bad bad Build.PL.
> Please ask them to provide reasonable defaults or switch to the new
> ask() method."
> if $ENV{PERL_MM_USE_DEFAULT}
> && (called_without_default(y_n) || called_without_default(prompt);
Sure. What I really want though, is for CPAN.pm to be totally
automatable. If you want a good chuckle, check out the attached
hackety-hackety-hack I whipped together one afternoon to do an autobuild;
the scary thing is it actually works. <g>
- Tyler
#!/usr/bin/perl
use strict;
use warnings;
use CPAN;
use CPAN::FirstTime;
use YAML;
use Cwd;
use Config;
my $dist_dir = getcwd;
die "I refuse to run unless you set the ACTS_PREFIX environmnent variable"
unless $ENV{ACTS_PREFIX};
sub _wrap {
my($sub, $wrapper) = @_;
my $wrap_call;
{
no strict 'refs';
no warnings 'redefine';
my $sub_ref = \&{$sub};
$wrap_call = sub { $wrapper->($sub_ref, @_); };
*{$sub} = $wrap_call;
}
return $wrap_call;
}
local $INC{"CPAN/MyConfig.pm"} = "$ENV{ACTS_PREFIX}/.cpan/CPAN/MyConfig.pm";
$ENV{PERL5OPT} = qq[-I$ENV{ACTS_PREFIX}/lib];
unshift(@INC, "$ENV{ACTS_PREFIX}/lib");
-e "META.yml" or die "No META.yml in the current directory!";
my $meta;
open($meta, "META.yml") or die "failed to open META.yml: $!";
my $yaml = join('', <$meta>);
close($meta);
my $data = YAML::Load($yaml) or die "failed to read metadata";
my %requires = map { %{$_} } grep { $_ } @$data{'requires','build_requires'}
or die "requirements appear to be missing";
system("./Build distclean") if -e "./Build";
our $MakePL = join(" ",
qq[PREFIX=$ENV{ACTS_PREFIX}],
qq[LIB=$ENV{ACTS_PREFIX}/lib],
qq[INC=$ENV{ACTS_PREFIX}/include ],
qq[LDDLFLAGS="$Config{lddlflags} -L$ENV{ACTS_PREFIX}/lib"]
);
our $MB = join(" ",
qq[--install-base $ENV{ACTS_PREFIX}],
qq[--install-path lib=$ENV{ACTS_PREFIX}/lib],
qq[--install-path arch=$ENV{ACTS_PREFIX}/lib/arch],
qq[--extra-compiler-flags=-I$ENV{ACTS_PREFIX}/include],
qq[--extra-linker-flags=-L$ENV{ACTS_PREFIX}/lib]
);
eval "use CPAN::Config";
_wrap('CPAN::FirstTime::init', sub {
my($real, @args) = @_;
push(@args, autoconfig => 1);
$real->(@args);
});
_wrap('CPAN::Distribution::make', sub {
my($real, $self, @args) = @_;
warn "Building ", $self->id, "\n";
if($self->id =~ m{/Net(?:_|::|-)SSLeay}) {
warn "This is Net::SSLeay; fudging Makefile.PL arguments\n";
local $CPAN::Config->{makepl_arg} = qq[/usr -- $MakePL];
$real->($self, @args);
} else {
$real->($self, @args);
}
});
my $wrapper = sub {
my($real, @args) = @_;
if($args[0] =~ m{manual config}) {
$args[1] = 'no';
}
$real->(@args);
};
_wrap('ExtUtils::MakeMaker::prompt', $wrapper);
_wrap('CPAN::FirstTime::prompt', $wrapper);
$ENV{PERL_MM_USE_DEFAULT} = 1;
$CPAN::Config = {
'build_cache' => q[100],
'build_dir' => qq[$ENV{ACTS_PREFIX}/.cpan/build],
'cache_metadata' => q[1],
'cpan_home' => qq[$ENV{ACTS_PREFIX}/.cpan],
'ftp_passive' => q[1],
'ftp_proxy' => q[],
'getcwd' => q[cwd],
'histfile' => qq[$ENV{ACTS_PREFIX}/.cpan/histfile],
'histsize' => q[100],
'http_proxy' => q[],
'inactivity_timeout' => q[0],
'index_expire' => q[1],
'inhibit_startup_message' => q[0],
'keep_source_where' => qq[$ENV{ACTS_PREFIX}/.cpan/sources],
'make_arg' => q[],
'make_install_arg' => q[],
'makepl_arg' => $MakePL,
'mbuild_arg' => q[],
'mbuild_install_arg' => q[],
'mbuild_install_build_command' => q[./Build],
'mbuildpl_arg' => $MB,
'ncftp' => q[],
'ncftpget' => q[],
'no_proxy' => q[],
'prefer_installer' => q[MB],
'prerequisites_policy' => q[follow],
'scan_cache' => q[atstart],
'show_upload_date' => q[1],
'term_is_latin' => q[1],
'urllist' => [q[ftp://ftp.yi.org/CPAN]],
};
CPAN::Shell->reload('index');
## remove this block once M::B 0.28 goes live;
CPAN::Shell->notest('install', 'KWILLIAMS/Module-Build-0.27_07.tar.gz');
CPAN::Shell->force(
'install', grep { $_ ne 'Module::Build' } keys %requires
);
CPAN::Shell->force('install', 'KWILLIAMS/Module-Build-0.27_07.tar.gz');
{
# we have to install this twice to make sure it works if it's already
# installed by the system.
eval "use DBIx::Migration::Directories::ConfigData; 1;" or die $@;
DBIx::Migration::Directories::ConfigData->set_config(
"schema_dir", "$ENV{ACTS_PREFIX}/schemas"
);
DBIx::Migration::Directories::ConfigData->write;
CPAN::Shell->force('install', 'DBIx::Migration::Directories');
}
chdir($dist_dir);
{
local $ENV{HARNESS_PERL_SWITCHES} = "-MDevel::Cover";
local $CPAN::Config->{mbuildpl_arg} =
"$CPAN::Config->{mbuildpl_arg} --verbose";
my $dist = CPAN::Distribution->new(
build_dir => $dist_dir,
ID => 'Sophos-ACTS',
archived => 'Fake',
unwrapped => 'Yes',
modulebuild => 1
);
local *CPAN::Distribution::unsat_prereq = sub { (); };
$dist->install or die "Failed to install Sophos-ACTS!";
}