4 use Test::More tests => 6;
12 has 'thing' => ( is => 'rw' );
18 use MooseX::StrictConstructor;
20 has 'thing' => ( is => 'rw' );
26 use MooseX::StrictConstructor;
30 has 'size' => ( is => 'rw' );
36 use MooseX::StrictConstructor;
38 has 'thing' => ( is => 'rw' );
45 delete $params->{spy};
50 eval { Standard->new( thing => 1, bad => 99 ) };
51 is( $@, '', 'standard Moose class ignores unknown params' );
53 eval { Stricter->new( thing => 1, bad => 99 ) };
54 like( $@, qr/unknown attribute.+: bad/, 'strict constructor blows up on unknown params' );
56 eval { Tricky->new( thing => 1, spy => 99 ) };
57 is( $@, '', 'can work around strict constructor by deleting params in BUILD()' );
59 eval { Tricky->new( thing => 1, agent => 99 ) };
60 like( $@, qr/unknown attribute.+: agent/, 'Tricky still blows up on unknown params other than spy' );
62 eval { Subclass->new( thing => 1, bad => 99 ) };
63 like( $@, qr/unknown attribute.+: bad/, 'subclass constructor blows up on unknown params' );
65 eval { Subclass->new( thing => 1, size => 'large' ) };
66 is( $@, '', 'subclass constructor handles known attributes correctly' );