hesco has asked for the wisdom of the Perl Monks concerning the following question:

Greetings all:

The first major project I developed I resisted the encouragement, of a far more seasoned coder who was contributing to that project, that we break out our work into multiple files with distinct functions. The result is a challenging to maintain 12k line script of which only 2-5k lines are actually serving us well, but that is another story. The line I ran on him at the time was that I wanted our work to be easy to install (which I thought meant putting everything in a single file).

Now that I've made a shift from trying to be a manager who thought he knew how to code, to being a coder learning his craft, I'm ready to read how some of the masters have done it.

The real world needs of my current project suggest the following organization:

MyModule MyModule::Config MyModule::DB MyModule::AdminFunctions MyModule::AdminFunctions::ConfigureThis MyModule::AdminFunctions::ConfigureThat MyModule::UserFunctions MyModule::UserFunctions::ThisTool MyModule::UserFunctions::ThatTool MyModule::WWW::Admin MyModule::WWW::Users
But I'd like to read some working code which folks feel is well organized so I can get a better sense of how inheritance works and how methods spread through a hierarchy of modules in a distributions are used by one another and accessed.

This is a request for folks to recommend what you believe to be __well__organized__ code, your own or that of others. Your recommendations are appreciated.

-- Hugh

if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: Seeking Examples of Well Organized Code
by shmem (Chancellor) on May 19, 2007 at 20:35 UTC
    Inheritance and how you delegate methods and what package inherits from which depends entirely on your specs. It cannot be said whether the module layout you've posted suits without knowing them.

    As an example of a well written module see e.g. Net::SMTP::Server (first that came to my mind).

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Seeking Examples of Well Organized Code
by perrin (Chancellor) on May 19, 2007 at 20:34 UTC
    I generally like the way Template Toolkit is laid out. I also like the way Chris Winters organizes his code. Take a look at his OpenInteract and Workflow distributions for some good ideas about organizing OO projects.
Re: Seeking Examples of Well Organized Code
by Anonymous Monk on May 20, 2007 at 16:31 UTC
    just going by my feel of what the stated classes/methods would do, seems like a rather arbitrary and not particularly OO hierarchy. The usual (or minimal) system analysis and resulting specs provide a good starting point. writing long code without a suitable system analysis takes longer to produce than if you do analysis first. A dataflow diagram (DFD) usually points to an appropriate organisation of data transforming processes.