fix for compat with Moose 1.25
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Trait / Class.pm
index bfda93a..579b6c2 100644 (file)
@@ -1,12 +1,10 @@
 package MooseX::StrictConstructor::Trait::Class;
 
-use strict;
-use warnings;
+use Moose::Role;
 
-use B ();
-use Carp ();
+use namespace::autoclean;
 
-use Moose::Role;
+use B ();
 
 around '_inline_BUILDALL' => sub {
     my $orig = shift;
@@ -23,15 +21,26 @@ around '_inline_BUILDALL' => sub {
 
     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");',
         '}',
     );
-};
+} if $Moose::VERSION >= 1.9900;
 
-no Moose::Role;
+# 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;