From: gfx Date: Mon, 8 Feb 2010 04:00:58 +0000 (+0900) Subject: $tc->coerce() throws an error if it has no coercion, as Moose's tc does. X-Git-Tag: 0.50~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=de0d4152ac07ed26a928841729e97366187b2915 $tc->coerce() throws an error if it has no coercion, as Moose's tc does. --- diff --git a/lib/Mouse/Meta/TypeConstraint.pm b/lib/Mouse/Meta/TypeConstraint.pm index 43a03c5..2593b82 100644 --- a/lib/Mouse/Meta/TypeConstraint.pm +++ b/lib/Mouse/Meta/TypeConstraint.pm @@ -138,10 +138,14 @@ sub check { sub coerce { my $self = shift; + my $coercion = $self->_compiled_type_coercion; + if(!$coercion){ + Carp::confess("Cannot coerce without a type coercion"); + } + return $_[0] if $self->_compiled_type_constraint->(@_); - my $coercion = $self->_compiled_type_coercion; - return $coercion ? $coercion->(@_) : $_[0]; + return $coercion->(@_); } sub get_message { diff --git a/xs-src/MouseAttribute.xs b/xs-src/MouseAttribute.xs index 2b3e621..7b25881 100644 --- a/xs-src/MouseAttribute.xs +++ b/xs-src/MouseAttribute.xs @@ -54,7 +54,7 @@ mouse_build_xa(pTHX_ SV* const attr) { } } - if(predicate_calls(attr, "should_coerce")){ + if(predicate_calls(attr, "should_coerce") && predicate_calls(tc, "has_coercion")){ flags |= MOUSEf_ATTR_SHOULD_COERCE; }