Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^5: Creating dynamic parent/child relationships

by nysus (Vicar)
on Sep 04, 2019 at 13:21 UTC ( #11105590=note: print w/replies, xml ) Need Help??


in reply to Re^4: Creating dynamic parent/child relationships
in thread Creating dynamic parent/child relationships

Thanks, Corion. Yes, I tried your advice. Unfortunately, it appears my classes are too reliant on inheritance and I can't implement your idea in any sane way. It seems that if I treat the classes as nothing more than containers for methods using your suggestion, I lose access to the data in the attributes contained in the parent classes. My child objects need access to the parent attributes to work.

$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

  • Comment on Re^5: Creating dynamic parent/child relationships

Replies are listed 'Best First'.
Re^6: Creating dynamic parent/child relationships
by Corion (Pope) on Sep 04, 2019 at 13:28 UTC

    Consider passing what you call "the parent" around to each object that implements an action? So far you've been somewhat unclear about what you actually need, so it is somewhat hard to come up with good names for the parts that make sense in your context.

    Maybe using "configuration" as name for what you call "parent" and "action" as name for what you call "child" would help?

    my $cfg = My::Config->new_from_file('nysus.yml'); $cfg->process( $myfile ); package My::Config; use Module::Pluggable require => '1', sub_name => 'actions', instantiate => 'new', ; sub My::Config::process( $self, $filename ) { for my $action ($self->actions) { $action->operate( $self, $filename ); }; };

    I don't think that passing data around in $self should be an overarching design principle.

    Most of the code above is from Module::Pluggable, which still feels very applicable from what you've described so far and from the problems you encounter.

    Maybe if you can elaborate more on the concrete problem you're trying to solve and the problems you encounter, we can give you more concrete advice?

      Basically, to get a better familiarity with OO Perl, I'm cutting my teeth and trying to get better at native OO by writing a potential CPAN module (if I can get it to good enough quality), which you can see here: https://github.com/sdondley/File-Collector. The synopsis should have the needed details.

      $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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11105590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2020-12-03 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (57 votes). Check out past polls.

    Notices?