Skip to content

Commit

Permalink
Realized that DESTROY was clearing the cache, which was wrong.
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Oct 3, 2009
1 parent 80e2e8e commit f9f4bd3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
10 changes: 5 additions & 5 deletions lib/DBIx/Connection.pm
Expand Up @@ -27,12 +27,12 @@ CACHED: {
_svp_depth => 0,
} => $class;
}
}

sub DESTROY {
my $self = shift;
$self->disconnect if $self->connected;
delete $CACHE{ $self->{_key} };
}
sub DESTROY {
my $self = shift;
$self->disconnect if $self->connected;
return $self;
}

sub _connect {
Expand Down
30 changes: 30 additions & 0 deletions lib/DBIx/Connection/Driver.pm
Expand Up @@ -54,8 +54,38 @@ __END__
DBIx::Connection::Driver - Database-specific connection interface
=head1 Description
Some of the things that DBIx::Connection does are implemented differently by
different drivers, or the official interface provided by the DBI may not be
implemented for a particular driver. The driver-specific code therefore is
encapsulated in this separate driver class.
Most of the DBI drivers work uniformly, so in most cases the implementation
provided here in DBIx::Connection::Driver will work just fine. It's only when
something is different that a driver subclass needs to be added. In such a
case, the subclass's name is the same as the DBI driver. For example the
driver for DBD::Pg is
L<DBIx::Connection::Driver::Pg|DBIx::Connection::Driver::Pg> and the driver
for DBD::mysql is
L<DBIx::Connection::Driver::mysql|DBIx::Connection::Driver::mysql>.
If you're just a user of DBIx::Connection, you can ignore the driver classes.
DBIx::Connection uses them internally to do its magic, so you needn't worry
about them.
=head1 Interface
In case you need to implement a driver, here's the interface you can modify.
=head2 Constructor
=head3 C<new>
my $driver = DBIx::Connection::Driver->new( driver => $driver );
Constructs and returns a driver object.
=head3 C<ping>
=head3 C<begin_work>
Expand Down
3 changes: 1 addition & 2 deletions t/base.t
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use Test::More tests => 93;
use Test::More tests => 92;
#use Test::More 'no_plan';
use Test::MockModule;

Expand Down Expand Up @@ -71,7 +71,6 @@ ok !$disconnect, 'Disconnect should not have been called';
ok !$rollback, 'And neither should rollback';

ok my $new = $CLASS->new( 'dbi:ExampleP:dummy', '', '' ), 'Instantiate again';
isnt $new, $conn, 'It should be a different object';
ok $dbh = $new->dbh, 'Connect again';
$dbh->{AutoCommit} = 0;
ok $new->DESTROY, 'DESTROY with a connection';
Expand Down

0 comments on commit f9f4bd3

Please sign in to comment.