in reply to Re: How can I avoid creating two instances of the same object
in thread How can I avoid creating two instances of the same object

Not to detract from your post, but Class::DBI already gives you db_Main for free. Your getdbh == WebApp::DBI->db_Main.

Replies are listed 'Best First'.
Re^3: How can I avoid creating two instances of the same object
by mattr (Curate) on Mar 02, 2006 at 16:27 UTC
    Thanks you are correct and posted just as I was adding an explanation ("I'm wierd"). This is old code of mine, for some reason that seemed good at the time, but I don't remember instead of overriding db_Main I pulled it from Ima::DBI. I wonder why I did that.. put another way what other db handles would be in that array I wonder.
      Thank you all for your advice and for your help. I figured out how to get this done! Here is my final working code. I am loading my @ISA in the beginning with each of my packages and I am requiring the package in a method using an eval statement. It looks a little wierd but it works. I'll get a better benchmark of the speed when I get a good prototype working. Here is my calling script and the relevant methods.
      use Data::Dumper; use CBIDatabase; my $dbh = CBIDatabase->new(); $dbh->load_package('Company'); my %company; $company{'id'} = '03459875437'; my $ref = $dbh->Company::client(\%company,'*',); print "\n\nAsking for all matching table info:\n"; print Dumper($ref);
      Here is the load_package method of the CBIDatabase class
      use strict; use DBI; my @ISA = qw(Company); sub load_package { my $self = shift; my $package = shift; require eval{$package.'.pm'}; } sub new { ## database stuff here }
      I'm excited! This seems to work very well. I don't like to use eval statements but I think I'll have to if I want to require the modules dynamically. Again thanks for all of the help. This is a very old database that didn't follow any of the rules, that class::dbi seemed to need.