Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Creating dynamic parent/child relationships

by hippo (Chancellor)
on Sep 04, 2019 at 12:58 UTC ( #11105587=note: print w/replies, xml ) Need Help??


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

Why would it? SSCCE:

use strict; use warnings; package Foo; use Moo; package Trapezist; use Role::Tiny; sub swing { print "Whoooosh!\n"; } package Trumpeter; use Role::Tiny; sub swing { print "1, 2, ... 1, 2, 3, 4, Hit it!\n"; } package main; my $person1 = Foo->new; Role::Tiny->apply_roles_to_object ($person1, 'Trapezist'); my $person2 = Foo->new; Role::Tiny->apply_roles_to_object ($person2, 'Trumpeter'); $person1->swing; $person2->swing;

Replies are listed 'Best First'.
Re^4: Creating dynamic parent/child relationships
by nysus (Vicar) on Sep 04, 2019 at 14:44 UTC

    Nice. But how the F all you guys make coming up with these suggestions so effortless is beyond me. :)

    $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^4: Creating dynamic parent/child relationships
by nysus (Vicar) on Sep 04, 2019 at 16:22 UTC

    Well, so far, so good. This approach looks very promising. I've converted one module over so far and it works. Thanks a lot.

    One thing I wanted to accomplish with this module is to get a much better feel for OO Perl. I'm not sure what goes on under the hood with roles. My old Damian Conway book from like 2000 makes no mention of them. You know any good resources for learning about how they accomplish their jobs? I noticed the classes get tacked with a __WITH__ and then the name of the role.

    $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

      Roles are not part of the Perl language so they must be implemented via modules. The minutiae of the mechanisms for implementing roles will depend on which module you use. As ever, if you want to know the implementation details you only need to look in the source.

      More recent books such as Modern Perl by chromatic do mention roles but (quite reasonably) don't delve into the underlying mechanisms.

        This is the fascinating part about programming. Out there, in the oblivion, lies some mythical optimal solution. The really good programmers can intuit their way to that solution, or at least get closer to it faster, than inexperienced ones.

        $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://11105587]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2020-11-28 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?