in reply to Re^2: Intercept any changes to the sv_refcnt/SvREFCNT of an object
in thread Intercept any changes to the sv_refcnt/SvREFCNT of an object

Clone::Fast has programatic hooks that could be integrated into B. Give that a try.
  • Comment on Re^3: Intercept any changes to the sv_refcnt/SvREFCNT of an object

Replies are listed 'Best First'.
Re^4: Intercept any changes to the sv_refcnt/SvREFCNT of an object
by vernonlyon (Novice) on Sep 13, 2011 at 16:54 UTC

    Unfortuantely this requires code to call the clone method, so won't work for me.

      I'm probably just as confused as you are, but I had been thinking that, short of modifying the macros, that something like this might help:
      #!/usr/bin/perl -slw use strict; use warnings; use B; use Clone::Fast; use Object::Destroyer; my $ref = {}; print B::svref_2object($ref)->REFCNT; my $copy = Clone::Fast::clone($ref); print B::svref_2object($ref)->REFCNT; my $sentry = Object::Destroyer->new(sub { undef $copy }); print B::svref_2object($ref)->REFCNT;
      Then I ran it using Devel::FindRef:
      #!/usr/bin/perl use strict; use B; use Clone::Fast; use Devel::FindRef; use Scalar::Util; use Object::Destroyer; our $ref = {}; my $global_my = \$ref; our(%global_hash) = (ukukey => \$ref); our(%global_hashref) = {ukukey2 => \$ref}; sub testsub { my $testsub_local = my $global_hashref; print Devel::FindRef::track(\$ref); } my $closure = sub { my $closure_var = \$_[0]; Scalar::Util::weaken (my $weak_ref = \$ref); testsub; }; sub my_ref { my $ref = {}; print B::svref_2object($ref)->REFCNT; my $copy = Clone::Fast::clone($ref); print B::svref_2object($ref)->REFCNT; my $sentry = Object::Destroyer->new(sub {undef $copy}); print B::svref_2object($ref)->REFCNT; testsub; } $closure->($ref);