More style tweaks
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Trait / Class.pm
index 1bfb0f5..c6865c6 100644 (file)
@@ -5,7 +5,6 @@ use Moose::Role;
 use namespace::autoclean;
 
 use B ();
-use Carp ();
 
 around '_inline_BUILDALL' => sub {
     my $orig = shift;
@@ -25,11 +24,24 @@ around '_inline_BUILDALL' => sub {
         '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");',
         '}',
     );
 };
 
+# If the base class role is applied first, and then a superclass is added, we
+# lose the role.
+after superclasses => sub {
+    my $self = shift;
+
+    return unless @_;
+
+    Moose::Util::MetaRole::apply_base_class_roles(
+        for   => $self->name(),
+        roles => ['MooseX::StrictConstructor::Role::Object'],
+    );
+};
+
 1;
 
 # ABSTRACT: A role to make immutable constructors strict