Perl 6 Perl 6 today #58

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 accessor
    has $.tail is rw;       # public read-write accessor
    has @.legs;             # public read-only array accessor
    has $!brain;            # private scalar

    method bark() { say "w00f"; }
}

my Dog $fido .= new;

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