Ignore __INSTANCE__ as constructor arg
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Role / Object.pm
1 package MooseX::StrictConstructor::Role::Object;
2
3 use strict;
4 use warnings;
5
6 use Moose::Role;
7
8 after 'BUILDALL' => sub {
9     my $self   = shift;
10     my $params = shift;
11
12     my %attrs = (
13         __INSTANCE__ => 1,
14         map { $_ => 1 }
15         grep {defined}
16         map  { $_->init_arg() } $self->meta()->get_all_attributes()
17     );
18
19     my @bad = sort grep { !$attrs{$_} } keys %{$params};
20
21     if (@bad) {
22         confess
23             "Found unknown attribute(s) init_arg passed to the constructor: @bad";
24     }
25
26     return;
27 };
28
29 no Moose::Role;
30
31 1;
32
33 # ABSTRACT: A role which implements a strict constructor for Moose::Object
34
35 __END__
36
37 =pod
38
39 =head1 SYNOPSIS
40
41   Moose::Util::MetaRole::apply_base_class_roles
42       ( for_class => $caller,
43         roles =>
44         [ 'MooseX::StrictConstructor::Role::Object' ],
45       );
46
47 =head1 DESCRIPTION
48
49 When you use C<MooseX::StrictConstructor>, your objects will have this
50 role applied to them. It provides a method modifier for C<BUILDALL()>
51 from C<Moose::Object> that implements strict argument checking for
52 your class.
53
54 =cut