in reply to Creating dynamic parent/child relationships

This is a point where you really need mixins if you want to stick with object inheritance, but maybe you should rethink whether "file sorter" IS-A File::Collector or whether File::Collector HAS-A "file sorter" (or many file sorters as the case may be).

The idea of subclassing File::Collector to add categories seemed neat at the beginning, but this is starting to get unmaintainable.

To do this with mixins, define a "final derived class" that inherits from File::Collector and any number of "mixin" classes that provide sorting categories, using a form of the _run_chain method you mentioned in Unable to turn off strict refs to invoke methods across the mixins instead of working up a SUPER:: chain as the earlier versions did. Your application can adjust the @...::ISA array in that derived class (which should be otherwise empty) according to configuration, as LanX mentioned. Rewriting inheritance chains at runtime, while possible in Perl, is getting very close to "thermonuclear footgun" on the maintainability scale, and is almost certainly best avoided.

Replies are listed 'Best First'.
Re^2: Creating dynamic parent/child relationships
by nysus (Parson) on Sep 04, 2019 at 11:32 UTC

    Yeah, I'm feeling a little lost in the weeds. Taking away inheritance looks like it will necessitate implementing a lot of hacks and ugliness in the code to get to work properly. I was hoping to make it dead simple to implement a plug-in. My module works well, as is, with the parent-child inheritances hard coded in to the classes. I'll keep toying with it and see what I can come up with. At a minimum, I'll at least learn a lot.

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

Re^2: Creating dynamic parent/child relationships
by nysus (Parson) on Sep 04, 2019 at 17:57 UTC

    Well, thanks to Hippo and his suggestion to use Role::Tiny above, the module now has a way to flexibly change the order of the Collectors and Processors. Onward!

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