in reply to Overloading subs = weirdness in mod_perl

when I modify the parameter it appears my scalar reference suddenly maps back to overloaded sub instead of the original, thus creating an infinate self referencing call

I am taking an educated guess, but I think this is because mod_perl runs your code in a persistent environment. It does not "restart" each time. Once you override the WSC::Image::list_images subroutine, it stays like that. Then the next time your code is called, you take a new reference to that subroutine, which is still overridden by your own sub. Thus, the infinite loop.

You need to work out a way to store the original subroutine reference once and only once, then use that reference every time. Perhaps you could get this working with a BEGIN block, but again, I'm just taking an educated guess.

Replies are listed 'Best First'.
Re^2: Overloading subs = weirdness in mod_perl
by cfreak (Chaplain) on Nov 15, 2004 at 22:50 UTC

    I have other subs that work just fine with the same setup. It only happens when the $self->{apr} gets modified. The persistance is not a problem because the correct modules get loaded per request. Even if the name change is persistant for the one site that shouldn't matter (I don't think it is). Somehow the memory location where I stored the original routine gets overwritten ... you know I think I might know the problem ... I wonder if, by modifying anything in the $self variable that it changes the state of chain of references .... hmm I'll have to investigate that further.

    In the meantime I actually worked around the problem by creating a list_images() sub in the SWMetal::Buffs module, for this particular one I didn't need to call my modified routine in the entire program.