What is the difference between a Role and Trait? I've read the CPAN docs and even some of the academic papers trying to get my head wrapped around this stuff.

Reason being I'm active in the MTOS (Movable Type Open Source) community and the discussion about "whatever-able" classes comes up occasionally and whose use is growing.

Let me explain what I mean by "whatever-able" classes in how they are used in MT.

It started off as Taggable (object can be tagged), then Scorable (object can be rated or scored) was introduced and now there is discussion of others like comments and categories. The thing is these "whatever-able" classes are designed that your data object must inherit them which usually means multiple inheritance. It also means only the developer of the object class has the option of making an it taggable etc. So if I'm doing some consulting and the client needs a blog object to be taggable and it's not (not yet so far) I'm out of luck or I could trying some nasty hacking that is sure to break later when new versions are released.

After reading about roles and traits it seems one of these approaches is the saner/better way to go especially since modularity and flexibility and extensibility are cornerstones of MT going forward.

Here are some samples classes from MT to give you some code to look at:

So I need a sanity check and thought I'd post something here. Correct me if I'm wrong.

Your feedback would be appreciated. Thanks.


In reply to Sanity Check: Roles vs. Traits by tima

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.