0.49
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor.pm
index 30efaa6..455cec0 100644 (file)
@@ -28,6 +28,7 @@ sub _eval_code {
                                    ? $type_constraint_obj->_compiled_type_constraint
                                    : undef;
 
+    #warn "code for $attr_name =>\n" . $code . "\n";
     my $sub = eval $code;
     confess "Could not create writer for '$attr_name' because $@ \n code: $code" if $@;
     return $sub;
@@ -127,8 +128,7 @@ sub _inline_check_constraint {
     return sprintf <<'EOF', $value, $attr_name, $value, $value,
 $type_constraint->(%s)
         || confess "Attribute (%s) does not pass the type constraint because: "
-       . $type_constraint_obj->get_message(%s)
-  if defined(%s);
+       . $type_constraint_obj->get_message(%s);
 EOF
 }
 
@@ -145,7 +145,7 @@ sub _inline_check_required {
     my $attr_name = $attr->name;
     
     return '' unless $attr->is_required;
-    return qq{defined(\$_[1]) || confess "Attribute ($attr_name) is required, so cannot be set to undef";}
+    return qq{(\@_ >= 2) || confess "Attribute ($attr_name) is required, so cannot be set to undef";} # defined $_[1] is not good enough
 }
 
 sub _inline_check_lazy {
@@ -175,8 +175,8 @@ sub _inline_check_lazy {
             $code .= '    $default = $type_constraint_obj->coerce($default);'."\n"  if $attr->should_coerce;
             $code .= '    ($type_constraint->($default))' .
                      '            || confess "Attribute (" . $attr_name . ") does not pass the type constraint ("' .
-                     '           . $type_constraint_name . ") with " . (defined($default) ? overload::StrVal($default) : "undef")' .
-                     '          if defined($default);' . "\n";
+                     '           . $type_constraint_name . ") with " . (defined($default) ? overload::StrVal($default) : "undef");' 
+                     . "\n";
             $code .= '    ' . $self->_inline_init_slot($attr, $inv, $slot_access, '$default') . "\n";
         } 
         else {