info > Class::Load

Class::Load(3pm) User Contributed Perl Documentation Class::Load(3pm)

πŸ“› NAME

Class::Load - A working (require "Class::Name") and more

πŸš€ Quick Reference

Use CaseCommandDescription
Load a class and die on failure load_class('Class::Name') Loads the class, throws error if not found. Optionally checks version.
Try to load a class without dying try_load_class('Class::Name') Returns 1 if loaded, 0 if not, with error message in list context.
Check if a class is already loaded is_class_loaded('Class::Name') Returns 1 if loaded, 0 if not, using heuristics (handles inner packages).
Load first available class from list load_first_existing_class(@classes) Loads first class that exists and passes version check; throws error if none.
Load optional class with fallback load_optional_class('Class::Name') Returns 1 if exists and loads, 0 if not; croaks on syntax errors.

🏷️ VERSION

version 0.25

πŸ“ SYNOPSIS

use Class::Load ':all';

try_load_class('Class::Name')
    or plan skip_all => "Class::Name required to run these tests";

load_class('Class::Name');

is_class_loaded('Class::Name');

my $baseclass = load_optional_class('Class::Name::MightExist')
    ? 'Class::Name::MightExist'
    : 'Class::Name::Default';

πŸ“– DESCRIPTION

require EXPR only accepts Class/Name.pm style module names, not Class::Name. How frustrating! For that, we provide load_class 'Class::Name'.

It's often useful to test whether a module can be loaded, instead of throwing an error when it's not available. For that, we provide try_load_class 'Class::Name'.

Finally, sometimes we need to know whether a particular class has been loaded. Asking %INC is an option, but that will miss inner packages and any class for which the filename does not correspond to the package name. For that, we provide is_class_loaded 'Class::Name'.

πŸ› οΈ FUNCTIONS

⚠️ CAVEATS

Because of some of the heuristics that this module uses to infer whether a module has been loaded, some false positives may occur in is_class_loaded checks (which are also performed internally in other interfaces) -- if a class has started to be loaded but then dies, it may appear that it has already been loaded, which can cause other things to make the wrong decision. Module::Runtime doesn't have this issue, but it also doesn't do some things that this module does -- for example gracefully handle packages that have been defined inline in the same file as another package.

πŸ”— SEE ALSO

πŸ“ž SUPPORT

Bugs may be submitted through the RT bug tracker https://rt.cpan.org/Public/Dist/Display.html?Name=Class-Load (or bug-Class-Load@rt.org).

There is also a mailing list available for users of this distribution, at http://lists.perl.org/list/moose.html.

There is also an irc channel available for users of this distribution, at #moose on irc.perl.org irc://irc.perl.org/#moose.

πŸ‘€ AUTHOR

Shawn M Moore <sartak at bestpractical.com>

πŸ‘₯ CONTRIBUTORS

πŸ“„ COPYRIGHT AND LICENSE

This software is copyright (c) 2008 by Shawn M Moore.

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

Class::Load
πŸ“› NAME πŸš€ Quick Reference 🏷️ VERSION πŸ“ SYNOPSIS πŸ“– DESCRIPTION πŸ› οΈ FUNCTIONS ⚠️ CAVEATS πŸ”— SEE ALSO πŸ“ž SUPPORT πŸ‘€ AUTHOR πŸ‘₯ CONTRIBUTORS πŸ“„ COPYRIGHT AND LICENSE

Generated by phpman v4.9.26-1-g511901d Author: Che Dong Under GNU General Public License
2026-08-09 09:12 @2600:1f28:365:80b0:50b3:453e:ff52:20f7
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format