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 | |
32726d88 |
8 | |
9 | after 'BUILDALL' => sub |
10 | { |
11 | my $self = shift; |
12 | my $params = shift; |
13 | |
a83dec43 |
14 | my %attrs = |
15 | ( map { $_ => 1 } |
16 | grep { defined } |
17 | map { $_->init_arg() } |
8ce99ddb |
18 | $self->meta()->get_all_attributes() |
a83dec43 |
19 | ); |
32726d88 |
20 | |
d692165d |
21 | my @bad = sort grep { ! $attrs{$_} } keys %{ $params }; |
32726d88 |
22 | |
23 | if (@bad) |
24 | { |
a83dec43 |
25 | confess "Found unknown attribute(s) init_arg passed to the constructor: @bad"; |
32726d88 |
26 | } |
27 | |
28 | return; |
29 | }; |
30 | |
0cdff431 |
31 | no Moose::Role; |
32726d88 |
32 | |
33 | 1; |
2ffa7b60 |
34 | |
35 | __END__ |
36 | |
37 | =pod |
38 | |
39 | =head1 NAME |
40 | |
ab80b917 |
41 | MooseX::StrictConstructor::Role::Object - A role which implements a strict constructor for Moose::Object |
42 | |
43 | =head1 SYNOPSIS |
44 | |
45 | Moose::Util::MetaRole::apply_base_class_roles |
46 | ( for_class => $caller, |
47 | roles => |
48 | [ 'MooseX::StrictConstructor::Role::Object' ], |
49 | ); |
2ffa7b60 |
50 | |
51 | =head1 DESCRIPTION |
52 | |
fbfaa61f |
53 | When you use C<MooseX::StrictConstructor>, your objects will have this |
54 | role applied to them. It provides a method modifier for C<BUILDALL()> |
55 | from C<Moose::Object> that implements strict argument checking for |
56 | your class. |
2ffa7b60 |
57 | |
58 | =head1 AUTHOR |
59 | |
60 | Dave Rolsky, C<< <autarch@urth.org> >> |
61 | |
62 | =head1 COPYRIGHT & LICENSE |
63 | |
fbfaa61f |
64 | Copyright 2007-2008 Dave Rolsky, All Rights Reserved. |
2ffa7b60 |
65 | |
66 | This program is free software; you can redistribute it and/or modify |
67 | it under the same terms as Perl itself. |
68 | |
69 | =cut |