What is the modern way of creating an XS module from scratch?
Asked Answered
Z

4

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.

Zodiac answered 7/4, 2009 at 14:14 Comment(0)
G
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.

Gytle answered 7/4, 2009 at 14:24 Comment(2)
I used it years ago, I just thought it had been replaced.Zodiac
It's only been replaced for people not doing XS stuff (which is most authors).Assimilative
C
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.

Ceil answered 8/4, 2009 at 8:52 Comment(2)
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?Zodiac
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.Ceil
I
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...

Indiscriminate answered 19/4, 2012 at 15:42 Comment(0)
M
-1

You should also look at using Inline::C

Metallize answered 8/4, 2009 at 18:55 Comment(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).Zodiac

© 2022 - 2024 — McMap. All rights reserved.