Return-Path: Delivered-To: apmail-perl-dev-archive@www.apache.org Received: (qmail 35746 invoked from network); 23 Oct 2005 13:12:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Oct 2005 13:12:37 -0000 Received: (qmail 78662 invoked by uid 500); 23 Oct 2005 13:12:37 -0000 Delivered-To: apmail-perl-dev-archive@perl.apache.org Received: (qmail 78645 invoked by uid 500); 23 Oct 2005 13:12:36 -0000 Mailing-List: contact dev-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list dev@perl.apache.org Received: (qmail 78634 invoked by uid 99); 23 Oct 2005 13:12:36 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Oct 2005 06:12:36 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [210.226.20.147] (HELO black.imgsrc.co.jp) (210.226.20.147) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Oct 2005 06:12:34 -0700 Received: from localhost (localhost [127.0.0.1]) by black.imgsrc.co.jp (Postfix) with ESMTP id 55EA350D64 for ; Sun, 23 Oct 2005 22:12:14 +0900 (JST) Received: from pink.imgsrc.co.jp (unknown [IPv6:2001:218:422:1::36]) by black.imgsrc.co.jp (Postfix) with ESMTP id BE3F750D57 for ; Sun, 23 Oct 2005 22:12:12 +0900 (JST) Date: Sun, 23 Oct 2005 22:12:12 +0900 Message-ID: <7mk6g4pec3.wl%kuriyama@imgsrc.co.jp> From: Jun Kuriyama To: dev@perl.apache.org Subject: Possible improvements for module reloading User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.7 (=?ISO-8859-4?Q?Sanj=F2?=) APEL/10.6 Emacs/21.3 (i386--freebsd) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd 0.1 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 // IMG SRC, Inc. // FreeBSD Project --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org For additional commands, e-mail: dev-help@perl.apache.org