edwinorc has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, Trying to use override with my Moose::Role doesn't work if I am overriding a parent role's implementation.
package top; use Moose::Role; requires 'token'; sub foo { print "foo\n"; } sub useful_method{ print "I'm useful\n" } package bottom; use Moose::Role; with 'top'; override 'foo' => sub { print "bar\n"; }; package something; use Moose; with "bottom"; sub token { print "implement me in the concrete class"; } package main; my $something = new something; $something->foo;
Gives "Cannot add an override of method 'foo' because there is a local version of 'foo'". Just putting a normal sub instead of override doesn't work etither. I get: "Due to a method name conflict in roles 'bottom' and 'top', the method 'foo' must be implemented or excluded by 'something'". Basically the problem is: I want to use top's useful_method and bottom's foo and I don't want to implement "token" until the concrete class. Why can't I use Roles in this way?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose Roles and Override
by lune (Pilgrim) on Feb 07, 2012 at 12:02 UTC | |
by edwinorc (Novice) on Feb 08, 2012 at 08:16 UTC | |
|
Re: Moose Roles and Override
by Oberon (Monk) on Sep 17, 2019 at 01:58 UTC |