Tidy
gfx [Mon, 12 Oct 2009 07:29:02 +0000 (16:29 +0900)]
lib/Mouse/Meta/Attribute.pm
lib/Mouse/Meta/Class.pm

index 1b2fb03..1d4c15b 100644 (file)
@@ -263,15 +263,12 @@ sub _coerce_and_verify {
     my($self, $value, $instance) = @_;
 
     my $type_constraint = $self->{type_constraint};
-
-    return $value if !$type_constraint;
+    return $value if !defined $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;
@@ -281,7 +278,7 @@ sub verify_against_type_constraint {
     my ($self, $value) = @_;
 
     my $type_constraint = $self->{type_constraint};
-    return 1 if !$type_constraint;;
+    return 1 if !$type_constraint;
     return 1 if $type_constraint->check($value);
 
     $self->verify_type_constraint_error($self->name, $value, $type_constraint);
@@ -289,7 +286,8 @@ sub verify_against_type_constraint {
 
 sub verify_type_constraint_error {
     my($self, $name, $value, $type) = @_;
-    $self->throw_error("Attribute ($name) does not pass the type constraint because: " . $type->get_message($value));
+    $self->throw_error("Attribute ($name) does not pass the type constraint because: "
+        . $type->get_message($value));
 }
 
 sub coerce_constraint { # DEPRECATED
index ab75b2b..563a208 100644 (file)
@@ -188,7 +188,7 @@ sub _initialize_object{
         my $key  = $attribute->name;
 
         if (defined($from) && exists($args->{$from})) {
-            $object->{$key} = $attribute->_coerce_and_verify($args->{$from});
+            $object->{$key} = $attribute->_coerce_and_verify($args->{$from}, $object);
 
             weaken($object->{$key})
                 if ref($object->{$key}) && $attribute->is_weak_ref;
@@ -206,7 +206,7 @@ sub _initialize_object{
                                 : ref($default) eq 'CODE' ? $object->$default()
                                 :                           $default;
 
-                    $object->{$key} = $attribute->_coerce_and_verify($value, $object);;
+                    $object->{$key} = $attribute->_coerce_and_verify($value, $object);
 
                     weaken($object->{$key})
                         if ref($object->{$key}) && $attribute->is_weak_ref;