From: Graham Knop Date: Fri, 7 Jun 2013 15:34:27 +0000 (-0500) Subject: fix inflating method modifiers applied to multiple methods X-Git-Tag: v1.003000~69 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMoo.git;a=commitdiff_plain;h=25ceb5de9d057158b2d73d71bfb2bd454a2ebad8 fix inflating method modifiers applied to multiple methods --- diff --git a/lib/Moo/HandleMoose.pm b/lib/Moo/HandleMoose.pm index 1918522..5c763e8 100644 --- a/lib/Moo/HandleMoose.pm +++ b/lib/Moo/HandleMoose.pm @@ -179,7 +179,8 @@ sub inject_real_metaclass_for { $meta->add_required_methods(@{$info->{requires}}); foreach my $modifier (@{$info->{modifiers}}) { my ($type, @args) = @$modifier; - $meta->${\"add_${type}_method_modifier"}(@args); + my $code = pop @args; + $meta->${\"add_${type}_method_modifier"}($_, $code) for @args; } } else { foreach my $attr (@attrs) { diff --git a/xt/moose-method-modifiers.t b/xt/moose-method-modifiers.t index 2d49a8b..b90ec88 100644 --- a/xt/moose-method-modifiers.t +++ b/xt/moose-method-modifiers.t @@ -1,8 +1,6 @@ use strictures 1; use Test::More; -use Moo::HandleMoose; - { package ModifyFoo; use Moo::Role; @@ -36,4 +34,28 @@ ok($ModifyFoo::before_ran, 'before ran'); ok($ModifyFoo::after_ran, 'after ran'); ok($ModifyFoo::around_ran, 'around ran'); +{ + package ModifyMultiple; + use Moo::Role; + our $before = 0; + + before 'foo', 'bar' => sub { + $before++; + }; + + package Baz; + use Moose; + with 'ModifyMultiple'; + + sub foo {} + sub bar {} +} + +my $baz = Baz->new; +my $pre = $ModifyMultiple::before; +$baz->foo; +is $ModifyMultiple::before, $pre+1, "before applies to first of multiple subs"; +$baz->bar; +is $ModifyMultiple::before, $pre+2, "before applies to second of multiple subs"; + done_testing;