check defined rather than truth in weak
[p5sagit/curry.git] / t / curry.t
CommitLineData
fa8a151f 1use strict;
2use warnings FATAL => 'all';
3use Test::More qw(no_plan);
4use Scalar::Util qw(weaken);
5use curry;
6
7{
8 package Foo;
9
10 sub new { bless({}, shift) }
11
12 sub foo { [@_] }
13}
14
15my $foo = Foo->new;
16
17is_deeply($foo->foo(1), [ $foo, 1 ], 'Direct object call');
18is_deeply($foo->curry::foo->(1), [ $foo, 1 ], 'Curried object call');
19
20weaken(my $weak_foo = $foo);
21
22my $curry = $foo->curry::foo;
23
24undef($foo);
25
26ok($weak_foo, 'Weakened object kept alive by curry');
27
28undef($curry);
29
30ok(!$weak_foo, 'Weakened object dead');
31
32$foo = Foo->new;
33
34$curry = $foo->curry::weak::foo;
35
36is_deeply($curry->(1), [ $foo, 1 ], 'Curried weak object call');
37
38weaken($weak_foo = $foo);
39
40undef($foo);
41
42ok(!$weak_foo, 'Weak curry does not keep object alive');
43
44is($curry->(1), undef, 'Weak curry returns undef after object is dead');