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:
(my $modname = $module . '.pm') =~ s,::,/,g;
require $modname;
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.
for my $var (@import_list)
{
no strict 'refs';
*{$package . '::' . $imports{$var}} = *{$module . '::' . $var};
}
Of course, having gotten rid of the eval, the die isn't needed anymore, either.
A few more variables could make things a bit easier to read. Also, I would use references a bit more. This gives us:
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};
}
}
}
Unfortunately, that's completely untested. And still needs more commenting ;-) Good luck,