From: Matt S Trout Date: Sat, 28 Jan 2006 15:41:28 +0000 (+0000) Subject: disconnect, connected, ensure_connected on Storage from blblack X-Git-Tag: v0.05005~84 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=412db1f428e95eeeac2a63f12b3c2d1ce1b3223a;p=dbsrgits%2FDBIx-Class.git disconnect, connected, ensure_connected on Storage from blblack --- diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 51e56bd..93c70e6 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -143,6 +143,8 @@ Nigel Metheringham Jesper Krogh +Brandon Black + =head1 LICENSE You may distribute this code under the same terms as Perl itself. diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 0989880..f1bc49e 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -198,12 +198,31 @@ L environment variable. =cut -sub dbh { +sub disconnect { + my ($self) = @_; + + $self->_dbh->disconnect if $self->_dbh; +} + +sub connected { my ($self) = @_; + my $dbh; - unless (($dbh = $self->_dbh) && $dbh->FETCH('Active') && $dbh->ping) { + (($dbh = $self->_dbh) && $dbh->FETCH('Active') && $dbh->ping) +} + +sub ensure_connected { + my ($self) = @_; + + unless ($self->connected) { $self->_populate_dbh; } +} + +sub dbh { + my ($self) = @_; + + $self->ensure_connected; return $self->_dbh; }