Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-18 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found