I've also had a need for this sort of functionality although not necessarily in an OO context. For example, say you want a sub to be called in a manner similar to the built-in sort (most likely in a module). This example (toy) code throws an error:
#!/usr/bin/perl -w
use strict;
sub func (&@) {
my $func = shift;
foreach (@_) {
$func->($_);
}
}
sub func (@) {
foreach (@_) {
print $_;
}
}
my @list = ('bob', 'sally', 'joe');
func { print "!!!$_\n"; } @list;
func @list;
It would be quite nice to be able to do this sort of thing. If you didn't need the prototype to treat a block as a sub things would also work out. It is also easy to work around this issue by taking an explicit reference to a sub but the block is much more natural and provides subs that are similar in use to the built-in functions. Perhaps I am missing something obvious...