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.)
|