1 package MooseX::StrictConstructor::Trait::Class;
5 use namespace::autoclean;
9 around new_object => sub {
12 my $params = @_ == 1 ? $_[0] : {@_};
13 my $instance = $self->$orig(@_);
20 map { $_->init_arg() } $self->get_all_attributes()
24 my @bad = sort grep { !$attrs{$_} } keys %$params;
28 "Found unknown attribute(s) init_arg passed to the constructor: @bad"
35 around _inline_BUILDALL => sub {
39 my @source = $self->$orig();
43 map { B::perlstring($_) . ' => 1,' }
45 map { $_->init_arg() } $self->get_all_attributes()
50 'my @bad = sort grep { !$allowed_attrs{$_} } keys %{ $params };',
52 'Moose->throw_error("Found unknown attribute(s) passed to the constructor: @bad");',
55 } if $Moose::VERSION >= 1.9900;
57 around _eval_environment => sub {
61 my $env = $self->$orig();
63 my %attrs = map { $_ => 1 }
65 map { $_->init_arg() }
66 $self->get_all_attributes();
68 $attrs{__INSTANCE__} = 1;
70 $env->{'%allowed_attrs'} = \%attrs;
73 } if $Moose::VERSION >= 1.9900;
77 # ABSTRACT: A role to make immutable constructors strict
85 This role simply wraps C<_inline_BUILDALL()> (from
86 C<Moose::Meta::Class>) so that immutable classes have a