c:\@Work\Perl>perl -wMstrict -le "{ package ProcessData; ;; use warnings; use strict; use Carp qw(croak); ;; sub new { my ($pkg) = $_[0]; bless { _dispatch_table => {}, }, $pkg; } ;; sub add_subroutine { if($_[1] && $_[2]) { if(ref($_[2]) eq \"CODE\") { ${$_[0]->{_dispatch_table}}{$_[1]} = $_[2]; } else { croak qq{non-CODE reference '$_[2]' passed to add_subroutine()}; } } else { croak \"Insufficient arguments passed to add_subroutine(). \"; } } ;; sub process_data { my $self = shift; ;; die qq{no dispatch given} unless @_; my $dispatch = shift; die qq{unknown dispatch '$dispatch'} unless exists $self->{_dispatch_table}{$dispatch}; ;; return $self->{_dispatch_table}{$dispatch}->(@_); } ;; sub process_locations { my $self = shift; return $self->process_data('locations', @_); } ;; } ;; use warnings; use strict; ;; my $pd = ProcessData->new(); ;; $pd->add_subroutine('locations', \&get_locations); ;; $pd->process_locations(qw(here there everywhere)); ;; sub get_locations { print qq{we got stuff: @_} } " we got stuff: here there everywhere