[Bps-public-commit] r15483 - in Path-Dispatcher/trunk: lib/Path/Dispatcher
sartak at bestpractical.com
sartak at bestpractical.com
Tue Aug 26 10:55:05 EDT 2008
Author: sartak
Date: Tue Aug 26 10:55:04 2008
New Revision: 15483
Modified:
Path-Dispatcher/trunk/ (props changed)
Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm
Log:
r70371 at onn: sartak | 2008-08-26 10:54:56 -0400
We can't discard the invocant if run/dispatch are used as sugar
Modified: Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm
==============================================================================
--- Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm (original)
+++ Path-Dispatcher/trunk/lib/Path/Dispatcher/Declarative.pm Tue Aug 26 10:55:04 2008
@@ -2,9 +2,10 @@
package Path::Dispatcher::Declarative;
use strict;
use warnings;
-use Sub::Exporter;
use Path::Dispatcher;
+use Sub::Exporter;
+
our $CALLER; # Sub::Exporter doesn't make this available
our $OUTERMOST_DISPATCHER;
@@ -39,8 +40,10 @@
sub build_sugar {
my ($class, $group, $arg) = @_;
+ my $into = $CALLER;
+
my $dispatcher = Path::Dispatcher->new(
- name => $CALLER,
+ name => $into,
);
# if this is a subclass, then we want to set up a super dispatcher
@@ -51,14 +54,19 @@
return {
dispatcher => sub { $dispatcher },
dispatch => sub {
- shift; # don't need $self
+ # if caller is $into, then this function is being used as sugar
+ # otherwise, it's probably a method call, so discard the invocant
+ shift if caller ne $into;
+
local $OUTERMOST_DISPATCHER = $dispatcher
if !$OUTERMOST_DISPATCHER;
$OUTERMOST_DISPATCHER->dispatch(@_);
},
run => sub {
- shift; # don't need $self
+ # if caller is $into, then this function is being used as sugar
+ # otherwise, it's probably a method call, so discard the invocant
+ shift if caller ne $into;
local $OUTERMOST_DISPATCHER = $dispatcher
if !$OUTERMOST_DISPATCHER;
More information about the Bps-public-commit
mailing list