package My::Module; # no "use Exporter" or "use base 'Exporter'", we're on our own! # ... use Carp; our @EXPORT_FROM_PACKS = qw/ My::Module My::Module::Another /; sub import { my ($class, @export) = @_; my ($callerpack) = caller; my %export = map {$_=>1} @export; for my $frompack (@EXPORT_FROM_PACKS) { # loop over packages # attempt to load that module eval "require $frompack; 1" or croak "failed to load $frompack: $@"; # get their @EXPORT variable my @exps = do { no strict 'refs'; @{"${frompack}::EXPORT"} }; for my $ex (@exps) { # loop over their exports next if @export && !$export{$ex}; no strict 'refs'; # limit scope of "no strict" # target function <-- source function *{"${callerpack}::$ex"} = \&{"${frompack}::$ex"}; } } }