A tweak for backward compatibility
gfx [Thu, 8 Oct 2009 11:48:21 +0000 (20:48 +0900)]
lib/Mouse/Meta/Method/Accessor.pm

index 9c5b746..c5faa54 100755 (executable)
@@ -94,8 +94,11 @@ sub _generate_accessor{
         }
         elsif(defined $constraint){
             $accessor .= "my \$tmp = $value;\n";
+            #XXX: The following 'defined and' check is for backward compatibility
+            $accessor .= "defined(\$tmp) and ";
+
             $accessor .= "\$compiled_type_constraint->(\$tmp)";
-            $accessor .= "or \$attribute->verify_type_constraint_error(\$name, \$tmp, \$constraint);\n";
+            $accessor .= " || \$attribute->verify_type_constraint_error(\$name, \$tmp, \$constraint);\n";
             $accessor .= "$slot = \$tmp;\n";
         }
         else{