Add failing test for cloning attrs with weak refs
Florian Ragwitz [Fri, 13 May 2011 11:32:28 +0000 (13:32 +0200)]
t/attributes/clone_weak.t [new file with mode: 0644]

diff --git a/t/attributes/clone_weak.t b/t/attributes/clone_weak.t
new file mode 100644 (file)
index 0000000..55a0604
--- /dev/null
@@ -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;