# Define appropriate "methods" my @dispatch_methods = qw [ company financialDiary ]; # Routine to generate an anonymous sub using closure sub dispatch_add { my ($what) = @_; return sub { my ( $self, $data ) = @_; my $table = $what; my $data = $self->_generic_insert( $data, $table ); $self->{ _dbh }->commit if ! $self->{ _error }; return $data; }; } # Build the dispatch table, trying to minimize error sub new { # Usual stuff... my $self = bless ... # : $self->{dispatch} = { map { $_ => dispatch_add{$_} } @dispatch_methods }; } #### $thing->{dispatch}->{company}->($param);