On Mon, Aug 15, 2005 at 10:43:45AM -0700, Larry Wall wrote:
> : So the last line means a role can be used just like a class, and
> : _inherit_ its behaviour as well?
> : 
> :     role Point { has $.x; has $.y; method move_right { $.x++ } };
> :     role MyPoint is Point {
> :     method move_right { ./SUPER::move_right(); $.y++; }
> :     }
> 
> It means that when MyPoint is finally nailed down into a class, that
> class will inherit from Point.  The role itself doesn't inherit.

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 {
        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

Thanks,
/Autrijus/

Attachment: pgp7v9ZkEOKWK.pgp
Description: PGP signature

Reply via email to