The following snippets allow you to create objects of the right class. You did not ask for this, but I'm missing the point of creating classes automatically. What is the good of having two identical classes? Answer me this, and I'll answer your original question. (In fact, I've already written the answer.)
package Thingy; sub make_cog { my $self = shift; return Cog->new(@_); } { ... my $cog = $self->make_cog(...); ... } package MyThingy; sub make_cog { my $self = shift; return MyCog->new(@_); }
or (less recommended)
package Thingy; sub make_cog { my $self = shift; my $cog_class = ref($self) . '::Cog'; if ($cog_class->can('new')) { return $cog_class->new(@_); } else { return Thingy::Cog->new(@_); } }
Update: Reguarding your update which greatly clarified things, the second snippet should do the trick.
In reply to Re: Inheritence in a Suite of Modules
by ikegami
in thread Inheritance in a Suite of Modules
by japhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |