Hi,
I'm using following patch with mod_perl2 in my developing environment.
This might be helpful for others, but I'm not sure this will break
something in the environment with another configuration.
(1) With prefork MPM, fixup %INC variable to be stored as absolute
path after eval(). This cannot work if script changes its working
directory, but will work fine in most situation (should do
chdir_file() before this?)
(2) In Apache2::Reload, adding module path saved in %INC to @INC
before reloading. This allows reloading modules with related path
"use lib".
(3) Try to delete from package namespace in
ModPerl::Util::unload_package_pp() in addition to undef'ing it.
This will reduce "Subroutine xxx redefine" warnings in some
situation.
How do you think about this?
Index: xs/ModPerl/Util/Util_pm
===================================================================
--- xs/ModPerl/Util/Util_pm (revision 327784)
+++ xs/ModPerl/Util/Util_pm (working copy)
@@ -51,6 +51,8 @@
close $fullname;
}
}
+ eval { delete $tab->{$_}; };
+ if ($@) { warn "eval(delete) failed: $@" }
}
#Wipe from %INC
Index: lib/Apache2/Reload.pm
===================================================================
--- lib/Apache2/Reload.pm (revision 327784)
+++ lib/Apache2/Reload.pm (working copy)
@@ -157,6 +157,10 @@
if ($mtime > $Stat{$file}) {
my $package = module_to_package($key);
ModPerl::Util::unload_package($package);
+ (my $path = $key) =~ s|::|/|g;
+ (my $dir = $file) =~ s|/${path}$||;
+ local @INC;
+ push @INC, $dir;
require $key;
warn("Apache2::Reload: process $$ reloading $package from $key\n")
if $DEBUG;
Index: ModPerl-Registry/lib/ModPerl/Registry.pm
===================================================================
--- ModPerl-Registry/lib/ModPerl/Registry.pm (revision 327784)
+++ ModPerl-Registry/lib/ModPerl/Registry.pm (working copy)
@@ -58,6 +58,7 @@
error_check => 'error_check',
strip_end_data_segment => 'strip_end_data_segment',
convert_script_to_compiled_handler => 'convert_script_to_compiled_handler',
+ fixup_lib => 'fixup_lib',
);
# in this module, all the methods are inherited from the same parent
Index: ModPerl-Registry/lib/ModPerl/RegistryCooker.pm
===================================================================
--- ModPerl-Registry/lib/ModPerl/RegistryCooker.pm (revision 327784)
+++ ModPerl-Registry/lib/ModPerl/RegistryCooker.pm (working copy)
@@ -40,6 +40,7 @@
use ModPerl::Util ();
use ModPerl::Global ();
+use Cwd ();
use File::Spec::Functions ();
use File::Basename ();
@@ -406,6 +407,8 @@
return $rc unless $rc == Apache2::Const::OK;
$self->debug(qq{compiled package \"$self->{PACKAGE}\"}) if DEBUG & D_NOISE;
+ $self->fixup_lib;
+
$self->chdir_file(Apache2::ServerUtil::server_root());
# if(my $opt = $r->dir_config("PerlRunOnce")) {
@@ -789,5 +792,20 @@
}
+#########################################################################
+sub fixup_lib { }
+
+# func: fixup_lib_normal
+# desc: fixup %LIB contents to use absolute path.
+#
+# At this time, only RegistryPrefork.pm awares about CWD.
+# This fixup depends on working directory.
+sub fixup_lib_normal {
+ my ($self) = @_;
+ foreach (grep { $INC{$_} !~ /^\// } keys %INC) {
+ $INC{$_} = Cwd::realpath("$base/$INC{$_}");
+ }
+}
+
1;
__END__
Index: ModPerl-Registry/lib/ModPerl/RegistryPrefork.pm
===================================================================
--- ModPerl-Registry/lib/ModPerl/RegistryPrefork.pm (revision 327784)
+++ ModPerl-Registry/lib/ModPerl/RegistryPrefork.pm (working copy)
@@ -21,5 +21,7 @@
*chdir_file = \&ModPerl::RegistryCooker::chdir_file_normal;
+*fixup_lib = \&ModPerl::RegistryCooker::fixup_lib_normal;
+
1;
__END__
--
Jun Kuriyama <[EMAIL PROTECTED]> // IMG SRC, Inc.
<[EMAIL PROTECTED]> // FreeBSD Project
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]