Instantly share code, notes, and snippets.

@0racle /Bla.pm6 forked from FCO/Bla.pm6
Created Oct 26, 2018

Embed
What would you like to do?
Exportation Exploration
use Exportable;
sub bla is exportable { "bla" }
sub ble is exportable { "ble" }
sub bli is exportable { "bli" }
sub blo is exportable { "blo" }
sub blu is exportable { "blu" }
multi exported-EXPORT() {
{}
}
multi exported-EXPORT(%funcs, Whatever --> Hash()) {
%funcs.kv.map: -> $k, &v { "&$k" => &v }
}
multi exported-EXPORT(%funcs, *@funcs --> Hash()) {
do for @funcs {
when Pair {
"&{.value}" => %funcs{ .key }
}
default {
"&$_" => %funcs{ $_ }
}
}
}
sub EXPORT {
my Routine %funcs;
multi trait_mod:<is>(Routine \r, Bool :$exportable! where * === True) is export {
trait_mod:<is>(r, :exportable(r.name))
}
multi trait_mod:<is>(Routine \r, Str :$exportable!) is export {
%funcs{ $exportable } = r
}
{
'&EXPORT' => sub (*@funcs) { exported-EXPORT %funcs, |@funcs }
}
}
use lib ".";
use Bla \[ "bla", ble => "blebleble" ];
say bla;
say blebleble;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment