I have a new project I'm working on, and I'm tinkering with OOP for variable storing (I could just use hashes, but I'm wanting to learn more about OOP). The problem is, it's a database application, and I want to keep the work perl has to do to a minimum.
I've got 2 packages in separate pm modules so far: TArtLib and TArt::Editor (it's for TalkArticles... TArt seemed cute :P). TArtLib holds a $dbh database connection handle and uses DBI. TArt::Editor is just a data object with accessor methods. What I want is for my TArt::Editor to use the DBI connection ($TArtLib::dbh) from the TArtLib program, so it doesn't have to use DBI and make the connection for every Editor Data object I create. That way TArt::Editor can populate itself with the data for an editor by itself, instead of having arguments passed to it to populate them.
package main;
use TArtLib;
use TArt::Editor;
my $lib = new TArtLib;
# This object would populate itself from the database,
# using the number passed to it as the primary key,
# and hopefully using TArtLib's DBI connection.
my $ed = new TArt::Editor(1);
print $ed->{NAME}; # etc. etc.
I know Apache::DBI will keep the DB connections going (It's running in mod_perl), but I'm wanting it to do it from the command line as well. I'm just not sure how to get TArt::Editor to get TArtLib's DBI connection. BTW, TArtLib will always be called before TArt::Editor, if that helps.