I started using a dynamic @INC (set up in a TransHandler), and discovered
that Apache::Reload (v0.07) was not doing its job correctly in that case.
Note, changing @INC in a transhandler won't have the desired Apache::Reload
effects unless the PerlInitHandler for Apache::Reload is placed in a
<Location> section of httpd.conf.

The following patch corrects this, though it adds a few extra stat() calls
if the module is found at the end of @INC instead of near the beginning (as
mine are).  You could make this behavior an optional one for strange folks
like me :).  Oh, I just added that to the patch manually:

   PerlSetVar ReloadDynamicInc 1

...will enable this @INC-scanning behavior.  I think I hacked the patch
correctly :)

Note, if a module is loaded with one @INC, then on a subsequent request,
@INC changes such that the module would be not-found, the module is not
removed from memory.  If you do that and use it from a script (served when
@INC doesn't have the module), you'll get erratic behavior - it'll work fine
sometimes and error out other times.  "So don't do that.", as a wise man
said.  Instead, make sure @INC always has the right libs for your script -
test from a freshly-started server to be sure.

Separate from this strange Dynamic-@INC use case, there's another bug in the
release version of the module: if you moved a module from one @INC dir to
another, the @INC loop at the top of handler() would not find the file, as
it was looking for <inc-dir>/<full-path-name> instead of
<inc-dir>/<relative-path-name>.  This patch should fix this too, whether
ReloadDynamicInc is used or not.

I haven't tested this with wildcard settings or ReloadAll.

Enjoy,

Randy


--- Reload.pm   Sat Oct 12 16:22:02 2002
+++ Reload.pm.new       Sat Oct 12 17:08:07 2002
@@ -108,35 +108,40 @@

     while (my($key, $file) = each %Apache::Reload::INCS) {
         local $^W;
         warn "Apache::Reload: Checking mtime of $key\n" if $DEBUG;

         my $mtime = (stat $file)[9];

-        unless (defined($mtime) && $mtime) {
-            for (@INC) {
-                $mtime = (stat "$_/$file")[9];
-                last if defined($mtime) && $mtime;
-            }
-        }
+
+        my $found = $file;
+        if( $r->dir_config("ReloadDynamicInc") || !$mtime ) {
+            # seek out the file in @INC.
+            my $mt;
+            for (@INC) {
+                $mt = (stat "$_/$key")[9];
+                $mtime = $mt, $found = "$_/$key", last if defined($mt) &&
$mt;
+            }
+        }
+
         warn("Apache::Reload: Can't locate $file\n"),next
                 unless defined $mtime and $mtime;

         unless (defined $Stat{$file}) {
             $Stat{$file} = $^T;
         }

-        if ($mtime > $Stat{$file}) {
+        if( $found ne $file || $mtime > $Stat{$file} ) {
             delete $INC{$key};
             if (my $symref = $UndefFields{$key}) {
 #                warn "undeffing fields\n";
                 no strict 'refs';
                 undef %{$symref};

Reply via email to