3 our $VERSION = '2.000001';
4 $VERSION = eval $VERSION;
7 my ($invocant, $code) = splice @_, 0, 2;
9 sub { $invocant->$code(@args => @_) }
12 sub curry::_ { &$curry }
16 my ($method) = our $AUTOLOAD =~ /^curry::(.+)$/;
19 $invocant->$method(@args => @_);
28 my ($invocant, $code) = splice @_, 0, 2;
29 Scalar::Util::weaken($invocant) if length ref $invocant;
32 return unless defined $invocant;
33 $invocant->$code(@args => @_)
37 sub curry::weak::_ { &$curry::weak }
41 Scalar::Util::weaken($invocant) if length ref $invocant;
42 my ($method) = our $AUTOLOAD =~ /^curry::weak::(.+)$/;
45 return unless defined $invocant;
46 $invocant->$method(@args => @_);
54 curry - Create automatic curried method call closures for any class or object
60 my $code = $obj->curry::frobnicate('foo');
64 my $code = sub { $obj->frobnicate(foo => @_) };
66 If you have a method name (or a coderef), you can call (as of version 2):
68 my $code = $obj->curry::_($method => 'foo');
74 my $code = $obj->curry::weak::frobnicate('foo');
79 Scalar::Util::weaken(my $weak_obj = $obj);
81 return unless $weak_obj; # in case it already went away
82 $weak_obj->frobnicate(foo => @_)
86 Similarly, given a method name or coderef (as of version 2):
88 my $code = $obj->curry::weak::_($method => 'foo');
90 There are also C<$curry::curry> and C<$curry::weak> globals that work
91 equivalently to C<curry::_> and C<curry::weak::_> respectively - you'll
92 quite possibly see them in existing code because they were provided in
93 pre-2.0 versions but they're unlikely to be the best option for new code.
97 How many times have you written
99 sub { $obj->something($some, $args, @_) }
101 or worse still needed to weaken it and had to check and re-check your code
102 to be sure you weren't closing over things the wrong way?
104 Right. That's why I wrote this.
108 I gave a lightning talk on this module (and L<Safe::Isa> and L<Import::Into>) at
109 L<YAPC::NA 2013|https://www.youtube.com/watch?v=wFXWV2yY7gE&t=46m05s>.
113 mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
117 None yet - maybe this software is perfect! (ahahahahahahahahaha)
121 Copyright (c) 2012 the curry L</AUTHOR> and L</CONTRIBUTORS>
126 This library is free software and may be distributed under the same terms