Checking in changes prior to tagging of version 0.62.
[gitmo/Mouse.git] / lib / Mouse / Meta / Method / Constructor.pm
index 1fe3b08..dbbbf06 100644 (file)
@@ -51,6 +51,11 @@ sub _generate_processattrs {
     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 = '';
@@ -100,7 +105,11 @@ sub _generate_processattrs {
                 $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) {
@@ -141,13 +150,18 @@ sub _generate_processattrs {
         push @res, $code;
     }
 
+    if($strict){
+        push @res, q{if($used < keys %{$args})}
+            . q{{ $metaclass->_report_unknown_args(\@attrs, $args) }};
+    }
+
     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;
@@ -197,7 +211,7 @@ Mouse::Meta::Method::Constructor - A Mouse method generator for constructors
 
 =head1 VERSION
 
-This document describes Mouse version 0.4501
+This document describes Mouse version 0.62
 
 =head1 SEE ALSO