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!
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |