Notice that its purpose is to assist the porting process, not provide the backcompatibility layer, so it dies every time it has to say something.
I'm considering to put it into the core, next to Apache/compat.pm.
You just need to load it at the server startup, and it installs UNIVERSAL::AUTOLOAD at the child_init phase. Please give it a try (you need the latest cvs to use it):
--- /dev/null 1969-12-31 16:00:00.000000000 -0800
+++ lib/Apache/porting.pm 2003-08-07 22:19:08.000000000 -0700
@@ -0,0 +1,49 @@
+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;
+
+my %avail_methods = map { $_ => 1 }
+ (ModPerl::MethodLookup::avail_methods(),
+ ModPerl::MethodLookup::avail_methods_compat());
+
+# 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;
+}
+
+1;I'm also trying to handle the mp1 core packages that are no longer exist, by overriding CORE::require, but I'm stuck at not being able to do 'goto &CORE::require', since in pure perl you can't reference core functions (at least I couldn't figure out how to do that) :( Any idea how to resolve that?
### handling removed 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 {
# in case someone has already overriden require respect that
# my $sub = *CORE::GLOBAL::require{CODE} || *CORE::require{CODE};
# my $sub = \&CORE::GLOBAL::require || \&CORE::require{CODE};
#my $sub = \&CORE::require;
*CORE::GLOBAL::require = sub {
#die "require called with @_"; my $package = $_[0];
$package =~ s|/|::|g;
$package =~ s|.pm$||; if ($packages{$package}) {
my $msg = "mod_perl 2.0 API doesn't include package '$package'.";
my @replacements = @{ $packages{$package}||[] };
if (@replacements) {
$msg .= "'$package' has moved to " .
join " ", map qq/'$_'/, @replacements;
}
croak $msg;
}
else {
my ($package, $filename, $line) = caller;
# call the original function
CORE::require(@_);
#eval "package $package; CORE::require(@_)";
#goto &$sub;
#$sub->(@_);
}
};
}
__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
