Devel-Refcount
view release on metacpan or search on metacpan
lib/Devel/Refcount.pm view on Meta::CPAN
use Exporter 'import';
our @EXPORT_OK = qw( refcount assert_oneref );
require XSLoader;
if( !eval { XSLoader::load( __PACKAGE__, $VERSION ) } ) {
*refcount = \&_refcount_pp;
require B;
}
use Carp;
use Scalar::Util qw( weaken );
=head1 NAME
C<Devel::Refcount> - obtain the REFCNT value of a referent
=head1 SYNOPSIS
use Devel::Refcount qw( refcount );
my $anon = [];
lib/Devel/Refcount.pm view on Meta::CPAN
If at the time of deleting there are any other references to this object then
the assertion will fail; and if C<Devel::FindRef> is available the other
locations will be printed.
=cut
sub assert_oneref
{
my $object = shift;
weaken $object;
my $refcount = refcount( $object );
return if $refcount == 1;
my $message = Carp::shortmess( "Expected $object to have only one reference, found $refcount" );
if( eval { require Devel::FindRef } ) {
my $track = Devel::FindRef::track( $object );
die "$message\n$track\n";
}
( run in 0.601 second using v1.01-cache-2.11-cpan-65fba6d93b7 )