package B; my @models; # factory model, get it? sub add { my $self = shift; my $child_coderef = shift; push @models, $child_coderef; } sub new { my $class = shift; # ignore my $type = shift; return unless $type; my $child_coderef = @models[$type - 1]; return unless defined &$child_coderef; return $child_coderef->(@_); } package D3; @D3::ISA = qw( B ); use B; # gotta be done here B->add(\&new); sub new { # etc }