http://qs1969.pair.com?node_id=1144049

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?