Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Perl DBI: Overloading statement handle

by sherab (Scribe)
on Nov 08, 2010 at 19:06 UTC ( [id://870168]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl DBI: Overloading statement handle
in thread Perl DBI: Overloading statement handle

Ken, this is a great beginning. new_dbh is not a subclass though, it's a subroutine (or maybe my knowledge of the terms is off, I admit to being fairly new with packages). new_dbh is a subroutine in MyModule::Database I can see how in the example given (thanks so much for this) where the differences are between ::db and ::st

If I setup a prepare subroutine in MyModule::Database then that would take precedence over DBI's prepare? I would just prefer than any solution not have me tracking down every $sth in our codebase and fix it (which your example helps with greatly) or having to re-code the entire MyModule::Database module to a separation of ::db and ::st

......or do I need to just setup a subclass like this...
package MyModule::Database::db; use vars qw(@ISA); @ISA = qw(DBI::db); sub prepare { my ($dbh, @args) = @_; my $sth = $dbh->SUPER::prepare(@args) or return; $sth->{private_mysubdbi_info} = { foo => 'bar' }; return $sth; }
I understand my question might not even make sense. I do enjoy this the more I learn it.

Replies are listed 'Best First'.
Re^3: Perl DBI: Overloading statement handle
by kcott (Archbishop) on Nov 08, 2010 at 21:42 UTC

    sherab, your terminology seems fine - I think you just misread my post. I wrote: "... is in a subclass ..." not "... is a subclass ...".

    You have thrown me a bit with "I see I can't edit/delete the above. ...". I'm not sure if you're referring to the examlpe moritz provided or the one I linked to in the DBI documentation.

    Anyway, the basic idea is that you do not re-code the one million my $sth = $dbh->prepare(...) lines you currently have; nor do you re-code any existing $dbh = new_dbh(...) lines. Instead, you make a single change to your new_dbh routine which I envisage to be as simple as:

    # Old: # return $dbh; # New: return bless $dbh, 'My::DBI::st';

    Then add the code provided by moritz above that.

    Hopefully, that answers some of your questions. If you have more, feel free to ask.

    -- Ken

      Thanks Ken, the info that you and moritz provided was dead on. I was referring more to my own post in regards to deletion. I posted it before I noticed that moritz update his post. Also here's my very public thank you to you and moritz for being such saints and guiding me on this on: THANK YOU! It also gave me a new area to start practice into.
Re^3: Perl DBI: Overloading statement handle
by sherab (Scribe) on Nov 08, 2010 at 20:35 UTC
    I see I can't edit/delete the above. The example that moritz gave at the top: WOW! It's just what I was after.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://870168]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-03-29 07:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found