Daniel Ruoso wrote: > Jon Lang wrote: >> Note that this ought only be true of class inheritance; with role >> composition, there should only be one $!bar in the class, no matter >> how many roles define it. > > er... what does that mean exactly?
Unless something has drastically changed since I last checked the docs, roles tend to be even more ethereal than classes are. You can think of a class as being the engine that runs objects; a role, OTOH, should be thought of as a blueprint that is used to construct a class. Taking your example: > role B { > has $!a; > } > > role C { > has $!a; > } > > class A does B, C { > method foo() { > say $!a; > } > } > > I think in this case $!B::a and $!C::a won't ever be visible, while the > reference to $!a in class A will be a compile time error. :snip: > Or does that mean that > > class A does B, C {...} > > actually makes the declarations in B and C as if it were declared in the > class A? Correct. Declarations in roles are _always_ treated as if they were declared in the class into which they're composed. And since only classes are used to instantiate objects, the only time that a role actually gets used is when it is composed into a class. -- Jonathan "Dataweaver" Lang