You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Colin Wetherbee <cw...@denterprises.org> on 2007/06/27 22:25:58 UTC

[mp2] Apache2::Reload doesn't reload

It seems like I've tried everything, and I can't get Apache2::Reload to 
reload my modules.

I have a handler in a module called JetSet::Handler.  That module 
depends on a number of other modules, which I've tried to include with 
'use', with limited success.  It seems, sometimes, symbols act just fine 
and reload when they should, but other times, I have to restart Apache 
in order to get the symbols to reload.

I have run the Reload debugger, and it says everything is reloading just 
like it should.  But, I believe my problem is described in the 
Apache2::Reload documentation; Apache keeps the old function pointer 
around from the first 'use', even though the changed function now has a 
new pointer.

The Apache2::Reload documentation also says Registry (which I'm not 
actually explicitly using) doesn't play nicely with Exporter when 'use' 
is used, so I tried the 'require';'import()' method described in the 
documentation.  With this, I'm unable to import my symbols.  For example:

# In Handler.pm:
require JetSet::Debug; JetSet::Debug->import();
# ...
   JetSet::Debug::DebugLevel(JetSet::Debug::DEBUG_WARN);
# End

Where DEBUG_WARN is declared either by sub DEBUG_WARN() { 3 }; or with 
'use constant' in Debug.pm.  It is then exported in @EXPORT or 
@EXPORT_OK.  Any combination of these things gives the following error.

# From error_log:
failed to resolve handler `JetSet::Handler': Bareword 
"JetSet::Debug::DEBUG_WARN" not allowed while "strict subs" in use at 
/home/cww/sites/rain/htdocs/jet-set/JetSet/Handler.pm line 19.
# End

I read in the list archives that doing away with Exporter altogether 
might be the preferred way of dealing with this.  Implementing my 
modules as objects instead of exporting functions, it seems, might 
eliminate the not-exporting errors and make Reload work correctly:

http://www.gossamer-threads.com/lists/modperl/modperl/82283#82283

I'm not opposed to doing that, but in that case, how does one deal with 
things like constants?  Perhaps I would just have to keep all my 
constants in a single Exporter-style file and then restart Apache every 
time I change it?  Frankly, that sounds like a pretty lousy way to have 
to deal with this.

Here are some snippets that might help with the diagnosis.

# From my virtual host configuration:
   PerlRequire /home/cww/sites/rain/htdocs/perl-static/startup.pl
   PerlModule Apache2::Reload
   PerlInitHandler Apache2::Reload
   PerlSetVar ReloadDirectories "/home/cww/sites/rain/htdocs"
   <Location /jet-set>
     SetHandler perl-script
     PerlResponseHandler JetSet::Handler
   </Location>
# End

# startup.pl:
use lib qw(/home/cww/sites/rain/htdocs/jet-set);

1;
# End

# Apache2 version string:
Apache/2.2.3 (Debian) mod_ssl/2.2.3 OpenSSL/0.9.8e 
mod_apreq2-20051231/2.6.0 mod_perl/2.0.2 Perl/v5.8.8 Server at rain Port 80
# End

Thank you for your assistance.

Colin

Re: [mp2] Apache2::Reload doesn't reload

Posted by Perrin Harkins <pe...@elem.com>.
On 6/27/07, Colin Wetherbee <cw...@denterprises.org> wrote:
> I have a handler in a module called JetSet::Handler.  That module
> depends on a number of other modules, which I've tried to include with
> 'use', with limited success.  It seems, sometimes, symbols act just fine
> and reload when they should, but other times, I have to restart Apache
> in order to get the symbols to reload.

You have to understand, Perl has no support for reloading modules.
What Reload and similar modules do (clearing the symbol table and %INC
and loading the module again) usually works, but it's never going to
be work for 100% of all perl code because it's not an actual language
feature.

> # In Handler.pm:
> require JetSet::Debug; JetSet::Debug->import();
> # ...
>    JetSet::Debug::DebugLevel(JetSet::Debug::DEBUG_WARN);
> # End

Why import it at all if you're going to fully qualify it like that?
Is this your actual code?

> # From error_log:
> failed to resolve handler `JetSet::Handler': Bareword
> "JetSet::Debug::DEBUG_WARN" not allowed while "strict subs" in use at
> /home/cww/sites/rain/htdocs/jet-set/JetSet/Handler.pm line 19.

You can declare the sub names with the "use subs" pragma.  Adding
parentheses on the end of DEBUG_WARN might help too.

> I'm not opposed to doing that, but in that case, how does one deal with
> things like constants?

I think what you're really asking here is how do you handle
configuring your application.  There are many ways to do it.  I
usually end up having a configuration object of some kind, usually
implemented as a singleton.  And yes, I restart when I want to change
them.  It's fairly easy to implement a periodic check for changes in
your config file though, if you want to.  Things like Log4Perl have
this built in.

Or, if you really did mean constants, I put them in the files where
they are used, and never touch them, since they are... constants.

- Perrin

Re: [mp2] Apache2::Reload doesn't reload

Posted by Colin Wetherbee <cw...@denterprises.org>.
Jonathan Vanasco wrote:
> sub handler {
>     $page= myapp::Page->new();
>     $page->whatever;
> }

So, Page.pm defines an object... do you have Page.pm including other 
Exporter-style modules?  And, do those work properly?

Thanks.

Colin

Re: [mp2] Apache2::Reload doesn't reload

Posted by Jonathan Vanasco <jv...@2xlp.com>.
I've found Reload to work poorly on the handler sub -- i haven't been  
able to figure out why, but it just works poorly.

To get around that, I just have the handler call/wrap other subs.


package myapp;

sub handler {
	$page= myapp::Page->new();
	$page->whatever;
}


any changes go into myapp Page, or other modules.

i never have to worry about the reload issues on the handler.  pretty  
simple.







// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|   CEO/Founder SyndiClick Networks
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|     Founder/CTO/CVO
|      FindMeOn.com - The cure for Multiple Web Personality Disorder
|      Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|      RoadSound.com - Tools For Bands, Stuff For Fans
|      Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -