It seems like this is a lot of effort to modify the objects instead of fixing the initial data structure used to track selections. For example, why not just add selected items to a Set::Object? (Or, for lower tech, just an array.)
use Set::Object; my $selected = Set::Object->new; # create set $selected->insert( @some_objects ); # add objects @servers = $@selected; # get them back
What happens when the object goes out of scope?
You're using something like the inside-out technique with all the usual problems cleaning up afterwards. You could wrap the primary class' DESTROY method (or add one) to clean up the trait and then continue with destruction.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
In reply to Re: Maintaining State with Runtime Traits
by xdg
in thread Maintaining State with Runtime Traits
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |