When I have wanted to use can for anything other than the truth value I have generally wanted to either verify which function implements it (which your suggestion breaks) or else I have wanted to wrap the existing implementation with another and it is not certain that I want to necessarily use the same object. Indeed I might locate can with the class and then feed it real objects later.
I don't want to do either often, but on the rare occasions when I do, your suggestion is less convenient than the current behaviour.
But more than that, the vast majority of the time when people want to check can they just want to check truth. Why create a closure just to see it get thrown away?
But if you really want it, just create another method to do what you want:
sub UNIVERSAL::bind_meth {
my ($self, $meth, @args) = @_;
my $func = $self->can($meth);
if (defined($func)) {
return sub {$func->($self, @args, @_)};
}
else {
return undef;
}
}
And now you can curry a method, and curry a few arguments as well while you are at currying favour. And I still get the can that I know and like.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|