HAS_ITHREADS => $Config{useithreads} ? 1 : 0,
+ UNSTABLE_DOLLARAT => ( "$]" < 5.013002 ) ? 1 : 0,
+
DBICTEST => $INC{"DBICTest/Util.pm"} ? 1 : 0,
# During 5.13 dev cycle HELEMs started to leak on copy
our @EXPORT_OK = qw(
sigwarn_silencer modver_gt_or_eq modver_gt_or_eq_and_lt
fail_on_internal_wantarray fail_on_internal_call
- refdesc refcount hrefaddr is_exception detected_reinvoked_destructor
+ refdesc refcount hrefaddr
+ scope_guard is_exception detected_reinvoked_destructor
quote_sub qsub perlstring serialize deep_clone
UNRESOLVABLE_CONDITION
);
nfreeze($_[0]);
}
+sub scope_guard (&) {
+ croak 'Calling scope_guard() in void context makes no sense'
+ if ! defined wantarray;
+
+ # no direct blessing of coderefs - DESTROY is buggy on those
+ bless [ $_[0] ], 'DBIx::Class::_Util::ScopeGuard';
+}
+{
+ package #
+ DBIx::Class::_Util::ScopeGuard;
+
+ sub DESTROY {
+ &DBIx::Class::_Util::detected_reinvoked_destructor;
+
+ local $@ if DBIx::Class::_ENV_::UNSTABLE_DOLLARAT;
+
+ eval {
+ $_[0]->[0]->();
+ 1;
+ } or do {
+ Carp::cluck "Execution of scope guard $_[0] resulted in the non-trappable exception:\n\n$@";
+ };
+ }
+}
+
+
sub is_exception ($) {
my $e = $_[0];
use Test::More;
use Test::Exception;
-use Scope::Guard ();
use Try::Tiny;
use DBIx::Class::Optional::Dependencies ();
+use DBIx::Class::_Util 'scope_guard';
use lib qw(t/lib);
use DBICTest;
auto_savepoint => 1
});
- my $guard = Scope::Guard->new(sub{ cleanup($schema) });
+ my $guard = scope_guard { cleanup($schema) };
my $dbh = $schema->storage->dbh;
use Test::More;
use Test::Exception;
use DBIx::Class::Optional::Dependencies ();
-use Scope::Guard ();
+use DBIx::Class::_Util 'scope_guard';
use List::Util 'shuffle';
use Try::Tiny;
use lib qw(t/lib);
});
my $dbh = $schema->storage->dbh;
- my $sg = Scope::Guard->new(sub { cleanup($schema) });
+ my $sg = scope_guard { cleanup($schema) };
eval { $dbh->do(q[DROP TABLE "artist"]) };
$dbh->do(<<EOF);
use Test::More;
use Test::Exception;
-use Scope::Guard ();
use Try::Tiny;
use DBIx::Class::Optional::Dependencies ();
+use DBIx::Class::_Util 'scope_guard';
use lib qw(t/lib);
use DBICTest;
LongReadLen => $maxloblen,
});
- my $guard = Scope::Guard->new(sub { cleanup($schema) });
+ my $guard = scope_guard { cleanup($schema) };
my $dbh = $schema->storage->dbh;
use warnings;
use Test::More;
+use DBIx::Class::_Util 'scope_guard';
use lib qw(t/lib);
use DBICTest;
-use Scope::Guard ();
my $env2optdep = {
DBICTEST_FIREBIRD => 'test_rdbms_firebird',
on_connect_call => [ 'datetime_setup' ],
});
- my $sg = Scope::Guard->new(sub { cleanup($schema) } );
+ my $sg = scope_guard { cleanup($schema) };
eval { $schema->storage->dbh->do('DROP TABLE "event"') };
$schema->storage->dbh->do(<<'SQL');
use warnings;
use Test::More;
+use DBIx::Class::_Util 'scope_guard';
use lib qw(t/lib);
use DBICTest;
-use Scope::Guard ();
my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_INFORMIX_${_}" } qw/DSN USER PASS/};
my $schema;
on_connect_call => [ 'datetime_setup' ],
});
- my $sg = Scope::Guard->new(sub { cleanup($schema) } );
+ my $sg = scope_guard { cleanup($schema) };
eval { $schema->storage->dbh->do('DROP TABLE event') };
$schema->storage->dbh->do(<<'SQL');
use warnings;
use Test::More;
-use Scope::Guard ();
use Try::Tiny;
+use DBIx::Class::_Util 'scope_guard';
use lib qw(t/lib);
use DBICTest;
quote_names => 1,
});
- my $guard = Scope::Guard->new(sub { cleanup($schema) });
+ my $guard = scope_guard { cleanup($schema) };
try { local $^W = 0; $schema->storage->dbh->do('DROP TABLE track') };
$schema->storage->dbh->do(<<"SQL");
use Test::More;
use Test::Exception;
-use Scope::Guard ();
use Try::Tiny;
+use DBIx::Class::_Util 'scope_guard';
use lib qw(t/lib);
use DBICTest;
}
}
- my $guard = Scope::Guard->new(sub{ cleanup($schema) });
+ my $guard = scope_guard { cleanup($schema) };
# $^W because DBD::ADO is a piece of crap
try { local $^W = 0; $schema->storage->dbh->do("DROP TABLE track") };
use warnings;
use Test::More;
-use Scope::Guard ();
+use DBIx::Class::_Util 'scope_guard';
use lib qw(t/lib);
use DBICTest;
on_connect_call => 'datetime_setup',
});
- my $sg = Scope::Guard->new(sub { cleanup($schema) } );
+ my $sg = scope_guard { cleanup($schema) };
eval { $schema->storage->dbh->do('DROP TABLE event') };
$schema->storage->dbh->do(<<"SQL");
use Test::More;
use Test::Exception;
-use Scope::Guard ();
-use Try::Tiny;
+use DBIx::Class::_Util 'scope_guard';
use lib qw(t/lib);
use DBICTest;
on_connect_call => 'datetime_setup',
});
- my $guard = Scope::Guard->new(sub { cleanup($schema) } );
+ my $guard = scope_guard { cleanup($schema) };
$schema->storage->ensure_connected;
use DBICTest::Util qw( local_umask await_flock dbg DEBUG_TEST_CONCURRENCY_LOCKS );
use DBICTest::Schema;
use DBICTest::Util::LeakTracer qw/populate_weakregistry assert_empty_weakregistry/;
-use DBIx::Class::_Util 'detected_reinvoked_destructor';
+use DBIx::Class::_Util qw( detected_reinvoked_destructor scope_guard );
use Carp;
use Path::Class::File ();
use File::Spec;
use Fcntl qw/:DEFAULT :flock/;
use Config;
-use Scope::Guard ();
=head1 NAME
my $guard;
if ( ($ENV{TRAVIS}||'') eq 'true' and my $old_dbg = $schema->storage->debug ) {
- $guard = Scope::Guard->new(sub { $schema->storage->debug($old_dbg) });
+ $guard = scope_guard { $schema->storage->debug($old_dbg) };
$schema->storage->debug(0);
}
my $guard;
if ( ($ENV{TRAVIS}||'') eq 'true' and my $old_dbg = $schema->storage->debug ) {
- $guard = Scope::Guard->new(sub { $schema->storage->debug($old_dbg) });
+ $guard = scope_guard { $schema->storage->debug($old_dbg) };
$schema->storage->debug(0);
}
use Fcntl qw(:DEFAULT :seek :flock);
use Time::HiRes 'sleep';
-use Scope::Guard ();
+use DBIx::Class::_Util 'scope_guard';
use DBICTest::Util::LeakTracer qw(populate_weakregistry assert_empty_weakregistry);
use DBICTest::Util qw( local_umask await_flock dbg DEBUG_TEST_CONCURRENCY_LOCKS );
use namespace::clean;
qw(debugcb debugobj debug)
};
- my $sg = Scope::Guard->new(sub {
+ my $sg = scope_guard {
$self->storage->$_ ( $orig_states->{$_} ) for keys %$orig_states;
- });
+ };
$self->storage->debugcb(undef);
$self->storage->debugobj( my $tracer_obj = DBICTest::SQLTracerObj->new );
;
use Config;
-use Carp 'confess';
+use Carp qw(cluck confess croak);
use Fcntl ':flock';
use Scalar::Util qw(blessed refaddr);
-use DBIx::Class::_Util;
+use DBIx::Class::_Util 'scope_guard';
use base 'Exporter';
our @EXPORT_OK = qw(
return $res;
}
-sub local_umask {
+
+sub local_umask ($) {
return unless defined $Config{d_umask};
- die 'Calling local_umask() in void context makes no sense'
+ croak 'Calling local_umask() in void context makes no sense'
if ! defined wantarray;
- my $old_umask = umask(shift());
+ my $old_umask = umask($_[0]);
die "Setting umask failed: $!" unless defined $old_umask;
- return bless \$old_umask, 'DBICTest::Util::UmaskGuard';
-}
-{
- package DBICTest::Util::UmaskGuard;
- sub DESTROY {
- &DBIx::Class::_Util::detected_reinvoked_destructor;
-
- local ($@, $!);
- eval { defined (umask ${$_[0]}) or die };
- warn ( "Unable to reset old umask ${$_[0]}: " . ($!||'Unknown error') )
- if ($@ || $!);
- }
+ scope_guard(sub {
+ local ($@, $!, $?);
+
+ eval {
+ defined(umask $old_umask) or die "nope";
+ 1;
+ } or cluck (
+ "Unable to reset old umask '$old_umask': " . ($! || 'Unknown error')
+ );
+ });
}
sub stacktrace {
# and that's a whole another bag of dicks
BEGIN { $ENV{DBIC_SHUFFLE_UNORDERED_RESULTSETS} = 0 }
+use DBIx::Class::_Util 'scope_guard';
+
use DBICTest::Schema::CD;
BEGIN {
# the default scalarref table name will not work well for this test
$schema->is_executed_sql_bind( sub {
my $orig_umi = $schema->storage->_use_multicolumn_in;
- my $sg = Scope::Guard->new(sub {
+ my $sg = scope_guard {
$schema->storage->_use_multicolumn_in($orig_umi);
- });
+ };
$schema->storage->_use_multicolumn_in(1);
use Test::More;
use Test::Exception;
-use DBIx::Class::_Util qw(modver_gt_or_eq sigwarn_silencer);
+use DBIx::Class::_Util qw(modver_gt_or_eq sigwarn_silencer scope_guard);
use lib qw(t/lib);
use DBICTest;
{ $_ => $schema->storage->$_ }
qw(debugcb debugobj debug)
};
- my $sg = Scope::Guard->new(sub {
+ my $sg = scope_guard {
$schema->storage->$_ ( $orig_states->{$_} ) for keys %$orig_states;
- });
+ };
$schema->storage->debugobj (my $stats = DBICTest::SVPTracerObj->new);
$schema->storage->debug (1);