Interesting. Your Trait::Selected
class
looks very much like an inside-out class. In
fact, using
Object::InsideOut it could be
implemented, very simply, as follows:
package Trait::Selected;
use Object::InsideOut;
my %is_selected :Field :Acc(is_selected);
(Of course, looking at
Class::Trait, I see that it offers a lot of functionality beyond that covered by my simple example above.)
Class::Trait->apply( $some_class, 'Trait::Selected' );
Ah, sweet synergy! This prompted me to add a
runtime inheritance mechanism to
Object::InsideOut:
My::Class->add_class('Trait::Selected');
What happens when the object goes
out of scope? The trait still retains that
object’s selected value and it’s tricky to remove.
If done using Object::InsideOut, this is no issue
at all: The trait will be automatically cleaned
up when an object is destroyed.
I just uploaded Object::InsideOut v2.08 (which contains the runtime inheritance feature) to CPAN. Thanks for the idea.
Remember: There's always one more bug.