No such thing as a small change | |
PerlMonks |
Re: How to share DBI connections between objects?by GrandFather (Saint) |
on Mar 26, 2007 at 05:29 UTC ( [id://606519]=note: print w/replies, xml ) | Need Help?? |
In code I'm working on at present I have two classes of interest. One class is intended for creating a single instance from that manages the database connection. The second class is the base class for a bundle of classes that mediate access to different tables in the database. The table accessors don't require a connection at create time and can do a limited range of stuff without a connection being provided, but they die if you try to use them in a way that would require a connection and you've not provided one yet. That allows a Task object to be created for example with a bunch of task information, then handed over to a scheduler that gets the task queued (added to the task table). The table object base class provides members to insert a derived instance into its table and to update/fetch/delete entries matching various criteria. The base class will also create the table for a derived class if the table doesn't exist (the derived class provides a column spec). Typical derived class code looks like:
and typical usage looks like:
DWIM is Perl's answer to Gödel
In Section
Seekers of Perl Wisdom
|
|