I'm mentally going over the ways to do it.
class Foo;
# the perl5 way
use base <<Base>>;
sub new {
my $class = shift;
my $self = $class.SUPER::new(@_); # syntax?
return $self;
}
sub do_it {
my($self, $arg) = @_;
say "doing $arg!";
}
class Foo is Base {
# the perl6 way
method do_it(String $arg) {
say "doing $arg!";
}
}
# add behavior through multi-dispatch
multi sub do_it(Base $x, String $arg) {
say "doing $arg!";
}
# behavior via mixin
my Base $x does role {
method do_it($arg) {
say "doing $arg!";
}
};
# behavior through prototype -- guessing realistic syntax
Base.meta.add_method(
do_it => method ($arg) {
say "doing $arg!";
});
# or, just add it to a single instance
$x.meta.add_method(
do_it => method ($arg) {
say "doing $arg!";
});
Did I miss any good ones? Or bad ones? :)
Ashley Winters