Created
October 21, 2011 15:59
-
-
Save stevan/1304204 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get the dispatcher instance .... | |
my $dispatcher = $class->dispatcher(':canonical'); | |
# walk the methods | |
my $method = ::WALKMETH($dispatcher, $label, %opts); | |
unless (defined $method) { | |
# if we find an AUTOLOAD anywhere in the chain, then we can use it ... | |
if ($method = ::WALKMETH($class->dispatcher(':canonical'), 'AUTOLOAD', %opts)) { | |
$class->STORE('$AUTOLOAD' => $label); | |
} | |
} | |
(defined $method) | |
|| confess "Method ($label) not found for " . $opts{for} . " ($self)"; | |
# store the dispatcher state | |
{ | |
no warnings 'redefine'; | |
local *::next_METHOD = sub { | |
my $method = ::WALKMETH($dispatcher, $label, %opts); | |
confess "No next-method for '$label' found" unless defined $method; | |
return $method->($self, @{$args}); | |
}; | |
# call the method | |
return $method->($self, @{$args}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment