tags:

views:

194

answers:

3

I need to write an XS module for Perl. It is my understanding that h2xs is pretty much deprecated today, what is the preferred method for starting an XS module today? I looked at Module::Starter, but it only handles pure Perl modules.

+14  A: 

No, h2xs is not deprecated. Module::Starter is certainly more convenient if you create many pure Perl modules, but there's no reason to avoid h2xs. I would recommend reading all the way through its doc before using it, though, so that you know what all you might want it to do or not do.

ysth
I used it years ago, I just thought it had been replaced.
Chas. Owens
It's only been replaced for people not doing XS stuff (which is most authors).
brian d foy
+3  A: 

Personally I just use Module::Starter and add the .xs file myself. It depends on what your aim is: if you're making a one-on-one mapping to a C api then h2xs can do a lot of boilerplate for you, but if you're making a completely new interface, or when you're only doing things with perl itself (and not some external library) it doesn't add much but trouble IMHO.

Leon Timmermans
Good to know. I never paid attention to the magic that happens in the pm file, but it looks like you just need to add two lines to it require XSLoader;XSLoader::load('Pax::PerlHash', $VERSION); Is this right, and do you just copy ppport.h from another module, or is it unnecessary?
Chas. Owens
ppport.h is for portability to older versions of Perl. The kind of stuff I do usually makes that impossible anyway (most of my XS modules require 5.8 anyway, one even requires 5.10), but in your case it may be different. The proper way to generate ppport.h is using Devel::PPPort.
Leon Timmermans
A: 

You should also look at using Inline::C

mpeters
Well, since I am rewriting something to not need/use Inline::C, that would be foolish (grin). Inline::C is great for rapid prototyping, but sucks for deploying to production (some users don't have home directories, so the object files wind up in /_Inline and other problems).
Chas. Owens