use strict;
use warnings;
-use Test::More tests => 12;
+use Test::More tests => 15;
{
}
{
+ package ImmutableInitArg;
+
+ use MooseX::StrictConstructor;
+
+ has 'thing' => ( is => 'rw', 'init_arg' => 'other' );
+ has 'size' => ( is => 'rw', 'init_arg' => undef );
+
+ no Moose;
+ __PACKAGE__->meta()->make_immutable();
+}
+
+{
package Immutable;
use MooseX::StrictConstructor;
eval { Stricter->new( thing => 1, bad => 99 ) };
like( $@, qr/unknown attribute.+: bad/, 'strict constructor blows up on unknown params' );
+eval { Subclass->new( thing => 1, size => 'large' ) };
+is( $@, '', 'subclass constructor handles known attributes correctly' );
+
eval { Tricky->new( thing => 1, spy => 99 ) };
is( $@, '', 'can work around strict constructor by deleting params in BUILD()' );
eval { Subclass->new( thing => 1, bad => 99 ) };
like( $@, qr/unknown attribute.+: bad/, 'subclass constructor blows up on unknown params' );
-eval { Subclass->new( thing => 1, size => 'large' ) };
-is( $@, '', 'subclass constructor handles known attributes correctly' );
+eval { InitArg->new( thing => 1 ) };
+like( $@, qr/unknown attribute.+: thing/,
+ 'InitArg blows up with attribute name' );
+
+eval { InitArg->new( size => 1 ) };
+like( $@, qr/unknown attribute.+: size/,
+ 'InitArg blows up when given attribute with undef init_arg' );
+
+eval { InitArg->new( other => 1 ) };
+is( $@, '',
+ 'InitArg works when given proper init_arg' );
+
+eval { ImmutableInitArg->new( thing => 1 ) };
+like( $@, qr/unknown attribute.+: thing/,
+ 'ImmutableInitArg blows up with attribute name' );
+
+eval { ImmutableInitArg->new( size => 1 ) };
+like( $@, qr/unknown attribute.+: size/,
+ 'ImmutableInitArg blows up when given attribute with undef init_arg' );
+
+eval { ImmutableInitArg->new( other => 1 ) };
+is( $@, '',
+ 'ImmutableInitArg works when given proper init_arg' );
eval { Immutable->new( thing => 1, bad => 99 ) };
like( $@, qr/unknown attribute.+: bad/,
eval { ImmutableTricky->new( thing => 1, agent => 99 ) };
like( $@, qr/unknown attribute.+: agent/,
'ImmutableTricky still blows up on unknown params other than spy' );
-
-eval { InitArg->new( thing => 1 ) };
-like( $@, qr/unknown attribute.+: thing/,
- 'InitArg blows up with attribute name' );
-
-eval { InitArg->new( size => 1 ) };
-like( $@, qr/unknown attribute.+: size/,
- 'InitArg blows up when given attribute with undef init_arg' );
-
-eval { InitArg->new( other => 1 ) };
-is( $@, '',
- 'InitArg works when given proper init_arg' );