jacques has asked for the wisdom of the Perl Monks concerning the following question:

I've been looking at the guts of CGI.pm and noticed how stein calls a subroutine called initialize_globals, which, as the name implies, initializes a bunch of global variables. The purpose of such a routine, I believe, is to counter the caching that occurs with Apache::Registry. Am I right? Would such a routine be necessary for modules run under mod_perl version 2?

What is the best way to maintain mod_perl compatibility (versions 1 & 2) while preventing mod_perl "caching" of data -- when you are designing a module that presents data that should not be from the previous uses of this module? This data can be either user supplied or gleaned from environment variables.

Replies are listed 'Best First'.
Re: CGI.pm and mod_perl caching
by perrin (Chancellor) on Apr 14, 2005 at 22:16 UTC
    He only has to do that because CGI.pm puts everything into global variables. If you just use lexical (my) variables, the values will not be retained between requests.
Re: CGI.pm and mod_perl caching
by jbrugger (Parson) on Apr 14, 2005 at 22:21 UTC
    I don't understand your point. cgi works fine in mod_perl 1 and 2, i've seen no problems whatsoever, but You need to install at least version 2.87 of CGI.pm to work under mod_perl 2.0, as earlier CGI.pm versions aren't mod_perl 2.0 aware. (as taken from the mod_perl2 apace documentation.

    for comparibility use PerlModule Apache2::compat
    If you don't want caching in mp-1, don't use Apache::Registry but Apache::PerlRun I think it's not needed anymore in mp-2.

    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
Re: CGI.pm and mod_perl caching
by dmitri (Priest) on Apr 14, 2005 at 22:12 UTC
    If I understand your question correctly, you want to move from apache to apache2 and from mod_perl to mod_perl2. Specifically, you are intreseted in compatibility. I've been running mod_perl 1.99.09 (long time, yes) with no problems, and I have several hundred CGIs running under Apache::Registry.

    I believe the best advice is to use lexical variables; the rest will be taken care of for you.

    Note: I've been keeping up with mod_perl mailing list. Be extra careful which RC tarball you get, there are major API changes between RC4 and RC5.