On Wed, Aug 21, 2002 at 09:59:23PM -0700, David Wheeler wrote:
> Hi All,
>
> I'd like to submit a simple patch that causes the DBI connect() method
> to execute a HandleError code reference if it has one. There's a
> comment suggesting that it could be added, and it makes sense to me, so
> I submit this patch.
>
> --- DBI.pm.org Wed Aug 21 21:09:27 2002
> +++ DBI.pm Wed Aug 21 21:24:28 2002
> @@ -503,7 +503,8 @@
> unless ($dbh = $drh->$connect_meth($dsn, $user, $pass, $attr)) {
> my $msg = "$class->connect($dsn) failed: ".$drh->errstr;
> if (%attr) {
> - # XXX add $attr{HandleError} logic here?
> + # XXX add $attr{HandleError} logic here? Yes!
> + $attr->{HandleError}($msg, $drh, $dbh) if
> $attr->{HandleError};
> Carp::croak($msg) if $attr->{RaiseError};
> Carp::carp ($msg) if $attr->{PrintError};
> }
That syntax is not supported in perl5.005; the arrow before the subroutine
arguments was required until perl5.6.
It might also be good to make sure $attr->{HandleError} is actually a code
reference before dereferencing it.
$attr->{HandleError}->($msg, $drh, $dbh)
if (ref $attr->{HandleError} && UNIVERSAL::isa($attr->{HandleError}, 'CODE'));
Ronald