| 1 | |||
| 2 | package DBIx::Romani::Connection; | ||
| 3 | use base qw(DBIx::Romani::Connection::Base); | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | |||
| 7 | sub new | ||
| 8 | { | ||
| 9 | my $class = shift; | ||
| 10 | my $args = shift; | ||
| 11 | |||
| 12 | my $dbh; | ||
| 13 | my $driver; | ||
| 14 | my $disconnect; | ||
| 15 | |||
| 16 | if ( ref($args) eq 'HASH' ) | ||
| 17 | { | ||
| 18 | $driver = $args->{driver}; | ||
| 19 | $dbh = $args->{dbh}; | ||
| 20 | $disconnect = $args->{disconnect} | ||
| 21 | } | ||
| 22 | else | ||
| 23 | { | ||
| 24 | $driver = $args; | ||
| 25 | $dbh = shift; | ||
| 26 | } | ||
| 27 | |||
| 28 | if ( not defined $disconnect ) | ||
| 29 | { | ||
| 30 | $disconnect = 1; | ||
| 31 | } | ||
| 32 | |||
| 33 | my $self = $class->SUPER::new({ dbh => $dbh, driver => $driver }); | ||
| 34 | |||
| 35 | # store our disconnect state | ||
| 36 | $self->{disconnect} = $disconnect; | ||
| 37 | |||
| 38 | bless $self, $class; | ||
| 39 | return $self; | ||
| 40 | } | ||
| 41 | |||
| 42 | sub disconnect | ||
| 43 | { | ||
| 44 | my $self = shift; | ||
| 45 | |||
| 46 | if ( $self->{disconnect} ) | ||
| 47 | { | ||
| 48 | $self->SUPER::disconnect(); | ||
| 49 | } | ||
| 50 | |||
| 51 | $self->{dbh} = undef; | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; | ||
| 55 |