muba has asked for the wisdom of the Perl Monks concerning the following question:
I have a superclass (MyClass), which creates instances of a subclass on demand. MyClass implements a custom method "get_subclass_instance" for this. The subclass (SubClass) extends 'MyClass';, however, this generates a "Subroutine get_subclass_instance redefined" warning.
Minimal example:
# MyClass.pm package MyClass; use SubClass; use Moose; sub get_subclass_object { return SubClass->new; } 1;
# SubClass.pm package SubClass; use Moose; extends 'MyClass'; 1;
$ perl -MMyClass -e 0 Subroutine get_subclass_object redefined at MyClass.pm line 5. $
I understand that extends(...) tries to load the class(es) passed to it. Consequently, if I remove the Extends 'MyClass' line from SubClass.pm, the warning disappears.
But I don't want to remove that line, because SubClass does extend MyClass!
Of course, I could simply ignore the warning, but that doesn't feel clean to me. So what am I doing wrong, and how can I have MyClass load and instantiate SubClass, while SubClass explicitly extends MyClass?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: [Moose] extends(...) throws "Subroutine redefined" warnings
by MidLifeXis (Monsignor) on Oct 07, 2015 at 12:25 UTC | |
by muba (Priest) on Oct 07, 2015 at 12:48 UTC | |
by MidLifeXis (Monsignor) on Oct 07, 2015 at 12:51 UTC | |
Re: [Moose] extends(...) throws "Subroutine redefined" warnings
by Athanasius (Archbishop) on Oct 07, 2015 at 13:01 UTC | |
by muba (Priest) on Oct 07, 2015 at 13:05 UTC | |
Re: [Moose] extends(...) throws "Subroutine redefined" warnings
by kcott (Archbishop) on Oct 08, 2015 at 04:58 UTC |