First of all, you probably want to have your httpd.conf file have:

PerlModule Apache::DBI

that will take care of connection pooling for each Apache child process.
Any attempt to connect to the database will get an existing handle back if one has already been created using the same DSN/user/password/attributes


Second, for a global, you would do:

our $dbh; # instead of the older use vars qw( $dbh );

You do that in the test::master package and then in the derived classes.

Look up 'our' in Programming Perl, 3rd edition, page 755.


At 10:13 AM +1000 10/9/03, Morton-Allen, Matt wrote:
Hi,
I'm trying to find a way in which I can stash some commonly used data
(e.g. a database handle) in a location that I can access from anywhere
within a large OO mod_perl application.

After learning the ills of using globals under mod_perl the hard way I
am now toying with the use of class wide variables in an object
inherited by all within the application.

My tests so far have been positive but I just wanted to check against
the mod_perl brains out there if this is safe.

The code is as follows:

Client Object snippet

use vars qw(test::master);

Master Object (inherited everywhere object)

== snip ==

package test::master;

{
        my $dbh = etc etc;
}

In this scenario it looks like the single $dbh is returned from any call
to it from a
"client" object ok and can't find any evidence of crossover between
httpd children (sorry if that's the wrong term).

So, is this crazy thinking or am I on the right track?

Thanks,
Matt.


--
------------------------------------------
Matisse Enzer
Doodlelab Inc.
415-925-5294 ext. 212 (office)
415-225-6703 (mobile)

Reply via email to