use strict; use warnings; my $o = overlord::baseclass->new(choice=>"delegate2"); $o->display("badger"); exit 0; package overlord; package overlord::baseclass; sub new { my $self = shift; my %obj = @_; $obj{delegate} = "overlord::$obj{choice}"->new(); return bless \%obj,$self; } sub display { my $self = shift; my $param = shift; $self->{delegate}->display($param); } package overlord::delegate1; sub new { my $self = shift; my %obj; return bless \%obj,$self; } sub display { my $self = shift; my $param = shift; print $param."\n"; } package overlord::delegate2; sub new { my $self = shift; my %obj; return bless \%obj,$self; } sub display { my $self = shift; my $param = shift; print "$param\n"; } 1;