I think the confusion arises between class method handlers and object method handlers. Both are available, but the 'official' description of mod_perl 1 method handlers doesn't make the distinction very clear. Both are marked by the special prototype.

A (class) method handler is defined in httpd.conf with something like:

PerlHandler MyPackage->method

Here, as in the example you posted, MyPackage::method gets called with "MyPackage" as the first argument, and the request as the second (as if you'd said MyPackage->method($r) in normal perl). As you've seen, there's no magical new called on the way.

An (object) handler involves the explicit construction of an object at server start-up time, normally in startup.pl. The newly created object is assigned to a package variable, then a method of that variable is specified as a handler

# in startup.pl $My::handler_obj = $MyPackage->new('foo' => 'bar'); # then, in httpd.conf - NOTE THE '$' SIGIL PerlHandler $My::handler_obj->method

In this case, what MyPackage->method will receive as arguments is a blessed reference to $My::handler_obj (not the package name, as above), and secondly the request object, as before.

I don't know whether & how changes to the handler object persist. In particular, if you use object handlers, be careful not to make DBI connections in the new method that gets called in startup.pl, as you'll run into problems. Just use Apache::DBI and connect at handler time; re-use of DBI connections will be dealt with for you.

HTH
ViceRaid


In reply to Re: mod_perl and objects by ViceRaid
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.