Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Why isn't ->can() curried?

by chromatic (Archbishop)
on Jan 20, 2003 at 17:33 UTC ( #228406=note: print w/replies, xml ) Need Help??


in reply to Why isn't ->can() curried?

How do you tell, programatically, whether the function is intended to be called as a method or a function?

Replies are listed 'Best First'.
Re^2: Why isn't ->can() curried?
by diotalevi (Canon) on Jan 20, 2003 at 18:03 UTC

    You wouldn't. But then I think it'd be pretty daft to call a method as a function seeing as how the implementing code is expecting an object as the first parameter.


    Seeking Green geeks in Minnesota

      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->( @_ ) }; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://228406]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2021-03-04 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (108 votes). Check out past polls.

    Notices?