PodTests became PodCoverageTests + PodSyntaxTests.
[gitmo/MooseX-StrictConstructor.git] / lib / MooseX / StrictConstructor / Trait / Class.pm
CommitLineData
1a4f7732 1package MooseX::StrictConstructor::Trait::Class;
c001451a 2
d99e6f32 3use Moose::Role;
4
5use namespace::autoclean;
c001451a 6
79b37c7d 7use B ();
5c3f24ed 8use Carp ();
c001451a 9
01265e2a 10around '_inline_BUILDALL' => sub {
64c958ef 11 my $orig = shift;
c001451a 12 my $self = shift;
13
01265e2a 14 my @source = $self->$orig();
c001451a 15
5a0d4921 16 my @attrs = (
df9653e6 17 '__INSTANCE__ => 1,',
79b37c7d 18 map { B::perlstring($_) . ' => 1,' }
5a0d4921 19 grep {defined}
01265e2a 20 map { $_->init_arg() } $self->get_all_attributes()
5a0d4921 21 );
c001451a 22
01265e2a 23 return (
24 @source,
93a34553 25 'my %attrs = (' . ( join ' ', @attrs ) . ');',
01265e2a 26 'my @bad = sort grep { !$attrs{$_} } keys %{ $params };',
27 'if (@bad) {',
28 'Carp::confess "Found unknown attribute(s) passed to the constructor: @bad";',
29 '}',
30 );
c001451a 31};
32
c001451a 331;
58370717 34
0639c294 35# ABSTRACT: A role to make immutable constructors strict
36
58370717 37__END__
38
39=pod
40
58370717 41=head1 DESCRIPTION
42
01265e2a 43This role simply wraps C<_inline_BUILDALL()> (from
44C<Moose::Meta::Class>) so that immutable classes have a
fbfaa61f 45strict constructor.
58370717 46
58370717 47=cut