in Example::DB in DBIx::AnyDBD, we see code which always returns
a viable database handle or throws an exception. The question is
shouldn't this type of behavior be available as part of DBI?
sub instance {
if ($DB && $DB->ping) {
# rollback uncommited transactions
# this doesn't work where multiple nested method calls
might call insta\
nce()
# $DB->rollback;
return $DB;
}
my $class = shift;
my $x = 0;
do {
if ($DB) {
eval { $DB->disconnect; };
undef $DB;
}
$class->connect;
return $DB if $DB && $DB->ping
} until ($x++ > MAX_ATTEMPTS);
die "Couldn't connect to database";
}