http://www.perlmonks.org?node_id=900883


in reply to Re: Free-Form Delegated Behavior
in thread Free-Form Delegated Behavior

Interesting. If I understand that correctly, the gist of it is explained with this: Causes the local_impl() subroutine to be added as the method method_name in the pluggable class. That is, it adds methods to a class.

That sounds a lot like Roles in Perl 6 or Moose. So today I could just add a role to a class using with within the class (or after the fact if it's not been sealed), or even do it on a per-object basis. The latter doesn't have supplied syntactic sugar in Moose but is a primitive in Perl 6.

Your implementation has an interesting feature in specifying which methods are injected into the host class, rather than just taking all of them. That means within that method, a dispatched call will see the host object, but a regular sub call will be compiled in the scope of the package it was actually declared in. It can call non-virtual helpers that don't become overridable in the host class.

I think as a means of changing/extending the functionality of a class, this is the same as deriving a new class. Roles and plug-ins just allow such units of extensibility to be packaged and reused easier.

Replies are listed 'Best First'.
Re^3: Free-Form Delegated Behavior
by pemungkah (Priest) on Jul 02, 2011 at 19:18 UTC
    Sorry to be so dilatory in getting back to you on this - yes, the concept is essentially to allow you to arbitrarily subclass in a particular way. It grew out of the hand-implemented version of this in WWW::Mechanize::Pluggable, which was designed to get around the problem of proliferating subclasses of Mech, or in having a single big heterogenous subclass to add all the features I wanted.