$tc->coerce() throws an error if it has no coercion, as Moose's tc does.
gfx [Mon, 8 Feb 2010 04:00:58 +0000 (13:00 +0900)]
lib/Mouse/Meta/TypeConstraint.pm
xs-src/MouseAttribute.xs

index 43a03c5..2593b82 100644 (file)
@@ -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 {
index 2b3e621..7b25881 100644 (file)
@@ -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;
         }