in reply to Lazy DBI Connection Handles
It just gets to be a pain to use $dbh->() every where. You could also use my Multi-Method closures technique, but you need to remember to put {} around the method names. There's also the issue of keeping the hash keys synced with DBI's methods. You could tie the underlying hash so that it looked up each method on first invoke and kept it around for later. Then we are back to square one - tying tied variables.my $dbh = lazy_dbh( $dsn, $user, $pass, \%attr ); $dbh->()->ping(); sub lazy_dbh { my @args = @_; my $dbh; return sub { require DBI; if ( ! defined $dbh || ! $dbh->ping() ) { $dbh = DBI->connect( @args ) or die $DBI::errstr; } return $dbh; }; }
I guess what I am saying is that I think this is a nice use of Tie::Constrained, but that there is no such thing as a free lunch.
Cheers - L~R
|
---|