X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FTypeRegistry.pm;fp=lib%2FMouse%2FTypeRegistry.pm;h=a37ce3b88c04b3d366a7a990e77f9716d72cac47;hb=adebd0a83f0b7b52be8834444b40eedd0ddc2d66;hp=c722ec1ba43f5eb0812c4ea9aeeaf6c89816f0fb;hpb=d3982c7e7f662fb205f4fca0a264c3479bba4438;p=gitmo%2FMouse.git diff --git a/lib/Mouse/TypeRegistry.pm b/lib/Mouse/TypeRegistry.pm index c722ec1..a37ce3b 100644 --- a/lib/Mouse/TypeRegistry.pm +++ b/lib/Mouse/TypeRegistry.pm @@ -139,18 +139,21 @@ sub _role_type { } sub typecast_constraints { - my($class, $pkg, $type, $value) = @_; - return $value unless $COERCE->{$type}; - + my($class, $pkg, $type_constraint, $types, $value) = @_; my $optimized_constraints = optimized_constraints(); - for my $coerce_type (keys %{ $COERCE->{$type} }) { - local $_ = $value; - if ($optimized_constraints->{$coerce_type}->()) { + + for my $type (ref($types) eq 'ARRAY' ? @{ $types } : ( $types )) { + next unless $COERCE->{$type}; + + for my $coerce_type (keys %{ $COERCE->{$type} }) { local $_ = $value; - return $COERCE->{$type}->{$coerce_type}->(); + if ($optimized_constraints->{$coerce_type}->()) { + local $_ = $value; + local $_ = $COERCE->{$type}->{$coerce_type}->(); + return $_ if $type_constraint->(); + } } } - return $value; }