Generates XS code to import C header constants, allowing Perl modules to AUTOLOAD constants defined in C library header files. Generally, you should not touch ExtUtils::Constant functions, since they are already implemented by h2xs.
For example:
use ExtUtils::Constant qw (WriteConstants); WriteConstants( NAME => `Nate', NAMES => [qw(Nate Nathan Nathaniel)], # not Nat ); # Generates wrapper code to make the values of the constants # Nate Nathan Nathaniel available to perl
Currently, this module understands the following types, although h2xs may only know a subset. The sizes of the numeric types are chosen by the Configure script at compile time.
ExtUtils::Constant implements the following functions.
assign |
assign indent, type, pre, post, value ...
Returns a suitable assignment clause. If type is aggregate (e.g., PVN expects both pointer and length), then there should be multiple values for the components. pre and post, if defined, give snippets of C code to proceed and follow the assignment. preis at the start of a block, so variables may be defined in it.
autoload |
autoload package, version, autoloader
Generates the AUTOLOAD subroutine for the module package. version is the Perl version with which the code should be backwards-compatible. It defaults to the version of Perl running the subroutine. If autoloaderis true, the AUTOLOAD subroutine falls back on AutoLoader::AUTOLOAD for all names that the constant() routine doesn't recognize.
C_constant |
C_constant package, subname, default_type, types, indent, breakout, item ...
Returns a list of C subroutine definitions that return the value and type of constants when passed the name by the XS wrapper. item... gives a list of constant names. These can be strings, which are taken as a C macro name, or references to a hash with the following keys:
#if defined (foo) #if !defined (bar) ... #endif #endif
which are used to determine if a constant will be defined.
A macro of 1 signals that the constant is always defined, so the #if/#endif test is omitted.
constant_types |
constant_types
Returns a single scalar with #define definitions for the constants used internally between the generated C and XS functions.
C_stringify |
C_stringify name
Returns a 7-bit ASCII correctly \-escaped version of the string passed. Suitable for C "" or ''. It will die if passed Unicode characters.
dump_names |
dump_names default_type, types, indent, options, item ...
An internal function to generate the embedded Perl code to regenerate the constant subroutines. default_type, types, and items are the same as for C_constant. indent is the number of spaces to indent. options is a hashref of options; currently, only declare_types is recognized. If the value is true, a types is always declared in the generated Perl code; if defined and false, one is never declared; and if undefined, types is declared only if the values in types as passed in cannot be inferred from default_types and the items.
memEQ_clause |
memEQ_clause name, checked_at, indent
Returns a suitable C if statement to check whether name is equal to the C variable name. If checked_at is defined, then it is used to avoid memEQ for short names.
params |
params what
An internal function. what should be a hashref of types the constant function will return. params returns a hashref keyed IV NV PV SV to show which combination of pointers will be needed in the C argument list.
perl_stringify |
perl_stringify name
Returns a 7-bit ASCII correctly \-escaped version of the string passed. Suitable for a Perl "" string.
return_clause |
return_clause item, indent
Returns a suitable #ifdef clause. item is a hashref passed to C_constant and match_clause. indent is the number of spaces to indent; defaulting is 6.
switch_clause |
switch_clause indent, namelen, itemhash, item ...
An internal function to generate a suitable switch clause, called by C_constant. items are in the hashref format as given in the description of C_constant and must all have names of the same length, given by namelen. itemhash is a reference to a hash, keyed by name, with values as the hashrefs in the item list.
XS_constant |
XS_constant package, types, subname, c_subname
Generates the XS code to implement the Perl subroutine package::constant used by package::AUTOLOAD to load constants. This XS code is a wrapper around a C subroutine usually generated by C_constant and usually named constant
types should be given either as a comma-separated list of types that the C subroutine constant will generate or as a reference to a hash. It should be the same list of types that C_constant was given. Otherwise, XS_constant and C_constant may have different ideas about the number of parameters passed to the C function constant.
You can call the Perl visible subroutine something other than "constant" if you give the parameter subname. The C subroutine it calls defaults to the name of the Perl visible subroutine, unless you give the parameter c_subname.
Copyright © 2002 O'Reilly & Associates. All rights reserved.