package TestPkg; use Dispatch; sub sub_a { # ... } sub sub_b { # ... } sub _sub_b_helper { # not part of the table! # ... } sub sub_c { print $_[0]; } package main; my $table = create_dptable TestPkg; # or TestPkg::create_dptable(); $table->{sub_c}->("Hello!"); #### package Dispatch; sub import { my $pkg = (caller)[0]; *{"${pkg}::create_dptable"} = sub { my %dispatch; my @oksymbols = grep { !/^_/ && !/^create_dptable$/ && defined *{"${pkg}::$_"}{CODE} } keys %{*{"${pkg}::"}}; $dispatch{$_} = *{"${pkg}::$_"}{CODE} foreach ( @oksymbols ); return \%dispatch }; } 1;