Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / man / man3 / SelfLoader.3
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
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 "SelfLoader 3"
132.TH SelfLoader 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134SelfLoader \- load functions only on demand
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 2
138\& package FOOBAR;
139\& use SelfLoader;
140.Ve
141.PP
142.Vb 1
143\& ... (initializing code)
144.Ve
145.PP
146.Vb 2
147\& __DATA__
148\& sub {....
149.Ve
150.SH "DESCRIPTION"
151.IX Header "DESCRIPTION"
152This module tells its users that functions in the \s-1FOOBAR\s0 package are to be
153autoloaded from after the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR token. See also
154\&\*(L"Autoloading\*(R" in perlsub.
155.Sh "The _\|_DATA_\|_ token"
156.IX Subsection "The __DATA__ token"
157The \f(CW\*(C`_\|_DATA_\|_\*(C'\fR token tells the perl compiler that the perl code
158for compilation is finished. Everything after the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR token
159is available for reading via the filehandle \s-1FOOBAR::DATA\s0,
160where \s-1FOOBAR\s0 is the name of the current package when the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR
161token is reached. This works just the same as \f(CW\*(C`_\|_END_\|_\*(C'\fR does in
162package 'main', but for other modules data after \f(CW\*(C`_\|_END_\|_\*(C'\fR is not
163automatically retrievable, whereas data after \f(CW\*(C`_\|_DATA_\|_\*(C'\fR is.
164The \f(CW\*(C`_\|_DATA_\|_\*(C'\fR token is not recognized in versions of perl prior to
1655.001m.
166.PP
167Note that it is possible to have \f(CW\*(C`_\|_DATA_\|_\*(C'\fR tokens in the same package
168in multiple files, and that the last \f(CW\*(C`_\|_DATA_\|_\*(C'\fR token in a given
169package that is encountered by the compiler is the one accessible
170by the filehandle. This also applies to \f(CW\*(C`_\|_END_\|_\*(C'\fR and main, i.e. if
171the 'main' program has an \f(CW\*(C`_\|_END_\|_\*(C'\fR, but a module 'require'd (_not_ 'use'd)
172by that program has a 'package main;' declaration followed by an '\f(CW\*(C`_\|_DATA_\|_\*(C'\fR',
173then the \f(CW\*(C`DATA\*(C'\fR filehandle is set to access the data after the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR
174in the module, _not_ the data after the \f(CW\*(C`_\|_END_\|_\*(C'\fR token in the 'main'
175program, since the compiler encounters the 'require'd file later.
176.Sh "SelfLoader autoloading"
177.IX Subsection "SelfLoader autoloading"
178The \fBSelfLoader\fR works by the user placing the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR
179token \fIafter\fR perl code which needs to be compiled and
180run at 'require' time, but \fIbefore\fR subroutine declarations
181that can be loaded in later \- usually because they may never
182be called.
183.PP
184The \fBSelfLoader\fR will read from the \s-1FOOBAR::DATA\s0 filehandle to
185load in the data after \f(CW\*(C`_\|_DATA_\|_\*(C'\fR, and load in any subroutine
186when it is called. The costs are the one-time parsing of the
187data after \f(CW\*(C`_\|_DATA_\|_\*(C'\fR, and a load delay for the _first_
188call of any autoloaded function. The benefits (hopefully)
189are a speeded up compilation phase, with no need to load
190functions which are never used.
191.PP
192The \fBSelfLoader\fR will stop reading from \f(CW\*(C`_\|_DATA_\|_\*(C'\fR if
193it encounters the \f(CW\*(C`_\|_END_\|_\*(C'\fR token \- just as you would expect.
194If the \f(CW\*(C`_\|_END_\|_\*(C'\fR token is present, and is followed by the
195token \s-1DATA\s0, then the \fBSelfLoader\fR leaves the \s-1FOOBAR::DATA\s0
196filehandle open on the line after that token.
197.PP
198The \fBSelfLoader\fR exports the \f(CW\*(C`AUTOLOAD\*(C'\fR subroutine to the
199package using the \fBSelfLoader\fR, and this loads the called
200subroutine when it is first called.
201.PP
202There is no advantage to putting subroutines which will _always_
203be called after the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR token.
204.Sh "Autoloading and package lexicals"
205.IX Subsection "Autoloading and package lexicals"
206A 'my \f(CW$pack_lexical\fR' statement makes the variable \f(CW$pack_lexical\fR
207local _only_ to the file up to the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR token. Subroutines
208declared elsewhere _cannot_ see these types of variables,
209just as if you declared subroutines in the package but in another
210file, they cannot see these variables.
211.PP
212So specifically, autoloaded functions cannot see package
213lexicals (this applies to both the \fBSelfLoader\fR and the Autoloader).
214The \f(CW\*(C`vars\*(C'\fR pragma provides an alternative to defining package-level
215globals that will be visible to autoloaded routines. See the documentation
216on \fBvars\fR in the pragma section of perlmod.
217.Sh "SelfLoader and AutoLoader"
218.IX Subsection "SelfLoader and AutoLoader"
219The \fBSelfLoader\fR can replace the AutoLoader \- just change 'use AutoLoader'
220to 'use SelfLoader' (though note that the \fBSelfLoader\fR exports
221the \s-1AUTOLOAD\s0 function \- but if you have your own \s-1AUTOLOAD\s0 and
222are using the AutoLoader too, you probably know what you're doing),
223and the \f(CW\*(C`_\|_END_\|_\*(C'\fR token to \f(CW\*(C`_\|_DATA_\|_\*(C'\fR. You will need perl version 5.001m
224or later to use this (version 5.001 with all patches up to patch m).
225.PP
226There is no need to inherit from the \fBSelfLoader\fR.
227.PP
228The \fBSelfLoader\fR works similarly to the AutoLoader, but picks up the
229subs from after the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR instead of in the 'lib/auto' directory.
230There is a maintenance gain in not needing to run AutoSplit on the module
231at installation, and a runtime gain in not needing to keep opening and
232closing files to load subs. There is a runtime loss in needing
233to parse the code after the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR. Details of the \fBAutoLoader\fR and
234another view of these distinctions can be found in that module's
235documentation.
236.Sh "_\|_DATA_\|_, _\|_END_\|_, and the \s-1FOOBAR::DATA\s0 filehandle."
237.IX Subsection "__DATA__, __END__, and the FOOBAR::DATA filehandle."
238This section is only relevant if you want to use
239the \f(CW\*(C`FOOBAR::DATA\*(C'\fR together with the \fBSelfLoader\fR.
240.PP
241Data after the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR token in a module is read using the
242\&\s-1FOOBAR::DATA\s0 filehandle. \f(CW\*(C`_\|_END_\|_\*(C'\fR can still be used to denote the end
243of the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR section if followed by the token \s-1DATA\s0 \- this is supported
244by the \fBSelfLoader\fR. The \f(CW\*(C`FOOBAR::DATA\*(C'\fR filehandle is left open if an
245\&\f(CW\*(C`_\|_END_\|_\*(C'\fR followed by a \s-1DATA\s0 is found, with the filehandle positioned at
246the start of the line after the \f(CW\*(C`_\|_END_\|_\*(C'\fR token. If no \f(CW\*(C`_\|_END_\|_\*(C'\fR token is
247present, or an \f(CW\*(C`_\|_END_\|_\*(C'\fR token with no \s-1DATA\s0 token on the same line, then
248the filehandle is closed.
249.PP
250The \fBSelfLoader\fR reads from wherever the current
251position of the \f(CW\*(C`FOOBAR::DATA\*(C'\fR filehandle is, until the
252\&\s-1EOF\s0 or \f(CW\*(C`_\|_END_\|_\*(C'\fR. This means that if you want to use
253that filehandle (and \s-1ONLY\s0 if you want to), you should either
254.PP
2551. Put all your subroutine declarations immediately after
256the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR token and put your own data after those
257declarations, using the \f(CW\*(C`_\|_END_\|_\*(C'\fR token to mark the end
258of subroutine declarations. You must also ensure that the \fBSelfLoader\fR
259reads first by calling 'SelfLoader\->\fIload_stubs()\fR;', or by using a
260function which is selfloaded;
261.PP
262or
263.PP
2642. You should read the \f(CW\*(C`FOOBAR::DATA\*(C'\fR filehandle first, leaving
265the handle open and positioned at the first line of subroutine
266declarations.
267.PP
268You could conceivably do both.
269.Sh "Classes and inherited methods."
270.IX Subsection "Classes and inherited methods."
271For modules which are not classes, this section is not relevant.
272This section is only relevant if you have methods which could
273be inherited.
274.PP
275A subroutine stub (or forward declaration) looks like
276.PP
277.Vb 1
278\& sub stub;
279.Ve
280.PP
281i.e. it is a subroutine declaration without the body of the
282subroutine. For modules which are not classes, there is no real
283need for stubs as far as autoloading is concerned.
284.PP
285For modules which \s-1ARE\s0 classes, and need to handle inherited methods,
286stubs are needed to ensure that the method inheritance mechanism works
287properly. You can load the stubs into the module at 'require' time, by
288adding the statement 'SelfLoader\->\fIload_stubs()\fR;' to the module to do
289this.
290.PP
291The alternative is to put the stubs in before the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR token \s-1BEFORE\s0
292releasing the module, and for this purpose the \f(CW\*(C`Devel::SelfStubber\*(C'\fR
293module is available. However this does require the extra step of ensuring
294that the stubs are in the module. If this is done I strongly recommend
295that this is done \s-1BEFORE\s0 releasing the module \- it should \s-1NOT\s0 be done
296at install time in general.
297.SH "Multiple packages and fully qualified subroutine names"
298.IX Header "Multiple packages and fully qualified subroutine names"
299Subroutines in multiple packages within the same file are supported \- but you
300should note that this requires exporting the \f(CW\*(C`SelfLoader::AUTOLOAD\*(C'\fR to
301every package which requires it. This is done automatically by the
302\&\fBSelfLoader\fR when it first loads the subs into the cache, but you should
303really specify it in the initialization before the \f(CW\*(C`_\|_DATA_\|_\*(C'\fR by putting
304a 'use SelfLoader' statement in each package.
305.PP
306Fully qualified subroutine names are also supported. For example,
307.PP
308.Vb 4
309\& __DATA__
310\& sub foo::bar {23}
311\& package baz;
312\& sub dob {32}
313.Ve
314.PP
315will all be loaded correctly by the \fBSelfLoader\fR, and the \fBSelfLoader\fR
316will ensure that the packages 'foo' and 'baz' correctly have the
317\&\fBSelfLoader\fR \f(CW\*(C`AUTOLOAD\*(C'\fR method when the data after \f(CW\*(C`_\|_DATA_\|_\*(C'\fR is first
318parsed.