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!

In reply to Moose Roles and Override by edwinorc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.