in reply to How to dynamically invoke one of several similarly named modules
G'day onemojofilter,
Welcome to the Monastery.
If the APIs for all of those *::LogTable classes are the same, I'd probably do something like this:
{ my %class_for = ( lonprod => sub { require App::London::Production::LogTable; return 'App::London::Production::LogTable'; }, parprod => sub { require App::Paris::Production::LogTable; return 'App::Paris::Production::LogTable'; }, ... ); sub get_class { $class_for{$_[0]}->() } } my $class = get_class($database); $class->find_and_create(...);
— Ken
|
|---|