From: Dave Rolsky Date: Sat, 17 Jul 2010 16:01:08 +0000 (-0500) Subject: Ignore __INSTANCE__ as constructor arg X-Git-Tag: v0.10~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-StrictConstructor.git;a=commitdiff_plain;h=d78f8e746b0fc4ab8e44dfa9ea7dcc8f28cce880 Ignore __INSTANCE__ as constructor arg --- diff --git a/lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm b/lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm index 9c869e8..4000083 100644 --- a/lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm +++ b/lib/MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm @@ -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() } diff --git a/lib/MooseX/StrictConstructor/Role/Object.pm b/lib/MooseX/StrictConstructor/Role/Object.pm index f755234..861afa2 100644 --- a/lib/MooseX/StrictConstructor/Role/Object.pm +++ b/lib/MooseX/StrictConstructor/Role/Object.pm @@ -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 index 0000000..687b470 --- /dev/null +++ b/t/instance.t @@ -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();