in reply to Dynamic use/require
I'm not entirely clear on what you're doing or why. You point to an eval in a loop, and it sounds as if you want to take the separate parts of the eval and put them in different places.
You say you want to remove dynamically instantiating the module from the loop. I'm guessing you're talking about the use part of what you're doing. It looks as if inside the loop is where you know what modules you want to use, so that's where you'll need to use them. If you want, you can loop twice.
while ( ... ) { my $cat = $$methods{'category'}; my $class = 'Category::' . $category{$cat}->[0]; eval "use $class;" die $@ if $@; } while ( ... ) { my $cat = $$methods{'category'}; my $class = 'Category::' . $category{$cat}->[0]; my $method = $category{$cat}->[1]; eval "$class->new()->$method(\$key, \$params, \$testCase)"; die $@ if $@; }
Note, though, that in the second case, you don't really need the string interpolation. You could do this instead:
eval { $class->new()->$method( $key, $params, $testCase ) };
Perhaps you're trying to avoid doing the use part more than once for each module. This tends not to be a problem. If the module's already loaded, use does not load it again anyway.
|
|---|