Skip to content

Instantly share code, notes, and snippets.

@masak
Created December 5, 2015 15:35
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 masak/3b2e4b16482781431b3b to your computer and use it in GitHub Desktop.
Save masak/3b2e4b16482781431b3b to your computer and use it in GitHub Desktop.
exporting a multi
$ cat A.pm
multi foo(Int) is export {
say "Int";
}
multi foo(Str) {
say "Str";
}
$ perl6 -I. -e 'use A; foo(42); foo("OH HAI")'
Int
Str
@nkh
Copy link

nkh commented Dec 5, 2015

Hi, yes your example works but the problem is more complicated than that.

in script:

use dumper ;

# module dumper has a multi sub filter() ... matching Lists, Array, Int, Any
dump(<a b c>) ;
dump(42) ;

my SomeClass $x ; # with an arbitrary class, either defined in this context or that we get from some call

# without changing anything in SomeClass, I want to add a filter for it.
multi sub filter (Classes::SomeClass $o) { say "SomeClass specific filter" }

# This would use the default filter as module dumper has no idea about the filter we defined above 
do_filter($x) ;

# to be able to use the filter above I need to inject it in dumper namespace
# better yet, it needs to be injected in the instance of the dumper so different dumpers can have different filters, this becomes even more important if the dumpers are run in different threads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment