s/Role::Meta/Trait/g
[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,
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 );
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 SYNOPSIS
45
48ad7621 46 Moose::Util::MetaRole::apply_metaroles(
47 for_class => $caller,
48 class => {
49 constructor =>
1a4f7732 50 ['MooseX::StrictConstructor::Trait::Method::Constructor'],
48ad7621 51 },
52 );
58370717 53
54=head1 DESCRIPTION
55
01265e2a 56This role simply wraps C<_inline_BUILDALL()> (from
57C<Moose::Meta::Class>) so that immutable classes have a
fbfaa61f 58strict constructor.
58370717 59
58370717 60=cut