Updated SYNOPSIS
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Role / Meta / Method / Constructor.pm
CommitLineData
fbfaa61f 1package MooseX::StrictConstructor::Role::Meta::Method::Constructor;
c001451a 2
3use strict;
4use warnings;
5
5c3f24ed 6use Carp ();
c001451a 7
64c958ef 8use Moose::Role;
c001451a 9
64c958ef 10around '_generate_BUILDALL' => sub
c001451a 11{
64c958ef 12 my $orig = shift;
c001451a 13 my $self = shift;
14
64c958ef 15 my $source = $self->$orig();
5c3f24ed 16 $source .= ";\n" if $source;
c001451a 17
0f795b43 18 my @attrs =
19 ( map { "$_ => 1," }
20 grep { defined }
21 map { $_->init_arg() }
22 @{ $self->attributes() }
23 );
c001451a 24
5c3f24ed 25 $source .= <<"EOF";
26my \%attrs = (@attrs);
c001451a 27
5c40fb22 28my \@bad = sort grep { ! \$attrs{\$_} } keys \%{ \$params };
5c3f24ed 29
30if (\@bad) {
31 Carp::confess "Found unknown attribute(s) passed to the constructor: \@bad";
32}
c001451a 33EOF
34
5c3f24ed 35 return $source;
c001451a 36};
37
64c958ef 38no Moose::Role;
c001451a 39
401;
58370717 41
42__END__
43
44=pod
45
46=head1 NAME
47
fbfaa61f 48MooseX::StrictConstructor::Role::Meta::Method::Constructor - A role to make immutable constructors strict
58370717 49
50=head1 SYNOPSIS
51
f83de654 52 Moose::Util::MetaRole::apply_metaclass_roles
53 ( for_class => $caller,
54 constructor_class_roles =>
55 ['MooseX::StrictConstructor::Role::Meta::Method::Constructor'],
56 );
58370717 57
58=head1 DESCRIPTION
59
fbfaa61f 60This role simply wraps C<_generate_BUILDALL()> (from
61C<Moose::Meta::Method::Constructor>) so that immutable classes have a
62strict constructor.
58370717 63
64=head1 AUTHOR
65
66Dave Rolsky, C<< <autarch@urth.org> >>
67
68=head1 COPYRIGHT & LICENSE
69
fbfaa61f 70Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
58370717 71
72This program is free software; you can redistribute it and/or modify
73it under the same terms as Perl itself.
74
75=cut
76