The short answer is that new() doesn't get called.

The "OO" approach is used solely for inheritance, not for a typical object. A contrived example:

package MyHandler; sub handler($$) { my($class, $r) = @_; $class->do_this(); $class->do_that(); } sub do_this { # some default behavior } sub do_that { # some default behavior } package MyHandlerSubClass; use base qw(MyHandler); sub do_this { # do something else } sub do_that { ... }

So in the above example you could extend on MyHandler by subclassing it and changing how do_this() and do_that() behaves. But the handler method will still be called directly without ever "instantiating" anything, you still would be passing the class name.

In your case, since all you're storing is the DBI object, you could store it in $r->pnotes() earlier in the pipeline, or create a wrapper object/function that does that for you:

# I use Apache::DBI and also do something that resembles this in my + code, but YMMV package My::DB; sub connect { my $r = Apache->request; my $dbh =$r->pnotes('MyDBIHandle'); if(!$dbh) { $dbh = DBI->connect(...); $r->pnotes('MyDBIHandle' => $dbh); } return $dbh; }

In reply to Re: mod_perl and objects by lestrrat
in thread mod_perl and objects by geektron

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.