atom feed23 messages in org.perl.dbi-devRe: Callbacks
FromSent OnAttachments
David WheelerJan 31, 2005 10:28 pm 
Tim BunceFeb 1, 2005 2:44 am 
David WheelerFeb 1, 2005 9:16 am 
Tim BunceFeb 2, 2005 2:59 am 
David WheelerFeb 2, 2005 10:50 am 
David WheelerFeb 2, 2005 10:58 am 
Tim BunceFeb 3, 2005 7:45 am 
David WheelerFeb 3, 2005 8:40 am 
Tim BunceFeb 3, 2005 3:30 pm 
David WheelerFeb 3, 2005 3:49 pm 
Tim BunceFeb 4, 2005 2:08 am 
David WheelerFeb 4, 2005 10:38 am 
Sheikin SergeiFeb 4, 2005 11:31 am 
Michael A ChaseFeb 4, 2005 12:22 pm 
David WheelerFeb 11, 2005 11:18 am 
Tim BunceFeb 12, 2005 10:11 am 
David WheelerFeb 12, 2005 4:35 pm 
Tim BunceFeb 13, 2005 2:44 pm 
David WheelerFeb 13, 2005 5:54 pm 
Tim BunceFeb 14, 2005 3:09 am 
David WheelerFeb 15, 2005 10:38 am 
Tim BunceFeb 15, 2005 2:22 pm 
David WheelerFeb 15, 2005 9:01 pm 
Subject:Re: Callbacks
From:David Wheeler (
Date:Feb 4, 2005 10:38:32 am

On Feb 4, 2005, at 2:08 AM, Tim Bunce wrote:

One way I'd had in the back of my mind way to use the DBI dispatcher to fire the callbacks.

$h->{Callbacks}->{$method_name} = \&foo; # called on entry $h->{Callbacks}->{$method_name} = [ \&foo, \&bar ]; # foo on entry, bar on exit $h->{Callbacks}->{$method_name} = [ \@subrefs, \&bar ]; # each of @subrefs on entry, bar on exit

that way _every_ method would get pre and post call hooks for free. If a handle has no callbacks the cost would be unmeasurable (just a bit flag test in the dispatcher). If a handle has any callbacks then the added cost for calling a method that doesn't have a callback would just be one hash lookup.

Ah, yes, that sounds really nice.

How's your C coding? :)

I gave up when I got to my first malloc. Sorry, I'm JAPH. I can help with the Perl code, though!

This approach doesn't directly support callbacks that need to fire _within_ a method, such as the proposed OnConnectCached firing only if connect_cached() does _not_ need to call connect().

[For that case you could have an pre-connect_cached callback that temporarily installs a connect callback which sets a flag, and a post-connect_cached callback that resets %$attr if the flag's not set. But that's getting quite baroque!]

Yah, my NoReset solution is starting to look better. Maybe the get_child() stuff should take priority?

Alternatively connect_cached() could call a new method in that situation and the hooks could be applied to that. But that's relatively expensive and it would be 'odd' for that method to be called with the $attr that was passed to connect_cached().

Alternatively some pseudo-method-names could be supported in the $h->{Callbacks} hash (ie "connect_cached.reused") and the relevant methods could check for and call them directly. Then the extra code in connect_cached would something like this:

if (my $cb = $dbh->{Callbacks}) { my $oc = $cb->{"connect_cached.reused"}; $oc->($dbh, $dsn, $user, $pass, $attr) if ref $oc eq 'CODE'; }

Umm, food for thought...

That's starting to get might complex, isn't it?