Ok, I am little confused now. I have changed the code to the following: Master ------
package test::master; our $dbh; sub dbh { == snip == return $dbh; } Client ------ packge test::client; use test::master; use vars qw(test::master); @ISA = qw(test::master); our $dbh; sub query { my $dbh = $self->dbh; } The dbh method in the master is set so that it checks if there's an existing handle and uses it where possible. I have put in some debugging that reports the sequence of requests. For CGI it looks as you'd expect if things were ok. For example: CGI: loaded CGI: found CGI: found When I run under mod_perl I get the same results on the first hit but for subsequent hits I get the following: CGI: found CGI: loaded CGI: found CGI: found I don't understand how there's a) a new call that I didn't make and b) how it can be found prior to loading and yet somehow think it needs loading later in the execution. Either way it looks suspiciously like the Apache::Registry wrapping is playing some part. I also thought perhaps I might have misunderstood and shouldn't have the "our" in the client object so I tried it without it but got the same result which is in itself confusing. Matt. -----Original Message----- From: Matisse Enzer [mailto:[EMAIL PROTECTED] Sent: Thursday, 9 October 2003 10:47 AM To: [EMAIL PROTECTED] Subject: Re: Using class wide variables under mod_perl is safe? 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)