Scalar::Util::Refcount - Show an object's reference count
my $foo = Bar->new; say refcount($foo); # prints "1" my $baz = $foo; say refcount($foo); # prints "2"
Provides two functions to show reference counts of Perl objects.
This can be handy when testing/debugging and you want to know what the heck is going on.
This is a trivial module. The documentation is longer than the code. Heck, the BSD license at the top of the file is longer than the code. It took longer to make it release-ready than it took to write it. It's handy, but seems almost not worth releasing.
I bet many of us have code like that in our personal libraries, and I can't help thinking that if more of us took the hour to clean it up, put it in a sensible namespace, write some documentation, and release it, the world would be a better place.
Given a Perl scalar, return the object's reference count. If the passed scalar is a reference, it is dereferenced and the reference count of the referenced object is returned. Otherwise the reference count of the scalar itself is returned. This is normally what you want.
This function is exported by default.
Returns the reference count of the given scalar, even if it's a reference. This is normally not what you want -- normally you'll have a reference to an object and want to know the reference count of the underlying object, not of the reference itself -- but sometimes it is.
This function is not exported by default.
There are no non-core dependencies. You will need a C compiler to install. Tested on Perl 5.10.0 and 5.8.8.
SWIG is not necessary to build, install, or use this module, but will be necessary if you want to modify it. See the README file.
Jeremy Nixon <jnixon@cpan.org>
Released under a BSD license (3-clause).
To install Scalar::Util::Refcount, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Scalar::Util::Refcount
CPAN shell
perl -MCPAN -e shell install Scalar::Util::Refcount
For more information on module installation, please visit the detailed CPAN module installation guide.