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