Skip to content

Commit

Permalink
Reorganize constants handling, add escapes for fork-less OSes
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi committed Nov 3, 2012
1 parent 8249c09 commit 0d8817b
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 52 deletions.
61 changes: 27 additions & 34 deletions lib/DBIx/Class.pm
Expand Up @@ -19,48 +19,41 @@ BEGIN {
package # hide from pause
DBIx::Class::_ENV_;

if ($] < 5.009_005) {
require MRO::Compat;
*OLD_MRO = sub () { 1 };
}
else {
require mro;
*OLD_MRO = sub () { 0 };
}
use Config;

# ::Runmode would only be loaded by DBICTest, which in turn implies t/
*DBICTEST = eval { DBICTest::RunMode->is_author }
? sub () { 1 }
: sub () { 0 }
;
use constant {

# There was a brief period of p5p insanity when $@ was invisible in a DESTROY
*INVISIBLE_DOLLAR_AT = ($] >= 5.013001 and $] <= 5.013007)
? sub () { 1 }
: sub () { 0 }
;
# but of course
BROKEN_FORK => ($^O eq 'MSWin32') ? 1 : 0,

# During 5.13 dev cycle HELEMs started to leak on copy
*PEEPEENESS = (defined $ENV{DBICTEST_ALL_LEAKS}
# request for all tests would force "non-leaky" illusion and vice-versa
? ! $ENV{DBICTEST_ALL_LEAKS}
HAS_ITHREADS => $Config{useithreads} ? 1 : 0,

# otherwise confess that this perl is busted ONLY on smokers
: do {
if (eval { DBICTest::RunMode->is_smoker }) {
# ::Runmode would only be loaded by DBICTest, which in turn implies t/
DBICTEST => eval { DBICTest::RunMode->is_author } ? 1 : 0,

# leaky 5.13.6 (fixed in blead/cefd5c7c)
if ($] == '5.013006') { 1 }
# During 5.13 dev cycle HELEMs started to leak on copy
PEEPEENESS =>
# request for all tests would force "non-leaky" illusion and vice-versa
defined $ENV{DBICTEST_ALL_LEAKS} ? !$ENV{DBICTEST_ALL_LEAKS}
# otherwise confess that this perl is busted ONLY on smokers
: eval { DBICTest::RunMode->is_smoker } && ($] >= 5.013005 and $] <= 5.013006) ? 1
# otherwise we are good
: 0
,

# not sure why this one leaks, but disable anyway - ANDK seems to make it weep
elsif ($] == '5.013005') { 1 }
# There was a brief period of p5p insanity when $@ was invisible in a DESTROY
INVISIBLE_DOLLAR_AT => ($] >= 5.013001 and $] <= 5.013007) ? 1 : 0,

else { 0 }
}
else { 0 }
}
) ? sub () { 1 } : sub () { 0 };
};

if ($] < 5.009_005) {
require MRO::Compat;
constant->import( OLD_MRO => 1 );
}
else {
require mro;
constant->import( OLD_MRO => 0 );
}
}

use mro 'c3';
Expand Down
2 changes: 1 addition & 1 deletion lib/DBIx/Class/Carp.pm
Expand Up @@ -114,7 +114,7 @@ sub import {
## FIXME FIXME FIXME - something is tripping up V::M on 5.8.1, leading
# to segfaults. When n::c/B::H::EndOfScope is rewritten in terms of tie()
# see if this starts working
unless DBIx::Class::_ENV_::BROKEN_NAMESPACE_CLEAN();
unless DBIx::Class::_ENV_::BROKEN_NAMESPACE_CLEAN;
}

sub unimport {
Expand Down
16 changes: 8 additions & 8 deletions lib/DBIx/Class/Storage/DBI.pm
Expand Up @@ -207,7 +207,7 @@ sub new {
END {
local $?; # just in case the DBI destructor changes it somehow

# destroy just the object if not native to this process/thread
# destroy just the object if not native to this process
$_->_verify_pid for (grep
{ defined $_ }
values %seek_and_destroy
Expand All @@ -233,7 +233,7 @@ sub DESTROY {
my $self = shift;

# some databases spew warnings on implicit disconnect
$self->_verify_pid;
$self->_verify_pid unless DBIx::Class::_ENV_::BROKEN_FORK;
local $SIG{__WARN__} = sub {};
$self->_dbh(undef);

Expand Down Expand Up @@ -885,7 +885,7 @@ sub connected {
sub _seems_connected {
my $self = shift;

$self->_verify_pid;
$self->_verify_pid unless DBIx::Class::_ENV_::BROKEN_FORK;

my $dbh = $self->_dbh
or return 0;
Expand Down Expand Up @@ -933,7 +933,7 @@ sub dbh {
# this is the internal "get dbh or connect (don't check)" method
sub _get_dbh {
my $self = shift;
$self->_verify_pid;
$self->_verify_pid unless DBIx::Class::_ENV_::BROKEN_FORK;
$self->_populate_dbh unless $self->_dbh;
return $self->_dbh;
}
Expand Down Expand Up @@ -1007,7 +1007,7 @@ sub _populate_dbh {

$self->_dbh($self->_connect(@info));

$self->_conn_pid($$) if $^O ne 'MSWin32'; # on win32 these are in fact threads
$self->_conn_pid($$) unless DBIx::Class::_ENV_::BROKEN_FORK; # on win32 these are in fact threads

$self->_determine_driver;

Expand Down Expand Up @@ -1366,7 +1366,7 @@ sub _exec_txn_begin {
sub txn_commit {
my $self = shift;

$self->_verify_pid if $self->_dbh;
$self->_verify_pid unless DBIx::Class::_ENV_::BROKEN_FORK;
$self->throw_exception("Unable to txn_commit() on a disconnected storage")
unless $self->_dbh;

Expand Down Expand Up @@ -1397,7 +1397,7 @@ sub _exec_txn_commit {
sub txn_rollback {
my $self = shift;

$self->_verify_pid if $self->_dbh;
$self->_verify_pid unless DBIx::Class::_ENV_::BROKEN_FORK;
$self->throw_exception("Unable to txn_rollback() on a disconnected storage")
unless $self->_dbh;

Expand Down Expand Up @@ -1430,7 +1430,7 @@ for my $meth (qw/svp_begin svp_release svp_rollback/) {
no strict qw/refs/;
*{__PACKAGE__ ."::$meth"} = subname $meth => sub {
my $self = shift;
$self->_verify_pid if $self->_dbh;
$self->_verify_pid unless DBIx::Class::_ENV_::BROKEN_FORK;
$self->throw_exception("Unable to $meth() on a disconnected storage")
unless $self->_dbh;
$self->next::method(@_);
Expand Down
2 changes: 1 addition & 1 deletion lib/DBIx/Class/Storage/TxnScopeGuard.pm
Expand Up @@ -111,7 +111,7 @@ sub DESTROY {
return if $self->{inactivated};

# if our dbh is not ours anymore, the $dbh weakref will go undef
$self->{storage}->_verify_pid;
$self->{storage}->_verify_pid unless DBIx::Class::_ENV_::BROKEN_FORK;
return unless $self->{dbh};

my $exception = $@ if (
Expand Down
3 changes: 3 additions & 0 deletions t/53lean_startup.t
Expand Up @@ -32,6 +32,9 @@ BEGIN {
strict
warnings
constant
Config
base
mro
overload
Expand Down
4 changes: 2 additions & 2 deletions t/55namespaces_cleaned.t
Expand Up @@ -109,7 +109,7 @@ for my $mod (@modules) {

for my $name (keys %all_method_like) {

next if ( DBIx::Class::_ENV_::BROKEN_NAMESPACE_CLEAN() and $name =~ /^carp(?:_unique|_once)?$/ );
next if ( DBIx::Class::_ENV_::BROKEN_NAMESPACE_CLEAN and $name =~ /^carp(?:_unique|_once)?$/ );

# overload is a funky thing - it is not cleaned, and its imports are named funny
next if $name =~ /^\(/;
Expand Down Expand Up @@ -154,7 +154,7 @@ for my $mod (@modules) {
}
}

next if DBIx::Class::_ENV_::BROKEN_NAMESPACE_CLEAN();
next if DBIx::Class::_ENV_::BROKEN_NAMESPACE_CLEAN;

# some common import names (these should never ever be methods)
for my $f (qw/carp carp_once carp_unique croak confess cluck try catch finally/) {
Expand Down
4 changes: 2 additions & 2 deletions t/71mysql.t
Expand Up @@ -388,7 +388,7 @@ ZEROINSEARCH: {

TODO: {
local $TODO = "Perl $] is known to leak like a sieve"
if DBIx::Class::_ENV_::PEEPEENESS();
if DBIx::Class::_ENV_::PEEPEENESS;

ok (! defined $orig_dbh, 'Parent $dbh handle is gone');
}
Expand All @@ -412,7 +412,7 @@ ZEROINSEARCH: {

TODO: {
local $TODO = "Perl $] is known to leak like a sieve"
if DBIx::Class::_ENV_::PEEPEENESS();
if DBIx::Class::_ENV_::PEEPEENESS;

ok (! defined $orig_dbh, 'DBIC operation triggered reconnect - old $dbh is gone');
}
Expand Down
2 changes: 1 addition & 1 deletion t/lib/DBICTest.pm
Expand Up @@ -189,7 +189,7 @@ sub _database {
}

sub __mk_disconnect_guard {
return if DBIx::Class::_ENV_::PEEPEENESS(); # leaks handles, delaying DESTROY, can't work right
return if DBIx::Class::_ENV_::PEEPEENESS; # leaks handles, delaying DESTROY, can't work right

my $db_file = shift;
return unless -f $db_file;
Expand Down
5 changes: 2 additions & 3 deletions t/storage/error.t
Expand Up @@ -6,8 +6,7 @@ use Test::Warn;
use Test::Exception;

use lib qw(t/lib);
use_ok( 'DBICTest' );
use_ok( 'DBICTest::Schema' );
use DBICTest;

my $schema = DBICTest->init_schema;

Expand Down Expand Up @@ -35,7 +34,7 @@ throws_ok (
# exception fallback:

SKIP: {
if (DBIx::Class::_ENV_::PEEPEENESS()) {
if (DBIx::Class::_ENV_::PEEPEENESS) {
skip "Your perl version $] appears to leak like a sieve - skipping garbage collected \$schema test", 1;
}

Expand Down

0 comments on commit 0d8817b

Please sign in to comment.