# phpman > perldoc > UNIVERSAL::require

## NAME
    [UNIVERSAL::require](https://www.chedong.com/phpMan.php/perldoc/UNIVERSAL%3A%3Arequire/markdown) - require() modules from a variable [deprecated]

## SYNOPSIS
      # This only needs to be said once in your program.
      require [UNIVERSAL::require](https://www.chedong.com/phpMan.php/perldoc/UNIVERSAL%3A%3Arequire/markdown);

      # Same as "require [Some::Module](https://www.chedong.com/phpMan.php/perldoc/Some%3A%3AModule/markdown)"
      my $module = '[Some::Module](https://www.chedong.com/phpMan.php/perldoc/Some%3A%3AModule/markdown)';
      $module->require or die $@;

      # Same as "use [Some::Module](https://www.chedong.com/phpMan.php/perldoc/Some%3A%3AModule/markdown)"
      BEGIN { $module->use or die $@ }

## DESCRIPTION
    Before using this module, you should look at the alternatives, some of which are listed in SEE
    ALSO below.

    This module provides a safe mechanism for loading a module at runtime, when you have the name of
    the module in a variable.

    If you've ever had to do this...

        eval "require $module";

    to get around the bareword caveats on require(), this module is for you. It creates a universal
### require
    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.

## Methods
   require
      my $return_val = $module->require           or die $@;
      my $return_val = $module->require($version) or die $@;

    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](https://www.chedong.com/phpMan.php/perldoc/UNIVERSAL%3A%3Arequire/markdown) 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](https://www.chedong.com/phpMan.php/perldoc/UNIVERSAL%3A%3Arequire%3A%3AERROR/markdown).

        $module->require or die $@;

   use
        my $require_return = $module->use           or die $@;
        my $require_return = $module->use(@imports) or die $@;

    Like "[UNIVERSAL::require](https://www.chedong.com/phpMan.php/perldoc/UNIVERSAL%3A%3Arequire/markdown)", this allows you to "use" a $module without having to eval to work
    around the bareword requirement. It returns the same as require.

    Should either the require or the import fail it will return false. The error will be in $@.

    If possible, call this inside a BEGIN block to emulate a normal "use" as closely as possible.

        BEGIN { $module->use }

## SECURITY NOTES
    [UNIVERSAL::require](https://www.chedong.com/phpMan.php/perldoc/UNIVERSAL%3A%3Arequire/markdown) makes use of "eval STRING". In previous versions of [UNIVERSAL::require](https://www.chedong.com/phpMan.php/perldoc/UNIVERSAL%3A%3Arequire/markdown) 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.

    [UNIVERSAL::require](https://www.chedong.com/phpMan.php/perldoc/UNIVERSAL%3A%3Arequire/markdown) is taint clean.

## COPYRIGHT
    Copyright 2001, 2005 by Michael G Schwern <<schwern@pobox.com>>.

    This program is free software; you can redistribute it and/or modify it under the same terms as
    Perl itself.

    See <http://www.perl.com/perl/misc/Artistic.html>

## AUTHOR
    Michael G Schwern <<schwern@pobox.com>>

    Now maintained by Neil Bowers (NEILB).

## SEE ALSO
    [Module::Load](https://www.chedong.com/phpMan.php/perldoc/Module%3A%3ALoad/markdown) provides functions for loading code, and importing functions. It's actively
    maintained.

    [Module::Runtime](https://www.chedong.com/phpMan.php/perldoc/Module%3A%3ARuntime/markdown) provides a number of usesful functions for require'ing and use'ing modules, and
    associated operations.

    [Mojo::Loader](https://www.chedong.com/phpMan.php/perldoc/Mojo%3A%3ALoader/markdown) is a class loader and plugin framework. [Module::Loader](https://www.chedong.com/phpMan.php/perldoc/Module%3A%3ALoader/markdown) is a stand-alone module that
    was inspired by "[Mojo::Loader](https://www.chedong.com/phpMan.php/perldoc/Mojo%3A%3ALoader/markdown)".

    There are many other modules that may be of interest on CPAN. An old review of some of them can
    be read at <<https://neilb.org/reviews/module-loading.html>>.

    "require" in perlfunc.

