Commit | Line | Data |
fa8a151f |
1 | use strict; |
2 | use warnings FATAL => 'all'; |
3 | use Test::More qw(no_plan); |
4 | use Scalar::Util qw(weaken); |
5 | use curry; |
6 | |
7 | { |
8 | package Foo; |
9 | |
10 | sub new { bless({}, shift) } |
11 | |
12 | sub foo { [@_] } |
13 | } |
14 | |
15 | my $foo = Foo->new; |
16 | |
17 | is_deeply($foo->foo(1), [ $foo, 1 ], 'Direct object call'); |
18 | is_deeply($foo->curry::foo->(1), [ $foo, 1 ], 'Curried object call'); |
51f11f71 |
19 | is_deeply( |
20 | $foo->curry::_('foo')->(1), [ $foo, 1 ], |
21 | 'Curried string method call' |
22 | ); |
fa8a151f |
23 | |
24 | weaken(my $weak_foo = $foo); |
25 | |
26 | my $curry = $foo->curry::foo; |
27 | |
28 | undef($foo); |
29 | |
30 | ok($weak_foo, 'Weakened object kept alive by curry'); |
31 | |
32 | undef($curry); |
33 | |
34 | ok(!$weak_foo, 'Weakened object dead'); |
35 | |
36 | $foo = Foo->new; |
37 | |
38 | $curry = $foo->curry::weak::foo; |
39 | |
40 | is_deeply($curry->(1), [ $foo, 1 ], 'Curried weak object call'); |
41 | |
51f11f71 |
42 | my $curry2 = $foo->curry::weak::_('foo'); |
43 | |
bedcecab |
44 | is_deeply($curry2->(1), [ $foo, 1 ], 'Curried weak string method call'); |
51f11f71 |
45 | |
fa8a151f |
46 | weaken($weak_foo = $foo); |
47 | |
48 | undef($foo); |
49 | |
50 | ok(!$weak_foo, 'Weak curry does not keep object alive'); |
51 | |
52 | is($curry->(1), undef, 'Weak curry returns undef after object is dead'); |