I came across this slight annoyance working in Perl 5 today:
sub preserve(&) {...}
sub foo {
preserve {
$_[0]->bar;
}
}
That didn't call "bar" on the invocant of "foo", but rather on "undef",
because preserve's block was a hiding sub.
Perl 6 is making it easier to define custom block constructs like this
one. I worry about:
method foo () {
preserve {
.bar;
}
}
This one's a tad more subtle. Normally preserve's block would be 0-ary.
But in this case it's unary, since it implicitly references $_.
Is there a way to declare preserve so that its block will always be
parsed 0-ary? "if" is certainly able to do this (consider the above
example with s/preserve/if $baz/).
Luke