Made it work with immutable classes.
[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
6use Moose;
7
8extends 'Moose::Meta::Method::Constructor';
9
10sub _generate_BUILDALL ## no critic RequireArgUnpacking
11{
12 my $self = shift;
13
14 my $calls = $self->SUPER::_generate_BUILDALL(@_);
15
16 $calls .= <<'EOF';
17 my %attrs = map { $_->name() => 1 } $self->meta()->compute_all_applicable_attributes();
18
19 my @bad = sort grep { ! $attrs{$_} } keys %params;
20
21 if (@bad)
22 {
23 confess "Found unknown attribute(s) passed to the constructor: @bad";
24 }
25EOF
26
27 return $calls;
28};
29
30
311;