Ignore __INSTANCE__ as constructor arg
Dave Rolsky [Sat, 17 Jul 2010 16:01:08 +0000 (11:01 -0500)]
lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm
lib/MooseX/StrictConstructor/Role/Object.pm
t/instance.t [new file with mode: 0644]

index 9c869e8..4000083 100644 (file)
@@ -15,6 +15,7 @@ around '_generate_BUILDALL' => sub {
     $source .= ";\n" if $source;
 
     my @attrs = (
+        "__INSTANCE__ => 1",
         map  {"$_ => 1,"}
         grep {defined}
         map  { $_->init_arg() } @{ $self->_attributes() }
index f755234..861afa2 100644 (file)
@@ -10,6 +10,7 @@ after 'BUILDALL' => sub {
     my $params = shift;
 
     my %attrs = (
+        __INSTANCE__ => 1,
         map { $_ => 1 }
         grep {defined}
         map  { $_->init_arg() } $self->meta()->get_all_attributes()
diff --git a/t/instance.t b/t/instance.t
new file mode 100644 (file)
index 0000000..687b470
--- /dev/null
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Moose qw( with_immutable );
+
+{
+    package Foo;
+    use Moose;
+    use MooseX::StrictConstructor;
+}
+
+with_immutable {
+    eval { Foo->new( __INSTANCE__ => Foo->new ); };
+    ok( !$@, '__INSTANCE__ is ignored when passed to ->new' );
+
+    eval { Foo->meta->new_object( __INSTANCE__ => Foo->new ); };
+    ok( !$@, '__INSTANCE__ is ignored when passed to ->new_object' );
+}
+'Foo';
+
+done_testing();