I'd write the get_this() and get_that() methods. It provides data isolation (you have control over what is 'exported') and documentation.

I tend to view Modules (Objects) as three headed thingies:

  1. Housekeeping -- new(), DESTROY(), _init(), etc
  2. Low level manipulation -- parse(), get_xxx(), set_xxx()
  3. API -- all of the other accessor methods that extract portions of the Object data, massage it a bit, and send it off to the End Consumer.
The API is what really documents your Object, between the methods supplied and the POD. An additional benefit is that as you develop the API, additional things will occur to you ('I can do this as well if I only....'; Increased Functionality -- that's what I tell my boss). Unless you do something really radical using AUTOLOAD, the 'speed hit' for an additional accessor routine will be almost unmeasurable.

There is some penalty at load time (use/require MyModule), but that is a one-time cost, amortized over the life span of the Module Instance. It's relatively big for batch programming -- say 1-2% of the run time, each time; but it's negligable for long running apps (read a mod_perl handler or its ilk). (This is the "I don't care that it takes fifteen more seconds at Apache start-up, the last time we re-initialized Apache was four MONTHS ago, and every third request uses that API!" argument.)

On balance, I'd go with the accessors.

----
I Go Back to Sleep, Now.

OGB


In reply to Re: [OO] export data from Module by Old_Gray_Bear
in thread [OO] export data from Module by Jaap

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.