For the sake of completeness, yet another approach would be to directly import Exporter's import method into the namespace of your module. In that case it doesn't need to be looked up via inheritance, so you don't need to setup @ISA or use base ...

In other words, from the following 3 options, you can choose whichever you like best:

package One; use strict; use warnings; # --- option 1 - inheritance via @ISA # require Exporter; # our @ISA = qw(Exporter); # --- # --- option 2 - inheritance via use base ... # use base "Exporter"; # --- # --- option 3 - directly import Exporter's import() use Exporter "import"; # --- # ( @EXPORT or @EXPORT_OK always needed ) our @EXPORT = qw(method1); sub method1 { print "method1 greets hello"; } 1;

(Also, note that I changed the package name to "One" (capitalized). AFAIK, lowercase module names are - by convention - reserved for pragmatic modules like use strict;, use integer;, etc.)

BTW, a slight peculiarity with use strict; use warnings; in this particular case is that it does not (and cannot) warn you about potential problems due to not loading Exporter yourself (because, as ferreira pointed out, Exporter already is being loaded as a side effect of using strictures). For this reason, it could be argued that options 2 or 3 are the ones to prefer, as they do not share this potential pitfall...


In reply to Re: Issue with Exporter by almut
in thread Issue with Exporter by palette

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.