Writing a Perl Core Feature

(Index) | < Prev | Next >

One of the headline features that was added in Perl version 5.32.0 was the isa operator. This feature was written by me, and while the actual development history of it spanned many commits, they were all squashed into one to be merged into the actual blead branch, which is the main development head for the Perl interpreter itself.

That commit can be seen on github.

At initial glance the commit looks quite long and involved - some might even say scary. But in practice there's somewhat less to it than may first appear. For one thing, while the commit touches 33 different files, 12 of those files are automatically generated from other files in the repository, and comprise the majority of the actual lines of diff (413 of the 656 lines in total).

One thing I found while writing that and getting it reviewed was how few people are actually aware of all the inner details of what goes into creating such a feature. Therefore I've decided to write this blog post series, in which I will take that commit apart in detail, and go over all the individual pieces. My aim here is to not only explain what they're all doing there, but additionally to talk you through the process of creating a feature yourself. Along the way we'll also take a look at some other commits and details of other features. We'll also follow the development of a new, hypothetical feature called banana - a word unlikely to collide with any existing or future feature, so it should be easy enough to grep out, and find in these examples.

These examples have all been written midway through the Perl version 5.33.x development series, and so will relate to various internal details of that version. If you are reading this at some point off in the future when internals have change significantly you may have to adjust to cope - but hopefully I will have edited these posts to remain relevant to whatever is current-generation technology in the meantime.

I'll be entirely honest here - at least half of the point of my writing this series is as a handy reference for me to read again in future the next time I want to do one of these. But I hope other people will find it useful too. Readers are expected to be familiar with using and writing Perl code, as well as have some experience of writing C code. Some knowledge of the internals of the Perl interpreter (such as from writing XS code) might be useful, but I'll try to explain any particularly in-depth concepts as we encounter them, so don't worry too much there.

Rather than write the whole thing in one big post, I shall split it across various sections. Each of them will be linked from this list for easy reference. Not every potential new feature will need every one of these stages, and of course there may be situations where other things need adding or changing, but overall this is a reasonable first guess at what may need to be done.

If you're generally curious about what goes into these things, or looking for a general overview of the process, I suggest reading all of them in order - several will depend on concepts introduced previously. I'll also leave a handy index of all of them here, for easy reference if you want to look up particular things.

The next parts of this post series are:

  1. feature.pm
  2. warnings.pm
  3. Keyword
  4. Opcode
  5. Lexer
  6. Parser
  7. Support functions
  8. Interpreter internals
  9. Tests
  10. Documentation

(Index) | < Prev | Next >

Source: leonerds code

Writing a Perl Core Feature