Mike Carlton wrote:
I'm running a web application under Apache::Register and mod_perl 1 --
using CGI::Application, Class::DBI and Template Toolkit.

I have a question on package globals.  My expectation is that each
instance of the Apache intrepeter will have its own copy of the package
globals.
I.e. in any given thread I can assign to a package variable and have it
be unchanged for the remainder of the request.  However I'm seeing weird
behavior that could be explained by the value changing.

I am extracting the currently logged in user from an encoded cookie in
my CGI::App code and setting a package variable value on every invocation:
   package TestApp;
   use base 'CGI::Application';
   use vars qw( $user );



   sub cgiapp_prerun
   {
       my $self = shift;
       my $runmode = shift;
       $user = $self->query->cookie('user');
   ...

is it possible that cgiapp_prerun() is not always run and you end up with the data from the previous request/user (since global variables persist and don't get destroyed at the end of request)?.


If you have an entry point that is always executed at the beginning of a request, like 'sub handler { ... } ', you should make sure to reset all your globals before using them.

Even better, drop the usage of globals and create a class an instance of which will contain all the objects you will ever want to access (e.g. using Singleton), which will get destroyed at the end of request. So you don't have to worry about resetting globals.
http://search.cpan.org/search?query=singleton&mode=module



If my understanding is correct, then I've got a bug elsewhere in my
code.  I'm in the progress of migrating to modperl 2/Apache 2, so
comments on the same scenario in MP2 are of interest too...

It isn't any different under mp2.


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


-- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html



Reply via email to