[cgiapp] New to working with CGI::App and OO perl. Testing under
mod_perl. The old inconsistent data with reloads problem.
Michael Peters
mpeters at plusthree.com
Thu Mar 19 12:00:44 EDT 2009
Derek Walker wrote:
> I'm running into the old chestnut of a problem of how to properly
> 'wrap' a perl application under mod_perl to avoid the shared global
> variable issue (that I only partially understand at this point)
The basic idea is don't use globals (to make things simpler, "my" package scoped
variables are the same as globals in this email). The problem is remembering
that your package won't be recompiled on every request so anything you put in a
global will stick around for every request. Sometimes this is what you want (say
for a configuration object which doesn't change between requests) but in others
it's not. I see you have a $user and @roles. Those are definitely per-request
kinds of things and should never be globals.
Also, you really shouldn't put a database handle as a global either since that
could timeout and then you'll get strange problems at 6am when people start
using your app again in the morning after it's been sitting for hours without
any use. Under mod_perl Apache::DBI takes care of giving you a nice peristant DB
conection without you having to worry about things like timeouts.
--
Michael Peters
Plus Three, LP
More information about the cgiapp
mailing list