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(@_); } }