So I’ve been integrating Ash Berlin’s work on making MooseX::POE work
with MooseX::Declare. One of the things I came across was that the
method
keyword didn’t work as I expected.
I figured that something like:
class Counter {
use MooseX::POE;
method START {
$self->yield('increment_counter');
}
event 'counter' => method {
$self->counter($self->counter + 1);
};
}
would DWIM. But currently a method
without a parameter list is slightly
undefined. It happens to default to the same as an empty parameter list (ie
method ($self:) { ... }
) but Florian and Ash both agreed that perhaps that wasn’t
the best choice. To my mind I think that the right choice is that
method { ... }
should be the equivlent of method ($self, @_) { ... }
.
That is it should alias the invocant and pass through the rest of the args as
a slurpy array.
Then tonight I was reading the Perl 6 Design Minutes for 26 March 2009 and found the following:
Patrick:
- if you have a method declared without a parameter list, does it get @_ like a sub, or no parameters?
Larry:
- I've been thinking it comes in the same way Perl 5 does it
- hadn't bothered to try to think about it the other way
Patrick:
- Rakudo assumes @_
Larry:
- but it leaves out the invocant
- that's the difference
- I haven't decided
- it's further from what a Perl 5 programmer might expect
- but it might be more useful
I think it’s closer to what a Perl 5 Moose programmer expects than Larry thinks.
UPDATED: upon talking with Ash I've clarified what I meant to say. Never blog while tired.