Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

CHECK and INIT under mod_perl

by Ovid (Cardinal)
on Dec 12, 2004 at 16:34 UTC ( #414238=perlquestion: print w/replies, xml ) Need Help??
Ovid has asked for the wisdom of the Perl Monks concerning the following question:

Currently I've discovered that Sub::Signatures does not run efficiently unless I postpone some work to a CHECK or INIT block. I'm trying to work around this but in the meantime, since CHECK and INIT do not function properly under mod_perl, I'm wondering if there is a standard workaround that's fairly transparent to the end user? I'd rather not force them to explicitly call a setup method. Since the code uses a filter, I suppose I could explicitly set up the setup call for them, but that seems rather ugly.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re: CHECK and INIT under mod_perl
by stvn (Monsignor) on Dec 12, 2004 at 17:03 UTC
    I'm wondering if there is a standard workaround that's fairly transparent to the end user? I'd rather not force them to explicitly call a setup method.

    I have tried to do this same thing with Class::Trait and never managed to get it to work. And recently dragonchild and I did the same thing with Class::LazyLoad. I also think liz had a similiar issue with one of her thread modules as well. The general solution seems to be to force the use to explictly call the set up under mod_perl. To be honest, this is ugly, but has never been a big problem since it can just go in the startup.pl which I load at server startup anyway.

    Since the code uses a filter, I suppose I could explicitly set up the setup call for them, but that seems rather ugly.

    I don't think that seems ugly at all. It is doing what the user would expect it to do, which is what it would do under non-mod_perl circumstances. As far as I am concerned that is an elegant solution since it prevents the user from having to deal with your internals or be concerned about silly internal issues under mod_perl. It might look ugly in the code, but I don't think the perl parser will be offended :)

    -stvn
Re: CHECK and INIT under mod_perl
by perrin (Chancellor) on Dec 12, 2004 at 17:18 UTC
    It's pretty unusual to actually need a CHECK or INIT, so this doesn't come up a lot on the mod_perl list, but I would guess that you could replace it with a sub called during a phase like PerlChildInitHandler. You can make your BEGIN block register this handler automatically if $ENV{'MOD_PERL'} is true.
      So, if I understand you correctly, you recommend the following:
      package Floober; sub do_at_init { # Does something nifty } INIT { do_at_init(); } BEGIN { if ( $ENV{ 'MOD_PERL' } ) { ##### # What do I put here? ##### } } 1;
        Depending on when you need it to run, you could do something like this:
        Apache->push_handlers("PerlInitHandler", \&do_at_init);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://414238]
Approved by wfsp
Front-paged by astaines
help
Chatterbox?
[Lady_Aleena]: Hello. Why is this dying at -exec: my @music_times = qx(find ~/Music/Albums/ -type f -iname '*.mp3' -exec {} \;); with the error find: missing argument to `-exec'
[Lady_Aleena]: ACK! my @music_times = qx(find ~/Music/Albums/ -type f -iname '*.mp3' -exec mp3info -p "%S\n" {} \;);
[marioroy]: :)
marioroy adds oatmeal cookies to the platter on the sideboard.
marioroy adds oatmeal raisin cookies to the platter on the sideboard.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2017-04-23 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (430 votes). Check out past polls.