C::Scan::Constants - Slurp constants from specified C header (.h) files


C-Scan-Constants documentation  | view source Contained in the C-Scan-Constants distribution.

Index


NAME

Top

C::Scan::Constants - Slurp constants from specified C header (.h) files

VERSION

Top

This documentation refers to C::Scan::Constants version 1.020.

SYNOPSIS

Top

  ## Intended for use in your module's Makefile.PL file, to
  ## add DWIMery to use of C constants within your module.

  use C::Scan::Constants;

  my @hdr_files = (
      "/path/to/first_header.h",
      "/path/to/second_header.h",
  );

  ## Slurp a list of constant information from C headers
  my @constants = extract_constants_from( @hdr_files );

  ## Create the C, XS, and pure-Perl machinery needed to
  ## provide automagical access to C constants at runtime.
  write_constants_module( "Your::Module", @constants );

DESCRIPTION

Top

This module provides an alternative to using the h2ph command to generate Perl header (.ph) files that are then subsequently required by your module code. When you need access to C numeric and enumerated type constants, especially in a dynamic source tree environment, there are times when you'd like something a little more automagical and closely tailored to what you actually need. Now you have it, in this module.

C::Scan::Constants was born out of a recognition that ModPerl::CScan and ExtUtils::Constant provide a wealth of capabilities in the area of C code parsing and autogenerated XS access to C constants, but that the actual mechanisms for harnessing them to do those things were really rather opaque. This module should help take (most of) the mystery out of those activities.

Here's a brief overview of the module:

SUBROUTINES

Top

The following two subroutines are exported by default.

@blobs = extract_constants_from( @header_paths )

Takes a list of C header (.h) files and returns a list of constants information suitable for supplying as the NAME parameter to ExtUtils::Constant.

Returns an array of constant name "blobs" suitable for feeding into ExtUtils::Constant::WriteConstants() as the value of the NAME parameter.

write_constants_module( $pkg_name, @c_constants )

Writes a Constants/C/Symbols.pm submodule into the invoking Makefile.PL module's namespace. Really just a value-added wrapper around ExtUtils::Constant::WriteConstants().

No return value -- call for side-effects only.

DIAGNOSTICS

Top

TBD. I owe you a list of error and warning messages you might see when invoking functions from C::Scan::Constants.

CONFIGURATION AND ENVIRONMENT

Top

TBD. If/when populated, this section will describe in detail how/where to add the necessary extra code to wire in the autogenerated files to your module. It will also describe what you need in your Makefile.PL to assure that the autogenerated stuff goes away at make clean time.

For the time being, write_constants_module() outputs to STDERR a number of hints that should provide the needed answers to these types of questions.

DEPENDENCIES

Top

For the program proper:

Carp, Data::Flow, ExtUtils::Constants, ModPerl::CScan, C::Scan, File::Temp, File::Copy, File::Spec, File::Path, Exporter

Additional modules needed for tests (over and above Test::More):

Scalar::Util, List::MoreUtils, Cwd

COMPATIBILITY NOTES

Top

This version of C::Scan::Constants is known to work with ExtUtil::Constants versions 0.14 - 0.16. It may not work properly with earlier or later versions. I welcome your comments and patches to assure continued compatibility going forward.

BUGS AND LIMITATIONS

Top

The amount of code you are currently required to add to your module to make use of the files C::Scan::Constants generates seems rather too much. It would be highly useful to provide a more streamlined usage, or to provide scripts that would assist you in inserting the needed code into your module.

Also, the tests are incomplete. The runtime usability of constants generated by the module is not tested at all. I need to set up some tests that actually create a new module, invoke the C::Scan::Constants functionality, and then do a

    perl Makefile.PL
    make
    make test

regimen on that module in order to accomplish this. That's pretty tricky, so I haven't tackled it yet.

Finally (well probably not), it would be nice to be able to specify whether cpp should "follow" #include statements in C header files. Sometimes, that's what you really want. This version of C::Scan::Constants suppresses all such "following" behavior.

Other than that, there are no known bugs in this module.

Please report problems to Philip Monsen (philip.monsen@gmail.com). Patches are especially welcome.

AUTHOR

Top

Philip Monsen (philip.monsen@gmail.com)

COPYRIGHT AND LICENSE

Top


C-Scan-Constants documentation  | view source Contained in the C-Scan-Constants distribution.