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

I've begun writing a class of modules for myself to facilitate the gathering of events in my community. I'm using the Moose extension to help me write OO code.

So far, I have an EventRepository class that in ~/perl-lib/EventRepository.pm file on my computer. I now wish to create a subclass of EventRepository that will be called something like EventRepository::SubClass.

I'm unsure where to put the code for SubClass.pm, however. Do I just drop it into ~/perl-lib/ alongside of the EventRepository.pm file. But I see other families of classes nesting their directories inside of one another to mimic the class hierarchy but I'm not sure how to make that work. Do I create an EventRepository folder and put EventRepository.pm inside of that folder along with a SubClass subfolder and drop SubClass.pm into that subfolder?

Any guidance on best practices would be appreciated. Thanks.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: How to structure files and subdirectories for related classes and subclasses?
by choroba (Cardinal) on Apr 03, 2016 at 17:02 UTC
    The standard way (and the only way that works smoothly with use) is to replace :: with / and add .pm to get the path to the module. So, in your case:

    use EventRepository; # lib/EventRepository.pm use EventRepository::SubClass; # lib/EventRepository/SubClass.p +m

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Got it. Thanks for saving me some time getting that worked out.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks