Skip to content

Commit

Permalink
Merge pull request #14 from tsucchi/add_disconnect
Browse files Browse the repository at this point in the history
Add disconnect
  • Loading branch information
ytnobody committed Nov 13, 2015
2 parents 7dee547 + 5617208 commit 34dcbda
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 62 deletions.
57 changes: 2 additions & 55 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,9 @@
# =========================================================================

use 5.008_001;

use strict;
use warnings;
use utf8;

use Module::Build;
use File::Basename;
use File::Spec;

my %args = (
license => 'perl',
dynamic_config => 0,

configure_requires => {
'Module::Build' => 0.38,
},

name => 'Otogiri',
module_name => 'Otogiri',
allow_pureperl => 0,

script_files => [glob('script/*'), glob('bin/*')],
c_source => [qw()],
PL_files => {},

test_files => ((-d '.git' || $ENV{RELEASE_TESTING}) && -d 'xt') ? 't/ xt/' : 't/',
recursive_test_files => 1,


);
if (-d 'share') {
$args{share_dir} = 'share';
}

my $builder = Module::Build->subclass(
class => 'MyBuilder',
code => q{
sub ACTION_distmeta {
die "Do not run distmeta. Install Minilla and `minil install` instead.\n";
}
sub ACTION_installdeps {
die "Do not run installdeps. Run `cpanm --installdeps .` instead.\n";
}
}
)->new(%args);
$builder->create_build_script();

use File::Copy;

print "cp META.json MYMETA.json\n";
copy("META.json","MYMETA.json") or die "Copy failed(META.json): $!";
use Module::Build::Tiny 0.035;

if (-f 'META.yml') {
print "cp META.yml MYMETA.yml\n";
copy("META.yml","MYMETA.yml") or die "Copy failed(META.yml): $!";
} else {
print "There is no META.yml... You may install this module from the repository...\n";
}
Build_PL();

4 changes: 2 additions & 2 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ytnobody <ytnobody@gmail.com>"
],
"dynamic_config" : 0,
"generated_by" : "Minilla/v2.3.0, CPAN::Meta::Converter version 2.143240",
"generated_by" : "Minilla/v3.0.0, CPAN::Meta::Converter version 2.141170",
"license" : [
"perl_5"
],
Expand All @@ -28,7 +28,7 @@
"prereqs" : {
"configure" : {
"requires" : {
"Module::Build" : "0.38"
"Module::Build::Tiny" : "0.035"
}
},
"develop" : {
Expand Down
19 changes: 16 additions & 3 deletions lib/DBIx/Otogiri.pm
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,19 @@ sub reconnect {

$self->_in_transaction_check();

my $dbh = $self->{dbh};
$self->{dbh}->disconnect();
$self->owner_pid(undef);
$self->disconnect();

my $dbh = $self->{dbh};
$self->{dbh} = $dbh->clone();
$self->owner_pid($$);
}

sub disconnect {
my ($self) = @_;
$self->{dbh}->disconnect();
$self->owner_pid(undef);
}

sub dbh {
my ($self) = @_;
my $dbh = $self->{dbh};
Expand Down Expand Up @@ -324,6 +329,14 @@ returns DBIx::TransactionManager::ScopeGuard's instance. See L<DBIx::Transaction
returns last_insert_id. (mysql_insertid in MySQL or last_insert_rowid in SQLite)
=head2 disconnect
disconnect database.
=head2 reconnect
reconnect database.
=head1 LICENSE
Expand Down
4 changes: 2 additions & 2 deletions t/15_auto_reconnect.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ my $person_id = $db->last_insert_id();


subtest 'reconnect', sub {
$db->dbh->disconnect();
$db->disconnect();
$db->reconnect();
my $row = $db->single('person', { id => $person_id });
ok( defined $row );
};

subtest 'auto reconnect', sub {
$db->dbh->disconnect();
$db->disconnect();
#$db->reconnect();
my $row = $db->single('person', { id => $person_id });
ok( defined $row );
Expand Down

0 comments on commit 34dcbda

Please sign in to comment.