1 package MooseX::StrictConstructor;
8 use Moose::Util::MetaRole;
10 use MooseX::StrictConstructor::Trait::Class;
11 use MooseX::StrictConstructor::Trait::Method::Constructor;;
13 Moose::Exporter->setup_import_methods(
15 class => ['MooseX::StrictConstructor::Trait::Class'],
17 ['MooseX::StrictConstructor::Trait::Method::Constructor'],
23 # ABSTRACT: Make your object constructors blow up on unknown attributes
34 use MooseX::StrictConstructor;
40 # this blows up because color is not a known attribute
41 My::Class->new( size => 5, color => 'blue' );
45 Simply loading this module makes your constructors "strict". If your
46 constructor is called with an attribute init argument that your class
47 does not declare, then it calls C<Moose->throw_error()>. This is a great way
50 =head2 Subverting Strictness
52 You may find yourself wanting to have your constructor accept a
53 parameter which does not correspond to an attribute.
55 In that case, you'll probably also be writing a C<BUILD()> or
56 C<BUILDARGS()> method to deal with that parameter. In a C<BUILDARGS()>
57 method, you can simply make sure that this parameter is not included
58 in the hash reference you return. Otherwise, in a C<BUILD()> method,
59 you can delete it from the hash reference of parameters.
65 if ( delete $params->{do_something} ) {
72 Please report any bugs or feature requests to
73 C<bug-moosex-strictconstructor@rt.cpan.org>, or through the web
74 interface at L<http://rt.cpan.org>. I will be notified, and then
75 you'll automatically be notified of progress on your bug as I make