comments specifying how these traits are applied, just to keep it straight
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Role / Object.pm
CommitLineData
0cdff431 1package MooseX::StrictConstructor::Role::Object;
32726d88 2
d6932ec6 3# applied as base_class_roles => [ __PACKAGE__ ], for all Moose versions.
4# wraps the constructor for mutable classes.
5
0cdff431 6use Moose::Role;
32726d88 7
d99e6f32 8use namespace::autoclean;
9
5a0d4921 10after 'BUILDALL' => sub {
32726d88 11 my $self = shift;
12 my $params = shift;
13
5a0d4921 14 my %attrs = (
d78f8e74 15 __INSTANCE__ => 1,
5a0d4921 16 map { $_ => 1 }
17 grep {defined}
18 map { $_->init_arg() } $self->meta()->get_all_attributes()
19 );
32726d88 20
5a0d4921 21 my @bad = sort grep { !$attrs{$_} } keys %{$params};
32726d88 22
5a0d4921 23 if (@bad) {
675cf837 24 Moose->throw_error(
25 "Found unknown attribute(s) init_arg passed to the constructor: @bad");
32726d88 26 }
27
28 return;
29};
30
32726d88 311;
2ffa7b60 32
0639c294 33# ABSTRACT: A role which implements a strict constructor for Moose::Object
34
2ffa7b60 35__END__
36
37=pod
38
ab80b917 39=head1 SYNOPSIS
40
fd098db8 41 Moose::Util::MetaRole::apply_base_class_roles(
42 for_class => $caller,
43 roles =>
44 ['MooseX::StrictConstructor::Role::Object'],
45 );
2ffa7b60 46
47=head1 DESCRIPTION
48
fbfaa61f 49When you use C<MooseX::StrictConstructor>, your objects will have this
50role applied to them. It provides a method modifier for C<BUILDALL()>
51from C<Moose::Object> that implements strict argument checking for
52your class.
2ffa7b60 53
2ffa7b60 54=cut