From: Guillermo Roditi Date: Tue, 13 Nov 2007 01:05:02 +0000 (+0000) Subject: builder inline accessor bug fix and new test X-Git-Tag: 0_27~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f8a0bbe03f83eb1dba1a1a0a106dead95184d45;p=gitmo%2FMoose.git builder inline accessor bug fix and new test --- diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index 530e23e..6b387da 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -160,7 +160,7 @@ sub _inline_check_lazy { ' my $default; '. ' $default = $attr->default(' . $inv . ') if $attr->has_default;' . ' if ( $attr->has_builder ) { '. - ' my $builder = $self->builder;'. + ' my $builder = $attr->builder;'. ' if($builder = '.$inv.'->can($builder)){ '. ' $default = '.$inv.'->$builder; '. ' } else { '. diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index ae234ea..c43f520 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -116,7 +116,7 @@ sub _generate_slot_initializer { '|| confess "Attribute (' . $attr->name . ') is required";'); } - if ($attr->has_default && !($is_moose &&$attr->is_lazy)) { + if ($attr->has_default && !($is_moose && $attr->is_lazy)) { push @source => 'if (exists $params{\'' . $attr->init_arg . '\'}) {'; diff --git a/t/300_immutable/001_immutable_moose.t b/t/300_immutable/001_immutable_moose.t index 1a4dd25..bf21347 100644 --- a/t/300_immutable/001_immutable_moose.t +++ b/t/300_immutable/001_immutable_moose.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 12; +use Test::More tests => 14; use Test::Exception; BEGIN { @@ -21,9 +21,12 @@ BEGIN { package Foo; use Moose; + #two checks because the inlined methods are different when + #there is a TC present. has 'foos' => (is => 'ro', lazy_build => 1); + has 'bars' => (isa => 'Str', is => 'ro', lazy_build => 1); sub _build_foos{ "many foos" } - + sub _build_bars{ "many bars" } } { @@ -32,10 +35,12 @@ BEGIN { lives_ok{ Foo->new } "lazy_build works"; is(Foo->new->foos, 'many foos' , "correct value for 'foos'"); + is(Foo->new->bars, 'many bars' , "correct value for 'bars'"); lives_ok{ $meta->make_immutable } "Foo is imutable"; dies_ok{ $meta->add_role($foo_role) } "Add Role is locked"; lives_ok{ Foo->new } "Inlined constructor works with lazy_build"; is(Foo->new->foos, 'many foos' , "correct value for 'foos'"); + is(Foo->new->bars, 'many bars' , "correct value for 'bars'"); lives_ok{ $meta->make_mutable } "Foo is mutable"; lives_ok{ $meta->add_role($foo_role) } "Add Role is unlocked";