in reply to Re^13: RFC: OO Perl using Moo/Moose book (GoF / Updated)
in thread RFC: OO Perl using Moo/Moose book

So, the Perl Moo* equivalent would be something like
package My::Obj; use Moo; has deputy => (is => 'ro', delegates => 'frobnicate');

where calling $obj->frobnicate(42); would in fact call

$obj->deputy->can('frobnicate')->($obj, 42);
?

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^15: RFC: OO Perl using Moo/Moose book (updated)
by LanX (Saint) on May 01, 2019 at 22:56 UTC
    Yes, looks like the WP definition of "Delegation" to me.

    But I'd say this niche is more or less (?)* filled by "Roles" in Moo/Moose ( of course with different implementation)

    Theoretically speaking. ..

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

    Update

    *) one difference might be that "deputy" is an attribute of the instance while roles belong to the class.

Re^15: RFC: OO Perl using Moo/Moose book (prototypical inheritance)
by LanX (Saint) on May 01, 2019 at 23:32 UTC
    As a side note, if you replace "deputy" with "__prototype__" and don't restrict to methods like "frobnicate" you'll have more or less the JS model of inheritance.

    That's why Self and JS are listed as examples for "Delegation".

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice