{
    "mode": "perldoc",
    "parameter": "Class::Load",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ALoad/json",
    "generated": "2026-06-09T17:47:33Z",
    "synopsis": "use Class::Load ':all';\ntryloadclass('Class::Name')\nor plan skipall => \"Class::Name required to run these tests\";\nloadclass('Class::Name');\nisclassloaded('Class::Name');\nmy $baseclass = loadoptionalclass('Class::Name::MightExist')\n? 'Class::Name::MightExist'\n: 'Class::Name::Default';",
    "sections": {
        "NAME": {
            "content": "Class::Load - A working (require \"Class::Name\") and more\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 0.25\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Class::Load ':all';\n\ntryloadclass('Class::Name')\nor plan skipall => \"Class::Name required to run these tests\";\n\nloadclass('Class::Name');\n\nisclassloaded('Class::Name');\n\nmy $baseclass = loadoptionalclass('Class::Name::MightExist')\n? 'Class::Name::MightExist'\n: 'Class::Name::Default';\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"require EXPR\" only accepts \"Class/Name.pm\" style module names, not \"Class::Name\". How\nfrustrating! For that, we provide \"loadclass 'Class::Name'\".\n\nIt's often useful to test whether a module can be loaded, instead of throwing an error when it's\nnot available. For that, we provide \"tryloadclass 'Class::Name'\".\n\nFinally, sometimes we need to know whether a particular class has been loaded. Asking %INC is an\noption, but that will miss inner packages and any class for which the filename does not\ncorrespond to the package name. For that, we provide \"isclassloaded 'Class::Name'\".\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "loadclass Class::Name, \\%options\n\"loadclass\" will load \"Class::Name\" or throw an error, much like \"require\".\n\nIf \"Class::Name\" is already loaded (checked with \"isclassloaded\") then it will not try to load\nthe class. This is useful when you have inner packages which \"require\" does not check.\n\nThe %options hash currently accepts one key, \"-version\". If you specify a version, then this\nsubroutine will call \"Class::Name->VERSION( $options{-version} )\" internally, which will throw\nan error if the class's version is not equal to or greater than the version you requested.\n\nThis method will return the name of the class on success.\n\ntryloadclass Class::Name, \\%options -> (0|1, error message)\nReturns 1 if the class was loaded, 0 if it was not. If the class was not loaded, the error will\nbe returned as a second return value in list context.\n\nAgain, if \"Class::Name\" is already loaded (checked with \"isclassloaded\") then it will not try\nto load the class. This is useful when you have inner packages which \"require\" does not check.\n\nLike \"loadclass\", you can pass a \"-version\" in %options. If the version is not sufficient, then\nthis subroutine will return false.\n\nisclassloaded Class::Name, \\%options -> 0|1\nThis uses a number of heuristics to determine if the class \"Class::Name\" is loaded. There\nheuristics were taken from Class::MOP's old pure-perl implementation.\n\nLike \"loadclass\", you can pass a \"-version\" in %options. If the version is not sufficient, then\nthis subroutine will return false.\n\nloadfirstexistingclass Class::Name, \\%options, ...\nThis attempts to load the first loadable class in the list of classes given. Each class name can\nbe followed by an options hash reference.\n\nIf any one of the classes loads and passes the optional version check, that class name will be\nreturned. If *none* of the classes can be loaded (or none pass their version check), then an\nerror will be thrown.\n\nIf, when attempting to load a class, it fails to load because of a syntax error, then an error\nwill be thrown immediately.\n\nloadoptionalclass Class::Name, \\%options -> 0|1\n\"loadoptionalclass\" is a lot like \"tryloadclass\", but also a lot like \"loadclass\".\n\nIf the class exists, and it works, then it will return 1. If you specify a version in %options,\nthen the version check must succeed or it will return 0.\n\nIf the class doesn't exist, and it appears to not exist on disk either, it will return 0.\n\nIf the class exists on disk, but loading from disk results in an error (e.g.: a syntax error),\nthen it will \"croak\" with that error.\n\nThis is useful for using if you want a fallback module system, i.e.:\n\nmy $class = loadoptionalclass($foo) ? $foo : $default;\n\nThat way, if $foo does exist, but can't be loaded due to error, you won't get the behaviour of\nit simply not existing.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "Because of some of the heuristics that this module uses to infer whether a module has been\nloaded, some false positives may occur in \"isclassloaded\" checks (which are also performed\ninternally in other interfaces) -- if a class has started to be loaded but then dies, it may\nappear that it has already been loaded, which can cause other things to make the wrong decision.\nModule::Runtime doesn't have this issue, but it also doesn't do some things that this module\ndoes -- for example gracefully handle packages that have been defined inline in the same file as\nanother package.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "<http://blog.fox.geek.nz/2010/11/searching-design-spec-for-ultimate.html>\nThis blog post is a good overview of the current state of the existing modules for loading\nother modules in various ways.\n\n<http://blog.fox.geek.nz/2010/11/handling-optional-requirements-with.html>\nThis blog post describes how to handle optional modules with Class::Load.\n\n<http://d.hatena.ne.jp/tokuhirom/20110202/1296598578>\nThis Japanese blog post describes why DBIx::Skinny now uses Class::Load over its\ncompetitors.\n\nMoose, Jifty, Prophet, etc\nThis module was designed to be used anywhere you have \"if (eval \"require $module\"; 1)\",\nwhich occurs in many large projects.\n\nModule::Runtime\nA leaner approach to loading modules\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Bugs may be submitted through the RT bug tracker\n<https://rt.cpan.org/Public/Dist/Display.html?Name=Class-Load> (or bug-Class-Load@rt.cpan.org\n<mailto:bug-Class-Load@rt.cpan.org>).\n\nThere is also a mailing list available for users of this distribution, at\n<http://lists.perl.org/list/moose.html>.\n\nThere is also an irc channel available for users of this distribution, at \"#moose\" on\n\"irc.perl.org\" <irc://irc.perl.org/#moose>.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Shawn M Moore <sartak at bestpractical.com>\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "*   Dave Rolsky <autarch@urth.org>\n\n*   Karen Etheridge <ether@cpan.org>\n\n*   Shawn Moore <sartak@bestpractical.com>\n\n*   Jesse Luehrs <doy@tozt.net>\n\n*   Kent Fredric <kentfredric@gmail.com>\n\n*   Paul Howarth <paul@city-fan.org>\n\n*   Olivier Mengué <dolmen@cpan.org>\n\n*   Caleb Cushing <xenoterracide@gmail.com>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is copyright (c) 2008 by Shawn M Moore.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        }
    },
    "summary": "Class::Load - A working (require \"Class::Name\") and more",
    "flags": [],
    "examples": [],
    "see_also": []
}