in reply to Re^2: Two Moose classes consumering the same role and using each other
in thread Two Moose classes consumering the same role and using each other
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Two Moose classes consumering the same role and using each other
by v_melnik (Scribe) on Jun 27, 2014 at 08:50 UTC |