Re: Time to Document Callbacks

2009-10-25 Thread David E. Wheeler

On Oct 24, 2009, at 2:50 PM, Tim Bunce wrote:


Callbacks are handled by the method dispatcher so all method names are
valid (so don't bother trying to list them in the docs :)

Plus the two special cases for connect_cached: 'connect_cached.new'  
and
'connect_cached.reused'. (There's also '*' but that's not really  
recommended.)


Thanks!

Tim.

p.s. Might be worth skimming through the archives
http://tinyurl.com/yl582mt


Thanks. Following up on [this post](http://markmail.org/message/fus3dfauxs6yz6sv 
), I wrote this code:


my $dbh = DBI-connect('dbi:Pg:dbname=bric', '', '', {
Callbacks = {
execute = sub { print Set in DBH\n; return; }
}
});

my $sth = $dbh-prepare('SELECT id FROM pref WHERE name = ?');
#$sth-{Callbacks}{execute} = sub { print Set in STH\n; return; };
$sth-execute('Time Zone');

It output nothing. When I uncommented that second-to-last line, it  
output Set in STH. So it seems that a callback added to the dbh for  
a statement method name does not end up getting passed on to the  
statement handle. So I guess the Callbacks attribute is not passed on  
to statement handles created for the database handle? Seems a shame…


Best,

David

Re: Time to Document Callbacks

2009-10-25 Thread David E . Wheeler

On Oct 25, 2009, at 10:24 PM, David E. Wheeler wrote:

It output nothing. When I uncommented that second-to-last line, it  
output Set in STH. So it seems that a callback added to the dbh  
for a statement method name does not end up getting passed on to the  
statement handle. So I guess the Callbacks attribute is not passed  
on to statement handles created for the database handle? Seems a  
shame…


One other thing: It's nice that the callbacks execute before the  
method call, so that you can disable it by undefing $_. But it'd be  
equally handle to have callbacks after the method call. For example,  
I'd love to be able to create a callback on a statement handle to  
convert a timestamp column to a DateTime object:


$sth-{PostCallbacks}{fetch} = sub {
my ($sth, $row) = @_;
$row-[3] = DateTime::Format::Pg-parse_datetime($row-[3]);
};

Is this something that's done at any level in the callbacks, or would  
it have to be added? Thoughts?


Thanks,

David