Phoenix Rising has asked for the wisdom of the Perl Monks concerning the following question:

I am experiencing a rather annoying problem with our mod_perl based application. We are in a heavy development period, and it seems Apache::Reload isn't always reloading our modules. Sometimes it does, sometimes it doesn't, apparently dependent on which httpd process handles your request. We are using the standard implicit method of defining Reload modules. All httpd.conf perl options as follows:
PerlOptions +Parent PerlSwitches -I /prog/v060111/web/perllib PerlRequire /prog/v060111/web/perllib/startup.pl PerlInitHandler Apache::Reload PerlSetVar ReloadAll Off
We then load mod_perl and Apache::Reload with Module::Load::Conditional's can_load() call (for single code-base mod_perl/mod_perl2 support):
use Module::Load::Conditional qw(can_load check_install requires); if (can_load(modules=> {'mod_perl'=>undef})) { # other mod_perl loads omitted for brevity can_load(modules=> {'Apache::Reload'=>undef})); }
Any ideas as to why this works sporadically? Is Module::Load::Conditional actually doing enough work to simulate a 'use Apache::Reload'?

Replies are listed 'Best First'.
Re: Odd Apache::Reload failure
by perrin (Chancellor) on Jun 05, 2008 at 20:14 UTC
    What's the behavior you see when it doesn't work, i.e. how can you tell?

    UPDATE:

    I think I see the problem. Your code has to call Apache::Reload::import(), which normally happens when you use a module but not when you do it via Module::Load::Conditional::can_load(). Test this by replacing that line with a normal "use Apache::Reload".

      That looks like it'll do it! I didn't think of it because I'm not importing any methods from the package, but Apache::Reload uses import() to call register_module(). Well, testing explicit Reload now. If it works, I may just do away with the implicit Reloads. If not, then I'll be inserting a lot of import() calls into modules!
        This, by the way, is another example of why I think using import() for things other than importing is a bad idea. If the docs had said you must call Apache::Reload::register_module() instead of doing it for you magically when you use Apache::Reload, you wouldn't have wondered why it wasn't working.