My question is similar to this one posted 1 year ago
Passing Database handles to other modules.
I'm building a little application in mod_perl, and have written the bulk of database connectivity into its own package (myApp::DB) , so that I can easily access database handles.
Currently, I open a connection to the database in the 'main' perl script that sets the apache handler. ( my $dbh = myApp::DB->dbconnect(); # returns a ref)
I then either pass the reference around to supplementary packages that need it.
I've been working on a custom form processing package however, that needs to handle certain SQL select statements.
Which is where my problem now comes in:
Right now, the form validation package is built as a generic package that I can reuse. I'm passing in a ref to the dbh when needed -- and that works fine, but its a little annoying, as I feel that I'm passing the ref around alot.
I've considered subclassing my form validator, to have a getDBH function on an init. I've also considered not passing refs around, and just calling connects repeatedly, and letting apache::dbi handle the intercepting.
Both those solutions seem equally as inefficient as the one I've currently got.
Can anyone reccommend something that makes more sense?