[Catalyst-commits] r11356 - in branches/Catalyst-Model-DBI/theory:
. lib/Catalyst/Model
theory at dev.catalyst.perl.org
theory at dev.catalyst.perl.org
Sat Sep 12 20:52:16 GMT 2009
Author: theory
Date: 2009-09-12 20:52:16 +0000 (Sat, 12 Sep 2009)
New Revision: 11356
Modified:
branches/Catalyst-Model-DBI/theory/Changes
branches/Catalyst-Model-DBI/theory/lib/Catalyst/Model/DBI.pm
Log:
Modified `connect(`) to log failed connections as errors and to re-throw
exceptions.
Modified: branches/Catalyst-Model-DBI/theory/Changes
===================================================================
--- branches/Catalyst-Model-DBI/theory/Changes 2009-09-12 20:48:02 UTC (rev 11355)
+++ branches/Catalyst-Model-DBI/theory/Changes 2009-09-12 20:52:16 UTC (rev 11356)
@@ -1,5 +1,7 @@
Revision history for Perl extension Catalyst::Model::DBI.
- Switch from NEXT to next::method
+ - modified connect() to log failed connections as errors and to re-throw
+ exceptions.
0.20 Sun Dec 07 17:36:00 2008
- fixed issue: http://rt.cpan.org/Public/Bug/Display.html?id=38121
- fixed issue: http://rt.cpan.org/Public/Bug/Display.html?id=39884
Modified: branches/Catalyst-Model-DBI/theory/lib/Catalyst/Model/DBI.pm
===================================================================
--- branches/Catalyst-Model-DBI/theory/lib/Catalyst/Model/DBI.pm 2009-09-12 20:48:02 UTC (rev 11355)
+++ branches/Catalyst-Model-DBI/theory/lib/Catalyst/Model/DBI.pm 2009-09-12 20:52:16 UTC (rev 11356)
@@ -107,23 +107,32 @@
=item $self->connect
-Connects to the database and returns the handle.
+Connects to the database and returns the handle. If the connect fails, it
+returns C<undef> and logs the error at the "error" log level. If an exception
+is raised during the attempt to connect to the database, the exception will be
+logged at the "fatal" log level and re-thrown.
=cut
sub connect {
my $self = shift;
- my $dbh;
- eval {
- $dbh = DBI->connect(
+ my $dbh = eval {
+ DBI->connect(
$self->{dsn},
$self->{user},
$self->{password},
$self->{options}
);
};
- if ($@) { $self->{log}->debug( qq{Couldn't connect to the database "$@"} ) if $self->{debug} }
- else { $self->{log}->debug ( 'Connected to the database via dsn:' . $self->{dsn} ) if $self->{debug}; }
+ if ($@) {
+ $self->{log}->fatal( qq{Couldn't connect to the database: "$@"} );
+ die $@;
+ } elsif (!$dbh) {
+ $self->{log}->error( qq{Couldn't connect to the database: $DBI::errstr});
+ } else {
+ $self->{log}->debug ( "Connected to the database via dsn: $self->{dsn}" )
+ if $self->{debug};
+ }
$self->_pid( $$ );
$self->_tid( threads->tid ) if $INC{'threads.pm'};
return $dbh;
More information about the Catalyst-commits
mailing list