Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Do you think it's kosher to "re-bless" a Moose object?

by Anonymous Monk
on Nov 17, 2011 at 14:43 UTC ( #938627=note: print w/ replies, xml ) Need Help??


in reply to Do you think it's kosher to "re-bless" a Moose object?

Channelling mst from #moose:

Better to apply a role to an instance, or if you really must change the class use ->meta->rebless_instance. But applying a role at runtime is generally better. And if you have the data early enough, $class->with_traits(...)->new using MooseX::Traits would be ideal.


Comment on Re: Do you think it's kosher to "re-bless" a Moose object?
Select or Download Code
Re^2: Do you think it's kosher to "re-bless" a Moose object?
by sundialsvc4 (Abbot) on Nov 17, 2011 at 16:38 UTC

    It would be very helpful indeed if you could elaborate a bit on just what you mean by “early enough” ...

      It would be very helpful indeed if you could elaborate a bit on just what you mean by “early enough” ...

      He means that if you know what traits you want applied before the instance is created, then MooseX::Traits is likely useful (since you use it prior to constructing an instance). But if you don't know what traits you want to apply until after, then you can just use runtime role application (there is a cookbook for that I believe).

      -stvn

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://938627]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-09-22 06:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (182 votes), past polls