Skip to content

Instantly share code, notes, and snippets.

@scmorrison
Created November 16, 2017 11:15
Show Gist options
  • Save scmorrison/e8b73ecfb257ac94567e4aadb54a863c to your computer and use it in GitHub Desktop.
Save scmorrison/e8b73ecfb257ac94567e4aadb54a863c to your computer and use it in GitHub Desktop.
Module-wide multi overriding
use v6;
unit module Foo;
our proto sub bar(|) {*}
multi bar(
Hash $config,
*%sig where { is-overridden $config, $?PACKAGE, &?ROUTINE }) {
override($config<overrides>{ me }, :$config, :%sig);
}
# default core version of bar
multi bar() {
return "blah";
}
# %config looks like this
# %{
# overrides => %{ 'Foo::bar' => 'MyOtherModule::bar' }
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment