17

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.

Chas. Owens
  • 64,182
  • 22
  • 135
  • 226

4 Answers4

16

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
  • 96,171
  • 6
  • 121
  • 214
5

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
  • 30,029
  • 2
  • 61
  • 110
  • 1
    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 Apr 08 '09 at 11:43
  • 2
    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 Apr 09 '09 at 09:09
0

Personally, whenever I start making a new module I just do it by cping and editing files from another module of mine that's similar to it, and editing as appropriate. Of course, nothing in that approach says it has to be one of mine. There's plenty of code on CPAN you can take copies of and be inspired by...

LeoNerd
  • 8,344
  • 1
  • 29
  • 36
-1

You should also look at using Inline::C

mpeters
  • 4,737
  • 3
  • 27
  • 41
  • 1
    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 Apr 08 '09 at 20:48