Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
It's difficult to get roles and attributes to play nice. Attributes basically have two parts to the implementation:
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:
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.
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
In reply to Re^3: Object::InsideOut and Roles/Mixins
by tobyink
|
|