X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FAttribute.pm;h=b3e3e50a6edd3f8e397813be22e3d459370adc88;hb=c91d12e031bd905978b1e664df94fc41bc647d34;hp=6c90b3053fb7e554f2d7d1c8b6a4e0918a7ad1f0;hpb=33aaf11b51fd4b31581b8c118af54d8ff64060fb;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 6c90b30..b3e3e50 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -86,10 +86,9 @@ sub generate_accessor { } else { $accessor .= $value.';'; } - $accessor .= 'local $_ = $val;'; $accessor .= ' - unless ($constraint->()) { - $attribute->verify_type_constraint_error($name, $_, $attribute->type_constraint); + unless ($constraint->($val)) { + $attribute->verify_type_constraint_error($name, $val, $attribute->type_constraint); }' . "\n"; $value = '$val'; } @@ -237,7 +236,7 @@ sub _build_type_constraint { } else { $code = $optimized_constraints->{ $spec }; if (! $code) { - $code = sub { Scalar::Util::blessed($_) && $_->isa($spec) }; + $code = sub { Scalar::Util::blessed($_[0]) && $_[0]->isa($spec) }; $optimized_constraints->{$spec} = $code; } } @@ -275,8 +274,9 @@ sub create { _build_type_constraint($_) } @type_constraints; $code = sub { + local $_ = $_[0]; for my $code (@code_list) { - return 1 if $code->(); + return 1 if $code->($_); } return 0; }; @@ -389,7 +389,7 @@ sub verify_against_type_constraint { sub verify_type_constraint_error { my($self, $name, $value, $type) = @_; $type = ref($type) eq 'ARRAY' ? join '|', @{ $type } : $type; - my $display = defined($_) ? overload::StrVal($_) : 'undef'; + my $display = defined($value) ? overload::StrVal($value) : 'undef'; Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $display"); }