No, problem, I'll add some actual code.

Here is the role:

package MonkeyMan::CloudStack::Element; use strict; use warnings; use Moose::Role; use namespace::autoclean; with 'MonkeyMan::ErrorHandling'; # ^^^ by the way, the role consumes one more role, but it doesn't gene +rate any warnings # <...> sub find_related_to_me { # <...> my $quasi_object = eval { require "MonkeyMan//CloudStack//Elements//$module_name.pm"; return("MonkeyMan::CloudStack::Elements::$module_name"->new(m +m => $mm)); }; # <...> } # <...> 1;

And here goest our "ClassA":

package MonkeyMan::CloudStack::Elements::Domain; use strict; use warnings; use MonkeyMan::Constants; use Moose; use MooseX::UndefTolerant; use namespace::autoclean; with 'MonkeyMan::CloudStack::Element'; sub element_type { # <...> } sub _load_full_list_command { # <...> } sub _generate_xpath_query { # <...> } 1;

ClassB looks almost the same way:

package MonkeyMan::CloudStack::Elements::VirtualMachine; use strict; use warnings; use MonkeyMan::Constants; use Moose; use MooseX::UndefTolerant; use namespace::autoclean; with 'MonkeyMan::CloudStack::Element'; sub element_type { # <...> } sub _load_full_list_command { # <...> } sub _generate_xpath_query { # <...> } 1;

Yes, ClassA and ClassB are quite short and quite similar, the differences are only in a couple of lines, because all their logic is coded in the Element role. Then my main module calls ClassA->find_related_to_me(...) and it needs to create a ClassB object for doing some tricks. The object is being created, everything works fine, but here are some warnings:

Subroutine element_type redefined at /opt/monkeyman-0.2.x/bin/../lib/M +onkeyMan//CloudStack//Elements//VirtualMachine.pm line 17. Subroutine _load_full_list_command redefined at /opt/monkeyman-0.2.x/b +in/../lib/MonkeyMan//CloudStack//Elements//VirtualMachine.pm line 23. Subroutine _generate_xpath_query redefined at /opt/monkeyman-0.2.x/bin +/../lib/MonkeyMan//CloudStack//Elements//VirtualMachine.pm line 30.

So it doesn't like that I defined element_type(), _load_full_list_command() and _generate_xpath_query() in MonkeyMan::CloudStack::Elements::Domain and then I require MonkeyMan::CloudStack::Elements::VirtualMachine where the same methods are defined as well.

I'm pretty sure that my case isn't too "exotic" and many Perl developers are facing with the necessity of using "sibling" classes consuming the same role.

Thank you!

V.Melnik

In reply to Re^2: Two Moose classes consumering the same role and using each other by v_melnik
in thread Two Moose classes consumering the same role and using each other by v_melnik

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.