in reply to [OO] export data from Module

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

Replies are listed 'Best First'.
Re: Re: [OO] export data from Module
by Jaap (Curate) on Apr 29, 2004 at 18:27 UTC
    Thanks chromatic and Old_Gray_Bear for the replies.
    It's unanimous, i'm going the getThis() and getThat() route.