Perl 6 Perl 6 today #37

Classes and objects

Perl 6 has formal support for classes, objects, and roles:

class Dog is Mammal does Pet {
    has $.name = "fido";    # public read-only
    has $.tail is rw;       # public read-write
    has @.legs;             # public read-only array
    has $!brain;            # private scalar

    method feed ($food) { ... }
    ...
}

my Dog $fido .= new;

$fido.feed('bone');
say $fido.name;
Copyright © 2009
http://www.pmichaud.com/2009/pres/