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

I am humbly aspiring to learn mod_perl by converting an existing, fairly complex, cgi application. Though I have been pretty successful getting most scripts to run under ModPerl::Registry, I'm getting remembered cgi.pm params. Which leads me to believe I have no clue on what gets shared. I have one module called Security.pm with no global vars. I call a function which creates $q=CGI->new;, checks authorization and displays a login page with a param('login_name') if they are not logged in yet. I have many different scripts with the following basic format:
sub main { my $q = CGI->new; my $func = $q->param('func'); if ($func eq 'somefunc') { &somefunc } } sub somefunc { my $q = CGI->new; }
My problem is that if I use param('login_name') in &somefunc it has a retained value from elsewhere, like the one entered in during login from the Security module. I tried '-override=>1' on that param and received an error that indicated I could not change the value of that param.

So are $q vars being somehow loaded up once in mod_perl and never cleared with each CGI->new?

I could certainly use some tips on understanding variable usage and sharing/not sharing under mod_perl. I am searching through 'practical mod_perl' as well.

I'd appreciate any pointers or direction on how to properly use modules like CGI.pm or how modules behave after they are loaded and compiled in mod_perl.

Your Humble Servant

Replies are listed 'Best First'.
Re: mod_perl and CGI variable lifetime puzzle
by perrin (Chancellor) on May 13, 2005 at 19:59 UTC
    You're creating a closure somewhere. You have code somewhere that looks like this:
    my $q = CGI->new(); sub something { $q->param().... }
    You need to explicitly pass the CGI object to each sub that uses it.
      Okay, I'll go back through all the scripts and instantiate one instance of CGI in the main sub, and then passed it to any subs being called. Also, if I had any lingering CGI.pm calls using the old function oriented calls rather than the object oriented calls, might that cause an issue?
        The function syntax isn't a problem.
Re: mod_perl and CGI variable lifetime puzzle
by Adrade (Pilgrim) on May 14, 2005 at 02:13 UTC
    Check out 17.3.2 of CGI Programming with Perl. There's a section there on mod_perl considerations that's quite concise and helpful. Converting from CGI to mod_perl can sometimes be painful, but once all the kinks have been ironed out, the benefit is really quite nice. As for CGI, I'm still stuck in the stone-ages - I use a variant of ReadParse from an old cgi-lib.pl for most of my stuff.. :-)
      -Adam
    P.S. Also be sure so check out the mod_perl docs, though I'm sure you prob already have :-)