Debian Codegraph @

upstream/opensuse-tumbleweed/man3/ExtUtils::Constant::Base.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "ExtUtils::Constant::Base 3pm"
61 .TH ExtUtils::Constant::Base 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 ExtUtils::Constant::Base \- base class for ExtUtils::Constant objects
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 2
71 \& require ExtUtils::Constant::Base;
72 \& @ISA = \*(AqExtUtils::Constant::Base\*(Aq;
73 .Ve
74 .SH DESCRIPTION
75 .IX Header "DESCRIPTION"
76 ExtUtils::Constant::Base provides a base implementation of methods to
77 generate C code to give fast constant value lookup by named string. Currently
78 it\*(Aqs mostly used ExtUtils::Constant::XS, which generates the lookup code
79 for the \fBconstant()\fR subroutine found in many XS modules.
80 .SH USAGE
81 .IX Header "USAGE"
82 ExtUtils::Constant::Base exports no subroutines. The following methods are
83 available
84 .IP header 4
85 .IX Item "header"
86 A method returning a scalar containing definitions needed, typically for a
87 C header file.
88 .IP "memEQ_clause args_hashref" 4
89 .IX Item "memEQ_clause args_hashref"
90 A method to return a suitable C \f(CW\*(C`if\*(C'\fR statement to check whether \fIname\fR
91 is equal to the C variable \f(CW\*(C`name\*(C'\fR. If \fIchecked_at\fR is defined, then it
92 is used to avoid \f(CW\*(C`memEQ\*(C'\fR for short names, or to generate a comment to
93 highlight the position of the character in the \f(CW\*(C`switch\*(C'\fR statement.
94 .Sp
95 If i<checked_at> is a reference to a scalar, then instead it gives
96 the characters pre\-checked at the beginning, (and the number of chars by
97 which the C variable name has been advanced. These need to be chopped from
98 the front of \fIname\fR).
99 .IP "dump_names arg_hashref, ITEM..." 4
100 .IX Item "dump_names arg_hashref, ITEM..."
101 An internal function to generate the embedded perl code that will regenerate
102 the constant subroutines. \fIdefault_type\fR, \fItypes\fR and \fIITEM\fRs are the
103 same as for C_constant. \fIindent\fR is treated as number of spaces to indent
104 by. If \f(CW\*(C`declare_types\*(C'\fR is true a \f(CW$types\fR is always declared in the perl
105 code generated, if defined and false never declared, and if undefined \f(CW$types\fR
106 is only declared if the values in \fItypes\fR as passed in cannot be inferred from
107 \&\fIdefault_types\fR and the \fIITEM\fRs.
108 .IP "assign arg_hashref, VALUE..." 4
109 .IX Item "assign arg_hashref, VALUE..."
110 A method to return a suitable assignment clause. If \fItype\fR is aggregate
111 (eg \fIPVN\fR expects both pointer and length) then there should be multiple
112 \&\fIVALUE\fRs for the components. \fIpre\fR and \fIpost\fR if defined give snippets
113 of C code to proceed and follow the assignment. \fIpre\fR will be at the start
114 of a block, so variables may be defined in it.
115 .IP "return_clause arg_hashref, ITEM" 4
116 .IX Item "return_clause arg_hashref, ITEM"
117 A method to return a suitable \f(CW\*(C`#ifdef\*(C'\fR clause. \fIITEM\fR is a hashref
118 (as passed to \f(CW\*(C`C_constant\*(C'\fR and \f(CW\*(C`match_clause\*(C'\fR. \fIindent\fR is the number
119 of spaces to indent, defaulting to 6.
120 .IP "switch_clause arg_hashref, NAMELEN, ITEMHASH, ITEM..." 4
121 .IX Item "switch_clause arg_hashref, NAMELEN, ITEMHASH, ITEM..."
122 An internal method to generate a suitable \f(CW\*(C`switch\*(C'\fR clause, called by
123 \&\f(CW\*(C`C_constant\*(C'\fR \fIITEM\fRs are in the hash ref format as given in the description
124 of \f(CW\*(C`C_constant\*(C'\fR, and must all have the names of the same length, given by
125 \&\fINAMELEN\fR. \fIITEMHASH\fR is a reference to a hash, keyed by name, values being
126 the hashrefs in the \fIITEM\fR list. (No parameters are modified, and there can
127 be keys in the \fIITEMHASH\fR that are not in the list of \fIITEM\fRs without
128 causing problems \- the hash is passed in to save generating it afresh for
129 each call).
130 .IP "params WHAT" 4
131 .IX Item "params WHAT"
132 An "internal" method, subject to change, currently called to allow an
133 overriding class to cache information that will then be passed into all
134 the \f(CW\*(C`*param*\*(C'\fR calls. (Yes, having to read the source to make sense of this is
135 considered a known bug). \fIWHAT\fR is be a hashref of types the constant
136 function will return. In ExtUtils::Constant::XS this method is used to
137 returns a hashref keyed IV NV PV SV to show which combination of pointers will
138 be needed in the C argument list generated by
139 C_constant_other_params_definition and C_constant_other_params
140 .IP "dogfood arg_hashref, ITEM..." 4
141 .IX Item "dogfood arg_hashref, ITEM..."
142 An internal function to generate the embedded perl code that will regenerate
143 the constant subroutines. Parameters are the same as for C_constant.
144 .Sp
145 Currently the base class does nothing and returns an empty string.
146 .IP "normalise_items args, default_type, seen_types, seen_items, ITEM..." 4
147 .IX Item "normalise_items args, default_type, seen_types, seen_items, ITEM..."
148 Convert the items to a normalised form. For 8 bit and Unicode values converts
149 the item to an array of 1 or 2 items, both 8 bit and UTF\-8 encoded.
150 .IP "C_constant arg_hashref, ITEM..." 4
151 .IX Item "C_constant arg_hashref, ITEM..."
152 A function that returns a \fBlist\fR of C subroutine definitions that return
153 the value and type of constants when passed the name by the XS wrapper.
154 \&\fIITEM...\fR gives a list of constant names. Each can either be a string,
155 which is taken as a C macro name, or a reference to a hash with the following
156 keys
157 .RS 4
158 .IP name 8
159 .IX Item "name"
160 The name of the constant, as seen by the perl code.
161 .IP type 8
162 .IX Item "type"
163 The type of the constant (\fIIV\fR, \fINV\fR etc)
164 .IP value 8
165 .IX Item "value"
166 A C expression for the value of the constant, or a list of C expressions if
167 the type is aggregate. This defaults to the \fIname\fR if not given.
168 .IP macro 8
169 .IX Item "macro"
170 The C pre\-processor macro to use in the \f(CW\*(C`#ifdef\*(C'\fR. This defaults to the
171 \&\fIname\fR, and is mainly used if \fIvalue\fR is an \f(CW\*(C`enum\*(C'\fR. If a reference an
172 array is passed then the first element is used in place of the \f(CW\*(C`#ifdef\*(C'\fR
173 line, and the second element in place of the \f(CW\*(C`#endif\*(C'\fR. This allows
174 pre\-processor constructions such as
175 .Sp
176 .Vb 5
177 \& #if defined (foo)
178 \& #if !defined (bar)
179 \& ...
180 \& #endif
181 \& #endif
182 .Ve
183 .Sp
184 to be used to determine if a constant is to be defined.
185 .Sp
186 A "macro" 1 signals that the constant is always defined, so the \f(CW\*(C`#if\*(C'\fR/\f(CW\*(C`#endif\*(C'\fR
187 test is omitted.
188 .IP default 8
189 .IX Item "default"
190 Default value to use (instead of \f(CW\*(C`croak\*(C'\fRing with "your vendor has not
191 defined...") to return if the macro isn\*(Aqt defined. Specify a reference to
192 an array with type followed by value(s).
193 .IP pre 8
194 .IX Item "pre"
195 C code to use before the assignment of the value of the constant. This allows
196 you to use temporary variables to extract a value from part of a \f(CW\*(C`struct\*(C'\fR
197 and return this as \fIvalue\fR. This C code is places at the start of a block,
198 so you can declare variables in it.
199 .IP post 8
200 .IX Item "post"
201 C code to place between the assignment of value (to a temporary) and the
202 return from the function. This allows you to clear up anything in \fIpre\fR.
203 Rarely needed.
204 .IP def_pre 8
205 .IX Item "def_pre"
206 .PD 0
207 .IP def_post 8
208 .IX Item "def_post"
209 .PD
210 Equivalents of \fIpre\fR and \fIpost\fR for the default value.
211 .IP utf8 8
212 .IX Item "utf8"
213 Generated internally. Is zero or undefined if name is 7 bit ASCII,
214 "no" if the name is 8 bit (and so should only match if \fBSvUTF8()\fR is false),
215 "yes" if the name is utf8 encoded.
216 .Sp
217 The internals automatically clone any name with characters 128\-255 but none
218 256+ (ie one that could be either in bytes or utf8) into a second entry
219 which is utf8 encoded.
220 .IP weight 8
221 .IX Item "weight"
222 Optional sorting weight for names, to determine the order of
223 linear testing when multiple names fall in the same case of a switch clause.
224 Higher comes earlier, undefined defaults to zero.
225 .RE
226 .RS 4
227 .Sp
228 In the argument hashref, \fIpackage\fR is the name of the package, and is only
229 used in comments inside the generated C code. \fIsubname\fR defaults to
230 \&\f(CW\*(C`constant\*(C'\fR if undefined.
231 .Sp
232 \&\fIdefault_type\fR is the type returned by \f(CW\*(C`ITEM\*(C'\fRs that don\*(Aqt specify their
233 type. It defaults to the value of \f(CWdefault_type()\fR. \fItypes\fR should be given
234 either as a comma separated list of types that the C subroutine \fIsubname\fR
235 will generate or as a reference to a hash. \fIdefault_type\fR will be added to
236 the list if not present, as will any types given in the list of \fIITEM\fRs. The
237 resultant list should be the same list of types that \f(CW\*(C`XS_constant\*(C'\fR is
238 given. [Otherwise \f(CW\*(C`XS_constant\*(C'\fR and \f(CW\*(C`C_constant\*(C'\fR may differ in the number of
239 parameters to the constant function. \fIindent\fR is currently unused and
240 ignored. In future it may be used to pass in information used to change the C
241 indentation style used.] The best way to maintain consistency is to pass in a
242 hash reference and let this function update it.
243 .Sp
244 \&\fIbreakout\fR governs when child functions of \fIsubname\fR are generated. If there
245 are \fIbreakout\fR or more \fIITEM\fRs with the same length of name, then the code
246 to switch between them is placed into a function named \fIsubname\fR_\fIlen\fR, for
247 example \f(CW\*(C`constant_5\*(C'\fR for names 5 characters long. The default \fIbreakout\fR is
248 3. A single \f(CW\*(C`ITEM\*(C'\fR is always inlined.
249 .RE
250 .SH BUGS
251 .IX Header "BUGS"
252 Not everything is documented yet.
253 .PP
254 Probably others.
255 .SH AUTHOR
256 .IX Header "AUTHOR"
257 Nicholas Clark <[email protected]> based on the code in \f(CW\*(C`h2xs\*(C'\fR by Larry Wall and
258 others