Method modifiers (around)
- Use around when you need to change args or return value
has 'foo' => ( is => 'rw', isa => 'Int' );
around 'foo' => sub {
my ($next, $self, $value) = @_;
if(defined $value){
$self->$next($value + 1);
}
return $self->$next - 1;
}
- Here we add one to the value we're setting
- And we subtract one from the return value
- Why? No idea. It's an example.
- foo could have been inherited, or even declared in the class (sub foo)