Commit | Line | Data |
---|---|---|
0cdff431 | 1 | package MooseX::StrictConstructor::Role::Object; |
32726d88 | 2 | |
3 | use strict; | |
4 | use warnings; | |
5 | ||
0cdff431 | 6 | use Moose::Role; |
32726d88 | 7 | |
5a0d4921 | 8 | after 'BUILDALL' => sub { |
32726d88 | 9 | my $self = shift; |
10 | my $params = shift; | |
11 | ||
5a0d4921 | 12 | my %attrs = ( |
d78f8e74 | 13 | __INSTANCE__ => 1, |
5a0d4921 | 14 | map { $_ => 1 } |
15 | grep {defined} | |
16 | map { $_->init_arg() } $self->meta()->get_all_attributes() | |
17 | ); | |
32726d88 | 18 | |
5a0d4921 | 19 | my @bad = sort grep { !$attrs{$_} } keys %{$params}; |
32726d88 | 20 | |
5a0d4921 | 21 | if (@bad) { |
22 | confess | |
23 | "Found unknown attribute(s) init_arg passed to the constructor: @bad"; | |
32726d88 | 24 | } |
25 | ||
26 | return; | |
27 | }; | |
28 | ||
0cdff431 | 29 | no Moose::Role; |
32726d88 | 30 | |
31 | 1; | |
2ffa7b60 | 32 | |
0639c294 | 33 | # ABSTRACT: A role which implements a strict constructor for Moose::Object |
34 | ||
2ffa7b60 | 35 | __END__ |
36 | ||
37 | =pod | |
38 | ||
ab80b917 | 39 | =head1 SYNOPSIS |
40 | ||
41 | Moose::Util::MetaRole::apply_base_class_roles | |
42 | ( for_class => $caller, | |
43 | roles => | |
44 | [ 'MooseX::StrictConstructor::Role::Object' ], | |
45 | ); | |
2ffa7b60 | 46 | |
47 | =head1 DESCRIPTION | |
48 | ||
fbfaa61f | 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. | |
2ffa7b60 | 53 | |
2ffa7b60 | 54 | =cut |