my @res;
my $has_triggers;
+ my $strict = $metaclass->__strict_constructor;
+
+ if($strict){
+ push @res, 'my $used = 0;';
+ }
for my $index (0 .. @$attrs - 1) {
my $code = '';
my $post_process = '';
if(defined $type_constraint){
$post_process .= "\$checks[$index]->($instance_slot)";
- $post_process .= " or $attr_var->verify_type_constraint_error(q{$key}, $instance_slot, $constraint_var);\n";
+ $post_process .= " or $attr_var->_throw_type_constraint_error($instance_slot, $constraint_var);\n";
}
if($is_weak_ref){
$post_process .= "Scalar::Util::weaken($instance_slot) if ref $instance_slot;\n";
$code .= "push \@triggers, [$attr_var\->{trigger}, $instance_slot];\n";
}
- $code .= "\n} else {\n";
+ if ($strict){
+ $code .= '++$used;' . "\n";
+ }
+
+ $code .= "\n} else {\n"; # $value exists
}
if ($attr->has_default || $attr->has_builder) {
push @res, $code;
}
+ if($strict){
+ push @res, q{if($used < keys %{$args})}
+ . sprintf q{{ %s->_report_unknown_args($metaclass, \@attrs, $args) }}, $method_class;
+ }
+
if($metaclass->is_anon_class){
push @res, q{$instance->{__METACLASS__} = $metaclass;};
}
if($has_triggers){
unshift @res, q{my @triggers;};
- push @res, q{$_->[0]->($instance, $_->[1]) for @triggers;};
+ push @res, q{$_->[0]->($instance, $_->[1]) for @triggers;};
}
return join "\n", @res;
return join "\n", @code;
}
+sub _report_unknown_args {
+ my(undef, $metaclass, $attrs, $args) = @_;
+
+ my @unknowns;
+ my %init_args;
+ foreach my $attr(@{$attrs}){
+ my $init_arg = $attr->init_arg;
+ if(defined $init_arg){
+ $init_args{$init_arg}++;
+ }
+ }
+
+ while(my $key = each %{$args}){
+ if(!exists $init_args{$key}){
+ push @unknowns, $key;
+ }
+ }
+
+ $metaclass->throw_error( sprintf
+ "Unknown attribute passed to the constructor of %s: %s",
+ $metaclass->name, Mouse::Util::english_list(@unknowns),
+ );
+}
+
1;
__END__
=head1 VERSION
-This document describes Mouse version 0.40_08
+This document describes Mouse version 0.54
=head1 SEE ALSO