Slide 70
Slide 70 text
Parameterized Roles
role Counter (Int :$default = 0) {
has counter => (
is => 'ro',
isa => 'Int',
default => $default,
);
sub increment {
my $self = shift;
$self->counter($self->counter + 1);
}
} ͜ΕΛ͏ͱΈࠐΉଆ͕σϑΥϧτΛ
એݴͰ͖·͢
Friday, September 11, 2009
Here we have our old Counter role, but now each consumer can declare what default it wants for the
attribute. If they choose nothing, they get the default of 0.
rafl++ added parameterized role support to MooseX::Declare recently, so my examples get to look
much nicer.