Importing into your module means that function names that are defined nowhere in your code are suddenly significant. This is sort of OK and sometimes convenient, but only if done directly, IMO, by which I mean you use Some::Module and it exports functions into your space that you can lookup by saying perldoc Some::Module.

But if Some::Module imports from 4 other modules, then exports to your space, it gets harder to track down what's happening, espcially if one of those 4 other modules does the same.

Using an OO implemntation, where the module's methods are only aavailble via an object call (my $o = Some:Object->new(); my $result = $o->do_it_all_now(@parms)) means that you are far less likely to have name collision amongst the subs in your various modules because they're tracked down by the object. Then, if the modules you're calling needed to be broken down to work, they use and inherit from other modules, rather than imporutng and exporting (in general) for the same reasons.

It's cleaner, and that gets more important when more programs - and especially when more programmers - are involved.

There are lots of writeups that will do a much better job than I've just done of explaining this - I hope I've given some flavor of this.

--Bob Niederman, http://bob-n.com

In reply to Re: Re: Re: Re: Re: How do I make one package use a module from another package? by bobn
in thread How do I make one package use a module from another package? by Anonymous Monk

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.