.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Class::Loader 3pm" .TH Class::Loader 3pm "2018-01-18" "perl v5.26.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Class::Loader \- Load modules and create objects on demand. .SH "VERSION" .IX Header "VERSION" .Vb 2 \& $Revision: 2.2 $ \& $Date: 2001/07/18 20:21:39 $ .Ve .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& package Web::Server; \& use Class::Loader; \& @ISA = qw(Class::Loader); \& \& $self\->_load( \*(AqContent_Handler\*(Aq, { \& Module => "Filter::URL", \& Constructor => "new", \& Args => [ ], \& } \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Certain applications like to defer the decision to use a particular module till runtime. This is possible in perl, and is a useful trick in situations where the type of data is not known at compile time and the application doesn't wish to pre-compile modules to handle all types of data it can work with. Loading modules at runtime can also provide flexible interfaces for perl modules. Modules can let the programmer decide what modules will be used by it instead of hard-coding their names. .PP Class::Loader is an inheritable class that provides a method, \fI_load()\fR, to load a module from disk and construct an object by calling its constructor. It also provides a way to map modules names and associated metadata with symbolic names that can be used in place of module names at \fI_load()\fR. .SH "METHODS" .IX Header "METHODS" .IP "\fB\f(BInew()\fB\fR" 4 .IX Item "new()" A basic constructor. You can use this to create an object of Class::Loader, in case you don't want to inherit Class::Loader. .IP "\fB\f(BI_load()\fB\fR" 4 .IX Item "_load()" \&\fI_load()\fR loads a module and calls its constructor. It returns the newly constructed object on success or a non-true value on failure. The first argument can be the name of the key in which the returned object is stored. This argument is optional. The second (or the first) argument is a hash which can take the following keys: .RS 4 .IP "\fBModule\fR" 4 .IX Item "Module" This is name of the class to load. (It is not the module's filename.) .IP "\fBName\fR" 4 .IX Item "Name" Symbolic name of the module defined with \fI_storemap()\fR. Either one of Module or Name keys must be present in a call to \fI_load()\fR. .IP "\fBConstructor\fR" 4 .IX Item "Constructor" Name of the Module constructor. Defaults to \*(L"new\*(R". .IP "\fBArgs\fR" 4 .IX Item "Args" A reference to the list of arguments for the constructor. \fI_load()\fR calls the constructor with this list. If no Args are present, \fI_load()\fR will call the constructor without any arguments. .IP "\fB\s-1CPAN\s0\fR" 4 .IX Item "CPAN" If the Module is not installed on the local system, \fI_load()\fR can fetch & install it from \s-1CPAN\s0 provided the \s-1CPAN\s0 key is present. This functionality assumes availability of a pre-configured \s-1CPAN\s0 shell. .RE .RS 4 .RE .IP "\fB\f(BI_storemap()\fB\fR" 4 .IX Item "_storemap()" Class::Loader maintains a class table that maps symbolic names to parameters accepted by \fI_load()\fR. It takes a hash as argument whose keys are symbolic names and value are hash references that contain a set of \fI_load()\fR arguments. Here's an example: .Sp .Vb 5 \& $self\->_storemap ( "URL" => { Module => "Filter::URL", \& Constructor => "foo", \& Args => [qw(bar baz)], \& } \& ); \& \& # time passes... \& \& $self\->{handler} = $self\->_load ( Name => \*(AqURL\*(Aq ); .Ve .IP "\fB\f(BI_retrmap()\fB\fR" 4 .IX Item "_retrmap()" \&\fI_retrmap()\fR returns the entire map stored with Class::Loader. Class::Loader maintains separate maps for different classes, and \fI_retrmap()\fR returns the map valid in the caller class. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fIAnyLoader\fR\|(3) .SH "AUTHOR" .IX Header "AUTHOR" Vipul Ved Prakash, .SH "LICENSE" .IX Header "LICENSE" Copyright (c) 2001, Vipul Ved Prakash. All rights reserved. This code is free software; you can redistribute it and/or modify it under the same terms as Perl itself.