CPAN RT

# This only needs to be said once in your program.
require UNIVERSAL::require;
# Same as "require Some::Module"
my $module = 'Some::Module';
$module->require or die $@;
# Same as "use Some::Module"
BEGIN { $module->use or die $@ }

to get around the bareword caveats on require(), this module is for you. It creates a universal require() class method that will work with every Perl module and its secure. So instead of doing some arcane eval() work, you can do this:

$module->require;

It doesn't save you much typing, but it'll make a lot more sense to someone who's not a ninth level Perl acolyte.

This works exactly like Perl's require, except without the bareword restriction, and it doesn't die. Since require() is placed in the UNIVERSAL namespace, it will work on any module. You just have to use UNIVERSAL::require somewhere in your code.

Should the module require fail, or not be a high enough $version, it will simply return false and not die. The error will be in $@ as well as $UNIVERSAL::require::ERROR.

UNIVERSAL::require makes use of eval STRING. In previous versions of UNIVERSAL::require it was discovered that one could craft a class name which would result in code being executed. This hole has been closed. The only variables now exposed to eval STRING are the caller's package, filename and line which are not tainted.