X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FMethod%2FConstructor.pm;h=9c8d4f8574b5705e48b2cc6050b22429005d7a8d;hb=684db121da77d6c63be5a58e33606907ca2aa4fb;hp=5b8b5d25b89374bd59959d25f5721ea1d2191a53;hpb=3b46bd4991dea7ead4e7f52a089222d24554e2bd;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 5b8b5d2..9c8d4f8 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -42,7 +42,7 @@ sub _generate_processattrs { $code .= "if (exists \$args->{'$from'}) {\n"; if ($attr->should_coerce && $attr->type_constraint) { - $code .= "my \$value = Mouse::Util::TypeConstraints->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{find_type_constraint}, \$attrs[$index]->{type_constraint}, \$args->{'$from'});\n"; + $code .= "my \$value = Mouse::Util::TypeConstraints->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{type_constraint}, \$attrs[$index]->{type_constraint}, \$args->{'$from'});\n"; } else { $code .= "my \$value = \$args->{'$from'};\n"; @@ -50,8 +50,7 @@ sub _generate_processattrs { if ($attr->has_type_constraint) { $code .= "{ - local \$_ = \$value; - unless (\$attrs[$index]->{find_type_constraint}->(\$_)) { + unless (\$attrs[$index]->{type_constraint}->check(\$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"; @@ -78,7 +77,7 @@ sub _generate_processattrs { $code .= "my \$value = "; if ($attr->should_coerce && $attr->type_constraint) { - $code .= "Mouse::Util::TypeConstraints->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{find_type_constraint}, \$attrs[$index]->{type_constraint}, "; + $code .= "Mouse::Util::TypeConstraints->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{type_constraint}, \$attrs[$index]->{type_constraint}, "; } if ($attr->has_builder) { @@ -106,8 +105,7 @@ sub _generate_processattrs { if ($attr->has_type_constraint) { $code .= "{ - local \$_ = \$value; - unless (\$attrs[$index]->{find_type_constraint}->(\$_)) { + unless (\$attrs[$index]->{type_constraint}->check(\$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 { +{@_};