remove pointless SYNOPSES
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Trait / Class.pm
1 package MooseX::StrictConstructor::Trait::Class;
2
3 use strict;
4 use warnings;
5
6 use B ();
7 use Carp ();
8
9 use Moose::Role;
10
11 around '_inline_BUILDALL' => sub {
12     my $orig = shift;
13     my $self = shift;
14
15     my @source = $self->$orig();
16
17     my @attrs = (
18         '__INSTANCE__ => 1,',
19         map { B::perlstring($_) . ' => 1,' }
20         grep {defined}
21         map  { $_->init_arg() } $self->get_all_attributes()
22     );
23
24     return (
25         @source,
26         'my %attrs = (' . join(' ', @attrs) . ');',
27         'my @bad = sort grep { !$attrs{$_} } keys %{ $params };',
28         'if (@bad) {',
29             'Carp::confess "Found unknown attribute(s) passed to the constructor: @bad";',
30         '}',
31     );
32 };
33
34 no Moose::Role;
35
36 1;
37
38 # ABSTRACT: A role to make immutable constructors strict
39
40 __END__
41
42 =pod
43
44 =head1 DESCRIPTION
45
46 This role simply wraps C<_inline_BUILDALL()> (from
47 C<Moose::Meta::Class>) so that immutable classes have a
48 strict constructor.
49
50 =cut