I received the below request a while back for being able to reload modules in updated PAR files under Apache::PAR. I believe I've come up with a way of accommodating this, although it requires a change to PAR along with Apache::PAR. Below is a patch against PAR 0.73 which allows modules which have been required via PAR to be reloaded.
I'm afraid the approach may be naive, as for the most part I've avoided looking at the internals of PAR altogether (always figured it was better to keep it as a "black box" to avoid using unpublished interfaces.) However, with this change (and a change in Apache::PAR) I am able to make changes to modules in PAR files on disk and have them reload correctly. If possible, could you please look at this patch for possible inclusion in PAR? Also, let me know if you want pod for the change as I wasn't sure whether you would want to advertise it as available or not. If you have any questions, please let me know.
Thanks,
Nathan Byrd
--- PAR.pm.orig Wed Aug 06 17:08:44 2003 +++ PAR.pm Sun Aug 10 21:02:24 2003 @@ -136,7 +136,7 @@ =cut
use vars qw(@PAR_INC); # explicitly stated PAR library files
-use vars qw(@LibCache %LibCache); # I really miss pseudohash.
+use vars qw(@LibCache %LibCache %ModulesReqd); # I really miss pseudohash.
my $ver = $Config::Config{version};
my $arch = $Config::Config{archname};
@@ -225,10 +225,36 @@
$scheme = $path;
}
my $rv = unpar($path, $file, $member_only, 1);
- return $rv if defined($rv);
+ if(defined($rv)) {
+ push(@{$ModulesReqd{$path}}, $file);
+ return $rv;
+ }
} return;
+}
+
+sub get_modules_for_zip {
+ my $zipfile = shift;
+ if(exists($ModulesReqd{$zipfile})) {
+ return (@{$ModulesReqd{$zipfile}});
+ }
+ else {
+ return ();
+ }
+}
+
+sub reload_modules {
+ my $zipfile = shift;
+ my @reload_list = get_modules_for_zip($zipfile);
+
+ delete $LibCache{$zipfile};
+ if(@reload_list) {
+ foreach (@reload_list) {
+ delete $INC{$_};
+ require $_;
+ }
+ }
}sub read_file {
-------- Original Message -------- Subject: Reload changed .par files Date: Fri, 25 Jul 2003 12:36:40 +0000 From: <[EMAIL PROTECTED]> To: [EMAIL PROTECTED]
Hi Nathan,
Just a quick question, is there a way to get Apache::Reload to work with Apache::PAR? I've upgraded to Apache2 (2.0.46) and mod_perl1_99_10, added PerlInitHandler Apache::Reload to my conf, and got everything working OK with Apache::PAR on startup. However, if I make a change to any of my PAR'd .pm files all I get back from Apache::Reload is
Apache::Reload: Can't locate CODE(0x1bf7b2c)
I added a smaller handler to Apache::PAR (and changed the conf to reflect this) to re-import any changed par files, and managed to get it to work properly with .pl files, but, alas, I can't seem to reload any .pm files at all (it recognises that they have changed, but doesn't reload them despite the re-import).
This is a problem that's really slowing down development - Apache2/mod_perl2 is taking up to 5 minutes to shutdown/restart.
I've done quite a bit of googling, but to no avail.
Regards,
Raymond
----------------------------------------- Email provided by http://www.ntlhome.com/
