I think this is nothing to do with Moose. I think you're loading VirtualMachine.pm twice. Normally require uses %INC to avoid doing that, but the second time you're loading it as ""MonkeyMan//CloudStack//Elements//VirtualMachine.pm" with those strange doubled slashes, so require sees it as a different file name and loads it again.

You have warnings enabled, so you get a warning about the subs being redefined in the MonkeyMan::CloudStack::Elements::VirtualMachine package. This is because the first time VirtualMachine.pm is loaded, the subs get defined, and the second time it's loaded, they get redefined. (Redefined to the same definition, but redefined all the same!)

If you want to check to see if I'm right, do this in your role:

use Data::Dumper (); END { print Data::Dumper::Dumper(\%INC); }

... then run your script. When it exits you should get a big dump of all the modules that Perl loaded. VirtualMachine.pm will be in there twice with slightly differing paths.

I'd combat this problem by getting rid of this:

my $quasi_object = eval { require "MonkeyMan//CloudStack//Elements//$module_name.pm"; return("MonkeyMan::CloudStack::Elements::$module_name"->new(m +m => $mm)); };

And replacing it with something cleaner like this:

use Try::Tiny; use Module::Runtime qw(use_module); my $quasi_object = try { my $class = "MonkeyMan::CloudStack::Elements::$module_name"; use_module($class)->new( mm => $mm ); };

You won't be adding any extra dependencies because Moose already uses Try::Tiny and Module::Runtime internally!


In reply to Re^3: Two Moose classes consumering the same role and using each other by tobyink
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.