in reply to Preventing used modules from leaking to main script
That's just one of the problems with symbolic references (to packages, in this case). Unfortunately, Perl 5 doesn't really support anything but symbolic references when it comes to packages. It'd be nice if Perl 6 supported "real" references to packages and also supported something like "use strict 'packages'" to cause using symbolic reference to a package to become a fatal error.
More on this idea can be found at Re: $foo = "Foo::Bar"; $foo->new() works? (factories++).
In the mean time, you can do your best to avoid symbolic references to packages, mostly by using factories (for example, see Re: Getting rid of "new" (wrong target; perl6)).
Then you'd never write IO::Socket::INET->new(), you'd write code like this instead:
require IO::Socket::INET; my $SocketFactory= "IO::Socket::INET"; # ... my $socket= $SocketFactory->new( ... );
and that last line would fail if you hadn't included that first line in that particular chunk of code.
Some modules are nice enough to support the use of factories more cleanly such that you only have to type their module name once. But typing the module name twice as I show above is still better than typing it every time you want to create a new instance from it.
- tye
|
|---|