Generally, the commonly given advice is not to export anything by default. I.e. everything goes in @EXPORT_OK, nothing goes in @EXPORT, and it's helpful to include some sort of :all or other subsets in %EXPORT_TAGS. I think that's your option (2). The benefit is that it gives the most flexibility to your end-user. They can use fully-qualified names if they prefer, or they can import the function if they'd rather use a shorter name. I would find it annoying if you didn't put your functions into @EXPORT_OK and give me the option (and I'd probably just wind up doing my own aliasing if I was using a function frequently anyway).

What I believe is a common exception to that guideline is the case where a module only provides a few functions (or even just one!) and the whole point of the module is to make those functions available for frequent use. (E.g. Test::More and most of the Test:: modules.) In such cases, I personally think that putting these into @EXPORT is the right thing to do.

So my guidance is to think about what would be the most likely usage of the module and let that be your guide. If there are functions that 9 out of 10 users would import anyway, stick those into @EXPORT. Otherwise, put them all into </code>@EXPORT_OK</code> and include at least an :all tag.

(Note: I'm only speaking to function names above. I'd never advise automatically exporting package global variables and would discourage using even fully qualified package globals as an "interface" mechanism to your module.)

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


In reply to Re: Module Style and Usage by xdg
in thread Module Style and Usage by ozboomer

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.