[cgiapp] code reuse.

Michael Peters mpeters at plusthree.com
Mon Mar 17 10:16:53 EDT 2008


James.Q.L wrote:

>> I might be missing the point, but what's wrong with storing $uuid in
>> Company::Util as an "our" variable and accessing it from anywhere as
>> $Company::Util::uuid ?
>>
> 
> correct me if i am wrong. that won't work under mod_perl. because our $uuid is a global package
> variable and shared by all instances.

Does the UUID change per application instance? If so, then make it a method
instead of a variable. Then you can decide which actual uuid to return based on
how it's called.

> what i want is to setup $uuid and $dbh for the Company:: modules 

We have a large application that runs under mod_perl that needs to be have
differently for each site that it's serving. It basically comes down to having
something in your httpd.conf that you can read to determine which client you're
serving. Then we use that to look up the relevant section in the configuration
file to then be able to create the DB handle. Something like this:

  PerlSetVar UUID blahblah

Then your Company::Util::uuid() method will return that var and your
Company::Util::dbh() method could read that and then look up in your
configuration file to see which dbname/user/pw are associated with that UUID and
then return the db handle.

Or something like that.
-- 
Michael Peters
Plus Three, LP



More information about the cgiapp mailing list