Howdy, Perl Monks!

I'm trying to implement roles in our extensive codebase using Role::Tiny, but it's not behaving as expected. CPAN clearly states: "If a method is already defined on a class, that method will not be composed in from the role.". However in my current code it is clear that the method in the role is being used.

My code works as follows (package naming simplified for clarity):

  1. I have a parent package Generic, a child package File, and a role Draw.
  2. Both File and Draw have a method called 'render' which is identical apart from one line that adds text to the image (in the child) or omits it (in the role).
  3. After instantiation, the File object calls a method init from its parent which uses Role::Tiny::apply_roles_to_object, which duly changes the class from File to File__WITH__Role::Draw.
  4. However when the render method is called, the image has no text. The method from Draw is being used, even though there is a render method in File.

I can only assume that something arcane is happening with the combination of standard inheritance and roles, but I can't put my finger on it...


In reply to Role::Tiny not behaving as expected by webmistress_ming

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.