laziness, impatience, and hubris | |
PerlMonks |
SOLVED: Trying to DESTROY() a (closure-wrapped) objectby stevieb (Canon) |
on Dec 08, 2015 at 15:42 UTC ( [id://1149680]=perlquestion: print w/replies, xml ) | Need Help?? |
stevieb has asked for the wisdom of the Perl Monks concerning the following question: Hey Monks, I've read up on Scalar::Util::weaken(), but I can't figure out what exactly I need to do so that my object is DESTROY()ed before END. The output should read foo, baz, foo, but because the object isn't being destroyed before END, I'm getting foo, baz, baz. I know the problem is with this statement: *One::foo = sub { $self->{x} = 'x'; return "baz\n"; };, because I'm creating a reference to $self within the reference, increasing the REFCNT. Could someone please let me know if weaken() can help here (and how to implement it), or if there's a better way to do this? Here's my test script:
...and a simplified example module (well two, included inside of a single file):
I thought about using copies of the $self variables instead of directly within the sub re-def, but I don't think I can, as the real code is more like this:
Back to
Seekers of Perl Wisdom
|
|