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