use strict;
use warnings;
-use Test::More tests => 7;
+use Test::More tests => 9;
{
__PACKAGE__->meta()->make_immutable();
}
+{
+ package ImmutableTricky;
+
+ use MooseX::StrictConstructor;
+
+ has 'thing' => ( is => 'rw' );
+
+ sub BUILD
+ {
+ my $self = shift;
+ my $params = shift;
+
+ delete $params->{spy};
+ }
+}
+
eval { Standard->new( thing => 1, bad => 99 ) };
is( $@, '', 'standard Moose class ignores unknown params' );
eval { Immutable->new( thing => 1, bad => 99 ) };
like( $@, qr/unknown attribute.+: bad/,
'strict constructor in immutable class blows up on unknown params' );
+
+eval { ImmutableTricky->new( thing => 1, spy => 99 ) };
+is( $@, '',
+ 'immutable class can work around strict constructor by deleting params in BUILD()' );
+
+eval { ImmutableTricky->new( thing => 1, agent => 99 ) };
+like( $@, qr/unknown attribute.+: agent/,
+ 'ImmutableTricky still blows up on unknown params other than spy' );