);
};
+# if the Object role is applied first, and then a superclass added, we just
+# lost our BUILDALL modification.
+after superclasses => sub
+{
+ my $self = shift;
+ return if not @_;
+ Moose::Util::MetaRole::apply_base_class_roles(
+ for => $self->name,
+ roles => ['MooseX::StrictConstructor::Role::Object'],
+ )
+};
+
1;
# ABSTRACT: A role to make immutable constructors strict
}
{
+ package OtherStrictSubclass;
+
+ use Moose;
+ use MooseX::StrictConstructor;
+
+ extends 'Standard';
+
+ has 'size' => ( is => 'rw' );
+}
+
+{
package Tricky;
use Moose;
has 'size' => ( is => 'rw', 'init_arg' => undef );
}
-my @classes = qw( Standard Stricter Subclass StrictSubclass Tricky InitArg );
+my @classes = qw( Standard Stricter Subclass StrictSubclass OtherStrictSubclass Tricky InitArg );
with_immutable {
is(
);
is(
+ exception { OtherStrictSubclass->new( thing => 1, size => 'large', ) }, undef,
+ 'strict subclass from parent that doesn\'t use strict constructor handles known attributes correctly'
+ );
+
+ like(
+ exception { OtherStrictSubclass->new( thing => 1, bad => 99 ) },
+ qr/unknown attribute.+: bad/,
+ 'strict subclass from parent that doesn\'t use strict correctly recognizes bad attribute'
+ );
+
+ is(
exception { Tricky->new( thing => 1, spy => 99 ) }, undef,
'can work around strict constructor by deleting params in BUILD()'
);