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