On Wed, Jul 09, 2003 at 03:23:18PM -0400, Marc Mettes wrote: > > In my XS module, I need to make numerous enum's available to perl > and I'm looking for recommendations on which option to chose to > implement them. > > I've seen two variations, one using h2xs which auto-generated a > big mess, and another using the ALIAS keyword (borrowed from > DBI::Oracle).
> Can anyone share some insight as to which of the above choices > would be better or worse? h2xs prior to 5.8 certainly makes a big mess. (plus 5.6 and 5.6.1 are buggy in certain cases). h2xs scans for constants in the header file(s) it is told about, and generates a monolithic and unmaintainable switch statement in the XS routine. The constant code in h2xs is re-written: h2xs now stores the information about the found constants in the Makefile.PL. The strategy used for the switch code is different (should be more efficient, but certainly is tested and has no known bugs). The switch statement is generated at Makefile.PL run time (or fallback files provided by the module's maintainer are used). This lets the maintainer add new constants without messing with auto-generated code. The generated code understands utf8 (although h2xs' scanner doesn't) The generated code can do many types other than "number" (again, h2xs' scanner doesn't) If you want an example of how this works, all of the core modules that were using "constant" code generated by the old h2xs have been re-implemented using the new strategy in 5.8.0, as does Time::HiRes on CPAN. (Actually Time::HiRes is not a good example as it does lots of other stuff in its Makefile.PL, and it generates the list of constants with non-standard defaults) Admittedly, I'm biased, because I did the h2xs re-write and wrote the associated support module, ExtUtils::Constant (in 5.8.0, and on CPAN) Nicholas Clark
