Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Free-Form Delegated Behavior

by pemungkah (Priest)
on Apr 22, 2011 at 18:04 UTC ( #900848=note: print w/replies, xml ) Need Help??

in reply to Free-Form Delegated Behavior

Way back when I started on something similar to this called Class::AutoPlug. The idea was to be able to transform a class that didn't accept plugins to one that did with the minimum possible amount of code. It did use attributes to add methods, plus pre- and post-hooks for existing or added methods.

It has a number of shortcomings, notably that the plugin installation order is not defined. This makes it difficult for one plugin to re-delegate another, since there's no guaranteed order. It would of course be possible to add this via more attributes, but I moved on to another project; this one languished and has now suffered bit rot - it's currently no longer passing its tests on 5.10 and 5.12. Take a look if you'd like; it's on github here - if it's useful, feel free to fork and play with it. I'd be happy to pull any changes or fixes back.

Replies are listed 'Best First'.
Re^2: Free-Form Delegated Behavior
by John M. Dlugosz (Monsignor) on Apr 23, 2011 at 00:11 UTC
    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.

      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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://900848]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2018-03-21 17:12 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (270 votes). Check out past polls.