$tc->coerce() throws an error if it has no coercion, as Moose's tc does.
[gitmo/Mouse.git] / lib / Mouse / Meta / TypeConstraint.pm
index 266e53d..2593b82 100644 (file)
@@ -24,13 +24,6 @@ sub new {
 
     my $check = delete $args{optimized};
 
-    if($args{_compiled_type_constraint}){
-        Carp::cluck("'_compiled_type_constraint' has been deprecated, use 'optimized' instead")
-            if Mouse::Util::_MOUSE_VERBOSE;
-
-        $check = $args{_compiled_type_constraint};
-    }
-
     if($check){
         $args{hand_optimized_type_constraint} = $check;
         $args{compiled_type_constraint}       = $check;
@@ -88,6 +81,15 @@ sub create_child_type{
    );
 }
 
+sub name;
+sub parent;
+sub message;
+sub has_coercion;
+sub _compiled_type_constraint;
+sub _compiled_type_coercion;
+
+sub compile_type_constraint;
+
 sub _add_type_coercions{
     my $self = shift;
 
@@ -114,15 +116,15 @@ sub _add_type_coercions{
     }
     else{
         $self->{_compiled_type_coercion} = sub {
-           my($thing) = @_;\r
-           foreach my $pair (@{$coercions}) {\r
-                #my ($constraint, $converter) = @$pair;\r
-                if ($pair->[0]->check($thing)) {\r
+           my($thing) = @_;
+           foreach my $pair (@{$coercions}) {
+                #my ($constraint, $converter) = @$pair;
+                if ($pair->[0]->check($thing)) {
                   local $_ = $thing;
                   return $pair->[1]->($thing);
-                }\r
-           }\r
-           return $thing;\r
+                }
+           }
+           return $thing;
         };
     }
     return;
@@ -136,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 {
@@ -210,7 +216,7 @@ Mouse::Meta::TypeConstraint - The Mouse Type Constraint metaclass
 
 =head1 VERSION
 
-This document describes Mouse version 0.40_08
+This document describes Mouse version 0.49
 
 =head1 DESCRIPTION