From: Dave Rolsky Date: Mon, 12 Jan 2009 00:52:42 +0000 (+0000) Subject: Fix the super recursion bug perigrin found X-Git-Tag: 0.65~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=991933fb70aae0e2b6a27a01e52009025f838fe8;p=gitmo%2FMoose.git Fix the super recursion bug perigrin found --- diff --git a/Changes b/Changes index 51b56c0..51cf345 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ Revision history for Perl extension Moose -Pending +0.65 + * Moose and Moose::Meta::Method::Overridden + - If an overridden method called super(), and then the + superclass's method (not overridden) _also_ called super(), + Moose went into an endless recursion loop. Test provided by + Chris Prather. (Dave Rolsky) * Moose::Meta::TypeConstraint - Add some explanation for a few explanationless methods (gphat) diff --git a/lib/Moose.pm b/lib/Moose.pm index 45ac965..504096a 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -94,8 +94,15 @@ sub around { Moose::Util::add_method_modifier($class, 'around', \@_); } +our $SUPER_PACKAGE; +our $SUPER_BODY; +our @SUPER_ARGS; + sub super { - return unless our $SUPER_BODY; $SUPER_BODY->(our @SUPER_ARGS); + # This check avoids a recursion loop - see + # t/100_bugs/020_super_recursion.t + return if defined $SUPER_PACKAGE && $SUPER_PACKAGE ne caller(); + return unless $SUPER_BODY; $SUPER_BODY->(@SUPER_ARGS); } sub override { diff --git a/lib/Moose/Meta/Method/Overriden.pm b/lib/Moose/Meta/Method/Overriden.pm index 589dcad..a3bd26a 100644 --- a/lib/Moose/Meta/Method/Overriden.pm +++ b/lib/Moose/Meta/Method/Overriden.pm @@ -16,7 +16,7 @@ sub new { # it is really more like body's compilation stash # this is where we need to override the definition of super() so that the # body of the code can call the right overridden version - my $_super_package = $args{package} || $args{class}->name; + my $super_package = $args{package} || $args{class}->name; my $name = $args{name}; @@ -30,13 +30,14 @@ sub new { my $method = $args{method}; my $body = sub { + local $Moose::SUPER_PACKAGE = $super_package; local @Moose::SUPER_ARGS = @_; local $Moose::SUPER_BODY = $super_body; return $method->(@_); }; # FIXME do we need this make sure this works for next::method? - # subname "${_super_package}::${name}", $method; + # subname "${super_package}::${name}", $method; # FIXME store additional attrs $class->wrap(