From: Florian Ragwitz Date: Fri, 13 May 2011 11:32:28 +0000 (+0200) Subject: Add failing test for cloning attrs with weak refs X-Git-Tag: 2.0100~102 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b04e9927b4714f3d39da3d2f063c442f84c0ff02;p=gitmo%2FMoose.git Add failing test for cloning attrs with weak refs --- diff --git a/t/attributes/clone_weak.t b/t/attributes/clone_weak.t new file mode 100644 index 0000000..55a0604 --- /dev/null +++ b/t/attributes/clone_weak.t @@ -0,0 +1,44 @@ +use strict; +use warnings; +use Test::More; + +{ + package Foo; + use Moose; + + has bar => ( + is => 'ro', + weak_ref => 1, + ); +} + +{ + package MyScopeGuard; + + sub new { + my ($class, $cb) = @_; + bless { cb => $cb }, $class; + } + + sub DESTROY { shift->{cb}->() } +} + +{ + my $destroyed = 0; + + my $foo = do { + my $bar = MyScopeGuard->new(sub { $destroyed++ }); + my $foo = Foo->new({ bar => $bar }); + my $clone = $foo->meta->clone_object($foo); + + is $destroyed, 0; + + $clone; + }; + + isa_ok($foo, 'Foo'); + is $foo->bar, undef; + is $destroyed, 1; +} + +done_testing;