http://www.perlmonks.org?node_id=228428


in reply to Re^2: A simple import() for those special moments
in thread A simple import() for those special moments

it exports the entire typeglob

I thought that was intentional. :)

If an importing package already has a $foo_bar, this routine will overwrite the typeglob in the process of exporting &foo_bar, even if it never exports a $foo_bar of its own.

It's more likely to be the other way around, i.e.

sub foo_var { 'a' } use Foo; foo_var(); # Undefined subroutine called.
It's easy to check if a glob gets overwritten though.

This isn't such a big issue as you seem to think. Problems will only occure when you import after defining your own data types. Special exception for subroutines though. They can be declared and that (including the prototype) can disappear. E.g.

sub foo_var ($$); use Foo; foo_var;
complains under strict because &foo_var isn't declared anymore when foo_var; is found.

Anyway, usually modules are use()d before subroutines are defined, and subroutines are usually defined before variables. So it's not that bad. This works perfectly (albeit a bit dangerous):

use Foo; sub foo_var { 1 } foo_var();

Cheers,
ihb