set instance to attributes default code
大沢 和宏 [Fri, 5 Dec 2008 13:56:41 +0000 (13:56 +0000)]
lib/Mouse/Meta/Method/Constructor.pm
lib/Mouse/Object.pm

index 2867d71..2a9bf6c 100644 (file)
@@ -81,7 +81,7 @@ sub _generate_processattrs {
                             push @code, "\$instance->$builder";
                         }
                         elsif (ref($default) eq 'CODE') {
-                            push @code, "\$attrs[$index]->default()->()";
+                            push @code, "\$attrs[$index]->default()->(\$instance)";
                         }
                         elsif (!defined($default)) {
                             push @code, 'undef';
index fcfaf6b..c7add33 100644 (file)
@@ -40,7 +40,7 @@ sub new {
                     my $value = $attribute->has_builder
                               ? $instance->$builder
                               : ref($default) eq 'CODE'
-                                  ? $default->()
+                                  ? $default->($instance)
                                   : $default;
 
                     $value = $attribute->coerce_constraint($value)