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.

In reply to OOP Access of variables by simeon2000

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.