It's difficult to get roles and attributes to play nice. Attributes basically have two parts to the implementation:
They need to be initialized in the constructor; and
You need to provide accessors for them.
The accessors are easy. But your role framework doesn't have any control over the constructor; the constructor gets built by the class framework!
That's why if you look at Perl implementations of roles, you'll see them fall into two neat categories:
Moose::Role, Mouse::Role, Moo::Role, and p5-mop roles all allow you to define attributes in roles.
These role implementations are all part of larger frameworks that include a class builder.
Role::Tiny and Role::Tiny do not allow you to define attributes in roles.
These role implementations are stand-alone.
So basically, if you want to write a role implementation that supports attributes, you'll need to write a class implementation to support it.
I'm not saying you shouldn't do it. It's a good learning experience.
In reply to Re^3: Object::InsideOut and Roles/Mixins
by tobyink
in thread Object::InsideOut and Roles/Mixins
by Yary
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |