The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

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');

DESCRIPTION

require EXPR only accepts Class/Name.pm style module names, not Class::Name. How frustrating!

It's often useful to test whether a module can be loaded, instead of throwing an error when it's not available.

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.

FUNCTIONS

load_class Class::Name

load_class will load Class::Name or throw an error, much like require.

If Class::Name is already loaded (checked with is_class_loaded) then it will not try to load the class. This is useful when you have inner packages which require does not check.

try_load_class Class::Name -> 0|1

Returns 1 if the class was loaded, 0 if it was not. If the class was not loaded, the error will be available in $Class::Load::ERROR.

Again, if Class::Name is already loaded (checked with is_class_loaded) then it will not try to load the class. This is useful when you have inner packages which require does not check.

is_class_loaded Class::Name -> 0|1

This uses a number of heuristics to determine if the class Class::Name is loaded. We check first whether it has an entry in %INC, then check its symbol table for interesting values.

SEE ALSO

UNIVERSAL::require

Adds a require method to UNIVERSAL so that you can say Class::Name->require. I personally dislike the pollution.

Module::Load

Supports Class::Name and Class/Name.pm formats, no try_to_load or is_class_loaded.

Moose, Jifty, Prophet, etc

This module was designed to be used anywhere you have if (eval "require $module"; 1).

AUTHOR

Shawn M Moore, <sartak at bestpractical.com>

BUGS

Please report any bugs or feature requests to bug-class-load at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Load.

COPYRIGHT & LICENSE

Copyright 2008 Best Practical Solutions.

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