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.
|
|---|