1 package MooseX::StrictConstructor::Trait::Method::Constructor;
5 use namespace::autoclean;
9 around _generate_BUILDALL => sub {
13 my $source = $self->$orig();
14 $source .= ";\n" if $source;
16 my @attrs = '__INSTANCE__ => 1,';
17 push @attrs, map { B::perlstring($_) . ' => 1,' }
19 map { $_->init_arg() } @{ $self->_attributes() };
23 my \%attrs = (@attrs);
25 my \@bad = sort grep { ! \$attrs{\$_} } keys \%{ \$params };
28 Moose->throw_error("Found unknown attribute(s) passed to the constructor: \@bad");
33 } if $Moose::VERSION < 1.9900;
35 around _eval_environment => sub {
39 my $env = $self->$orig();
41 my %attrs = map { $_ => 1 }
43 map { $_->init_arg() }
44 $self->associated_metaclass()->get_all_attributes();
46 $attrs{__INSTANCE__} = 1;
48 $env->{'%allowed_attrs'} = \%attrs;
51 } if $Moose::VERSION >= 1.9900;
55 # ABSTRACT: A role to make immutable constructors strict
63 This role simply wraps C<_generate_BUILDALL()> (from
64 C<Moose::Meta::Method::Constructor>) so that immutable classes have a