package MooseX::StrictConstructor::Trait::Class;
-use strict;
-use warnings;
-
-use B ();
-use Carp ();
+# applied as class_metaroles => { class => [ __PACKAGE__ ] }, for Moose 1.99x and later
use Moose::Role;
+use namespace::autoclean;
+
+use B ();
+
around '_inline_BUILDALL' => sub {
my $orig = shift;
my $self = shift;
return (
@source,
- 'my %attrs = (' . join(' ', @attrs) . ');',
+ 'my %attrs = (' . ( join ' ', @attrs ) . ');',
'my @bad = sort grep { !$attrs{$_} } keys %{ $params };',
'if (@bad) {',
- 'Carp::confess "Found unknown attribute(s) passed to the constructor: @bad";',
+ 'Moose->throw_error("Found unknown attribute(s) passed to the constructor: @bad");',
'}',
);
};
-no Moose::Role;
+# 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;