in reply to mod_perl and objects

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; }

Replies are listed 'Best First'.
Re: Re: mod_perl and objects
by geektron (Curate) on Jul 25, 2003 at 08:33 UTC
    this is along the lines of what i was looking for, answer-wise.

    in playing around, i figured that new() never gets called, because if i put a $self = $class->new() i get the OO beavior i was expecting.

    i ( wrongly, it seems ) read the docs to mean that new() was auto-magically called ... and couldn't figure out where the magic happened.