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