Perl 6 Cool Perl 6 #92

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 © 2010
http://www.pmichaud.com/2010/pres/