| 1 |
NAME |
| 2 |
curry - Create automatic curried method call closures for any class or |
| 3 |
object |
| 4 |
|
| 5 |
SYNOPSIS |
| 6 |
use curry; |
| 7 |
|
| 8 |
my $code = $obj->curry::frobnicate('foo'); |
| 9 |
|
| 10 |
is equivalent to: |
| 11 |
|
| 12 |
my $code = sub { $obj->frobnicate(foo => @_) }; |
| 13 |
|
| 14 |
If you have a method name (or a coderef), you can call (as of version |
| 15 |
2): |
| 16 |
|
| 17 |
my $code = $obj->curry::_($method => 'foo'); |
| 18 |
|
| 19 |
Additionally, |
| 20 |
|
| 21 |
use curry::weak; |
| 22 |
|
| 23 |
my $code = $obj->curry::weak::frobnicate('foo'); |
| 24 |
|
| 25 |
is equivalent to: |
| 26 |
|
| 27 |
my $code = do { |
| 28 |
Scalar::Util::weaken(my $weak_obj = $obj); |
| 29 |
sub { |
| 30 |
return unless $weak_obj; # in case it already went away |
| 31 |
$weak_obj->frobnicate(foo => @_) |
| 32 |
}; |
| 33 |
}; |
| 34 |
|
| 35 |
Similarly, given a method name or coderef (as of version 2): |
| 36 |
|
| 37 |
my $code = $obj->curry::weak::_($method => 'foo'); |
| 38 |
|
| 39 |
There are also $curry::curry and $curry::weak globals that work |
| 40 |
equivalently to "curry::_" and "curry::weak::_" respectively - you'll |
| 41 |
quite possibly see them in existing code because they were provided in |
| 42 |
pre-2.0 versions but they're unlikely to be the best option for new |
| 43 |
code. |
| 44 |
|
| 45 |
RATIONALE |
| 46 |
How many times have you written |
| 47 |
|
| 48 |
sub { $obj->something($some, $args, @_) } |
| 49 |
|
| 50 |
or worse still needed to weaken it and had to check and re-check your |
| 51 |
code to be sure you weren't closing over things the wrong way? |
| 52 |
|
| 53 |
Right. That's why I wrote this. |
| 54 |
|
| 55 |
AUTHOR |
| 56 |
mst - Matt S. Trout (cpan:MSTROUT) <[email protected]> |
| 57 |
|
| 58 |
CONTRIBUTORS |
| 59 |
None yet - maybe this software is perfect! (ahahahahahahahahaha) |
| 60 |
|
| 61 |
COPYRIGHT |
| 62 |
Copyright (c) 2012 the curry "AUTHOR" and "CONTRIBUTORS" as listed |
| 63 |
above. |
| 64 |
|
| 65 |
LICENSE |
| 66 |
This library is free software and may be distributed under the same |
| 67 |
terms as perl itself. |
| 68 |
|