Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / AutoLoader.3
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "AutoLoader 3"
132.TH AutoLoader 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134AutoLoader \- load subroutines only on demand
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 2
138\& package Foo;
139\& use AutoLoader 'AUTOLOAD'; # import the default AUTOLOAD subroutine
140.Ve
141.PP
142.Vb 7
143\& package Bar;
144\& use AutoLoader; # don't import AUTOLOAD, define our own
145\& sub AUTOLOAD {
146\& ...
147\& $AutoLoader::AUTOLOAD = "...";
148\& goto &AutoLoader::AUTOLOAD;
149\& }
150.Ve
151.SH "DESCRIPTION"
152.IX Header "DESCRIPTION"
153The \fBAutoLoader\fR module works with the \fBAutoSplit\fR module and the
154\&\f(CW\*(C`_\|_END_\|_\*(C'\fR token to defer the loading of some subroutines until they are
155used rather than loading them all at once.
156.PP
157To use \fBAutoLoader\fR, the author of a module has to place the
158definitions of subroutines to be autoloaded after an \f(CW\*(C`_\|_END_\|_\*(C'\fR token.
159(See perldata.) The \fBAutoSplit\fR module can then be run manually to
160extract the definitions into individual files \fIauto/funcname.al\fR.
161.PP
162\&\fBAutoLoader\fR implements an \s-1AUTOLOAD\s0 subroutine. When an undefined
163subroutine in is called in a client module of \fBAutoLoader\fR,
164\&\fBAutoLoader\fR's \s-1AUTOLOAD\s0 subroutine attempts to locate the subroutine in a
165file with a name related to the location of the file from which the
166client module was read. As an example, if \fI\s-1POSIX\s0.pm\fR is located in
167\&\fI/usr/local/lib/perl5/POSIX.pm\fR, \fBAutoLoader\fR will look for perl
168subroutines \fB\s-1POSIX\s0\fR in \fI/usr/local/lib/perl5/auto/POSIX/*.al\fR, where
169the \f(CW\*(C`.al\*(C'\fR file has the same name as the subroutine, sans package. If
170such a file exists, \s-1AUTOLOAD\s0 will read and evaluate it,
171thus (presumably) defining the needed subroutine. \s-1AUTOLOAD\s0 will then
172\&\f(CW\*(C`goto\*(C'\fR the newly defined subroutine.
173.PP
174Once this process completes for a given function, it is defined, so
175future calls to the subroutine will bypass the \s-1AUTOLOAD\s0 mechanism.
176.Sh "Subroutine Stubs"
177.IX Subsection "Subroutine Stubs"
178In order for object method lookup and/or prototype checking to operate
179correctly even when methods have not yet been defined it is necessary to
180\&\*(L"forward declare\*(R" each subroutine (as in \f(CW\*(C`sub NAME;\*(C'\fR). See
181\&\*(L"\s-1SYNOPSIS\s0\*(R" in perlsub. Such forward declaration creates \*(L"subroutine
182stubs\*(R", which are place holders with no code.
183.PP
184The AutoSplit and \fBAutoLoader\fR modules automate the creation of forward
185declarations. The AutoSplit module creates an 'index' file containing
186forward declarations of all the AutoSplit subroutines. When the
187AutoLoader module is 'use'd it loads these declarations into its callers
188package.
189.PP
190Because of this mechanism it is important that \fBAutoLoader\fR is always
191\&\f(CW\*(C`use\*(C'\fRd and not \f(CW\*(C`require\*(C'\fRd.
192.Sh "Using \fBAutoLoader\fP's \s-1AUTOLOAD\s0 Subroutine"
193.IX Subsection "Using AutoLoader's AUTOLOAD Subroutine"
194In order to use \fBAutoLoader\fR's \s-1AUTOLOAD\s0 subroutine you \fImust\fR
195explicitly import it:
196.PP
197.Vb 1
198\& use AutoLoader 'AUTOLOAD';
199.Ve
200.Sh "Overriding \fBAutoLoader\fP's \s-1AUTOLOAD\s0 Subroutine"
201.IX Subsection "Overriding AutoLoader's AUTOLOAD Subroutine"
202Some modules, mainly extensions, provide their own \s-1AUTOLOAD\s0 subroutines.
203They typically need to check for some special cases (such as constants)
204and then fallback to \fBAutoLoader\fR's \s-1AUTOLOAD\s0 for the rest.
205.PP
206Such modules should \fInot\fR import \fBAutoLoader\fR's \s-1AUTOLOAD\s0 subroutine.
207Instead, they should define their own \s-1AUTOLOAD\s0 subroutines along these
208lines:
209.PP
210.Vb 2
211\& use AutoLoader;
212\& use Carp;
213.Ve
214.PP
215.Vb 16
216\& sub AUTOLOAD {
217\& my $sub = $AUTOLOAD;
218\& (my $constname = $sub) =~ s/.*:://;
219\& my $val = constant($constname, @_ ? $_[0] : 0);
220\& if ($! != 0) {
221\& if ($! =~ /Invalid/ || $!{EINVAL}) {
222\& $AutoLoader::AUTOLOAD = $sub;
223\& goto &AutoLoader::AUTOLOAD;
224\& }
225\& else {
226\& croak "Your vendor has not defined constant $constname";
227\& }
228\& }
229\& *$sub = sub { $val }; # same as: eval "sub $sub { $val }";
230\& goto &$sub;
231\& }
232.Ve
233.PP
234If any module's own \s-1AUTOLOAD\s0 subroutine has no need to fallback to the
235AutoLoader's \s-1AUTOLOAD\s0 subroutine (because it doesn't have any AutoSplit
236subroutines), then that module should not use \fBAutoLoader\fR at all.
237.Sh "Package Lexicals"
238.IX Subsection "Package Lexicals"
239Package lexicals declared with \f(CW\*(C`my\*(C'\fR in the main block of a package
240using \fBAutoLoader\fR will not be visible to auto-loaded subroutines, due to
241the fact that the given scope ends at the \f(CW\*(C`_\|_END_\|_\*(C'\fR marker. A module
242using such variables as package globals will not work properly under the
243\&\fBAutoLoader\fR.
244.PP
245The \f(CW\*(C`vars\*(C'\fR pragma (see \*(L"vars\*(R" in perlmod) may be used in such
246situations as an alternative to explicitly qualifying all globals with
247the package namespace. Variables pre-declared with this pragma will be
248visible to any autoloaded routines (but will not be invisible outside
249the package, unfortunately).
250.Sh "Not Using AutoLoader"
251.IX Subsection "Not Using AutoLoader"
252You can stop using AutoLoader by simply
253.PP
254.Vb 1
255\& no AutoLoader;
256.Ve
257.Sh "\fBAutoLoader\fP vs. \fBSelfLoader\fP"
258.IX Subsection "AutoLoader vs. SelfLoader"
259The \fBAutoLoader\fR is similar in purpose to \fBSelfLoader\fR: both delay the
260loading of subroutines.
261.PP
262\&\fBSelfLoader\fR uses the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR marker rather than \f(CW\*(C`_\|_END_\|_\*(C'\fR.
263While this avoids the use of a hierarchy of disk files and the
264associated open/close for each routine loaded, \fBSelfLoader\fR suffers a
265startup speed disadvantage in the one-time parsing of the lines after
266\&\f(CW\*(C`_\|_DATA_\|_\*(C'\fR, after which routines are cached. \fBSelfLoader\fR can also
267handle multiple packages in a file.
268.PP
269\&\fBAutoLoader\fR only reads code as it is requested, and in many cases
270should be faster, but requires a mechanism like \fBAutoSplit\fR be used to
271create the individual files. ExtUtils::MakeMaker will invoke
272\&\fBAutoSplit\fR automatically if \fBAutoLoader\fR is used in a module source
273file.
274.SH "CAVEATS"
275.IX Header "CAVEATS"
276AutoLoaders prior to Perl 5.002 had a slightly different interface. Any
277old modules which use \fBAutoLoader\fR should be changed to the new calling
278style. Typically this just means changing a require to a use, adding
279the explicit \f(CW'AUTOLOAD'\fR import if needed, and removing \fBAutoLoader\fR
280from \f(CW@ISA\fR.
281.PP
282On systems with restrictions on file name length, the file corresponding
283to a subroutine may have a shorter name that the routine itself. This
284can lead to conflicting file names. The \fIAutoSplit\fR package warns of
285these potential conflicts when used to split a module.
286.PP
287AutoLoader may fail to find the autosplit files (or even find the wrong
288ones) in cases where \f(CW@INC\fR contains relative paths, \fBand\fR the program
289does \f(CW\*(C`chdir\*(C'\fR.
290.SH "SEE ALSO"
291.IX Header "SEE ALSO"
292SelfLoader \- an autoloader that doesn't use external files.