Perl says:

DOES checks if the object or class performs the role ROLE. A role is a named group of specific behavior (often methods of particular names and signatures), similar to a class, but not necessarily a complete class by itself. For example, logging or serialization may be roles.

One must assume that types are roles for this definition to be equivalent to yours.

Similarly, you can only use Liskov's substitution principle's to justify DOES using ISA if you assume 1) that the principle applies to roles as well as types, and 2) that types are roles.

I agree that the principle applies to roles, but I'm not convinced that types are necessarily roles. Is there anything to support this assumption?


Back on subject, I went beyond a glance and came up with a researched answer.

Moose attributes don't have a type. isa specifies a type constraint, not a type. The value held by an instance of the attribute has a type, but does is a method of the attribute.

How then can does check the type of the attribute if the attribute doesn't have a type?

does "indicates whether the attribute itself does the given role. The role can be given as a full class name, or as a resolvable trait name. Note that this checks the attribute itself, not its type constraint, so it is checking the attribute's metaclass and any traits applied to the attribute." (Emphasis in original.)


In reply to Re^5: Introspection of Moose/Mouse attributes fails to find native trait with `does` by ikegami
in thread Introspection of Moose/Mouse attributes fails to find native trait with `does` by Your Mother

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.