Skip to content

Instantly share code, notes, and snippets.

@stevan
Created October 21, 2011 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevan/1304204 to your computer and use it in GitHub Desktop.
Save stevan/1304204 to your computer and use it in GitHub Desktop.
# 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