I'm delegating an attribute in my current class called 'dbc' as a DBIx::Connector so that I can call $self->dbc->dbh from inside methods, however I'm not really understanding some behaviors I'm seeing when calling the 'errstr' method on the DBI::db instance:
This:
eval {
$dbh->do($sql);
};
$self->log->warn("Warning SQL error: $dbh->errstr") if ($@);
returns WARN - Warning SQL error: DBI::db=HASH(0xaf43130)->errstr
However, this works, and returns a proper error string:
eval {
$dbh->do($sql);
};
if($@){
my $errstr = $dbh->errstr;
$self->log->warn("Warning SQL error: $errstr");
}
What's happening here?
Perl doesn't interpolate method calls inside double-quoted strings. $dbh->errstr
is calling a method. Try:
$self->log->warn("Warning SQL error: " . $dbh->errstr) if $@;