Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to dynamically invoke one of several similarly named modules

by kcott (Archbishop)
on Aug 23, 2022 at 07:32 UTC ( [id://11146302]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11146302]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found