On Tue, Aug 16, 2005 at 01:49:02AM +0800, Autrijus Tang wrote:
: Aye. But if a Role can be inherited _from_, then this should
: work too, right?
:
: role Point {
: has $.x; has $.y;
: method move_right { $.x++ }
: };
: role OurPoint is Point {
: method move_right { ./SUPER::move_right; $.y++ }
: }
: role MyPoint is MyPoint {
s:2nd/MyPoint/OurPoint/ I presume.
: method move_right { ./SUPER::move_right; $.x++ }
: }
:
: my MyPoint $point .= new( :x(0) :y(0) );
: $point.move_right;
: say $point.x; # 2
: say $point.y; # 1
Sure, except that you're not really inheriting from a role here.
You're really inheriting from an anonymous class of the same name. :-)
Much like: "The Illiad was not written by Homer, but by another blind
8th-century poet of the same name."
Basically, I'd like to keep the distinction that a class is a
valid dispatcher while a role is not. This is mostly a declarative
distinction to keep it straight in people's heads. But as with many
other things in Perl, if you use an X as a Y, it'll behave like one,
and so we try to make it easy for a role to "autovivify" itself in
a class context.
Larry