in reply to Re^4: eval "require $class" seems wrong
in thread eval "require $class" seems wrong
eval-require is a common idiom for conditional loading of modules and there is a need for that.
No, you don't need either eval functions to conditionally load a module.
if (condition) { require Foo::Bar; }
And you don't need eval EXPR* to do exception handling.
eval { require Foo::Bar; }; if ($@) { require Foo::Baz; }
You only need eval EXPR to load a module whose name is not known at compile-time. The only things I can think of that fits that description are plugins/drivers, things well served by high-level modules.
Do you have an example that requires require $class other than plugins/drivers?
* — Remember, nothing wrong with eval BLOCK (called try in some other languages). Unlike eval EXPR, it doesn't invoke the Perl compiler. That means it doesn't incure a huge speed penalty and it doesn't require careful escaping and validation its argument.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: eval "require $class" seems wrong
by rvosa (Curate) on Aug 22, 2007 at 22:40 UTC | |
Re^6: eval "require $class" seems wrong
by sgt (Deacon) on Aug 23, 2007 at 09:20 UTC |