Commit | Line | Data |
32726d88 |
1 | package MooseX::Object::StrictConstructor; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Moose; |
7 | |
8 | use Carp 'confess'; |
9 | |
10 | extends 'Moose::Object'; |
11 | |
12 | after 'BUILDALL' => sub |
13 | { |
14 | my $self = shift; |
15 | my $params = shift; |
16 | |
17 | my %attrs = map { $_->name() => 1 } $self->meta()->compute_all_applicable_attributes(); |
18 | |
d692165d |
19 | my @bad = sort grep { ! $attrs{$_} } keys %{ $params }; |
32726d88 |
20 | |
21 | if (@bad) |
22 | { |
23 | confess "Found unknown attribute(s) passed to the constructor: @bad"; |
24 | } |
25 | |
26 | return; |
27 | }; |
28 | |
29 | |
30 | 1; |
2ffa7b60 |
31 | |
32 | __END__ |
33 | |
34 | =pod |
35 | |
36 | =head1 NAME |
37 | |
38 | MooseX::Object::StrictConstructor - Implements strict constructors as a Moose::Object subclass |
39 | |
40 | =head1 DESCRIPTION |
41 | |
42 | This class has no external interface. When you use |
43 | C<MooseX::StrictConstructor>, your objects will subclass this class |
44 | rather than Moose::Object. |
45 | |
46 | =head1 AUTHOR |
47 | |
48 | Dave Rolsky, C<< <autarch@urth.org> >> |
49 | |
50 | =head1 COPYRIGHT & LICENSE |
51 | |
52 | Copyright 2007 Dave Rolsky, All Rights Reserved. |
53 | |
54 | This program is free software; you can redistribute it and/or modify |
55 | it under the same terms as Perl itself. |
56 | |
57 | =cut |