X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FClass.pm;h=af324735baa5e2d66e52be4e81ad900f4ea59ead;hb=1b4908919757668935d275af2612617d3d322091;hp=24a2216bb8408c91f33d1edd488c23089ee102a5;hpb=aa3b1c110ba2bde693d43554dc853696ccd41866;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 24a2216..af32473 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -271,7 +271,7 @@ sub make_mutable { sub is_immutable; sub is_mutable { !$_[0]->is_immutable } -sub _install_modifier_pp{ +sub _install_modifier { my( $self, $type, $name, $code ) = @_; my $into = $self->name; @@ -281,11 +281,17 @@ sub _install_modifier_pp{ 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_pp{ 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_pp{ } 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 @@ -337,61 +346,6 @@ sub _install_modifier_pp{ return; } -sub _install_modifier { - my ( $self, $type, $name, $code ) = @_; - - # load Data::Util first - my $no_cmm_fast = do{ - local $@; - eval q{ use Data::Util 0.55 () }; - $@; - }; - - my $impl; - if($no_cmm_fast){ - $impl = \&_install_modifier_pp; - } - else{ - $impl = sub { - my ( $self, $type, $name, $code ) = @_; - my $into = $self->name; - - my $method = Mouse::Util::get_code_ref( $into, $name ); - - if ( !$method || !Data::Util::subroutine_modifier($method) ) { - unless ($method) { - $method = $into->can($name) - or $self->throw_error("The method '$name' was not found in the inheritance hierarchy for $into"); - } - $method = Data::Util::modify_subroutine( $method, - $type => [$code] ); - - $self->add_method($name => $method); - } - else { - Data::Util::subroutine_modifier( $method, $type => $code ); - $self->add_method($name => Mouse::Util::get_code_ref($into, $name)); - } - - return; - }; - } - - # workaround older Perl's bug that caused segv :( - { - no warnings 'once'; - our $__not_used = \&_install_modifier; # keep the CV not to be released - } - - # replace this method itself :) - { - no warnings 'redefine'; - *_install_modifier = $impl; - } - - $self->$impl( $type, $name, $code ); -} - sub add_before_method_modifier { my ( $self, $name, $code ) = @_; $self->_install_modifier( 'before', $name, $code ); @@ -479,7 +433,7 @@ Mouse::Meta::Class - The Mouse class metaclass =head1 VERSION -This document describes Mouse version 0.65 +This document describes Mouse version 0.67 =head1 METHODS