Re: RFC: Apache::Reload

2000-08-16 Thread Ask Bjoern Hansen

On Fri, 11 Aug 2000, Matt Sergeant wrote:

 sub handler {
   my $r = shift;
   my $do_undef = ref($r)  
   (lc($r-dir_config("UndefOnReload") || '') eq
 'on');

Would be neat to have this as an import parameter.

I don't know why I never got it into StatINC, but I've changed that
to have a parameter for what files to reload and other things like
that. It would make a lot of sense to merge your reload and StatINC
I think, with an on/off switch for "old StatINC behavior", possibly
invoked by loading Apache::StatINC (which would load
Apache::Reload).

It should be called Apache::Reload and be distributed in the
mod_perl package, IMO.


 - ask

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




Re: RFC: Apache::Reload

2000-08-16 Thread Matt Sergeant

On Tue, 15 Aug 2000, Ask Bjoern Hansen wrote:

 On Fri, 11 Aug 2000, Matt Sergeant wrote:
 
  sub handler {
  my $r = shift;
  my $do_undef = ref($r)  
  (lc($r-dir_config("UndefOnReload") || '') eq
  'on');
 
 Would be neat to have this as an import parameter.

I've removed it from 0.02, apparently its unnecessary.

 I don't know why I never got it into StatINC, but I've changed that
 to have a parameter for what files to reload and other things like
 that. It would make a lot of sense to merge your reload and StatINC
 I think, with an on/off switch for "old StatINC behavior", possibly
 invoked by loading Apache::StatINC (which would load
 Apache::Reload).

See 0.02, its now a fully fledged StatINC replacement along with the new
functionality.

-- 
Matt/

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org




Re: RFC: Apache::Reload

2000-08-12 Thread Matt Sergeant

On Fri, 11 Aug 2000, Ken Williams wrote:

 Hi Matt,
 
 Is it possible that this functionality should be integrated into
 Apache::StatInc?  Perhaps with a couple of new directives to control
 behavior?

Thats a difficult one... Of course its possible to do, but is it
sensible? It would basically make StatINC a two-mode module. In one mode
it stats @INC, like its name suggests, and in another it only stats
modules that have use()'d it. I would have thought Apache::Reload would
then be a better name for it, overall. I also don't think these two bits
of functionality need to be in the same module, although they do use parts
of the same op code tree. I'd like to hear a bit more discussion about it
before I go about patching StatINC.pm

I know they're busy, but if the main mod_perl maintainers have anything to
add, I'd be very interested.

-- 
Matt/

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org




Re: RFC: Apache::Reload

2000-08-12 Thread Ken Williams

Matt Sergeant's message:

On Fri, 11 Aug 2000, Ken Williams wrote:

 Hi Matt,
 
 Is it possible that this functionality should be integrated into
 Apache::StatInc?  Perhaps with a couple of new directives to control
 behavior?

Thats a difficult one... Of course its possible to do, but is it
sensible? It would basically make StatINC a two-mode module. In one mode
it stats @INC, like its name suggests, and in another it only stats
modules that have use()'d it. I would have thought Apache::Reload would
then be a better name for it, overall.

That seems right - so perhaps it would be better to integrate the
StatINC functionality into Apache::Reload than the other way around.
If it's called Apache::Reload, then it might make sense to have a
directive like 'ReloadMode' that could be set to 'INC' to emulate
StatINC's behavior, or to 'Files' to explicitly name the files you
want checked with every request, or to 'Slave' (perhaps a bad choice)
to only check those files that do the "use Apache::Reload" thingy
you've written.

'Files' and 'INC' wouldn't be very different in implementation, but
'Files' gives you finer-grained control.  They both just take a list
of files and check them with every request.

One nice thing about this approach is that you could set the
ReloadMode differently for different URI files/directories in
httpd.conf, so you wouldn't have to shotgun your entire site when you
just need to test one little thing in your private area.

It might be nice to have only one [main] module for reloading changed
code files, both because of memespace issues and because the actual
reloading task seems to be a tricky one, and it would be nice to only
have to get it right once.  But if it doesn't make sense to combine
the approaches into one module, it doesn't make sense.


-Ken Williams
 The Math Forum
 [EMAIL PROTECTED]



Re: RFC: Apache::Reload

2000-08-12 Thread Ken Williams

Matt Sergeant's message:

On Sat, 12 Aug 100, Ken Williams wrote:

 That seems right - so perhaps it would be better to integrate the
 StatINC functionality into Apache::Reload than the other way around.
 If it's called Apache::Reload, then it might make sense to have a
 directive like 'ReloadMode' that could be set to 'INC' to emulate
 StatINC's behavior, or to 'Files' to explicitly name the files you
 want checked with every request, or to 'Slave' (perhaps a bad choice)
 to only check those files that do the "use Apache::Reload" thingy
 you've written.

Apart from the name "Slave" I think its right on the money :)

I think Required or Imported would be better.


Perhaps 'Import'?  Sounds more like a mode name to me than 'Imported'.
Or 'Register'?


-Ken Williams
 The Math Forum
 [EMAIL PROTECTED]



Re: RFC: Apache::Reload

2000-08-12 Thread Leslie Mikesell

According to Matt Sergeant:
 
 package Apache::Reload;

What I've always wanted along these lines is the ability
to load something in the parent process that would take
a list of directories where modules are always checked
and reloaded (for your local frequently changed scripts)
plus one filename that is checked every time and if it
has been touched then do the full StatINC procedure.  This
would keep the number of stat's down to a reasonable number
for production and still let you notify the server when
you have updated the infrequently changed modules.

  Les Mikesell
   [EMAIL PROTECTED]



Re: RFC: Apache::Reload

2000-08-12 Thread Matt Sergeant

On Sat, 12 Aug 2000, Leslie Mikesell wrote:

 According to Matt Sergeant:
  
  package Apache::Reload;
 
 What I've always wanted along these lines is the ability
 to load something in the parent process that would take
 a list of directories where modules are always checked
 and reloaded (for your local frequently changed scripts)

Right, Ken's list of reloaded files. Plus an option for a directory...

 plus one filename that is checked every time and if it
 has been touched then do the full StatINC procedure.  This
 would keep the number of stat's down to a reasonable number
 for production and still let you notify the server when
 you have updated the infrequently changed modules.

Thats an interesting idea. I'll look into it.

-- 
Matt/

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org




Re: RFC: Apache::Reload

2000-08-12 Thread Michael Robinton

On Sat, 12 Aug 2000, Leslie Mikesell wrote:

 According to Matt Sergeant:
  
  package Apache::Reload;
 
 What I've always wanted along these lines is the ability
 to load something in the parent process that would take
 a list of directories where modules are always checked
 and reloaded (for your local frequently changed scripts)
 plus one filename that is checked every time and if it


I use this simple library module. It is called from the beginning of the 
first script encountered in a set of scripts. This substitutes for a 
require statement for the corresponding modules.


Call as:

unshift @INC, './lib';
require 'LibChk.pl';
LibChk::Install (# check libraries for currency
'WhoisLib.pl',
'SocksLib.pl',
'DomRegLib.pl',
);




library:

#!/usr/bin/perl
#
# LibChk.pl
#
# version 1.01 6-16-00
# copyright Michael Robinton [EMAIL PROTECTED]
#
#   WARNING!! httpd must be 'HUP'ed if this library is modified
#
# check for library changes and load if necessary or not present
#
package LibChk;
use vars qw ( %Modified );  # library modification times

# Input:list of libraries (path must be in @INC)
sub Install {
  foreach my $i (@_) {
if ( ! exists $Modified{$i} ||  # if undefined time
 ! exists $INC{$i} ||   # missing
 $Modified{$i} != (stat "./$INC{$i}" )[9] ) {   # or changed
  delete $INC{$i} if defined $INC{$i};
  require $i;
  $Modified{$i} = (stat "./$INC{$i}" )[9];
}
  }
}
1;



Re: RFC: Apache::Reload

2000-08-12 Thread Matt Sergeant

On Sat, 12 Aug 100, Ken Williams wrote:

 That seems right - so perhaps it would be better to integrate the
 StatINC functionality into Apache::Reload than the other way around.
 If it's called Apache::Reload, then it might make sense to have a
 directive like 'ReloadMode' that could be set to 'INC' to emulate
 StatINC's behavior, or to 'Files' to explicitly name the files you
 want checked with every request, or to 'Slave' (perhaps a bad choice)
 to only check those files that do the "use Apache::Reload" thingy
 you've written.

Apart from the name "Slave" I think its right on the money :)

I think Required or Imported would be better.

 'Files' and 'INC' wouldn't be very different in implementation, but
 'Files' gives you finer-grained control.  They both just take a list
 of files and check them with every request.

There is some trickiness to it, such as you want to "do" a file, but
"require" a module (%INC gives you modules (and files) whereas Files mode
you'd probably just specify a bunch of files to stat).

 It might be nice to have only one [main] module for reloading changed
 code files, both because of memespace issues and because the actual
 reloading task seems to be a tricky one, and it would be nice to only
 have to get it right once.  But if it doesn't make sense to combine
 the approaches into one module, it doesn't make sense.

One issue that will always remain is the legacy of StatINC...

But this gives me something fun to hack on after I walk the dogs today :)

-- 
Matt/

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org




RFC: Apache::Reload

2000-08-11 Thread Matt Sergeant

This dates back to discussions nearly a year ago now, from Randal's
initial Stonehenge::Reload, and Doug saying he'd like to see a more
generic Apache::Reload that got rid of the necessity to call reload_me in
your own code... Anyway, I needed this facility too, since I wanted
modules to be able to just "use Apache::Reload" and have them reloaded,
without having to call something myself in some sort of
handler() function, because 90% of my modules don't use a handler() entry
point... So I came up with Apache::Reload based mostly on Apache::StatINC
and partly on Stonehenge::Reload, here's the code, comments welcome:

package Apache::Reload;

use strict;

$Apache::Reload::VERSION = '0.01';

my %Stat; # = ($INC{"Apache/Reload.pm"} = time);
my %INCS;

sub import {
my $class = shift;
my ($package,$file) = (caller)[0,1];
$package =~ s/::/\//g;
$package .= ".pm";

warn "Apache::Reload: $package loaded me\n";

if (grep /^off$/, @_) {
delete $INCS{$package};
}
else {
$INCS{$package} = $file;
}
}

sub handler {
my $r = shift;
my $do_undef = ref($r)  
(lc($r-dir_config("UndefOnReload") || '') eq
'on');

my $DEBUG = ref($r)  (lc($r-dir_config("ReloadDebug") || '') eq
'on');

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

my $mtime = (stat $file)[9];
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 ($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::Reload: process $$ reloading
$key\n")
if $DEBUG;
}
$Stat{$file} = $mtime;
}

return 1;
}

1;
__END__

=head1 NAME

Apache::Reload - Reload this module on each request (if modified)

=head1 SYNOPSIS

In httpd.conf:

  PerlInitHandler Apache::StatINC

Then your module:

  package My::Apache::Module;

  use Apache::Reload;
  
  sub handler { ... }
  
  1;

=head1 DESCRIPTION

This module is an adaptation of Randall Schwartz's Stonehenge::Reload
module that attempts to be a little more intuitive and makes the usage
easier. Like Apache::StatINC it must be installed as an Init Handler,
but unlike StatINC it must also be used by the module you want reloading.

If you want to temporarily turn off reloading of a module (which is 
slightly problematic since it won't happen until the next hit on the
same server because of the way this thing works) you can use the 'off'
option:

  use Apache::Reload 'off';

Obviously you wouldn't do that generally, but it can be useful if you 
intend to make large changes to a particular module.

=head1 AUTHOR

Matt Sergeant, [EMAIL PROTECTED]

=head1 SEE ALSO

Apache::StatINC, Stonehenge::Reload

=cut


-- 
Matt/

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org




Re: RFC: Apache::Reload

2000-08-11 Thread Matt Sergeant

On Fri, 11 Aug 2000, Matt Sergeant wrote:

 This dates back to discussions nearly a year ago now, from Randal's
 initial Stonehenge::Reload, and Doug saying he'd like to see a more
 generic Apache::Reload that got rid of the necessity to call reload_me in
 your own code... Anyway, I needed this facility too, since I wanted
 modules to be able to just "use Apache::Reload" and have them reloaded,
 without having to call something myself in some sort of
 handler() function, because 90% of my modules don't use a handler() entry
 point... So I came up with Apache::Reload based mostly on Apache::StatINC
 and partly on Stonehenge::Reload, here's the code, comments welcome:

I'm going to take a lack of negative replies as positive... I'll upload to
CPAN later.

-- 
Matt/

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org




Re: RFC: Apache::Reload

2000-08-11 Thread Ken Williams

[EMAIL PROTECTED] (Matt Sergeant) wrote:
On Fri, 11 Aug 2000, Matt Sergeant wrote:
 This dates back to discussions nearly a year ago now, from Randal's
 initial Stonehenge::Reload, and Doug saying he'd like to see a more
 generic Apache::Reload that got rid of the necessity to call reload_me in
 your own code... Anyway, I needed this facility too, since I wanted
 modules to be able to just "use Apache::Reload" and have them reloaded,
 without having to call something myself in some sort of
 handler() function, because 90% of my modules don't use a handler() entry
 point... So I came up with Apache::Reload based mostly on Apache::StatINC
 and partly on Stonehenge::Reload, here's the code, comments welcome:

I'm going to take a lack of negative replies as positive... I'll upload to
CPAN later.

Hi Matt,

Is it possible that this functionality should be integrated into
Apache::StatInc?  Perhaps with a couple of new directives to control
behavior?

That would be preferable to starting a new module, I think.