module Exporter; #### use strict; use warnings; use warnings::register; #assuming this continues to exist... #### sub import($pkg : ARRAY $export=undef, ARRAY $ok=undef, HASH $tags=undef) { #### ARRAY $export=undef #### ARRAY $export //= undef #### my $from_pkg=caller.package; #### my $from_pag = caller.MY.package; #### pkg_alias($from_pkg, "Exporter::From"); &Exporter::From::import := &myimport; #### sub pkg_alias($original, $new) { #Any sufficiently encapsulated hack... no strict 'refs'; %{"${original}::"} := %{"${new}::"}; #XXX will this actually work? } #### sub myimport($exp_from : *@symbols=() : *@options=()) { #### my $exp_to=caller.package; #is this how caller is used? pkg_alias($exp_from, "Exporter::From"); pkg_alias($exp_to, "Exporter::To"); #defaults @symbols //= @Exporter::From::EXPORT; #### $foo ||= 'bar'; #### $foo //= $bar // $baz // 'nothing to see here, folks'; #### #expand tags to their values @symbols=map { /^:/ ?? @{%Exporter::From::EXPORT_TAGS}{$_}} :: $_ } @symbols; #### for(@symbols) { #handle version numbers if(/^[\d.]+$/) { $exp_from.require_version($_); next; } #### #handle renamed exports my($to, $from)=$_.ref eq 'PAIR' ? ($_.left, $_.right) : ($_, $_); #### for($to, $from) { #make sure it has some sort of sigil $_='&' _ $_ unless m'^[$@%&]'; } #### warnings::warnif("$from exported from $exp_from conflicts with existing $to at $(caller.file) line $(caller.line).\n") if defined %Exporter::To::{$to}; #### %Exporter::To::{$to}=%Exporter::From::{$from}; } #### for(@options) { my($sign, $name, $value)=/[+-]([[\w]&&[^\d]]\w+)(?:=(.*))?/s; my $targ := ${$Exporter::From::{$name}}; given($sign) { when('+'): { if(defined $value) { $targ=$value; } else { $targ is true; } } when('-') { if($targ.props{true}) { $targ is false; } else { undef $targ; } } } } } #### if(defined $export) { @Exporter::From::EXPORT=@$export; } if(defined $ok) { @Exporter::From::EXPORT_OK=@$ok; } if(defined $tags) { %Exporter::From::EXPORT_TAGS=%$tags; } } #### if(defined $export) { @Exporter::From::EXPORT = $export; } if(defined $ok) { @Exporter::From::EXPORT_OK = $ok; } if(defined $tags) { %Exporter::From::EXPORT_TAGS = $tags; } }