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        


In reply to Re: Preventing used modules from leaking to main script (symbolic--) by tye
in thread Preventing used modules from leaking to main script by Crackers2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.