in reply to Redefining Exported Subroutines (esp. in mod_perl/mason)
Problem: Changes to modules aren't seen by mod_perl / mason / apache without an explicit 'apacheclt restart'
Solution First see Apache::Reload.
This will solve most cases, except for certain exporting
issues. use My::Module qw(testsub); still
seems to be using the old version of testsub().
Rewrite the above line to read. use My::Module; My::Module->import(qw(testsub)); which in conjunction with Apache::Reload should fix the problem. All scripts/pages should now see the new subroutine.
---- My::Module.pm ----
---- test.pl ----package My::Module; BEGIN { use Exporter (); use vars qw(@ISA @EXPORT @EXPORT_OK); @ISA = qw(Exporter); @EXPORT = qw(); @EXPORT_OK = qw(testsub); } use strict; use Apache::Reload; sub testsub { return "module subroutine"; } 1;
---- mason enabled index.html file ----#!/usr/bin/perl use My::Module; My::Module->import(qw(testsub)); print testsub(), "\n"; sub testsub { # "local" definition of subroutine return "local subroutine"; }
---- stuff in httpd.conf ----<% $txt %> <%INIT> use My::Module; My::Module->import(qw(testsub)); my $txt = testsub(); </%INIT>
---- stuff in startup.pl ----PerlInitHandler Apache::Reload PerlSetVar ReloadAll Off
Thanks to all who replied, especially tilly.use Apache::Reload;
-Blake
|
|---|