Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: How to share DBI connections between objects?

by adrianh (Chancellor)
on Mar 27, 2007 at 12:38 UTC ( #606751=note: print w/ replies, xml ) Need Help??


in reply to Re^3: How to share DBI connections between objects?
in thread How to share DBI connections between objects?

I'm not sure I understand. I presume you're objecting to My->Db, right?

Kinda. I'm objecting to their being one hard coded $dbh that everything uses. This makes it harder to, for example, swap in a test database, or maybe decide to split a system over multiple databases.

This isn't really just an issue of database handles, but all "shared" configuration information.

Instead I pass configuration objects in at object construction time, or use factories like Rose::DB to allow me to switch things around more easily.


Comment on Re^4: How to share DBI connections between objects?
Re^5: How to share DBI connections between objects?
by f00li5h (Chaplain) on Mar 28, 2007 at 00:21 UTC

    I've been meaning to read up on Rose::DB, so this seems a sensible time to do it.

    In my implementation My->Db did actually get it's connect info from My->get_config('db'); but that still does not allow individual things within My to get connections to other databases, or to allow for injecting of mock database objects for testing without nastyness.

    hrm, good thing you mentioned it adrianh, or I'd just have kept plodding along with this implementation.

    @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://606751]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-07-26 12:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (176 votes), past polls