in reply to Re: Re: Re: RFC : Pragma vs. Module
in thread RFC : Pragma vs. Module

Liz,

My apologies. You are completely correct, INIT and CHECK will not run anywhere in mod_perl. I checked every possible situation I could think of in one of my current mod_perl projects, and nothing worked. So I will now put my foot in my mouth.

Apparently even modules loaded with PerlModule and PerlRequire are at some level eval-ed. Which to me seems ugly, but not being a C programmer or Stas Beckmen, who am I to complain.

After some reading though, it seems to me that the PerlRestartHandler and PerlChildInitHandler could potentially be used to accomplish similar functionality. PerlRestartHandler happens before Apache pre-forks all the children, and PerlChildInitHandler runs at the begining of each child process. Has anyone ever tried to use these as CHECK/INIT replacements?

-stvn

Replies are listed 'Best First'.
Re^5: RFC : Pragma vs. Module
by Aristotle (Chancellor) on Mar 15, 2004 at 09:21 UTC
    These pseudohandlers could offer the right timing semantics, I guess. But how do you go about actually calling the CHECK and INIT blocks? Trying to call Foo::INIT() is a runtime error, because no such subroutine exists. I opine that it was a mistake to allow a sub INIT {} syntax, because their semantics are entirely distinct from subroutines — in particular, you can define any number of INIT or other special blocks and they'll accumulate, instead of overriding previous ones.

    Makeshifts last the longest.

      I agree. Personally, I never use the sub INIT {} form, I always do the block form INIT {} it makes them look (a little) more distinct in the code.

      But how do you go about actually calling the CHECK and INIT blocks?

      I would likely move the code in INIT out into another sub, and have INIT call that (allowing it to fail in mod_perl since it only produces a warning, although this would not be okay if you had set the warnings to be fatal). Then check for the mod_perl env, and push a handler that calls the sub-formerly-known-as-INIT. This is of course a simple and untested approach, but it certainly a surmountable problem.

      -stvn
        But rather than making vanilla INIT work under mod_perl you're then introducing new semantics. Which mod_perl already has: the pseudohandlers you pointed out before.

        Makeshifts last the longest.