On Fri, 11 Jan 2002, Terrence Brannon wrote:

> 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";
> }

Most people want very specialised behaviour on connection fails. This just
happens to be a common idiom. I wouldn't put this into the DBI core.

-- 
<!-- Matt -->
<:->Get a smart net</:->

Reply via email to