John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:
In Perl6, you have a but keyword that will dynamically apply a role to an instance, without having to name a new class for it and create the instance of that type.
I saw some clues in the manual the Moose might do this even though it doesn't offer syntactic sugar for it. Is there a good way to do this directly (as opposed to messing with MOP directly)?
That is, can Moose add a role ("traits") to an instance after it has been created, as opposed to having to declare a derived class that is based on the original class and adds the role as well? I'm thinking that one "plug in" might need to add roles to several collaborating objects, as well as do more mundane things with those object's APIs.
Catalyst, for example, lets you specify some extensions as arguments to new. Along the lines I'm thinking, the BUILD routine can slurp them in.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extensions via Moose
by stvn (Monsignor) on Apr 28, 2011 at 21:43 UTC | |
by John M. Dlugosz (Monsignor) on Apr 29, 2011 at 00:16 UTC | |
by stvn (Monsignor) on Apr 29, 2011 at 13:56 UTC | |
by John M. Dlugosz (Monsignor) on Apr 30, 2011 at 08:23 UTC | |
by stvn (Monsignor) on May 01, 2011 at 01:48 UTC | |
by John M. Dlugosz (Monsignor) on Apr 30, 2011 at 09:06 UTC | |
by stvn (Monsignor) on May 01, 2011 at 01:56 UTC |