From: Graham Knop Date: Thu, 2 May 2013 17:16:33 +0000 (-0400) Subject: moosify on overridden attributes adds to list of subs X-Git-Tag: v1.002000~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ef4ff8da82d5b2c2635da073084ad2a14b4d2050;p=gitmo%2FMoo.git moosify on overridden attributes adds to list of subs --- diff --git a/lib/Method/Generate/Constructor.pm b/lib/Method/Generate/Constructor.pm index 50a5659..b696346 100644 --- a/lib/Method/Generate/Constructor.pm +++ b/lib/Method/Generate/Constructor.pm @@ -14,8 +14,12 @@ sub register_attribute_specs { die "has '+${name}' given but no ${name} attribute already exists" unless my $old_spec = $specs->{$name}; foreach my $key (keys %$old_spec) { - $new_spec->{$key} = $old_spec->{$key} - unless exists $new_spec->{$key}; + if (!exists $new_spec->{$key}) { + $new_spec->{$key} = $old_spec->{$key} + } + elsif ($key eq 'moosify') { + $new_spec->{$key} = [map { ref $_ eq 'ARRAY' ? @$_ : $_ } ($old_spec->{$key}, $new_spec->{$key})]; + } } } $new_spec->{index} = scalar keys %$specs diff --git a/xt/moo-does-moose-role.t b/xt/moo-does-moose-role.t index 3847287..4e4fa10 100644 --- a/xt/moo-does-moose-role.t +++ b/xt/moo-does-moose-role.t @@ -175,6 +175,23 @@ BEGIN { extends 'Plank'; } +BEGIN { + package Plonk; + use Moo; + has kk => (is => 'rw', moosify => [sub { + $_[0]->{documentation} = 'parent'; + }]); +} +BEGIN { + package Plonker; + use Moo; + extends 'Plonk'; + has '+kk' => (moosify => sub { + my $spec = shift; + $spec->{documentation} .= 'child'; + }); +} + foreach my $s ( Splattered->new, Splattered2->new, @@ -203,9 +220,11 @@ foreach my $c (qw/ ok $c->can('has_splat'); } -foreach my $c (Plunker->new) { - is(Plunker->meta->find_attribute_by_name('pp')->documentation, 'moosify', 'moosify modifies attr specs'); - is(Planker->meta->find_attribute_by_name('vv')->documentation, 'moosify foo', 'moosify modifies attr specs as array'); -} +is(Plunker->meta->find_attribute_by_name('pp')->documentation, 'moosify', 'moosify modifies attr specs'); +is(Planker->meta->find_attribute_by_name('vv')->documentation, 'moosify foo', 'moosify modifies attr specs as array'); + +is( Plonker->meta->find_attribute_by_name('kk')->documentation, + 'parentchild', + 'moosify applies for overridden attributes with roles'); done_testing;