Skip to content

Commit 7fa4c56

Browse files
committed
Document role-assisted inheritence and method definition pecking order
1 parent c4e1d89 commit 7fa4c56

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

doc/Language/objects.pod

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,33 @@ This allows you to create roles that act as abstract interfaces.
685685
The implementation of the stubbed method may also be provided by another
686686
role.
687687
688+
=head2 Inheritance
689+
690+
Roles cannot inherit from classes, but they may cause any class which does
691+
that role to inherit from another class. So if you write:
692+
693+
=begin code
694+
role A is Exception { }
695+
class X::Ouch does A { }
696+
X::Ouch.^parents.say # ((Exception))
697+
=end code
698+
699+
...then C<X::Ouch> will inherit directly from Exception, as we can see above
700+
by listing its parents.
701+
702+
=head2 Pecking order
703+
704+
A method defined directly in a class will always override definitions from
705+
applied roles or from inherited classes. If no such definition exists, methods
706+
from roles override methods inherited from classes. This happens both when
707+
said class was brought in by a role, and also when said class was inherited
708+
directly.
709+
710+
Note that each candidate for a multi-method is its own method... in this case,
711+
the above only applies if two such candidates have the same signature.
712+
Otherwise, there is no conflict, and the candidate is just added to the
713+
multi-method.
714+
688715
=head2 Automatic Role Punning
689716
690717
Any attempt to instantiate (and many other kinds of usage) a role will

0 commit comments

Comments
 (0)