Paint me daft, then, I do it all the time in tests. :)
Perhaps any extra arguments to can() could be bound to the subref returned. It's a nice idea; it just seems really hard to get super-scary magic right. Here's some untested code that seems somewhat useful:
use Scalar::Util 'blessed';
sub curried_can
{
my ($thingie, $func) = splice( @_, 0, 2 );
my $sub = UNIVERSAL::can( $thingie, $func );
# $thingie cannot $func
return unless $sub;
# first argument is an object
return sub { $thingie->$func( @_ ) } if blessed $thingie;
# first argument is a class name, no arguments
return $sub unless @_;
# first argument is a class name, curried arguments
return sub { $sub->( @_ ) };
}
|