Apache-Bootstrap
view release on metacpan or search on metacpan
lib/Apache/Bootstrap.pm view on Meta::CPAN
$wanted ||= $self->_wanted_mp_generation();
unless ( $wanted == 1 || $wanted == 2 ) {
die "don't know anything about mod_perl generation: $wanted\n"
. "currently supporting only generations 1 and 2";
}
my $selected = 0;
if ( $wanted == 1 ) {
eval { require mod_perl };
if ($@) {
warn("require mod_perl failed");
return;
}
$selected = 1;
}
elsif ( $wanted == 2 ) {
eval { require mod_perl2 };
if ($@) {
warn("require mod_perl2 failed");
return;
}
$selected = 2;
}
else {
# try mp2 first
eval { require mod_perl2 };
if ($@) {
warn("require mod_perl2 failed");
eval { require mod_perl };
if ($@) {
warn("require mod_perl failed");
return;
}
}
$selected = $mod_perl::VERSION >= MIN_MP2_VER ? 2 : 1;
}
# make sure we have the needed build modules
my $build_pkg =
( $selected == 2 ) ? 'ModPerl::BuildMM' : 'ExtUtils::MakeMaker';
eval "require $build_pkg";
die "could not require package $build_pkg: $@" if $@;
$self->{maker} = $build_pkg;
return $self->{mp_gen} = $selected;
}
# _wanted_mp_generation()
#
# the function looks at %ENV and Makefile.PL option to figure out
# whether a specific mod_perl generation was requested.
# It uses the following logic:
# via options:
# perl Makefile.PL MOD_PERL=2
# or via %ENV:
# env MOD_PERL=1 perl Makefile.PL
#
# return value is:
# 1 or 2 if the specification was found (mp 1 and mp 2 respectively)
# 0 otherwise
# Currently the logic for determining the mod_perl generation
# is as follows.
# If a specific generation was passed as an argument,
# if satisfied
# return the same generation
# else
# die
# else @ARGV and %ENV will be checked for specific orders
# if the specification will be found
# if satisfied
# return the specified generation
# else
# die
# else if any mp generation is found
# return it
# else
# die
sub _wanted_mp_generation {
my $self = shift;
# check if we have a command line specification
# flag: 0: unknown, 1: mp1, 2: mp2
my $flag = 0;
foreach my $key (@ARGV) {
if ( $key =~ /^MOD_PERL=([12])$/ ) {
$flag = $1;
}
}
# check %ENV
my $env = exists $ENV{MOD_PERL} ? $ENV{MOD_PERL} : 0;
# check for contradicting requirements
if ( $env && $flag && $flag != $env ) {
warn <<EOF;
Can\'t decide which mod_perl version should be used, since you have
supplied contradicting requirements:
enviroment variable MOD_PERL=$env
Makefile.PL option MOD_PERL=$flag
EOF
die;
}
my $wanted = 0;
$wanted = 2 if $env == 2 || $flag == 2;
$wanted = 1 if $env == 1 || $flag == 1;
( run in 1.975 second using v1.01-cache-2.11-cpan-39bf76dae61 )