http://www.perlmonks.org?node_id=867968


in reply to Conditional inheritance strategy

few notes:
use dispatch map
our $dispatch_map = { xml => 'My::XML', json => 'My::JSON', }; sub new { ... die unless exists $dispatch_map->{$args{source}}; my $class = $dispatch_map->{$args{source}} Module::Load::load ($class); $self->{engine} = $class; # or $class->new ($self); }
you can call foreign methods ...
$self->My::JSON::_init; # or my $method = $self->{engine} . '::_init'; $self->$method;