X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStrictConstructor%2FTrait%2FClass.pm;h=7f756698b9e673eeb73389d24aad7095468fc954;hb=82b1f9fb53a8ae8a060f02861eea9c41d846c7f6;hp=bfda93a8a5383a86631396304d90075e98cf1736;hpb=ce8f6d73680c9395b9bc5add89f3c6e3be2bc1be;p=gitmo%2FMooseX-StrictConstructor.git diff --git a/lib/MooseX/StrictConstructor/Trait/Class.pm b/lib/MooseX/StrictConstructor/Trait/Class.pm index bfda93a..7f75669 100644 --- a/lib/MooseX/StrictConstructor/Trait/Class.pm +++ b/lib/MooseX/StrictConstructor/Trait/Class.pm @@ -1,13 +1,13 @@ 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; @@ -23,15 +23,25 @@ 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");', '}', ); }; -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;