{
    "mode": "perldoc",
    "parameter": "ExtUtils::Constant",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/ExtUtils%3A%3AConstant/json",
    "generated": "2026-06-12T19:50:19Z",
    "synopsis": "use ExtUtils::Constant qw (WriteConstants);\nWriteConstants(\nNAME => 'Foo',\nNAMES => [qw(FOO BAR BAZ)],\n);\n# Generates wrapper code to make the values of the constants FOO BAR BAZ\n#  available to perl",
    "sections": {
        "NAME": {
            "content": "ExtUtils::Constant - generate XS code to import C header constants\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use ExtUtils::Constant qw (WriteConstants);\nWriteConstants(\nNAME => 'Foo',\nNAMES => [qw(FOO BAR BAZ)],\n);\n# Generates wrapper code to make the values of the constants FOO BAR BAZ\n#  available to perl\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "ExtUtils::Constant facilitates generating C and XS wrapper code to allow perl modules to\nAUTOLOAD constants defined in C library header files. It is principally used by the \"h2xs\"\nutility, on which this code is based. It doesn't contain the routines to scan header files to\nextract these constants.\n",
            "subsections": []
        },
        "USAGE": {
            "content": "Generally one only needs to call the \"WriteConstants\" function, and then\n\n#include \"const-c.inc\"\n\nin the C section of \"Foo.xs\"\n\nINCLUDE: const-xs.inc\n\nin the XS section of \"Foo.xs\".\n\nFor greater flexibility use \"constanttypes()\", \"Cconstant\" and \"XSconstant\", with which\n\"WriteConstants\" is implemented.\n\nCurrently this module understands the following types. h2xs may only know a subset. The sizes of\nthe numeric types are chosen by the \"Configure\" script at compile time.\n\nIV  signed integer, at least 32 bits.\n\nUV  unsigned integer, the same size as *IV*\n\nNV  floating point type, probably \"double\", possibly \"long double\"\n\nPV  NUL terminated string, length will be determined with \"strlen\"\n\nPVN A fixed length thing, given as a [pointer, length] pair. If you know the length of a string\nat compile time you may use this instead of *PV*\n\nSV  A mortal SV.\n\nYES Truth. (\"PLsvyes\") The value is not needed (and ignored).\n\nNO  Defined Falsehood. (\"PLsvno\") The value is not needed (and ignored).\n\nUNDEF\n\"undef\". The value of the macro is not needed.\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "constanttypes\nA function returning a single scalar with \"#define\" definitions for the constants used\ninternally between the generated C and XS functions.\n\nXSconstant PACKAGE, TYPES, XSSUBNAME, CSUBNAME\nA function to generate the XS code to implement the perl subroutine *PACKAGE*::constant used\nby *PACKAGE*::AUTOLOAD to load constants. This XS code is a wrapper around a C subroutine\nusually generated by \"Cconstant\", and usually named \"constant\".\n\n*TYPES* should be given either as a comma separated list of types that the C subroutine\n\"constant\" will generate or as a reference to a hash. It should be the same list of types as\n\"Cconstant\" was given. [Otherwise \"XSconstant\" and \"Cconstant\" may have different ideas\nabout the number of parameters passed to the C function \"constant\"]\n\nYou can call the perl visible subroutine something other than \"constant\" if you give the\nparameter *XSSUBNAME*. The C subroutine it calls defaults to the name of the perl visible\nsubroutine, unless you give the parameter *CSUBNAME*.\n\nautoload PACKAGE, VERSION, AUTOLOADER\nA function to generate the AUTOLOAD subroutine for the module *PACKAGE* *VERSION* is the\nperl version the code should be backwards compatible with. It defaults to the version of\nperl running the subroutine. If *AUTOLOADER* is true, the AUTOLOAD subroutine falls back on\nAutoLoader::AUTOLOAD for all names that the constant() routine doesn't recognise.\n\nWriteMakefileSnippet\nWriteMakefileSnippet ATTRIBUTE => VALUE [, ...]\n\nA function to generate perl code for Makefile.PL that will regenerate the constant\nsubroutines. Parameters are named as passed to \"WriteConstants\", with the addition of\n\"INDENT\" to specify the number of leading spaces (default 2).\n\nCurrently only \"INDENT\", \"NAME\", \"DEFAULTTYPE\", \"NAMES\", \"CFILE\" and \"XSFILE\" are\nrecognised.\n\nWriteConstants ATTRIBUTE => VALUE [, ...]\nWrites a file of C code and a file of XS code which you should \"#include\" and \"INCLUDE\" in\nthe C and XS sections respectively of your module's XS code. You probably want to do this in\nyour \"Makefile.PL\", so that you can easily edit the list of constants without touching the\nrest of your module. The attributes supported are\n\nNAME\nName of the module. This must be specified\n\nDEFAULTTYPE\nThe default type for the constants. If not specified \"IV\" is assumed.\n\nBREAKOUTAT\nThe names of the constants are grouped by length. Generate child subroutines for each\ngroup with this number or more names in.\n\nNAMES\nAn array of constants' names, either scalars containing names, or hashrefs as detailed\nin \"Cconstant\".\n\nPROXYSUBS\nIf true, uses proxy subs. See ExtUtils::Constant::ProxySubs.\n\nCFH\nA filehandle to write the C code to. If not given, then *CFILE* is opened for writing.\n\nCFILE\nThe name of the file to write containing the C code. The default is \"const-c.inc\". The\n\"-\" in the name ensures that the file can't be mistaken for anything related to a\nlegitimate perl package name, and not naming the file \".c\" avoids having to override\nMakefile.PL's \".xs\" to \".c\" rules.\n\nXSFH\nA filehandle to write the XS code to. If not given, then *XSFILE* is opened for\nwriting.\n\nXSFILE\nThe name of the file to write containing the XS code. The default is \"const-xs.inc\".\n\nXSSUBNAME\nThe perl visible name of the XS subroutine generated which will return the constants.\nThe default is \"constant\".\n\nCSUBNAME\nThe name of the C subroutine generated which will return the constants. The default is\n*XSSUBNAME*. Child subroutines have \"\" and the name length appended, so constants with\n10 character names would be in \"constant10\" with the default *XSSUBNAME*.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Nicholas Clark <nick@ccl4.org> based on the code in \"h2xs\" by Larry Wall and others\n",
            "subsections": []
        }
    },
    "summary": "ExtUtils::Constant - generate XS code to import C header constants",
    "flags": [],
    "examples": [],
    "see_also": []
}