You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tim Esselens <ti...@gmail.com> on 2005/07/20 20:09:10 UTC

[mp2] Apache2::Reload using runtime PerlResponseHandlers

Hi,

I was wondering if it's possible to reload a PerlInitHandler's code when a
PerlResponseHandler's code changes. I'm inserting PerlResponseHandlers at
runtime, but when it's code changes, the code reference set by the
PerlInitHandler is pointing to the wrong piece of code. Like this:


PerlInitHandler Dispatcher
--
package Dispatcher;
handler {
        #...
        if(my $coderef = $mod->can($sub)) {
            $r->set_handlers(PerlResponseHandler => $coderef);
        }
}
--

package X #($mod)
sub y #($sub) 
{
        print "hello world";
        return 0
}


If I change the "hello world" string, the module gets reloaded ok, but I
presume the $coderef is pointing to the wrong piece of code?
I've also tried:
if(my $coderef = eval { $mod->can($sub) }) { ... }
but with no difference.
--
kind regards,
Tim Esselens


Re: [mp2] Apache2::Reload using runtime PerlResponseHandlers

Posted by Tim Esselens <ti...@gmail.com>.
Philippe M. Chiasson wrote:

>> I was wondering if it's possible to reload a PerlInitHandler's code when
>> a PerlResponseHandler's code changes. I'm inserting PerlResponseHandlers
>> at runtime, but when it's code changes, the code reference set by the
>> PerlInitHandler is pointing to the wrong piece of code. Like this:
 
> Problem probably is because Apache2::Reload is also a PerlInitHandler and
> probably comes in and reloads the module _after_ your Dispatcher handler. 
> You could either try and swap the order of both InitHandlers or use a
> method name instead of a code ref.
> if ($mod->can($sub)) {
>   $r->set_handlers(PerlResponseHandler => join '::', $mod, $sub);
> }

The init handlers were in the right order, but your suggestion of using a
method name worked like a charm. Thanks!

--
kind regards,
Tim Esselens


Re: [mp2] Apache2::Reload using runtime PerlResponseHandlers

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Tim Esselens wrote:
> Hi,
> 
> I was wondering if it's possible to reload a PerlInitHandler's code when a
> PerlResponseHandler's code changes. I'm inserting PerlResponseHandlers at
> runtime, but when it's code changes, the code reference set by the
> PerlInitHandler is pointing to the wrong piece of code. Like this:

Problem probably is because Apache2::Reload is also a PerlInitHandler and
probably comes in and reloads the module _after_ your Dispatcher handler.

You could either try and swap the order of both InitHandlers or use a
method name instead of a code ref.

if ($mod->can($sub)) {
  $r->set_handlers(PerlResponseHandler => join '::', $mod, $sub);
}

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5