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

Hi Monks!

What is the common practice in orginizing perl modules? If I have a module A and its helper modules A1,A2,.. and module B which extends A.

I've searched online and also in Object Oriented perl (Damian Conway) to no available.

My current class hierarchy and directory structure is:

module B.pm | - B1.pm | - B2.pm module A.pm | - A1.pm | - A2.pm | ...
Client code may use either module A or module B.

Replies are listed 'Best First'.
Re: perl Module and directory structure
by Discipulus (Canon) on Mar 03, 2017 at 08:23 UTC
    Hello pwagyi and welcome to the monastery!

    well I'm not the best modules expert here around.. but I suppose B must go under A if B extends A functionalities.

    Infact if you have Transports::Land you can have Transports::Land::Motrobike that extends the first one and Transports::Land::Motrobike::Kawasaki to extends it further.

    Normally each :: sign correspond to a directory level; so you'll have Transports/Land and Transports/Land/Motrobike and Transports/Land/Motrobike/Kawasaki directories structure.

    See also:

    My homenode contains lot of links about module creation.

    HtH

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: perl Module and directory structure
by stevieb (Canon) on Mar 03, 2017 at 14:23 UTC

    Personally, I would separate 'A' and 'B' projects into two separate distributions, and then lay them out like this:

    MyDist::A root directory/ Makefile.PL README CHANGES MANIFEST MANIFEST.SKIP lib/ MyDist/ A.pm A/ A1.pm A2.pm t/ test1.t test2.t ...

    In A.pm, you'd use MyDist::A::A1; and use MyDist::A::A2; to pull in the helpers. If you do want just a top-level namespace, just remove all references to MyDist.

    That's consistent with how most CPAN structures are laid out, so I'd stick with what works.

Re: perl Module and directory structure
by Anonymous Monk on Mar 03, 2017 at 16:31 UTC
    Module::Starter
    vagrant@localhost ~ $ module-starter --module=A,A::A1,A::A2,B,B::B1,B::B2 \
                            --author=you --email=you@there.com
    Added to MANIFEST: Changes
    Added to MANIFEST: ignore.txt
    Added to MANIFEST: lib/A.pm
    Added to MANIFEST: lib/A/A1.pm
    Added to MANIFEST: lib/A/A2.pm
    Added to MANIFEST: lib/B.pm
    Added to MANIFEST: lib/B/B1.pm
    Added to MANIFEST: lib/B/B2.pm
    Added to MANIFEST: Makefile.PL
    Added to MANIFEST: MANIFEST
    Added to MANIFEST: README
    Added to MANIFEST: t/00-load.t
    Added to MANIFEST: t/manifest.t
    Added to MANIFEST: t/pod-coverage.t
    Added to MANIFEST: t/pod.t
    Added to MANIFEST: xt/boilerplate.t
    Created starter directories and files
    vagrant@localhost ~ $ tree A/
    A/
    ├── Changes
    ├── ignore.txt
    ├── lib
    │   ├── A
    │   │   ├── A1.pm
    │   │   └── A2.pm
    │   ├── A.pm
    │   ├── B
    │   │   ├── B1.pm
    │   │   └── B2.pm
    │   └── B.pm
    ├── Makefile.PL
    ├── MANIFEST
    ├── README
    ├── t
    │   ├── 00-load.t
    │   ├── manifest.t
    │   ├── pod-coverage.t
    │   └── pod.t
    └── xt
        └── boilerplate.t
    
    5 directories, 16 files
    
      module-starter --module=A,A::A1,A::A2,B,B::B1,B::B2

      I've never had the need for anything like that before from Module::Starter, but that's a handy little trick to have seen.

        Thank you! Looking back I think OP wanted more like:
        --module=B,B::B1,B::B2,B::A,B::A::A1,B::A::A2
        
        A classes are indented within the B class, but they don't share B namespace so only OP know.
Re: perl Module and directory structure
by pwagyi (Monk) on Mar 04, 2017 at 03:24 UTC
    Thanks so much for your advice! I'll play around with some of the suggestions..