Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: Why isn't ->can() curried? by Anonymous Monk
in thread Why isn't ->can() curried? by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-18 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found