stas        2003/08/08 13:38:20

  Modified:    .        Changes
  Added:       lib/Apache porting.pm
  Log:
  new package Apache::porting to make it easier to port mp1 code to mp2
  
  Revision  Changes    Path
  1.1                  modperl-2.0/lib/Apache/porting.pm
  
  Index: porting.pm
  ===================================================================
  package Apache::porting;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Carp 'croak';
  
  use ModPerl::MethodLookup ();
  use Apache::ServerUtil;
  
  use Apache::Const -compile => 'OK';
  
  our $AUTOLOAD;
  
  ### methods ###
  # handle:
  # - removed and replaced methods
  # - hinting the package names in which methods reside
  
  my %avail_methods = map { $_ => 1 } 
      (ModPerl::MethodLookup::avail_methods(),
       ModPerl::MethodLookup::avail_methods_compat());
  
  # XXX: unfortunately it doesn't seem to be possible to install
  # *UNIVERSAL::AUTOLOAD at the server startup, httpd segfaults,
  # child_init seems to be the first stage where it works.
  Apache->server->push_handlers(PerlChildInitHandler => \&porting_autoload);
  
  sub porting_autoload {
      *UNIVERSAL::AUTOLOAD = sub {
          # This is a porting module, no compatibility layers are allowed in
          # this zone
          croak("Apache::porting can't be used with Apache::compat")
              if exists $ENV{"Apache/compat.pm"};
  
          (my $method = $AUTOLOAD) =~ s/.*:://;
  
          # we skip DESTROY methods
          return if $method eq 'DESTROY';
  
          # we don't handle methods that we don't know about
          croak "Undefined subroutine $AUTOLOAD called"
              unless defined $method && exists $avail_methods{$method};
  
          my ($hint, @modules) =
              ModPerl::MethodLookup::lookup_method($method, @_);
          $hint ||= "Can't find method $AUTOLOAD";
          croak $hint;
      };
  
      return Apache::OK;
  }
  
  ### packages ###
  # handle:
  # - removed and replaced packages
  
  my %packages = (
       'Apache::Constants' => [qw(Apache::Const)],
       'Apache::Table'     => [qw(APR::Table)],
       'Apache::File'      => [qw(Apache::Response Apache::RequestRec)],
       'Apache'            => [qw(ModPerl::Util Apache::Module)],
  );
  
  BEGIN {
      sub my_require {
          my $package = $_[0];
          $package =~ s|/|::|g;
          $package =~ s|.pm$||;
  
          # this picks the original require (which could be overriden
          # elsewhere, so we don't lose that) because we haven't
          # overriden it yet
          return require $_[0] unless $packages{$package};
  
          my $msg = "mod_perl 2.0 API doesn't include package '$package'.";
          my @replacements = @{ $packages{$package}||[] };
          if (@replacements) {
              $msg .= " The package '$package' has moved to " .
                  join " ", map qq/'$_'/, @replacements;
          }
          croak $msg;
      };
  
      *CORE::GLOBAL::require = sub (*) { my_require($_[0])};
  }
  
  1;
  
  
  
  1.206     +3 -0      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.205
  retrieving revision 1.206
  diff -u -r1.205 -r1.206
  --- Changes   7 Aug 2003 16:29:19 -0000       1.205
  +++ Changes   8 Aug 2003 20:38:20 -0000       1.206
  @@ -12,6 +12,9 @@
   
   =item 1.99_10-dev
   
  +new package Apache::porting to make it easier to port mp1 code to mp2
  +[Stas]
  +
   new Apache::Build methods: mpm_name(), mpm_is_threaded(). use them in
   the top-level Makefile.PL to require 5.8.0/ithreads if mpm requires
   threads. [Stas]
  
  
  

Reply via email to