Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Extensions via Moose

by John M. Dlugosz (Monsignor)
on Apr 30, 2011 at 08:23 UTC ( [id://902151]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Extensions via Moose
in thread Extensions via Moose

I am not sure what you are asking here, are you looking for a trigger to be fired when C1 is reblessed into the anon-class?
I did not think of that. I was supposing that whatever function wrapped the "pull in an extension" would apply a trait to C1, and then look up $instance->c2 and $instance->c3 and apply traits to them too.

Basically, there are two approaches: (1) Create the extended class before creating the instance, and (2) Extend an existing instance.

With (2), I can extend all the collaborators at the same time, using only logic within the function that loads and applies the extension.

With (1), the extension of the top-level class needs to somehow change things so that when the collaborators are created, they are of the extended types too.

Without a rebless hook, (2) needs to be wrapped by my code so I does all the steps; it can certainly call "lower level" Role->meta->apply as well. My original question was wondering if these had some syntactic sugar or more mature incarnations in another module already done (like Perl 6 "but" feature).

But, I'm also supposing that I'm not breaking new ground in wanting an extension mechanism for a more complex case (not a single class, but functionality is broken up into smaller classes) and other people may have approached it already.

As for my aversion to needless instance data, something I saw in MooseX::Traits raises another question. But I'll start a new post for that.

Thanks for your patience.

—John

Replies are listed 'Best First'.
Re^5: Extensions via Moose
by stvn (Monsignor) on May 01, 2011 at 01:48 UTC
    My original question was wondering if these had some syntactic sugar or more mature incarnations in another module already done (like Perl 6 "but" feature).

    No, there isn't any sugar. I think there are two reasons for that, 1) doing custom infix operators are pretty much impossible, 2) people don't mind the Role->meta->apply syntax that much (and 3, applying roles to instances is not all that commonly used a feature).

    But, I'm also supposing that I'm not breaking new ground in wanting an extension mechanism for a more complex case (not a single class, but functionality is broken up into smaller classes) and other people may have approached it already.

    Well, there is also MooseX::Object::Pluggable, but I think perhaps people are still exploring the possible features/complex-insanity that Moose and runtime-roles open up, so you probably have a lot of funky stuff out in the DarkPAN that has yet to reach the CPAN. Honestly, the Moose community on IRC is pretty active, I really think you would benefit from getting involved there.

    -stvn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-16 17:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found