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