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