From: gfx Date: Sat, 11 Sep 2010 06:18:04 +0000 (+0900) Subject: Tweaks for method modifiers X-Git-Tag: 0.68~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1b4908919757668935d275af2612617d3d322091;p=gitmo%2FMouse.git Tweaks for method modifiers --- diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index ba9d417..af32473 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -281,11 +281,17 @@ sub _install_modifier { my $modifier_table = $self->{modifiers}{$name}; if(!$modifier_table){ - my(@before, @after, @around, $cache, $modified); + my(@before, @after, $cache); $cache = $original; - $modified = sub { + my $around_only = ($type eq 'around'); + + my $modified = sub { + if($around_only) { + return $cache->(@_); + } + for my $c (@before) { $c->(@_) } if(wantarray){ # list context @@ -313,7 +319,8 @@ sub _install_modifier { before => \@before, after => \@after, - around => \@around, + around => \my @around, + around_only => \$around_only, cache => \$cache, # cache for around modifiers }; @@ -322,9 +329,11 @@ sub _install_modifier { } if($type eq 'before'){ + ${$modifier_table->{around_only}} = 0; unshift @{$modifier_table->{before}}, $code; } elsif($type eq 'after'){ + ${$modifier_table->{around_only}} = 0; push @{$modifier_table->{after}}, $code; } else{ # around