7d2017c8f52d6700cbedd147c4e371dad521468b
[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 Moose;
7
8 extends 'Moose::Meta::Method::Constructor';
9
10 sub _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     }
25 EOF
26
27     return $calls;
28 };
29
30
31 1;