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

NAME

6       Class::Loader - Load modules and create objects on demand.
7

VERSION

9           $Revision: 2.2 $
10           $Date: 2001/07/18 20:21:39 $
11

SYNOPSIS

13           package Web::Server;
14           use Class::Loader;
15           @ISA = qw(Class::Loader);
16
17           $self->_load( 'Content_Handler', {
18                                    Module => "Filter::URL",
19                               Constructor => "new",
20                                      Args => [ ],
21                                }
22                       );
23

DESCRIPTION

25       Certain applications like to defer the decision to use a particular
26       module till runtime. This is possible in perl, and is a useful trick in
27       situations where the type of data is not known at compile time and the
28       application doesn't wish to pre-compile modules to handle all types of
29       data it can work with. Loading modules at runtime can also provide
30       flexible interfaces for perl modules. Modules can let the programmer
31       decide what modules will be used by it instead of hard-coding their
32       names.
33
34       Class::Loader is an inheritable class that provides a method, _load(),
35       to load a module from disk and construct an object by calling its
36       constructor. It also provides a way to map modules names and associated
37       metadata with symbolic names that can be used in place of module names
38       at _load().
39

METHODS

41       new()
42           A basic constructor. You can use this to create an object of
43           Class::Loader, in case you don't want to inherit Class::Loader.
44
45       _load()
46           _load() loads a module and calls its constructor. It returns the
47           newly constructed object on success or a non-true value on failure.
48           The first argument can be the name of the key in which the returned
49           object is stored. This argument is optional. The second (or the
50           first) argument is a hash which can take the following keys:
51
52           Module
53               This is name of the class to load. (It is not the module's
54               filename.)
55
56           Name
57               Symbolic name of the module defined with _storemap(). Either
58               one of Module or Name keys must be present in a call to
59               _load().
60
61           Constructor
62               Name of the Module constructor. Defaults to "new".
63
64           Args
65               A reference to the list of arguments for the constructor.
66               _load() calls the constructor with this list. If no Args are
67               present, _load() will call the constructor without any
68               arguments.
69
70           CPAN
71               If the Module is not installed on the local system, _load() can
72               fetch & install it from CPAN provided the CPAN key is present.
73               This functionality assumes availability of a pre-configured
74               CPAN shell.
75
76       _storemap()
77           Class::Loader maintains a class table that maps symbolic names to
78           parameters accepted by _load(). It takes a hash as argument whose
79           keys are symbolic names and value are hash references that contain
80           a set of _load() arguments. Here's an example:
81
82               $self->_storemap ( "URL" => { Module => "Filter::URL",
83                                             Constructor => "foo",
84                                             Args => [qw(bar baz)],
85                                           }
86                                );
87
88               # time passes...
89
90               $self->{handler} = $self->_load ( Name => 'URL' );
91
92       _retrmap()
93           _retrmap() returns the entire map stored with Class::Loader.
94           Class::Loader maintains separate maps for different classes, and
95           _retrmap() returns the map valid in the caller class.
96

SEE ALSO

98       AnyLoader(3)
99

AUTHOR

101       Vipul Ved Prakash, <mail@vipul.net>
102

LICENSE

104       Copyright (c) 2001, Vipul Ved Prakash. All rights reserved. This code
105       is free software; you can redistribute it and/or modify it under the
106       same terms as Perl itself.
107
108
109
110perl v5.28.0                      2018-07-14                  Class::Loader(3)
Impressum