Really make the strict constructor work after immutabilization.
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Meta / Method / Constructor.pm
CommitLineData
c001451a 1package MooseX::StrictConstructor::Meta::Method::Constructor;
2
3use strict;
4use warnings;
5
5c3f24ed 6use Carp ();
c001451a 7use Moose;
8
9extends 'Moose::Meta::Method::Constructor';
10
5c3f24ed 11# using
c001451a 12sub _generate_BUILDALL ## no critic RequireArgUnpacking
13{
14 my $self = shift;
15
5c3f24ed 16 my $source = $self->SUPER::_generate_BUILDALL(@_);
17 $source .= ";\n" if $source;
c001451a 18
5c3f24ed 19 my @attrs = map { $_->name() . ' => 1,' } @{ $self->attributes() };
c001451a 20
5c3f24ed 21 $source .= <<"EOF";
22my \%attrs = (@attrs);
c001451a 23
5c3f24ed 24my \@bad = sort grep { ! \$attrs{\$_} } keys \%params;
25
26if (\@bad) {
27 Carp::confess "Found unknown attribute(s) passed to the constructor: \@bad";
28}
c001451a 29EOF
30
5c3f24ed 31 return $source;
c001451a 32};
33
34
351;