On Tue, Sep 20, 2005 at 08:16:23PM -0400, Stevan Little wrote: > http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel2.0/docs/ > p6_role_model.jpg > > I am planning on making Roles self-bootstrapping, so the class(Role) > will actually be the first Role in the system. From there, Class will > do Role, and Role will do Role. This also means that all the > instances of Class will also do Role, which means that classes > automatically can also be used as Roles.
Thanks for the pictures, Stevan. So every time a class does a new role, a new instance of the class is created as the role. If a class does three roles, there will be three role instances of the class, as well as the class' own instance of itself, and a user instance. When a method is called on the user instance, it asks the class instance if it can do the method, and the class instance looks at the methods in the class, and then at the methods in each role, and dispatches to the appropriate method definition. A role can be "done" by several classes at once, because a new instance is created for each class, specific to the class. Methods defined in a class are not clobbered by methods defined in a role. Rather, methods in a role are only catalogued by the class instance if it does not already have a method definition for that name. The order that a class does roles is significant, because if two roles define the same method, only the first one is catalogued by the class instance. -kolibrie