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 | |
02f0d848 |
15 | my $source = super(); |
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"; |
26 | my \%attrs = (@attrs); |
c001451a |
27 | |
5c40fb22 |
28 | my \@bad = sort grep { ! \$attrs{\$_} } keys \%{ \$params }; |
5c3f24ed |
29 | |
30 | if (\@bad) { |
31 | Carp::confess "Found unknown attribute(s) passed to the constructor: \@bad"; |
32 | } |
c001451a |
33 | EOF |
34 | |
5c3f24ed |
35 | return $source; |
c001451a |
36 | }; |
37 | |
58370717 |
38 | no Moose; |
39 | |
c001451a |
40 | |
41 | 1; |
58370717 |
42 | |
43 | __END__ |
44 | |
45 | =pod |
46 | |
47 | =head1 NAME |
48 | |
49 | MooseX::StrictConstructor::Meta::Method::Constructor - A meta class to make immutable constructors strict |
50 | |
51 | =head1 SYNOPSIS |
52 | |
53 | use MooseX::StrictConstructor; |
54 | |
55 | =head1 DESCRIPTION |
56 | |
57 | This class simply overrides C<_generate_BUILDALL()> in |
58 | C<Moose::Meta::Method::Constructor> so that classes that are made |
59 | immutable have a strict constructor. |
60 | |
61 | You should never have to use this class directly. |
62 | |
63 | =head1 AUTHOR |
64 | |
65 | Dave Rolsky, C<< <autarch@urth.org> >> |
66 | |
67 | =head1 COPYRIGHT & LICENSE |
68 | |
69 | Copyright 2007 Dave Rolsky, All Rights Reserved. |
70 | |
71 | This program is free software; you can redistribute it and/or modify |
72 | it under the same terms as Perl itself. |
73 | |
74 | =cut |
75 | |