Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Why is MooseX::Traits::apply_traits() deprecated?

by stevenl (Initiate)
on Nov 28, 2012 at 03:06 UTC ( [id://1005953]=perlquestion: print w/replies, xml ) Need Help??

stevenl has asked for the wisdom of the Perl Monks concerning the following question:

This question is specifically about MooseX::Traits. The method apply_traits() was deprecated a while ago and it gives a warning message as follows:
apply_traits is deprecated due to being fundamentally broken. disable this warning with "no warnings 'MooseX::Traits'"
Can anyone explain why it is 'fundamentally broken'? It passes its own tests on that method, and it works for what I'm trying to do. Is it because it uses Moose::Meta::Role::apply()?

Replies are listed 'Best First'.
Re: Why is MooseX::Traits::apply_traits() deprecated?
by tobyink (Canon) on Nov 28, 2012 at 07:59 UTC

    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. :-)

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Why is MooseX::Traits::apply_traits() deprecated?
by tobyink (Canon) on Nov 28, 2012 at 10:37 UTC

    PS: the deprecation was committed by jrockway so if you need a definitive answer, ask him.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1005953]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2024-03-28 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found