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