preserving call context
Stevan Little [Tue, 28 Feb 2006 19:30:31 +0000 (19:30 +0000)]
lib/Class/MOP/Method.pm

index 4de0cdf..912368a 100644 (file)
@@ -45,16 +45,21 @@ sub new {
                };
                my $method = $code->new(sub {
                        $_->(@_) for @{$modifier_table->{before}};
-                       my @rval;
+                       my (@rlist, $rval);
                        if (defined wantarray) {
-                               @rval = $modifier_table->{around}->{cache}->(@_);
+                               if (wantarray) {
+                                       @rlist = $modifier_table->{around}->{cache}->(@_);
+                               }
+                               else {
+                                       $rval = $modifier_table->{around}->{cache}->(@_);
+                               }
                        }
                        else {
                                $modifier_table->{around}->{cache}->(@_);
                        }
                        $_->(@_) for @{$modifier_table->{after}};                       
                        return unless defined wantarray;
-                       return wantarray ? @rval : $rval[0];
+                       return wantarray ? @rlist : $rval;
                });     
                $MODIFIERS{$method} = $modifier_table;
                $method;