X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FStrictConstructor%2FTrait%2FClass.pm;h=707c75fc187a89c4d882a5d87f28e51e3fd9cac4;hb=eb63f59e57cf8becf26666fa380fb73593e8f4a5;hp=776953bcce7d0c0fb5b22bc3c885788e79e10082;hpb=bf857f8277c39d208e9bd0d750e09275011a506b;p=gitmo%2FMooseX-StrictConstructor.git diff --git a/lib/MooseX/StrictConstructor/Trait/Class.pm b/lib/MooseX/StrictConstructor/Trait/Class.pm index 776953b..707c75f 100644 --- a/lib/MooseX/StrictConstructor/Trait/Class.pm +++ b/lib/MooseX/StrictConstructor/Trait/Class.pm @@ -6,6 +6,32 @@ use namespace::autoclean; use B (); +around new_object => sub { + my $orig = shift; + my $self = shift; + my $params = @_ == 1 ? $_[0] : {@_}; + my $instance = $self->$orig(@_); + + my %attrs = ( + __INSTANCE__ => 1, + ( + map { $_ => 1 } + grep {defined} + map { $_->init_arg() } $self->get_all_attributes() + ) + ); + + my @bad = sort grep { !$attrs{$_} } keys %$params; + + if (@bad) { + $self->throw_error( + "Found unknown attribute(s) init_arg passed to the constructor: @bad" + ); + } + + return $instance; +}; + around '_inline_BUILDALL' => sub { my $orig = shift; my $self = shift; @@ -27,18 +53,7 @@ around '_inline_BUILDALL' => sub { '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 if not @_; - Moose::Util::MetaRole::apply_base_class_roles( - for => $self->name, - roles => ['MooseX::StrictConstructor::Role::Object'], - ); -}; +} if $Moose::VERSION >= 1.9900; 1;