use DBIx::Class::Carp;
use Try::Tiny;
use Scalar::Util qw/weaken blessed/;
+use DBIx::Class::_Util 'refcount';
use Sub::Name 'subname';
-use B 'svref_2object';
use Devel::GlobalDestruction;
use namespace::clean;
# which will serve as a signal to not try doing anything else
# however beware - on older perls the exception seems randomly untrappable
# due to some weird race condition during thread joining :(((
- if (ref $srcs->{$source_name} and svref_2object($srcs->{$source_name})->REFCNT > 1) {
+ if (length ref $srcs->{$source_name} and refcount($srcs->{$source_name}) > 1) {
local $@;
eval {
$srcs->{$source_name}->schema($self);
use Scalar::Util qw(refaddr weaken);
use base 'Exporter';
-our @EXPORT_OK = qw(sigwarn_silencer modver_gt_or_eq fail_on_internal_wantarray);
+our @EXPORT_OK = qw(sigwarn_silencer modver_gt_or_eq fail_on_internal_wantarray refcount);
sub sigwarn_silencer {
my $pattern = shift;
return sub { &$orig_sig_warn unless $_[0] =~ $pattern };
}
+sub refcount {
+ croak "Expecting a reference" if ! length ref $_[0];
+
+ require B;
+ # No tempvars - must operate on $_[0], otherwise the pad
+ # will count as an extra ref
+ B::svref_2object($_[0])->REFCNT;
+}
+
sub modver_gt_or_eq {
my ($mod, $ver) = @_;
use Carp;
use Scalar::Util qw/isweak weaken blessed reftype refaddr/;
-use B 'svref_2object';
+use DBIx::Class::_Util 'refcount';
use DBICTest::Util 'stacktrace';
use base 'Exporter';
and
my $expected_refcnt = $classdata_refcounts->{$weak_registry->{$slot}{refaddr}}
) {
- # need to store the SVref and examine it separately,
- # to push the weakref instance off the pad
- my $sv = svref_2object($weak_registry->{$slot}{weakref});
- delete $weak_registry->{$slot} if $sv->REFCNT == $expected_refcnt;
+ delete $weak_registry->{$slot}
+ if refcount($weak_registry->{$slot}{weakref}) == $expected_refcnt;
}
}
}