package Exporter::All;
sub import {
my @packages = @_;
shift @packages;
@packages = (caller)[0] unless defined @packages;
foreach my $orig (@_) {
*{"${orig}::import"} = sub {
my $pkg = (caller)[0];
foreach (grep {!/^import|__ANON__|BEGIN|END$/}
keys %{"${orig}::"}) {
if (defined *{"${pkg}::$_"}) {
warn "Warning: symbol $_ already defined in $pkg."
}
else {
*{"${pkg}::$_"} = *{"${orig}::$_"};
}
}
}
}
}
1;
####
package Foo::Bar::Baz;
use Exporter::All;
sub x {print 1};
# ...
package main;
use Foo::Bar::Baz;
x();
####
package Foo::Bar::Baz;
sub x {print 1};
# ...
package main;
use Exporter::All qw(Foo::Bar::Baz);
x();