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 = ( |
13 | map { $_ => 1 } | |
14 | grep {defined} | |
15 | map { $_->init_arg() } $self->meta()->get_all_attributes() | |
16 | ); | |
32726d88 | 17 | |
5a0d4921 | 18 | my @bad = sort grep { !$attrs{$_} } keys %{$params}; |
32726d88 | 19 | |
5a0d4921 | 20 | if (@bad) { |
21 | confess | |
22 | "Found unknown attribute(s) init_arg passed to the constructor: @bad"; | |
32726d88 | 23 | } |
24 | ||
25 | return; | |
26 | }; | |
27 | ||
0cdff431 | 28 | no Moose::Role; |
32726d88 | 29 | |
30 | 1; | |
2ffa7b60 | 31 | |
0639c294 | 32 | # ABSTRACT: A role which implements a strict constructor for Moose::Object |
33 | ||
2ffa7b60 | 34 | __END__ |
35 | ||
36 | =pod | |
37 | ||
ab80b917 | 38 | =head1 SYNOPSIS |
39 | ||
40 | Moose::Util::MetaRole::apply_base_class_roles | |
41 | ( for_class => $caller, | |
42 | roles => | |
43 | [ 'MooseX::StrictConstructor::Role::Object' ], | |
44 | ); | |
2ffa7b60 | 45 | |
46 | =head1 DESCRIPTION | |
47 | ||
fbfaa61f | 48 | When you use C<MooseX::StrictConstructor>, your objects will have this |
49 | role applied to them. It provides a method modifier for C<BUILDALL()> | |
50 | from C<Moose::Object> that implements strict argument checking for | |
51 | your class. | |
2ffa7b60 | 52 | |
2ffa7b60 | 53 | =cut |