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

Monks,

I've been building a web app using CGI Application and hit a point where I need to split the application up into different folders, yet keep inheritince alive and well. I need some help splitting the application up.

Simplified, the directory structure of application looks like this:
www + App App.pm + Admin Admin.pm + Super Super.pm + Regular Regular.pm + User User.pm + Super Super.pm +Regular Regular.pm
Package names look like this:

App
App::Admin
App::Admin::Super

I need to move the Admin part of the application into a different www folder while still using App as the base class for Admin:
www + App App.pm + User User.pm + Super Super.pm +Regular Regular.pm www_other + Admin Admin.pm + Super Super.pm + Regular Regular.pm
Any suggestions for how to go about spliting the application up or general inheritance suggestions will be greatly appreciated.

Thank you,
Tatnall
"Recognizing who we aren't is only the first step toward knowing who we are." - Os Guinness

Replies are listed 'Best First'.
Re: Relationship between directories and inheritance
by chromatic (Archbishop) on Nov 13, 2006 at 20:52 UTC

    There's no relationship between directory layout and inheritance in Perl, unless you have some sort of non-technical convention. You have to specify module relationships yourself, explicitly, with code.

Re: Relationship between directories and inheritance
by pajout (Curate) on Nov 13, 2006 at 16:45 UTC
    From my point of view, you have some good reasons for the described structure of perl MODULES. It is ok. My strategy in the very similar cases is to keep my modules in some special directory, for instance, myperlmodules, which is NOT part of 'www'. In 'www' I have only small perl scripts, which do something as
    use lib "/whenever/i/have/myperlmodules"; use App::Admin::Super; App::Admin::Super::somemethod();
      We take this a step further and build the modules as if they were for CPAN release, then inject them into our private CPAN mirror and install them as regular modules. No use libs are then required. This also urges us to build the dists professionally, ie with manifests, tests, etc.

      As for inheritence, if one module needs to inherit from a parent, a simple

      use base 'Parent';
      is usually enough.

      Phil