Skip to content

Instantly share code, notes, and snippets.

@FCO
Created October 26, 2018 03:50
Show Gist options
  • Save FCO/18bbbbe640d7f8b83820fcb612ceec3d to your computer and use it in GitHub Desktop.
Save FCO/18bbbbe640d7f8b83820fcb612ceec3d to your computer and use it in GitHub Desktop.
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