Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Moose Roles and Override

by Oberon (Monk)
on Sep 17, 2019 at 01:58 UTC ( [id://11106271]=note: print w/replies, xml ) Need Help??


in reply to Moose Roles and Override

(I know I'm replying to a really old thread, but this is still one of the top Google search results for things like "moose role override", so I think it's worth adding a bit to the discussion. Hopefully this is helpful for people who stumble across this in the future.)

The reason this feature doesn't (and can't, really) work as edwinorc would hope is that there is no such thing as a "parent role." At composition time, all roles are equal. Regardless of how they got to the composing class, all their guts are just jammed into the class at once (or at least that's how I like to think of it). So this works:

package Role { use Moose::Role; before foo => sub {}; } package Class { use Moose; sub foo {} with 'Role'; }

because this works:

package Class { use Moose; sub foo {} before foo => sub {}; }

On the other hand, this doesn't work:

package Role { use Moose::Role; override foo => sub {}; } package Class { use Moose; sub foo {} with 'Role'; }

because this doesn't work:

package Class { use Moose; sub foo {} override foo => sub {}; }

And likewise this:

package Top { use Moose::Role; sub foo {} } package Bottom { use Moose::Role; override foo => sub {}; with 'Top'; } package Class { use Moose; with 'Bottom'; }

is just equivalent to this:

package Class { use Moose; sub foo {}; override foo => sub {}; }

so, again, it can't work. The fact that Top got composed via Bottom doesn't really matter.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-25 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found