# Build and require the subclass for this type: my $class = __PACKAGE__ . "::" . $opts{type}; eval "require $class"; if ($@) { Carp::carp("Part type '$opts{type}' unknown"); return undef; } # Build the Part object template: my $self = { # name provided directly, or implicitly by type. name => $opts{name} // $opts{type}, }; # Bless into the determined subclass for this type: bless $self, $class;