Small style tweaks
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Trait / Class.pm
CommitLineData
1a4f7732 1package MooseX::StrictConstructor::Trait::Class;
c001451a 2
3use strict;
4use warnings;
5
79b37c7d 6use B ();
5c3f24ed 7use Carp ();
c001451a 8
64c958ef 9use Moose::Role;
c001451a 10
01265e2a 11around '_inline_BUILDALL' => sub {
64c958ef 12 my $orig = shift;
c001451a 13 my $self = shift;
14
01265e2a 15 my @source = $self->$orig();
c001451a 16
5a0d4921 17 my @attrs = (
df9653e6 18 '__INSTANCE__ => 1,',
79b37c7d 19 map { B::perlstring($_) . ' => 1,' }
5a0d4921 20 grep {defined}
01265e2a 21 map { $_->init_arg() } $self->get_all_attributes()
5a0d4921 22 );
c001451a 23
01265e2a 24 return (
25 @source,
93a34553 26 'my %attrs = (' . ( join ' ', @attrs ) . ');',
01265e2a 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 );
c001451a 32};
33
64c958ef 34no Moose::Role;
c001451a 35
361;
58370717 37
0639c294 38# ABSTRACT: A role to make immutable constructors strict
39
58370717 40__END__
41
42=pod
43
58370717 44=head1 DESCRIPTION
45
01265e2a 46This role simply wraps C<_inline_BUILDALL()> (from
47C<Moose::Meta::Class>) so that immutable classes have a
fbfaa61f 48strict constructor.
58370717 49
58370717 50=cut