{
    "mode": "perldoc",
    "parameter": "UNIVERSAL::require",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/UNIVERSAL%3A%3Arequire/json",
    "generated": "2026-06-13T14:45:17Z",
    "synopsis": "# This only needs to be said once in your program.\nrequire UNIVERSAL::require;\n# Same as \"require Some::Module\"\nmy $module = 'Some::Module';\n$module->require or die $@;\n# Same as \"use Some::Module\"\nBEGIN { $module->use or die $@ }",
    "sections": {
        "NAME": {
            "content": "UNIVERSAL::require - require() modules from a variable [deprecated]\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "# This only needs to be said once in your program.\nrequire UNIVERSAL::require;\n\n# Same as \"require Some::Module\"\nmy $module = 'Some::Module';\n$module->require or die $@;\n\n# Same as \"use Some::Module\"\nBEGIN { $module->use or die $@ }\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Before using this module, you should look at the alternatives, some of which are listed in SEE\nALSO below.\n\nThis module provides a safe mechanism for loading a module at runtime, when you have the name of\nthe module in a variable.\n\nIf you've ever had to do this...\n\neval \"require $module\";\n\nto get around the bareword caveats on require(), this module is for you. It creates a universal",
            "subsections": [
                {
                    "name": "require",
                    "content": "some arcane eval() work, you can do this:\n\n$module->require;\n\nIt doesn't save you much typing, but it'll make a lot more sense to someone who's not a ninth\nlevel Perl acolyte.\n"
                }
            ]
        },
        "Methods": {
            "content": "require\nmy $returnval = $module->require           or die $@;\nmy $returnval = $module->require($version) or die $@;\n\nThis works exactly like Perl's require, except without the bareword restriction, and it doesn't\ndie. Since require() is placed in the UNIVERSAL namespace, it will work on any module. You just\nhave to use UNIVERSAL::require somewhere in your code.\n\nShould the module require fail, or not be a high enough $version, it will simply return false\nand not die. The error will be in $@ as well as $UNIVERSAL::require::ERROR.\n\n$module->require or die $@;\n\nuse\nmy $requirereturn = $module->use           or die $@;\nmy $requirereturn = $module->use(@imports) or die $@;\n\nLike \"UNIVERSAL::require\", this allows you to \"use\" a $module without having to eval to work\naround the bareword requirement. It returns the same as require.\n\nShould either the require or the import fail it will return false. The error will be in $@.\n\nIf possible, call this inside a BEGIN block to emulate a normal \"use\" as closely as possible.\n\nBEGIN { $module->use }\n",
            "subsections": []
        },
        "SECURITY NOTES": {
            "content": "UNIVERSAL::require makes use of \"eval STRING\". In previous versions of UNIVERSAL::require it was\ndiscovered that one could craft a class name which would result in code being executed. This\nhole has been closed. The only variables now exposed to \"eval STRING\" are the caller's package,\nfilename and line which are not tainted.\n\nUNIVERSAL::require is taint clean.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 2001, 2005 by Michael G Schwern <schwern@pobox.com>.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nSee http://www.perl.com/perl/misc/Artistic.html\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Michael G Schwern <schwern@pobox.com>\n\nNow maintained by Neil Bowers (NEILB).\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Module::Load provides functions for loading code, and importing functions. It's actively\nmaintained.\n\nModule::Runtime provides a number of usesful functions for require'ing and use'ing modules, and\nassociated operations.\n\nMojo::Loader is a class loader and plugin framework. Module::Loader is a stand-alone module that\nwas inspired by \"Mojo::Loader\".\n\nThere are many other modules that may be of interest on CPAN. An old review of some of them can\nbe read at <https://neilb.org/reviews/module-loading.html>.\n\n\"require\" in perlfunc.\n",
            "subsections": []
        }
    },
    "summary": "UNIVERSAL::require - require() modules from a variable [deprecated]",
    "flags": [],
    "examples": [],
    "see_also": []
}