From: 大沢 和宏 Date: Fri, 5 Dec 2008 13:56:41 +0000 (+0000) Subject: set instance to attributes default code X-Git-Tag: 0.19~136^2~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0e503bd950b9880c383861e1e7ef40beef90937c;p=gitmo%2FMouse.git set instance to attributes default code --- diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 2867d71..2a9bf6c 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -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'; diff --git a/lib/Mouse/Object.pm b/lib/Mouse/Object.pm index fcfaf6b..c7add33 100644 --- a/lib/Mouse/Object.pm +++ b/lib/Mouse/Object.pm @@ -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)