in reply to Re: RFC: Alias::Exporter
in thread RFC: Alias::Exporter
Update: Fixed some minor things in your code, and went back to importing to this module first. One thing to fix after that was the glob assignment. If you assign glob to glob, you end up with all functions initially imported with the same name being exported as the same (last exported) function (when you import to this module first). Another thing I might consider is using Tie::IxHash or something to process the lists of modules and symbols in their original order.
Another update: Another consideration...we're totally polluting the namespace of this module by doing it this way, so maybe we should initially import to Alias::Exporter::Junk or something...
sub import { my $class = shift; my %modules = @_; my $package = caller(); for my $module ( keys %modules ) { my $imports = $modules{$module}; # we need to load the module if it doesn't already exist. (my $modname = $module . '.pm') =~ s,::,/,g; require $modname; my @import_list = keys(%$imports); $module->import(@import_list); for my $var (@import_list) { no strict 'refs'; my $from = join '::', __PACKAGE__, $var; my $to = join '::', $package, $imports->{$var}; *{$to} = \&{$from}; } } }
|
|---|