in reply to Passing package/module names to script as argument
The most straightforward approach would be require or Module::Load or Module::Pluggable.
Module::Pluggable would automatically load all modules, while you need to load the modules when using require or Module::Load.
Module::Pluggable allows you to automatically instantiate objects when loading a plugin, and allows easy enumeration of loaded plugins, but for your case, I consider Module::Load or a simple require to be the clearer approach:
sub new_class { my $class = shift; (my $module = $class) =~ s!::!/!g; require "$module.pm"; $class->new( @_ ); } my $red = new_class('redObjects', color => 'red'); my $green = new_class('greenObjects', color => 'green');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing package/module names to script as argument
by Amblikai (Scribe) on Sep 13, 2018 at 13:40 UTC |