Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

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

Hi SBECK,

If the two sets of subs (first set: OO methods like new, getters, setters, etc.; second set: exported functions, like constants) have no overlaps, there shouldn't be any problems. So for example, I would make sure none of my objects have a method named import and I would make sure to never export methods. As to whether it's a "best practice" I'm not sure, but I think that as long as all you're exporting are constants with unique, uppercased names, you probably wouldn't step on anyone's toes.

However, what I might do is use @EXPORT_OK instead of @EXPORT. You can group all your constants in a tag (%EXPORT_TAGS) named e.g. :constants. Your users will then have to write use Module::Name ':constants';, which has the advantage that it signals to the reader that it isn't just an OO module (which normally doesn't export anything), but is an OO package that also exports something. Plus, the user has the choice of not getting the constants, or only selecting the two or three constants they need.

As to how to make it "more OO", I'm not sure I have any good ideas off the top of my head. You could of course make your constants method calls,

use Module::Name; my $c = Module::Name->new; print $c->LOCALE_LANG_ALPHA_2;

but even though that'd keep the namespace clean of all the constants, personally I don't find this solution much more elegant.

Hope this helps,
-- Hauke D


In reply to Re: Exporter in an OO module? by haukex
in thread Exporter in an OO module? by SBECK

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: (3)
As of 2024-04-20 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found