[svn:modperl-modules] rev 245 - Apache-Peek/trunk

[email protected]@cvs.perl.org 9 Jul 2005 23:02:18 -0000
Newsgroups perl.modperl.modules.svn
Message-ID <[email protected]>
Author: [email protected]
Date: Sat Jul  9 16:02:18 2005
New Revision: 245

Modified:
   Apache-Peek/trunk/Makefile.PL
Log:
Update for new mp2 api


Modified: Apache-Peek/trunk/Makefile.PL
==============================================================================
--- Apache-Peek/trunk/Makefile.PL	(original)
+++ Apache-Peek/trunk/Makefile.PL	Sat Jul  9 16:02:18 2005
@@ -1,258 +1,206 @@
 use strict;
-
-use Cwd;
-use File::Spec::Functions;
-use File::Path ();
+use warnings FATAL => 'all';
 use Config;
+use File::Copy ();
 use Symbol;
 
-use constant DEVEL => getpwuid($>) eq 'pgollucci';
-
-my $VERSION = '1.02';
-
-my @clean_files = ();
-
-my $mp_gen = satisfy_mp_generation();
-my $perl_gen = satisfy_perl_generation();
-
-#warn "using mp gen: $mp_gen, perl gen: $perl_gen\n";
-
-# currently we support only 5.8-perlio
-if ($perl_gen eq '5.8') {
-    die "Perl must be built with PerlIO support in order to use this module"
-        unless $Config{useperlio};
-}
+use constant DEVEL => getpwuid($>) =~ /^(?:stas|pgollucci)$/o;
 
-build_prepare($mp_gen, $perl_gen);
-warn "Goind to build against mod_perl/$mod_perl::VERSION Perl/$]\n";
-
-test_configure($mp_gen);
+my $VERSION = '1.03';
 
 my %prereq = (
-    "Apache::Test" => "1.10", # ipv6 fixes
-    "Devel::Peek"  => 0.96,
-);
+              "Apache::Test" => "1.25", # ipv6 fixes
+              "Devel::Peek"  => 0.96,
+             );
 
 my %common_opts = (
     NAME         => "Apache::Peek",
     VERSION_FROM => "Peek.pm",
     XSPROTOARG   => '-noprototypes',
     DEFINE       => '-DMOD_PERL',
-    clean        => { FILES => "@clean_files", },
     PREREQ_PM    => \%prereq,
 );
 
-if ($mp_gen == 1) {
+MAIN: {
+  exit &main();
+}
+
+sub main {
+
+  ## check PERL version
+
+  my $perl_ver = &get_perl_ver();
+
+  # currently we support only 5.8-perlio
+  die "Perl $] must be built with PerlIO support in order to use this module." if $perl_ver eq '5.8' && !$Config{useperlio};
+
+  ## which mp version ( 1.2x or 2.0.x)
+  my ($mp_wanted, $mp_ver) = &get_mp_ver();
+
+  print STDERR "Using Perl/$perl_ver and mod_perl/$mp_ver\n\n";
+
+  &prepare_build($perl_ver, $mp_wanted);
+
+  my @clean_files = &test_configure($mp_wanted);
+  $common_opts{clean} = { FILES =>"@clean_files"};
+
+  if ($mp_wanted == 2) {
+    $prereq{mod_perl} = 1.99023;
+    require ModPerl::MM;
+    ModPerl::MM::WriteMakefile(%common_opts);
+  }
+  else {
     require Apache::src;
     my $inc = Apache::src->new->inc;
     die "Can't find mod_perl header files installed" unless $inc;
 
     require ExtUtils::MakeMaker;
     ExtUtils::MakeMaker::WriteMakefile(
-        INC	     => $inc,
+        INC	         => $inc,
         LIBS         => [''],
-        %common_opts,
+        %common_opts
     );
+  }
 
-}
-else {
-    $prereq{mod_perl} = 1.9915;
-    require ModPerl::MM;
-    ModPerl::MM::WriteMakefile(
-        %common_opts,
-    );
+  return 0;
 }
 
-sub build_prepare {
-    my($mp_gen, $perl_gen) = @_;
+sub test_configure ($) {
 
-    my $xs = "Peek.xs";
-    my $pm = "Peek.pm";
-    push @clean_files, ($pm, $xs);
-
-    # now put together the build
-    my %files = map { $_ => join '.', $_, "mp$mp_gen", "perl$perl_gen" }
-        ($pm, $xs);
-
-    unlink $xs if -e $xs;
-    if (DEVEL and eval { symlink("", ""); 1 }) {
-        # so that it's easier to modify/rebuild w/o re-running Makefile.PL
-        symlink $files{$xs}, $xs 
-            or die "Couldn't symlink $files{$xs} => $xs: $!";
-    } else {
-        # copy the xs file as is
-        require File::Copy;
-        File::Copy::copy($files{$xs}, $xs);
-    }
+  my $mp_gen = shift;
+  my @clean_files = ();
 
-    # adjust the version and glue the doc (open() for 5.005_03 support)
-    my ($in, $out) = ($files{$pm}, $pm);
-    my ($ifh, $ofh) = (Symbol::gensym(), Symbol::gensym());
-    open $ifh,  "<$in"  or die "can't open $in: $!";
-    open $ofh, ">$out" or die "can't open $out: $!";
-    print $ofh "# WARNING: DO NOT EDIT THIS FILE, EDIT $in instead\n\n";
-    while (<$ifh>) {
-        s/(.*\$VERSION\s*=).*/$1 $VERSION;/;
-        print $ofh $_;
-    }
-    print $ofh <DATA>;
-    close $ifh;
-    close $ofh;
-}
+  if (eval { require Apache::TestMM }) {
+    Apache::TestMM->import(qw(test clean));
+    my @scripts = qw(t/TEST);
+    # accept the configs from command line
+    Apache::TestMM::filter_args();
 
-sub test_configure {
-    my $mp_gen = shift;
+    Apache::TestMM::generate_script($_) for @scripts;
 
-    if (eval { require Apache::TestMM }) {
-        Apache::TestMM->import(qw(test clean));
-        my @scripts = qw(t/TEST);
-        # accept the configs from command line
-        Apache::TestMM::filter_args();
-
-        Apache::TestMM::generate_script($_) for @scripts;
-
-        push @clean_files, @scripts;
-
-        my $httpd;
-        # mp2 already knows its 
-        if ($mp_gen == 1) {
-#        require Apache::test;
-#        # can't really use get_test_params, since it may pick the wrong httpd
-#        # must explicitly ask for the path to httpd
-#        my %params = Apache::test->get_test_params;
-#        $common_opts{macro}{APACHE} = $httpd;
-        }
-    } else {
-        warn "***: You should install Apache::Test to do real testing\n";
-        # META: soon on CPAN
-        *MY::test = sub {
-            return <<'EOF';
+    push @clean_files, @scripts;
+
+    my $httpd;
+    # mp2 already knows its 
+    if ($mp_gen == 1) {
+      #        require Apache::test;
+      #        # can't really use get_test_params, since it may pick the wrong httpd
+      #        # must explicitly ask for the path to httpd
+      #        my %params = Apache::test->get_test_params;
+      #        $common_opts{macro}{APACHE} = $httpd;
+    }
+  } else {
+    warn "***: You should install Apache::Test to do real testing\n";
+    # META: soon on CPAN
+    *MY::test = *MY::test = sub {
+      return <<'EOF';
 test : pure_all
 	@echo \*** This test suite requires Apache::Test available from the
 	@echo \*** mod_perl 2.0 sources or the httpd-test distribution.
 EOF
-        }
     }
-}
+  }
 
-sub satisfy_perl_generation {
-      eval { require 5.8.0 }    ? "5.8"
-    : eval { require 5.6.0 }    ? "5.6"
-    : eval { require 5.005_03 } ? "5.5"
-    : die "Perl version $] is unsupported";
+  return @clean_files;
 }
 
 
-# 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 satisfy_mp_generation {
-    my $wanted = shift || 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";
-    }
+sub prepare_build ($$) {
 
-    my $selected = 0;
+  my ($perl_ver, $mp_wanted) = @_;
 
-    if ($wanted == 1) {
-        require_mod_perl();
-        if ($mod_perl::VERSION >= 1.99) {
-            # so we don't pick 2.0 version if 1.0 is wanted
-            die "You don't seem to have mod_perl 1.0 installed";
-        }
-        $selected = 1;
-    }
-    elsif ($wanted == 2) {
-        #warn "Looking for mod_perl 2.0";
-        require Apache2;
-        require_mod_perl();
-        if ($mod_perl::VERSION < 1.99) {
-            die "You don't seem to have mod_perl 2.0 installed";
-        }
-        $selected = 2;
-    }
-    else {
-        require_mod_perl();
-        $selected = $mod_perl::VERSION >= 1.99 ? 2 : 1;
-        warn "Using $mod_perl::VERSION\n";
-    }
+  my $xs = "Peek.xs.mp$mp_wanted.perl$perl_ver";
+  my $pm = "Peek.pm.mp$mp_wanted.perl$perl_ver";
 
-    return $selected;
-}
+  unlink 'Peek.xs' if -e 'Peek.xs';
 
-sub require_mod_perl {
-    eval { require mod_perl };
-    die "Can't find mod_perl installed\nThe error was: $@" if $@;
+  if (DEVEL && eval { symlink("", ""); 1 }) {
+    # so that it's easier to modify/rebuild w/o re-running Makefile.PL
+    symlink $xs, 'Peek.xs' or die "Couldn't symlink $xs => 'Peek.xs': $!";
+  }
+  else {
+    File::Copy::copy($xs, 'Peek.xs');
+  }
+
+  # adjust the version and glue the doc (open() for 5.005_03 support)
+  my ($in, $out) = ($pm, 'Peek.pm');
+  my ($ifh, $ofh) = (Symbol::gensym(), Symbol::gensym());
+  open $ifh,  "<$in"  or die "can't open $in: $!";
+  open $ofh, ">$out" or die "can't open $out: $!";
+  print $ofh "# WARNING: DO NOT EDIT THIS FILE, EDIT $in instead\n\n";
+  while (<$ifh>) {
+    s/(.*\$VERSION\s*=).*/$1 $VERSION;/;
+    print $ofh $_;
+  }
+  print $ofh <DATA>;
+  close $ifh or die "can't close $in $!";
+  close $ofh or die "can't close $out $!";
+
+  return;
 }
 
-# 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
-sub wanted_mp_generation {
-
-    # check if we have a command line specification
-    # flag: 0: unknown, 1: mp1, 2: mp2
-    my $flag = 0;
-    my @pass;
-    while (@ARGV) {
-        my $key = shift @ARGV;
-        if ($key =~ /^MOD_PERL=(\d)$/) {
-            $flag = $1;
-        }
-        else {
-            push @pass, $key;
-        }
+##############################################################################
+##
+##
+##
+##
+##############################################################################
+sub get_mp_ver() {
+
+  my $flag = 0;
+  foreach my $arg (@ARGV) {
+    if ($arg =~ /^MOD_PERL=([12])$/) {
+      $flag = $1;
     }
-    @ARGV = @pass;
+  }
 
-    # check %ENV
-    my $env = exists $ENV{MOD_PERL} ? $ENV{MOD_PERL} : 0;
+  # check %ENV
+  my $env = exists $ENV{MOD_PERL} ? $ENV{MOD_PERL} : 0;
 
-    # check for contradicting requirements
-    if ($env && $flag && $flag != $env) {
-        die <<EOF;
+  # check for contradicting requirements
+  if ($env && $flag && $flag != $env) {
+    die <<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
-    }
+  }
+
+  my $wanted = 2; ## default ot wanting mp2
+  $wanted = 1 if $env == 1 || $flag == 1;
+
+  my $mp_ver;
 
-    my $wanted = 0; 
-    $wanted = 2 if $env == 2 || $flag == 2;
-    $wanted = 1 if $env == 1 || $flag == 1;
-
-    unless ($wanted) {
-        # if still unknown try to require mod_perl.pm
-        eval { require mod_perl };
-        unless ($@) {
-            $wanted = $mod_perl::VERSION >= 1.99 ? 2 : 1;
-        }
+  if ($wanted == 2) {
+    eval { require mod_perl2 };
+    if ($mod_perl2::VERSION < 1.99023 || $@) {
+      die "You don't seem to have mod_perl 2.0 installed";
+    }
+    else {
+      $mp_ver = $mod_perl2::VERSION;
+    }
+  }
+  else {
+    eval { require mod_perl };
+    if ($mod_perl::VERSION > 1.99 || $@) {
+      die "You don't seem to have mod_perl 1.0 installed";
+    }
+    else {
+      $mp_ver = $mod_perl::VERSION;
     }
+  }
+
+  return ($wanted, $mp_ver);
+}
+
+sub get_perl_ver() {
 
-    return $wanted;
+  #eval { requie 5.10.0 }   ? "5.10" :
+  eval { require 5.8.0 }    ? "5.8" :
+  eval { require 5.6.0 }    ? "5.6" :
+  eval { require 5.005_03 } ? "5.5" :
+  die "Perl version $] is unsupported";
 }
 
 1;