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?

In reply to Passing Database handles to other modules. #2 by nmerriweather

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.