MAN page from OpenSuSE perl-ExtUtils-Constant-0.25-1.1.noarch.rpm


Section: User Contributed Perl Documentation (3)
Updated: 2017-06-24


ExtUtils::Constant::Base - base class for ExtUtils::Constant objects 


    require ExtUtils::Constant::Base;    @ISA = 'ExtUtils::Constant::Base';


ExtUtils::Constant::Base provides a base implementation of methods togenerate C code to give fast constant value lookup by named string. Currentlyit's mostly used ExtUtils::Constant::XS, which generates the lookup codefor the constant() subroutine found in many XS modules. 


ExtUtils::Constant::Base exports no subroutines. The following methods areavailable
A method returning a scalar containing definitions needed, typically for aC header file.
memEQ_clause args_hashref
A method to return a suitable C "if" statement to check whether nameis equal to the C variable "name". If checked_at is defined, then itis used to avoid "memEQ" for short names, or to generate a comment tohighlight the position of the character in the "switch" statement.

If i<checked_at> is a reference to a scalar, then instead it givesthe characters pre-checked at the beginning, (and the number of chars bywhich the C variable name has been advanced. These need to be chopped fromthe front of name).

dump_names arg_hashref, ITEM...
An internal function to generate the embedded perl code that will regeneratethe constant subroutines. default_type, types and ITEMs are thesame as for C_constant. indent is treated as number of spaces to indentby. If "declare_types" is true a $types is always declared in the perlcode generated, if defined and false never declared, and if undefined $typesis only declared if the values in types as passed in cannot be inferred fromdefault_types and the ITEMs.
assign arg_hashref, VALUE...
A method to return a suitable assignment clause. If type is aggregate(eg PVN expects both pointer and length) then there should be multipleVALUEs for the components. pre and post if defined give snippetsof C code to proceed and follow the assignment. pre will be at the startof a block, so variables may be defined in it.
return_clause arg_hashref, ITEM
A method to return a suitable "#ifdef" clause. ITEM is a hashref(as passed to "C_constant" and "match_clause". indent is the numberof spaces to indent, defaulting to 6.
switch_clause arg_hashref, NAMELEN, ITEMHASH, ITEM...
An internal method to generate a suitable "switch" clause, called by"C_constant" ITEMs are in the hash ref format as given in the descriptionof "C_constant", and must all have the names of the same length, given byNAMELEN. ITEMHASH is a reference to a hash, keyed by name, values beingthe hashrefs in the ITEM list. (No parameters are modified, and there canbe keys in the ITEMHASH that are not in the list of ITEMs withoutcausing problems - the hash is passed in to save generating it afresh foreach call).
params WHAT
An ``internal'' method, subject to change, currently called to allow anoverriding class to cache information that will then be passed into allthe "*param*" calls. (Yes, having to read the source to make sense of this isconsidered a known bug). WHAT is be a hashref of types the constantfunction will return. In ExtUtils::Constant::XS this method is used toreturns a hashref keyed IV NV PV SV to show which combination of pointers willbe needed in the C argument list generated byC_constant_other_params_definition and C_constant_other_params
dogfood arg_hashref, ITEM...
An internal function to generate the embedded perl code that will regeneratethe constant subroutines. Parameters are the same as for C_constant.

Currently the base class does nothing and returns an empty string.

normalise_items args, default_type, seen_types, seen_items, ITEM...
Convert the items to a normalised form. For 8 bit and Unicode values convertsthe item to an array of 1 or 2 items, both 8 bit and UTF-8 encoded.
C_constant arg_hashref, ITEM...
A function that returns a list of C subroutine definitions that returnthe value and type of constants when passed the name by the XS wrapper.ITEM... gives a list of constant names. Each can either be a string,which is taken as a C macro name, or a reference to a hash with the followingkeys
The name of the constant, as seen by the perl code.
The type of the constant (IV, NV etc)
A C expression for the value of the constant, or a list of C expressions ifthe type is aggregate. This defaults to the name if not given.
The C pre-processor macro to use in the "#ifdef". This defaults to thename, and is mainly used if value is an "enum". If a reference anarray is passed then the first element is used in place of the "#ifdef"line, and the second element in place of the "#endif". This allowspre-processor constructions such as

    #if defined (foo)    #if !defined (bar)    ...    #endif    #endif

to be used to determine if a constant is to be defined.

A ``macro'' 1 signals that the constant is always defined, so the "#if"/"#endif"test is omitted.

Default value to use (instead of "croak"ing with ``your vendor has notdefined...'') to return if the macro isn't defined. Specify a reference toan array with type followed by value(s).
C code to use before the assignment of the value of the constant. This allowsyou to use temporary variables to extract a value from part of a "struct"and return this as value. This C code is places at the start of a block,so you can declare variables in it.
C code to place between the assignment of value (to a temporary) and thereturn from the function. This allows you to clear up anything in pre.Rarely needed.
Equivalents of pre and post for the default value.
Generated internally. Is zero or undefined if name is 7 bit ASCII,``no'' if the name is 8 bit (and so should only match if SvUTF8() is false),``yes'' if the name is utf8 encoded.

The internals automatically clone any name with characters 128-255 but none256+ (ie one that could be either in bytes or utf8) into a second entrywhich is utf8 encoded.

Optional sorting weight for names, to determine the order oflinear testing when multiple names fall in the same case of a switch clause.Higher comes earlier, undefined defaults to zero.

In the argument hashref, package is the name of the package, and is onlyused in comments inside the generated C code. subname defaults to"constant" if undefined.

default_type is the type returned by "ITEM"s that don't specify theirtype. It defaults to the value of "default_type()". types should be giveneither as a comma separated list of types that the C subroutine subnamewill generate or as a reference to a hash. default_type will be added tothe list if not present, as will any types given in the list of ITEMs. Theresultant list should be the same list of types that "XS_constant" isgiven. [Otherwise "XS_constant" and "C_constant" may differ in the number ofparameters to the constant function. indent is currently unused andignored. In future it may be used to pass in information used to change the Cindentation style used.] The best way to maintain consistency is to pass in ahash reference and let this function update it.

breakout governs when child functions of subname are generated. If thereare breakout or more ITEMs with the same length of name, then the codeto switch between them is placed into a function named subname_len, forexample "constant_5" for names 5 characters long. The default breakout is3. A single "ITEM" is always inlined.



Not everything is documented yet.

Probably others. 


Nicholas Clark <> based on the code in "h2xs" by Larry Wall andothers




This document was created byman2html,using the manual pages.