There is a comment in the source code that offers a little (but not much) more explanation:
# this code is broken and should never have been added. i probably # won't delete it, but it is definitely not up-to-date with respect to # other features, and never will be. # # runtime role application is fundamentally broken. if you really # need it, write it yourself, but consider applying the roles before # you create an instance.
There are some obvious problems with run-time role application. For example, if you have an existing object $o, and you then apply this role to it at runtime:
package Example::Role { use Moose::Role; has thingy => (is => 'ro', isa => 'Str', required => 1); }
Then what is the value of $o->thingy? If you consider a role to be a contract that an object is obliged to implement, then the runtime application of Example::Role to $o is breaking that contract.
For runtime role application to an object, I'd use Moose::Util's ensure_all_roles function. It still suffers from the same problems but at least it doesn't have this annoying warning message. :-)
In reply to Re: Why is MooseX::Traits::apply_traits() deprecated?
by tobyink
in thread Why is MooseX::Traits::apply_traits() deprecated?
by stevenl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |