cvs commit: modperl/lib/Apache StatINC.pm

2001-06-14 Thread dougm

dougm   01/06/14 09:38:27

  Modified:.Changes ToDo
   lib/Apache StatINC.pm
  Log:
  make sure file to be reloaded can be found in @INC
  
  Revision  ChangesPath
  1.599 +4 -0  modperl/Changes
  
  Index: Changes
  ===
  RCS file: /home/cvs/modperl/Changes,v
  retrieving revision 1.598
  retrieving revision 1.599
  diff -u -r1.598 -r1.599
  --- Changes   2001/06/14 05:26:27 1.598
  +++ Changes   2001/06/14 16:38:15 1.599
  @@ -10,6 +10,10 @@
   
   =item 1.25_01-dev
   
  +make sure file to be reloaded can be found in @INC, adjusting based on
  +%INC value if needed
  +[Ilya Konstantinov [EMAIL PROTECTED]]
  +
   croak if the filehandle passed to $r-send_fd is NULL, otherwise
   apache will segfault
   
  
  
  
  1.284 +0 -2  modperl/ToDo
  
  Index: ToDo
  ===
  RCS file: /home/cvs/modperl/ToDo,v
  retrieving revision 1.283
  retrieving revision 1.284
  diff -u -r1.283 -r1.284
  --- ToDo  2001/06/14 16:14:58 1.283
  +++ ToDo  2001/06/14 16:38:18 1.284
  @@ -51,8 +51,6 @@
   
   - Apache::FakeRequest improvments [Gary Richardson [EMAIL PROTECTED]]
   
  -- Apache::StatINC patch [Ilya Konstantinov [EMAIL PROTECTED]]
  -
   - From: Dave Rolsky [EMAIL PROTECTED]
 Subject: Apache::test patch
   
  
  
  
  1.15  +26 -4 modperl/lib/Apache/StatINC.pm
  
  Index: StatINC.pm
  ===
  RCS file: /home/cvs/modperl/lib/Apache/StatINC.pm,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- StatINC.pm2000/03/07 02:50:38 1.14
  +++ StatINC.pm2001/06/14 16:38:24 1.15
  @@ -11,7 +11,7 @@
   $r-dir_config(UndefOnReload)) || '') eq on);
   my $DEBUG = ref($r)  (lc($r-dir_config(StatINCDebug) || '') eq on);
   $DEBUG = $r-dir_config(StatINC_Debug) if ref($r)  
$r-dir_config(StatINC_Debug);
  -
  +
   while(my($key,$file) = each %INC) {
local $^W = 0;
my $mtime = (stat $file)[9];
  @@ -20,16 +20,38 @@
unless(defined $Stat{$file}) { 
$Stat{$file} = $^T;
}
  +# if modified, reload the module
if($mtime  $Stat{$file}) {
  + # make sure file's prefix is in @INC
  + my $found_in_inc;
  + for (@INC) {
  +if(index($file,$_) == 0) {
  +   $found_in_inc = 1;
  +   last;
  +}
  + }
  +
  +if(!$found_in_inc) {
  +   my $inc_dir = substr($file, 0, length($file)-length($key)-1);
  +   push @INC, $inc_dir;
  +warn Apache::StatINC: process $$ adding $inc_dir to \@INC\n
  +   if $DEBUG  0;
  +}
  +
if($do_undef and $key =~ /\.pm$/) {
require Apache::Symbol;
my $class = Apache::Symbol::file2class($key);
$class-Apache::Symbol::undef_functions( undef, 1 );
}
delete $INC{$key};
  - require $key;
  - warn Apache::StatINC: process $$ reloading $key\n
  - if $DEBUG  0;
  + eval{ require $key };
  + if ($@) {
  +   warn Apache::StatINC: process $$ failed to reload $key. $@
  +  if $DEBUG  0;
  + } else {
  +warn Apache::StatINC: process $$ reloading $key.\n
  +  if $DEBUG  0;
  +}
}
$Stat{$file} = $mtime;
   }
  
  
  



Re: Apache::StatINC.pm

2000-03-28 Thread Oleg Bartunov

Sorry for a little off-thread.
What will happen if I use shared library
generated by SWIG when it's updated but
perl module, which is just a wrapper, doesn't
changed. Does Apache::StatINC.pm will take care ?
Do I need just 'touch' perl module.

regards,
Oleg
On Mon, 27 Mar 2000, Ask Bjoern Hansen wrote:

 Date: Mon, 27 Mar 2000 23:56:58 -0800 (PST)
 From: Ask Bjoern Hansen [EMAIL PROTECTED]
 To: "[iso-8859-1] René Seindal" [EMAIL PROTECTED]
 Cc: Ken Williams [EMAIL PROTECTED], [EMAIL PROTECTED]
 Subject: Re: Apache::StatINC.pm
 
 On Mon, 27 Mar 2000, Ask Bjoern Hansen wrote:
 
 [...]
   setting a variable with PerlSetVar would change it to what we have
   proposed.
  
  Or maybe it could try the other if the first doesn't work. (Except that
  might get very confusing.. hmn).
 
 Sorry about following up to my own message.
 
 Maybe the clued thing to do would be making our own "require" and add the
 functionality that is like doing a bare "do" of the old filename. (And
 change everything so it would end up doing both what you and Ken is
 proposing and the old thing.
 
 
  - ask
 
 -- 
 ask bjoern hansen - http://www.netcetera.dk/~ask/
 more than 70M impressions per day, http://valueclick.com
 

_
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: [EMAIL PROTECTED], http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83




Apache::StatINC.pm

2000-03-27 Thread René Seindal

I just got bitten by the problem of Apache::StatINC not reloading
modules found through an element of @INC, which is no longer present
when StatINC runs. This happens when a module adds a private directory
to @INC, which is then reset by mod_perl after the request is done.

This problem is mentioned in the mod_perl guide at
porting.html#Using_Apache_StatINC_for_the_De

If you load a module, say Data.om, from . then $INC{'Data.pm'} eq
'Data.pm', and StatINC won't be able to find it.  This is easily solved
with

use Cwd;
use lib Cwd::cwd;

which puts the current working directory in the path.  Make the obvious
adjustments if you use a subdirectory. Now the local modules will load
from $CWD (full path) and not from . (relative path), and %INC will hold
the absolute path name of locally found modules.

The next problem is that Apache::StatINC won't reload your modules
anyway.  StatINC scans %INC and stats all the files, and when one is out
of date, it does a require() on the module name. This fails, because the
directory of the module is no longer in the path. Yet StatINC knows the
filename, because it could do a stat on it.

A small change to StatINC solves the problem. Since StatINC could stat
the file, the file is accessible, only not through require(). The fix is
to change StatINC to load the file instead of the module, which is
achieved with this little patch (against 1.06 from mod_perl 1.21, but
nothing seems to have changed):

***
*** 25,32 
my $class = Apache::Symbol::file2class($key);
 $class-Apache::Symbol::undef_functions( undef, 1 );
}
!   delete $INC{$key};
!   require $key;
warn "Apache::StatINC: process $$ reloading $key\n"
  if $DEBUG;
}
--- 25,33 
my $class = Apache::Symbol::file2class($key);
 $class-Apache::Symbol::undef_functions( undef, 1 );
}
!   # delete $INC{$key};
!   # require $key;
!   do $INC{$key};
warn "Apache::StatINC: process $$ reloading $key\n"
  if $DEBUG;
}



Presumably one could do a 'do $file' as well, which would be a bit
faster.

-- 
René Seindal ([EMAIL PROTECTED])  http://www.seindal.dk/rene/



Re: Apache::StatINC.pm

2000-03-27 Thread Ken Williams

[EMAIL PROTECTED] (René Seindal) wrote:
I just got bitten by the problem of Apache::StatINC not reloading
modules found through an element of @INC, which is no longer present
when StatINC runs. 
[...]
A small change to StatINC solves the problem. Since StatINC could stat
the file, the file is accessible, only not through require(). The fix is
to change StatINC to load the file instead of the module, which is
achieved with this little patch (against 1.06 from mod_perl 1.21, but
nothing seems to have changed):

I've been in favor of this change for a long time.  I last suggested it here:

  http://forum.swarthmore.edu/epigone/modperl/stexlorblay
  
I'm still in favor, perhaps this time it will happen?  The only problem seems
to happen when people use relative pathnames to source files, which is a bad
idea under mod_perl anyway.






Re: Apache::StatINC.pm

2000-03-27 Thread René Seindal

Ken Williams wrote:
 
 [EMAIL PROTECTED] (René Seindal) wrote:
 I just got bitten by the problem of Apache::StatINC not reloading
 modules found through an element of @INC, which is no longer present
 when StatINC runs.
 [...]
 A small change to StatINC solves the problem. Since StatINC could stat
 the file, the file is accessible, only not through require(). The fix is
 to change StatINC to load the file instead of the module, which is
 achieved with this little patch (against 1.06 from mod_perl 1.21, but
 nothing seems to have changed):
 
 I've been in favor of this change for a long time.  I last suggested it here:
   http://forum.swarthmore.edu/epigone/modperl/stexlorblay
 I'm still in favor, perhaps this time it will happen?  The only problem seems
 to happen when people use relative pathnames to source files, which is a bad
 idea under mod_perl anyway.

If both ways cause problems, then the right solution is to leave it to
the user.  Apache::StatINC already uses dir_config() to adjust its
behaviour according to user preferences, so adding another configuration
variable can't be a problem.  Current behaviour would be the default and
setting a variable with PerlSetVar would change it to what we have
proposed.

I'll make a patch relative to the cvs version if there is any change
such a change would make it into the distribution.  It will inspect a
PerlSetVar parameter, and use require() or do() accordingly - couldn't
be simpler.

-- 
René Seindal ([EMAIL PROTECTED])  http://www.seindal.dk/rene/



Re: Apache::StatINC.pm

2000-03-27 Thread Ask Bjoern Hansen

On Tue, 28 Mar 2000, René Seindal wrote:

 If both ways cause problems, then the right solution is to leave it to
 the user.  Apache::StatINC already uses dir_config() to adjust its
 behaviour according to user preferences, so adding another configuration
 variable can't be a problem.  Current behaviour would be the default and
 setting a variable with PerlSetVar would change it to what we have
 proposed.

Or maybe it could try the other if the first doesn't work. (Except that
might get very confusing.. hmn).

 I'll make a patch relative to the cvs version if there is any change
 such a change would make it into the distribution.  It will inspect a
 PerlSetVar parameter, and use require() or do() accordingly - couldn't
 be simpler.

Sure, that we can certainly put in the distribution.

Your patch should check the return value of "do".

I also believe it would be needed to populate $INC{} (or make sure it
doesn't get deleted), right?


 - ask

-- 
ask bjoern hansen - http://www.netcetera.dk/~ask/
more than 70M impressions per day, http://valueclick.com




Re: Apache::StatINC.pm

2000-03-27 Thread Ask Bjoern Hansen

On Mon, 27 Mar 2000, Ask Bjoern Hansen wrote:

[...]
  setting a variable with PerlSetVar would change it to what we have
  proposed.
 
 Or maybe it could try the other if the first doesn't work. (Except that
 might get very confusing.. hmn).

Sorry about following up to my own message.

Maybe the clued thing to do would be making our own "require" and add the
functionality that is like doing a bare "do" of the old filename. (And
change everything so it would end up doing both what you and Ken is
proposing and the old thing.


 - ask

-- 
ask bjoern hansen - http://www.netcetera.dk/~ask/
more than 70M impressions per day, http://valueclick.com