Commit | Line | Data |
c001451a |
1 | package MooseX::StrictConstructor::Meta::Method::Constructor; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
5c3f24ed |
6 | use Carp (); |
c001451a |
7 | use Moose; |
8 | |
9 | extends 'Moose::Meta::Method::Constructor'; |
10 | |
58370717 |
11 | override '_generate_BUILDALL' => sub ## no critic RequireArgUnpacking |
c001451a |
12 | { |
13 | my $self = shift; |
14 | |
5c3f24ed |
15 | my $source = $self->SUPER::_generate_BUILDALL(@_); |
16 | $source .= ";\n" if $source; |
c001451a |
17 | |
5c3f24ed |
18 | my @attrs = map { $_->name() . ' => 1,' } @{ $self->attributes() }; |
c001451a |
19 | |
5c3f24ed |
20 | $source .= <<"EOF"; |
21 | my \%attrs = (@attrs); |
c001451a |
22 | |
5c3f24ed |
23 | my \@bad = sort grep { ! \$attrs{\$_} } keys \%params; |
24 | |
25 | if (\@bad) { |
26 | Carp::confess "Found unknown attribute(s) passed to the constructor: \@bad"; |
27 | } |
c001451a |
28 | EOF |
29 | |
5c3f24ed |
30 | return $source; |
c001451a |
31 | }; |
32 | |
58370717 |
33 | no Moose; |
34 | |
c001451a |
35 | |
36 | 1; |
58370717 |
37 | |
38 | __END__ |
39 | |
40 | =pod |
41 | |
42 | =head1 NAME |
43 | |
44 | MooseX::StrictConstructor::Meta::Method::Constructor - A meta class to make immutable constructors strict |
45 | |
46 | =head1 SYNOPSIS |
47 | |
48 | use MooseX::StrictConstructor; |
49 | |
50 | =head1 DESCRIPTION |
51 | |
52 | This class simply overrides C<_generate_BUILDALL()> in |
53 | C<Moose::Meta::Method::Constructor> so that classes that are made |
54 | immutable have a strict constructor. |
55 | |
56 | You should never have to use this class directly. |
57 | |
58 | =head1 AUTHOR |
59 | |
60 | Dave Rolsky, C<< <autarch@urth.org> >> |
61 | |
62 | =head1 COPYRIGHT & LICENSE |
63 | |
64 | Copyright 2007 Dave Rolsky, All Rights Reserved. |
65 | |
66 | This program is free software; you can redistribute it and/or modify |
67 | it under the same terms as Perl itself. |
68 | |
69 | =cut |
70 | |