YES! :-)
On Mar 22, 2005, at 4:21 PM, Tim Bunce wrote:
It ended up a little different in that I don't use an extra element in the struct but just hv_fetch "Callbacks" when needed. So it's more like the way "Profile" is handled. I should have pointed you in that direction rather than to the older CachedKids style.
Ah, well, live and learn, eh?
Anyway, it's in now, with support for callbacks on *every* method and *every* handle. So this does what you'd expect:
$dbh->{Callbacks}->{ping} => sub { print "Called ping!\n"; return; }; $dbh->ping;
Nice.
The return; is because I've not decided how to interpret return values
so to avoid problems later I've mandated that callbacks must return nothing.
I can certainly live with that. Are return values currently ignored? I think I'd be inclined to have them mean nothing, and leave it up to callbacks to throw exceptions when something exceptional happens.
What's missing, roughly in order of importance...
0. Documentation.
Oh, I guess I didn't include any docs in my original patch. I'll take a shot at this in the next couple of days.
1. callbacks are only passed the handle, not the other method args.
That seems smart to me. If you passed it via method args (I assume you mean \%attrs), then would it last only for the execution of that method, or become permanent? The former would be okay, I think.
2. No support for post-call callbacks via
$dbh->{Callbacks}->{prepare} => [ \&pre, \&post ]
So when do the execute now?
3. The method name isn't available via a localized $_
Is it available at all?
4. Define interesting uses for the return values, if any.
See above.
5. A DBI::Callbacks module to provide an interface for managing callbacks, including a way to define callbacks to be applied to all future child statement handles (by using a post-prepare).
Not sure I understand what you mean here. Would you care to elaborate?
Any volunteers for any of those?
Docs coming soon.
p.s. There's no PurePerl support and I've no plans to add it anytime soon.
It was in my original patch. Quite simple, really:
--- lib/DBI/PurePerl.pm (revision 870)
+++ lib/DBI/PurePerl.pm (working copy)
@@ -143,6 +143,7 @@
Attribution
BegunWork
CachedKids
+ Callbacks
CursorName
Database
DebugDispatchThat may not be enough now, though, I honestly don't know.
Regards and many thanks,
David
