On May 10, 2010, at 11:17 PM, Christopher Brown wrote:
Mike,

Let me take a stab as I understand it. Hopefully, some of the other Moosers
will correct me if I am wrong:

Are traits and roles the same, here?

Yes. Metaclass traits are roles applied to the metaclass.  It IS that
simple.

Yup, Christopher is correct, that is all they really are.

I further generalize it to say that "traits" are roles applied to an instance, and most often that instance is a meta-object.

The reason for the different name comes from the Perl 6 roots of Moose. In Perl 6 they had "traits" which looked something like this:

  my $foo is Bedazzled;

where "Bedazzled" is a trait that is applied to $foo. The Perl 6 specs being very hand-wavey at times, didn't define exactly what a "trait" was (I think they have now locked it down, but I am going back 4 or so years here). In my meta-fueled imagination I always saw traits as being roles applied to the underlying meta-objects. In the above case the Bedazzled role would be applied to the underlying Scalar container object in order to alter it's behavior is some way.

So really, traits are just roles that are used in a particular way, nothing special beyond that.

- Stevan




Reply via email to