1Class::Load(3)        User Contributed Perl Documentation       Class::Load(3)
2
3
4

NAME

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

SYNOPSIS

9           use Class::Load ':all';
10
11           try_load_class('Class::Name')
12               or plan skip_all => "Class::Name required to run these tests";
13
14           load_class('Class::Name');
15
16           is_class_loaded('Class::Name');
17
18           my $baseclass = load_optional_class('Class::Name::MightExist')
19               ? 'Class::Name::MightExist'
20               : 'Class::Name::Default';
21

DESCRIPTION

23       "require EXPR" only accepts "Class/Name.pm" style module names, not
24       "Class::Name". How frustrating! For that, we provide "load_class
25       'Class::Name'".
26
27       It's often useful to test whether a module can be loaded, instead of
28       throwing an error when it's not available. For that, we provide
29       "try_load_class 'Class::Name'".
30
31       Finally, sometimes we need to know whether a particular class has been
32       loaded.  Asking %INC is an option, but that will miss inner packages
33       and any class for which the filename does not correspond to the package
34       name. For that, we provide "is_class_loaded 'Class::Name'".
35

FUNCTIONS

37   load_class Class::Name
38       "load_class" will load "Class::Name" or throw an error, much like
39       "require".
40
41       If "Class::Name" is already loaded (checked with "is_class_loaded")
42       then it will not try to load the class. This is useful when you have
43       inner packages which "require" does not check.
44
45   try_load_class Class::Name -> 0|1 =head2 try_load_class Class::Name ->
46       (0|1, error message)
47       Returns 1 if the class was loaded, 0 if it was not. If the class was
48       not loaded, the error will be returned as a second return value in list
49       context.
50
51       Again, if "Class::Name" is already loaded (checked with
52       "is_class_loaded") then it will not try to load the class. This is
53       useful when you have inner packages which "require" does not check.
54
55   is_class_loaded Class::Name -> 0|1
56       This uses a number of heuristics to determine if the class
57       "Class::Name" is loaded. There heuristics were taken from Class::MOP's
58       old pure-perl implementation.
59
60   load_optional_class Class::Name -> 0|1
61       "load_optional_class" is a lot like "try_load_class", but also a lot
62       like "load_class".
63
64       If the class exists, and it works, then it will return 1.
65
66       If the class doesn't exist, and it appears to not exist on disk either,
67       it will return 0.
68
69       If the class exists on disk, but loading from disk results in an error
70       ( ie: a syntax error ), then it will "croak" with that error.
71
72       This is useful for using if you want a fallback module system, ie:
73
74           my $class = load_optional_class($foo) ? $foo : $default;
75
76       That way, if $foo does exist, but can't be loaded due to error, you
77       won't get the behaviour of it simply not existing.
78

SEE ALSO

80       UNIVERSAL::require
81           Adds a "require" method to "UNIVERSAL" so that you can say
82           "Class::Name->require". I personally dislike the pollution.
83
84       Module::Load
85           Supports "Class::Name" and "Class/Name.pm" formats, no
86           "try_to_load" or "is_class_loaded".
87
88       Moose, Jifty, Prophet, etc
89           This module was designed to be used anywhere you have "if (eval
90           "require $module"; 1)", which occurs in many large projects.
91

AUTHOR

93       Shawn M Moore, "<sartak at bestpractical.com>"
94
95       The implementation of "is_class_loaded" has been taken from Class::MOP.
96

BUGS

98       Please report any bugs or feature requests to "bug-class-load at
99       rt.cpan.org", or through the web interface at
100       http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Load
101       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Load>.
102
104       Copyright 2008-2009 Best Practical Solutions.
105
106       This program is free software; you can redistribute it and/or modify it
107       under the same terms as Perl itself.
108
109
110
111perl v5.12.2                      2010-11-15                    Class::Load(3)
Impressum