Always use verify_against_type_constraint to check attribute value
Dave Rolsky [Fri, 27 Mar 2009 21:01:51 +0000 (16:01 -0500)]
validity (this doesn't fix perigrin's bug though)

lib/Moose/Meta/Attribute.pm

index 1330952..36acd78 100644 (file)
@@ -481,19 +481,11 @@ sub set_value {
         $self->throw_error("Attribute ($attr_name) is required", object => $instance);
     }
 
-    if ($self->has_type_constraint) {
-
-        my $type_constraint = $self->type_constraint;
-
-        if ($self->should_coerce) {
-            $value = $type_constraint->coerce($value);
-        }        
-        $type_constraint->_compiled_type_constraint->($value)
-            || $self->throw_error("Attribute (" 
-                     . $self->name 
-                     . ") does not pass the type constraint because " 
-                     . $type_constraint->get_message($value), object => $instance, data => $value);
+    my $type_constraint = $self->type_constraint;
+    if ($self->should_coerce && $type_constraint->has_coercion) {
+        $value = $type_constraint->coerce($value);
     }
+    $self->verify_against_type_constraint($value, instance => $instance);
 
     my $meta_instance = Class::MOP::Class->initialize(blessed($instance))
                                          ->get_meta_instance;