in reply to RFC: Alias::Exporter
There just has to be a way to remove that eval. ;-)
Why do you 'use $module ( \@import_list )'? You don't need to import anything into Alias::Exporter's namespace. So you only need to require it instead. That can pull it out of the eval if you do the required modifications:
Next, we want to pull that loop out of the eval. You have the right idea - it pretty much could have been done without the eval already, except that I just removed the importing from the other module. So now we need to point at the code in the desired module explicitly.(my $modname = $module . '.pm') =~ s,::,/,g; require $modname;
Of course, having gotten rid of the eval, the die isn't needed anymore, either.for my $var (@import_list) { no strict 'refs'; *{$package . '::' . $imports{$var}} = *{$module . '::' . $var}; }
A few more variables could make things a bit easier to read. Also, I would use references a bit more. This gives us:
Unfortunately, that's completely untested. And still needs more commenting ;-) Good luck,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; for my $var (@import_list) { no strict 'refs'; my $from = join '::', $module, $var; my $to = join '::', $package, $imports->{var}; *{$to} = *{$from}; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RFC: Alias::Exporter
by runrig (Abbot) on Sep 20, 2006 at 20:19 UTC |