update Distar url
[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');
51f11f71 19is_deeply(
20 $foo->curry::_('foo')->(1), [ $foo, 1 ],
21 'Curried string method call'
22);
fa8a151f 23
24weaken(my $weak_foo = $foo);
25
26my $curry = $foo->curry::foo;
27
28undef($foo);
29
30ok($weak_foo, 'Weakened object kept alive by curry');
31
32undef($curry);
33
34ok(!$weak_foo, 'Weakened object dead');
35
36$foo = Foo->new;
37
38$curry = $foo->curry::weak::foo;
39
40is_deeply($curry->(1), [ $foo, 1 ], 'Curried weak object call');
41
51f11f71 42my $curry2 = $foo->curry::weak::_('foo');
43
bedcecab 44is_deeply($curry2->(1), [ $foo, 1 ], 'Curried weak string method call');
51f11f71 45
fa8a151f 46weaken($weak_foo = $foo);
47
48undef($foo);
49
50ok(!$weak_foo, 'Weak curry does not keep object alive');
51
52is($curry->(1), undef, 'Weak curry returns undef after object is dead');