ExtUtils::Constant - generate XS code to import C header constants
use ExtUtils::Constant qw (WriteConstants);WriteConstants( NAME => 'Foo', NAMES => [qw(FOO BAR BAZ)],);# Generates wrapper code to make the values of the constants FOO BAR BAZ# available to perlExtUtils::Constant facilitates generating C and XS wrapper code to allow perl modules to AUTOLOAD constants defined in C library header files. It is principally used by theh2xs utility, on which this code is based. It doesn't contain the routines to scan header files to extract these constants.
Generally one only needs to call theWriteConstants function, and then
#include "const-c.inc"in the C section ofFoo.xs
INCLUDE: const-xs.incin the XS section ofFoo.xs.
For greater flexibility useconstant_types(),C_constant andXS_constant, with whichWriteConstants is implemented.
Currently this module understands the following types. h2xs may only know a subset. The sizes of the numeric types are chosen by theConfigure script at compile time.
signed integer, at least 32 bits.
unsigned integer, the same size asIV
floating point type, probablydouble, possiblylong double
NUL terminated string, length will be determined withstrlen
A fixed length thing, given as a [pointer, length] pair. If you know the length of a string at compile time you may use this instead ofPV
Amortal SV.
Truth. (PL_sv_yes) The value is not needed (and ignored).
Defined Falsehood. (PL_sv_no) The value is not needed (and ignored).
undef. The value of the macro is not needed.
A function returning a single scalar with#define definitions for the constants used internally between the generated C and XS functions.
A function to generate the XS code to implement the perl subroutinePACKAGE::constant used byPACKAGE::AUTOLOAD to load constants. This XS code is a wrapper around a C subroutine usually generated byC_constant, and usually namedconstant.
TYPES should be given either as a comma separated list of types that the C subroutineconstant will generate or as a reference to a hash. It should be the same list of types asC_constant was given. [OtherwiseXS_constant andC_constant may have different ideas about the number of parameters passed to the C functionconstant]
You can call the perl visible subroutine something other thanconstant if you give the parameterXS_SUBNAME. The C subroutine it calls defaults to the name of the perl visible subroutine, unless you give the parameterC_SUBNAME.
A function to generate the AUTOLOAD subroutine for the modulePACKAGEVERSION is the perl version the code should be backwards compatible with. It defaults to the version of perl running the subroutine. IfAUTOLOADER is true, the AUTOLOAD subroutine falls back on AutoLoader::AUTOLOAD for all names that the constant() routine doesn't recognise.
WriteMakefileSnippet ATTRIBUTE => VALUE [, ...]
A function to generate perl code for Makefile.PL that will regenerate the constant subroutines. Parameters are named as passed toWriteConstants, with the addition ofINDENT to specify the number of leading spaces (default 2).
Currently onlyINDENT,NAME,DEFAULT_TYPE,NAMES,C_FILE andXS_FILE are recognised.
Writes a file of C code and a file of XS code which you should#include andINCLUDE in the C and XS sections respectively of your module's XS code. You probably want to do this in yourMakefile.PL, so that you can easily edit the list of constants without touching the rest of your module. The attributes supported are
Name of the module. This must be specified
The default type for the constants. If not specifiedIV is assumed.
The names of the constants are grouped by length. Generate child subroutines for each group with this number or more names in.
An array of constants' names, either scalars containing names, or hashrefs as detailed in"C_constant".
If true, uses proxy subs. SeeExtUtils::Constant::ProxySubs.
A filehandle to write the C code to. If not given, thenC_FILE is opened for writing.
The name of the file to write containing the C code. The default isconst-c.inc. The- in the name ensures that the file can't be mistaken for anything related to a legitimate perl package name, and not naming the file.c avoids having to override Makefile.PL's.xs to.c rules.
A filehandle to write the XS code to. If not given, thenXS_FILE is opened for writing.
The name of the file to write containing the XS code. The default isconst-xs.inc.
The perl visible name of the XS subroutine generated which will return the constants. The default isconstant.
The name of the C subroutine generated which will return the constants. The default isXS_SUBNAME. Child subroutines have_ and the name length appended, so constants with 10 character names would be inconstant_10 with the defaultXS_SUBNAME.
Nicholas Clark <nick@ccl4.org> based on the code inh2xs by Larry Wall and others
Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.
The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.