>>>>> "Stas" == Stas Bekman <[EMAIL PROTECTED]> writes:
Stas> Apache::StatINC is perfect for development stage, if you need the same
Stas> behavior for just a few files on production server, see:
Stas> http://perl.apache.org/guide/porting.html#Reloading_Modules_and_Required_F
I don't know if this is in your guide, but I stopped using StatINC a
while ago when it kept stat'ing all over creation for every request,
and then never quite got the re-import right.
Instead, any module that I'm likely to change during the current server
restart, I add this:
sub handler { # the beginning of the request
use Stonehenge::Reload; goto &handler if Stonehenge::Reload->reload_me;
...
}
When I'm finally done tweaking the module, I remove the line, and it
reloads one last time, never to watch the file again.
Here's Stonehenge::Reload:
package Stonehenge::Reload;
use vars qw($VERSION);
$VERSION = (qw$Revision: 1.1 $ )[-1];
use Apache::Log;
my %mtime;
sub reload_me {
goto &reload_me if &_reload_caller; # test myself first
goto &_reload_caller; # now test for caller
}
sub _reload_caller {
my $file = (caller)[1];
## Apache->server->log->notice("$$ is testing $file with $mtime{$file}");
return 0 if exists $mtime{$file} and $mtime{$file} == -M $file;
## Apache->server->log->notice("$$ is recompiling $file");
delete @INC{grep $INC{$_} eq $file, keys %INC};
my $old = \&{(caller(1))[3]};
do $file;
my $new = \&{(caller(1))[3]};
## Apache->server->log->notice("$$ got $old => $new for $file");
return 0 if $old == $new; # safety
$mtime{$file} = -M $file;
return 1;
}
sub import {
my $file = (caller)[1];
## Apache->server->log->notice("$$ is importing ",__PACKAGE__," into $file");
$mtime{$file} = -M $file;
}
BEGIN {
__PACKAGE__->import; # for self reload watching
};
1;
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!