X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FAttribute.pm;h=4b3539fc160954c7b04d537ba805bcbb40079c48;hp=1ef8a77802ce88c363afb7a19b85d9ce548a04c5;hb=ffbbf459fec594dcd08b5f7d05014740390bde58;hpb=a15d1371334de8874a74618597d0c1995fdca276 diff --git a/lib/Mouse/Meta/Attribute.pm b/lib/Mouse/Meta/Attribute.pm index 1ef8a77..4b3539f 100644 --- a/lib/Mouse/Meta/Attribute.pm +++ b/lib/Mouse/Meta/Attribute.pm @@ -265,15 +265,32 @@ sub create { return $self; } +sub _coerce_and_verify { + my($self, $value, $instance) = @_; + + my $type_constraint = $self->{type_constraint}; + + return $value if !$type_constraint; + + if ($self->should_coerce && $type_constraint->has_coercion) { + $value = $type_constraint->coerce($value); + } + + return $value if $type_constraint->check($value); + + $self->verify_against_type_constraint($value); + + return $value; +} + sub verify_against_type_constraint { my ($self, $value) = @_; - my $tc = $self->type_constraint; - return 1 unless $tc; - local $_ = $value; - return 1 if $tc->check($value); + my $type_constraint = $self->{type_constraint}; + return 1 if !$type_constraint;; + return 1 if $type_constraint->check($value); - $self->verify_type_constraint_error($self->name, $value, $tc); + $self->verify_type_constraint_error($self->name, $value, $type_constraint); } sub verify_type_constraint_error {