1Moose::Spec::Role(3)  User Contributed Perl Documentation Moose::Spec::Role(3)
2
3
4

NAME

6       Moose::Spec::Role - Formal spec for Role behavior
7

DESCRIPTION

9       Components of a Role
10
11       Excluded Roles
12       Attributes
13       Methods
14       Required Methods
15       Overriden Methods
16           The "override" and "super" keywords are allowed in roles, but thier
17           behavior is different from that of it's class counterparts.  The
18           "super" in a class refers directly to that class's superclass,
19           while the "super" in a role is deferred and only has meaning once
20           the role is composed into a class. Once that composition occurs,
21           "super" then refers to that class's superclass.
22
23           It is key to remember that roles do not have hierarchy, so they can
24           never have a super role.
25
26       Method Modifiers
27
28       Role to Role Composition Rules
29
30       When a role is added to another role (using the "with" keyword) the two
31       roles are composed symmetrically. The product of the composition is a
32       third composite role.
33
34       Attributes
35           Attributes with the same name will conflict and are considered a
36           un-recoverable error. No other aspect of the attribute is exam‐
37           ained, it is enough that just the attribute names conflict.
38
39           The reason for such early and harsh conflicts with attributes is
40           because there is so much room for variance between two attributes
41           that the problem quickly explodes and rules get very complex. It is
42           my opinion that this complexity is not worth the trouble.
43
44       Methods
45           Methods with the same name will conflict, but no error is thrown,
46           instead the method name is added to the list of required methods
47           for the new composite role.
48
49           To look at this in terms of set theory, each role can be said to
50           have a set of methods. The symmetric difference of these two sets
51           is the new set of methods for the composite role, while the inter‐
52           section of these two sets are the conflicts. This can be illus‐
53           trated like so:
54
55              Role A has method set { a, b, c }
56              Role B has method set { c, d, e }
57
58              The composite role (A,B) has
59                  method   set { a, b, d, e }
60                  conflict set { c }
61
62       Overriden methods
63           An overriden method can conflict in one of two ways.
64
65           The first way is with another overriden method of the same name,
66           and this is considered an un-recoverable error. This is an obvious
67           error since you cannot override a method twice in the same class.
68
69           The second way for conflict is for an overriden method and a regu‐
70           lar method to have the same name. This is also an un-recoverable
71           error since there is no way to combine these two, nor is it okay
72           for both items to be composed into a single class at some point.
73
74           The use of override in roles can be tricky, but if used carefully
75           they can be a very powerful tool.
76
77       Method Modifiers (before, around, after)
78           Method modifiers are the only place where the ordering of role com‐
79           position matters. This is due to the nature of method modifiers
80           themselves.
81
82           Since a method can have multiple method modifiers, these are just
83           collected in order to be later applied to the class in that same
84           order.
85
86           In general, great care should be taken in using method modifiers in
87           roles. The order sensitivity can possibly lead to subtle and diffi‐
88           cult to find bugs if they are overused. As with all good things in
89           life, moderation is the key.
90

SEE ALSO

92       Traits
93           Roles are based on Traits, which originated in the Smalltalk commu‐
94           nity.
95
96           <http://www.iam.unibe.ch/~scg/Research/Traits/>
97               This is the main site for the original Traits papers.
98
99           Class::Trait
100               I created this implementation of traits several years ago,
101               after reading the papers linked above. (This module is now
102               maintatined by Ovid and I am no longer involved with it).
103
104       Roles
105           Since they are relatively new, and the Moose implementation is
106           probably the most mature out there, roles don't have much to link
107           to. However, here is some bits worth looking at (mostly related to
108           Perl 6)
109
110           <http://www.oreillynet.com/onlamp/blog/2006/08/roles_compos
111           able_units_of_obje.html>
112               This is chromatic's take on roles, which is worth reading since
113               he was/is one of the big proponents of them.
114
115           <http://svn.perl.org/perl6/doc/trunk/design/syn/S12.pod>
116               This is Synopsis 12, which is all about the Perl 6 Object Sys‐
117               tem.  Which, of course, includes roles.
118

AUTHOR

120       Stevan Little <stevan@iinteractive.com>
121
123       Copyright 2007 by Infinity Interactive, Inc.
124
125       <http://www.iinteractive.com>
126
127       This library is free software; you can redistribute it and/or modify it
128       under the same terms as Perl itself.
129
130
131
132perl v5.8.8                       2007-09-06              Moose::Spec::Role(3)
Impressum