XS is fun: a simple and easy tutorial on writing Perl XS
C Perl Other
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
build/tools Replace pod2pdf with LaTeX-based PDF production chain Apr 2, 2016
chapter_01 Improve chap01 introductory text Sep 21, 2016
chapter_03 Make chapter title capitalisation consistent Apr 2, 2016
chapter_04 Fix typo Jun 22, 2016
chapter_05 Remove unnecessary line Aug 20, 2016
chapter_06 Remove unnecessary whitespace in chapter_06 Aug 16, 2016
skeleton reduce perl version requirement Jun 26, 2016
.travis.yml Add Test::Fatal to list of Travis deps Sep 6, 2016
Makefile Replace pod2pdf with LaTeX-based PDF production chain Apr 2, 2016
README.md Use standard extension for markdown files Aug 16, 2016


XS Fun

Any XS guru will tell you XS is easy. I've heard this many times. While it may be true, I realized one thing: XS can be scary.

The purpose of this guide is to make XS fun. Yes, fun. Try it out, if you won't feel as exhilarated as I do as you make your way up the stairs of XS knowledge, I will fully reimburse your tuition.

Ground rules

  1. We use a template instead of h2xs.
  2. We do not bundle an additional C library.
  3. We assume you have at least Perl 5.14.2.

These are the best bits of advice I've received so far and they've proven to be crucial.

h2xs is old and crufty, and thus far seems more like a hurdle. Instead, this guide includes a skeleton for each exercise that you can copy and use each time you start a new project.

Bundling additional C libraries requires hacks with ExtUtils::MakeMaker (which is a war in and of itself), including tab character nightmares and additional recursive Makefiles. One way around the obvious "you need to have this library installed" problem is to provide an Alien package. This guide might go over it at some point but makes no promises.

Eliminating the use of h2xs and bundling any C libraries we use (that we haven't written by ourselves) removes a lot of needless complexity.

Perl 5.14.2 is prevalent enough to consider it a starting ground, though at this point it is not yet necessarily important.

Relevant resources

More advanced or specialized resources