disconnect, connected, ensure_connected on Storage from blblack
Matt S Trout [Sat, 28 Jan 2006 15:41:28 +0000 (15:41 +0000)]
lib/DBIx/Class.pm
lib/DBIx/Class/Storage/DBI.pm

index 51e56bd..93c70e6 100644 (file)
@@ -143,6 +143,8 @@ Nigel Metheringham <nigelm@cpan.org>
 
 Jesper Krogh
 
+Brandon Black
+
 =head1 LICENSE
 
 You may distribute this code under the same terms as Perl itself.
index 0989880..f1bc49e 100644 (file)
@@ -198,12 +198,31 @@ L<DBIX_CLASS_STORAGE_DBI_DEBUG> 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;
 }