much faster impl. for constructor/accessor. this is a same behavior with Moose.
[gitmo/Mouse.git] / lib / Mouse / Meta / Method / Constructor.pm
index 5b8b5d2..4c22fd8 100644 (file)
@@ -50,8 +50,7 @@ sub _generate_processattrs {
 
             if ($attr->has_type_constraint) {
                 $code .= "{
-                    local \$_ = \$value;
-                    unless (\$attrs[$index]->{find_type_constraint}->(\$_)) {
+                    unless (\$attrs[$index]->{find_type_constraint}->(\$value)) {
                         \$attrs[$index]->verify_type_constraint_error('$key', \$_, \$attrs[$index]->type_constraint)
                     }
                 }";
@@ -64,7 +63,7 @@ sub _generate_processattrs {
             }
 
             if ($attr->has_trigger) {
-                $code .= "\$attrs[$index]->{trigger}->( \$instance, \$value, \$attrs[$index] );\n";
+                $code .= "\$attrs[$index]->{trigger}->( \$instance, \$value );\n";
             }
 
             $code .= "\n} else {\n";
@@ -106,8 +105,7 @@ sub _generate_processattrs {
 
                 if ($attr->has_type_constraint) {
                     $code .= "{
-                        local \$_ = \$value;
-                        unless (\$attrs[$index]->{find_type_constraint}->(\$_)) {
+                        unless (\$attrs[$index]->{find_type_constraint}->(\$value)) {
                             \$attrs[$index]->verify_type_constraint_error('$key', \$_, \$attrs[$index]->type_constraint)
                         }
                     }";
@@ -136,21 +134,16 @@ sub _generate_BUILDARGS {
     my $self = shift;
     my $meta = shift;
 
-    if ($meta->name->can('BUILDARGS') != Mouse::Object->can('BUILDARGS')) {
+    if ($meta->name->can('BUILDARGS') && $meta->name->can('BUILDARGS') != Mouse::Object->can('BUILDARGS')) {
         return '$class->BUILDARGS(@_)';
     }
 
     return <<'...';
     do {
         if ( scalar @_ == 1 ) {
-            if ( defined $_[0] ) {
-                ( ref( $_[0] ) eq 'HASH' )
+            ( ref( $_[0] ) eq 'HASH' )
                 || Carp::confess "Single parameters to new() must be a HASH ref";
-                +{ %{ $_[0] } };
-            }
-            else {
-                +{};
-            }
+            +{ %{ $_[0] } };
         }
         else {
             +{@_};