(I'm used to using mod_perl only via Mason, so apologies in advance if some of my terminology
is a little off.)
I'm wondering if this approach to using variables in Perl modules (and setting/accessing these
variables during a request) is sane (both for a $dbH and a "generic" variable):
I have three "levels" of files: my .html pages, my Site:: modules, and my Gen:: modules.
Site:: modules are site-specific (I have multiple sites running under virtual hosts). Gen::
modules are lower-level, and contain no site-specific code.
When my .html page is invoked, I immediately call Site::Init(), which in turn calls Gen::DB::Connect(),
which opens a DBI connection. The actual $dbH variable is defined in the Gen::Init() module.
No code in my Site:: modules or my .html pages directly uses/accesses $dbH. As I process
the request, my page calls various Site:: functions, which in turn call Gen::DB() for all
DB access. At the end of my request, I call Gen::DB::Disconnect().
So far, for small sites, this appoach is working well. I'm wondering if there are any pitfalls.
Also, does anything change if my Gen::DB module is preloaded in my startup.pl file? I'm
wondering if multiple incoming requests (from different virtual host sites, all using Gen::DB)
will cause things to get confused.
Also, in the simpler case, if I have a $foo variable in, say, Gen::Foo, and I set it (at the
beginning of the request) via Gen::Foo::Set( '123' ), is this $foo variable "all mine" for
the duration of the request? That is, am I guaranteed that another request won't change this
value under the first request's nose? And, is this scenario affected by whether or not Gen::Foo
is preloaded via startup.pl?
(Sorry for all the question marks in this post.)
___
Bryn Dyment, bryn@hoologic.com
http://www.hoologic.com/
|