SPUG: Using import() as init under mod_perl

Doug Beaver dougb at scalar.org
Fri Aug 6 19:30:58 CDT 1999


On Fri, Aug 06, 1999 at 05:27:20PM +0000, El JoPe Magnifico wrote:
> FYI, CGI.pm deals with mod_perl by doing this in the new() 
> subroutine, which gets called on every 'use' of the module.

Actually, I don't think it calls CGI->new each time you C<use CGI;>.
CGI::import() doesn't call CGI->new for the user, the user instead has
to create a CGI object and then call methods on it (or just call the
class methods if they prefer).  Maybe you meant that and I was just
confused...

> Actually new() calls _reset_globals() which is a passthrough
> to intialize_globals(); the latter also gets called once in
> the main block, near the beginning of the module, apparently
> to "make mod_perl happy".  Suggest checking out the gory 
> details yourself. =)

It calls initialize_globals() when the module is first loaded to set
them to their initial values, and then it also registers a cleanup
handler with mod_perl to call _reset_globals() when each individual
HTTP request has finished being processed by mod_perl.

> Dunno about import() and mod_perl.  At best that's a kludgy
> place to put (re-)initialization.

Well, the choices are placing it in import(), a BEGIN block, an INIT
block (if you're using 5.005 and above), or in the constructor of the
object if you're creating an OO module.  (Can anyone think of any more?
I think I'm missing one.)

The main idea is that you should check $ENV{'GATEWAY_INTERFACE'} and if
it says you're running under mod_perl, setup a cleanup handler to be ran
once the request has completed.

'Writing Apache Modules with Perl and C' is an excellent book if you're
working with mod_perl, it helps take care of most the headaches you'll
encounter.  I can't say enough good things about the book, the authors
are Lincoln Stein (Mr. CGI.pm) and Doug MacEachern (creator of
mod_perl), so they really know what they're talking about...

Doug

> On Fri, 6 Aug 1999, Andrew Sweger wrote:
> > Subject: SPUG: Using import() as init under mod_perl
> > Let's say you've got a Perl module (Module.pm) that you've loaded
> > via the PerlRequire Apache directive (a la mod_perl) and you're
> > planning on 'use'ing it in a Perl script serviced under
> > Apache::Registry. Can anyone comment on any possible problems with
> > using Module::import() as an initialization routine to reset global
> > variables?

-- 
  Ned: So recycling is our way of giving Mother Earth a great big hug!
Burns: Yes, well, it does sound like fun.  I can't wait to start pawing
       through my trash like some starving racoon!
       [To Smithers] Release the hounds!

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list