This could be automated by letting objects 'de-register' themselves when they go out of scope e.g.
DESTROY { my $self = shift; delete $REGISTRY{$self}; }
The above will not actually work. DESTROY will never be called because $REGISTRY{$self} will have bumped the reference count. (Or rather it will get called, but only when the entire process ends - not when the object goes out of scope.)
Instead, you should use Scalar::Util to weaken $REGISTRY{$self} as part of the object construction. No DESTROY sub is necessary for this to work.
In reply to Re^2: Class confusion when testing using ref()
by tobyink
in thread Class confusion when testing using ref()
by atcroft
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |