From: Matt S Trout Date: Fri, 4 May 2012 20:40:08 +0000 (+0000) Subject: fix roles for accessor regeneration X-Git-Tag: v0.091002~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=db10ae2d7e82cc64f8f7b93f34bc924b7125c062;p=gitmo%2FMoo.git fix roles for accessor regeneration --- diff --git a/lib/Moo/Role.pm b/lib/Moo/Role.pm index 72f3808..5624585 100644 --- a/lib/Moo/Role.pm +++ b/lib/Moo/Role.pm @@ -83,8 +83,13 @@ sub _make_accessors { require Method::Generate::Accessor; Method::Generate::Accessor->new }); + my $con_gen = $Moo::MAKERS{$target}{constructor}; my @attrs = @{$INFO{$role}{attributes}||[]}; while (my ($name, $spec) = splice @attrs, 0, 2) { + # needed to ensure we got an index for an arrayref based generator + if ($con_gen) { + $spec = $con_gen->all_attribute_specs->{$name}; + } $acc_gen->generate_method($target, $name, $spec); } } diff --git a/t/accessor-generator-extension.t b/t/accessor-generator-extension.t index e0b5070..d894639 100644 --- a/t/accessor-generator-extension.t +++ b/t/accessor-generator-extension.t @@ -81,4 +81,24 @@ $o = ArrayTest2->new(one => 1, two => 2, three => 3, four => 4); is_deeply([ @$o ], [ 1, 2, 3, 4 ], 'Subclass object ok'); +{ + package ArrayTestRole; + + use Moo::Role; + + has four => (is => 'ro'); + + package ArrayTest3; + + use Moo; + + extends 'ArrayTest1'; + + with 'ArrayTestRole'; +} + +$o = ArrayTest3->new(one => 1, two => 2, three => 3, four => 4); + +is_deeply([ @$o ], [ 1, 2, 3, 4 ], 'Subclass object w/role'); + done_testing;