Re: Callbacks registered on class, not instance?

"Jenda Krynicky" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Message-ID <[email protected]>
Date sent:      	Mon, 9 Jul 2012 12:36:27 +0200
From:           	Michael Ludwig <[email protected]>
To:             	[email protected]
Subject:        	Callbacks registered on class, not instance?

> There's a huge perl process running, and we don't have access to the
> source code. We only have access to a loader script, which starts the
> entire process.
> 
> This process is doing lots of SQL via DBI. We'd like to change that SQL
> a little bit. This can be done via DBI callbacks as described in the
> manual:
> 
> http://search.cpan.org/~timb/DBI-1.622/DBI.pm#Callbacks
> 
> Callbacks are registered on DBI object instances. When the process is
> started we don't have access to handles, they have not been created yet.
> 
> However, in theory, we could load the DBI module in the loader script
> so the DBI code would be there, and then we could register callbacks on
> the *class*, not on the *instance*, and they would be called *from* the
> instance. In other words, global callbacks.
> 
> In practice it looks like this isn't supported. Or is it?
> 
> Michael

Hack it. Something like

use DBI;

{
  my $old_connect = \&DBI::connect;
  *DBI::connect = sub {
    my $connection = $old_connect->(@_) or return;
    do anything you like with the connection
    return $connection;
  }
}


Jenda
===== [email protected] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
	-- Terry Pratchett in Sourcery
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.