Some simplification of the inlined type check
Shawn M Moore [Wed, 16 Jul 2008 05:49:38 +0000 (05:49 +0000)]
lib/Mouse/Meta/Attribute.pm

index 4bdb9f8..ef50e05 100644 (file)
@@ -84,10 +84,10 @@ sub generate_accessor {
         }
 
             if ($constraint) {
-                $accessor .= 'do {
-                    my $display = defined($_) ? overload::StrVal($_) : "undef";
-                    Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $display") unless $constraint->();
-                };'
+                $accessor .= 'unless ($constraint->()) {
+                        my $display = defined($_) ? overload::StrVal($_) : "undef";
+                        Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $display");
+                }'
             }
 
             $accessor .= '$self->{$key} = $_;';