PERLHACK(1perl)
π perlhack(1perl) π
okay so this is perlhack, straight outta the Perl Programmers Reference Guide, and it's literally the whole guide to hacking on Perl. bestie, grab a snack π
πΈ NAME πΈ
perlhack β how to hack on Perl π
β¨ DESCRIPTION β¨
So this doc? It explains how Perl development actually works. Like, all of it. It's got the tea on the Perl 5 Porters email list, the Perl repository, the Perl bug tracker, the patch guidelines, and honestly a whole commentary section on the philosophy of Perl development. iconic. π
π SUPER QUICK PATCH GUIDE π
okay so if you just wanna yeet a single small patch β like a pod fix, a test for a bug, comment fixes, whatever β it's genuinely easy! here's the whole vibe: π
- Check out the source repository
the perl source lives in a git repository. you can clone it with this, no cap:
% git clone https://github.com/Perl/perl5.git perl
% cd perl
- Ensure you're following the latest advice
in case this guide got updated recently (it happens!), read the latest version straight from the perl source:
% perldoc pod/perlhack.pod
- Create a branch for your change
make a branch based on blead to commit your change to, which you'll later use to send it to the Perl issue tracker.
% git checkout -b mychange
- Make your change
hack, hack, hack. π οΈ but keep in mind that Perl runs on many different platforms, with different operating systems that have different capabilities, different filesystem organizations, and even different character sets. perlhacktips has the advice on this, iykyk.
- Test your change
you can run all the tests with these commands:
% ./Configure -des -Dusedevel
% make test
keep hacking until the tests pass. πͺ
- Commit your change
committing your work saves the change on your local system. first you need to add your work to the list of things to be committed. if you want everything in the files you've changed to be included, you can say:
% git add file1 file2 ...
but a more flexible method is:
% git add -i
and follow the prompts to selectively add what you want. this lets you double check what you're adding as you go along. once everything is added, do:
% git commit
git will open an editor (a default one, or the one you've configured it to) so you can type in a commit message that describes the change. when you're done, save and exit. β¨
it is important for the smooth functioning of the project, both now and in the future, to write a good commit message. this is covered below in "Commit message".
- Add your name to the Perl contributors list
we keep a list of all people who have contributed to Perl, as well as the Git commit history. the default is to show our gratitude by publicly listing their names and email addresses in the file named AUTHORS, which is part of the perl distribution. but some people choose to instead remain anonymous. π«Ά
if you've already contributed, you can skip this step, unless you wanna update your records with, say, a new email address. run:
perldoc Porting/updateAUTHORS.pl
to see the possibilities.
if you've never contributed, run one of the following:
- if you want to be publicly credited
perl Porting/updateAUTHORS.pl
- if you want to remain anonymous
perl Porting/updateAUTHORS.pl --exclude-me
then commit the change.
- Submit your changes to GitHub
next step is submitting your patch to GitHub.
create a GitHub fork of the perl5 repository and add it as a remote, if you haven't already, as described in the GitHub documentation at <https://help.github.com/en/articles/working-with-forks>.
% git remote add fork git@github.com:MyUser/perl5.git
for more info, see "Connecting to GitHub with SSH" <https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/connecting-to-github-with-ssh>.
if you'd rather use an HTTPS URL for your git push see "Cloning with HTTPS URLs" <https://docs.github.com/en/free-pro-team@latest/github/using-git/which-remote-url-should-i-use#cloning-with-https-urls>.
% git remote add fork https://github.com/MyUser/perl5.git
now you're ready to submit your work. to do this, push your new branch to your fork.
% git push -u fork mychange
finally, create a Pull Request on GitHub from your branch to blead as described in the GitHub documentation at <https://help.github.com/en/articles/creating-a-pull-request-from-a-fork>. π
- Thank you
the porters appreciate the time you spent helping to make Perl better. thank you! ππ
- Next time
the next time you wish to make a patch, you need to start from the latest perl in a pristine state. check you don't have any local changes or added files in your perl check-out which you wish to keep, then run these commands:
% git checkout blead
% git pull
% git reset --hard origin/blead
% git clean -dxf
π BUG REPORTING π
if you wanna report a bug in Perl, or browse existing Perl bugs and patches, use the GitHub issue tracker at <https://github.com/perl/perl5/issues>.
please check the archive of the perl5-porters list (see below) and/or the bug tracking system before submitting a bug report. often you'll find that the bug has been reported already. π
you can log in to the bug tracking system and comment on existing bug reports. if you have additional information regarding an existing bug, please add it β it helps the porters fix the bug. π«Ά
π PERL 5 PORTERS π
the perl5-porters (p5p) mailing list is where the Perl standard distribution is maintained and developed. the people who maintain Perl are also referred to as the "Perl 5 Porters", "p5p" or just the "porters". β¨
a searchable archive of the list is available at <https://markmail.org/search/?q=perl5-porters>. there is also an archive at <https://archive.develooper.com/perl5-porters@perl.org/>.
π perl-changes mailing list π
the perl5-changes mailing list receives a copy of each patch that gets submitted to the maintenance and development branches of the perl repository. see <https://lists.perl.org/list/perl5-changes.html> for subscription and archive information.
π§ #p5p on IRC π§
many porters are also active on the <irc://irc.perl.org/#p5p> channel. feel free to join the channel and ask questions about hacking on the Perl core. π
π¦ GETTING THE PERL SOURCE π¦
all of Perl's source code is kept centrally in a Git repository at github.com. the repository contains many Perl revisions from Perl 1 onwards and all the revisions from Perforce, the previous version control system. history, bestie. π¦
for much more detail on using git with the Perl repository, please see perlgit.
π» Read access via Git π»
you'll need a copy of Git for your computer. you can fetch a copy of the repository using the git protocol:
% git clone git@github.com:Perl/perl5.git perl
this clones the repository and makes a local copy in the perl directory.
if you cannot use the git protocol for firewall reasons, you can also clone via http:
% git clone https://github.com/Perl/perl5.git perl
π Read access via the web π
you may access the repository over the web. this lets you browse the tree, see recent commits, subscribe to repository notifications, search for particular commits and more. you may access it at <https://github.com/Perl/perl5>.
π Write access via git π
if you have a commit bit, please see perlgit for more details on using git. π
π οΈ PATCHING PERL π οΈ
if you're planning to do more extensive work than a single small fix, we encourage you to read the documentation below. this will help you focus your work and make your patches easier to incorporate into the Perl source. π
π¬ Submitting patches π¬
if you have a small patch to submit, please submit it via the GitHub Pull Request workflow. you may also send patches to the p5p list.
patches are reviewed and discussed on GitHub or the p5p list. simple, uncontroversial patches will usually be applied without any discussion. when the patch is applied, the ticket will be updated and you will receive email. β¨
in other cases, the patch will need more work or discussion. you're encouraged to participate in the discussion and advocate for your patch. sometimes your patch may get lost in the shuffle. it's appropriate to send a reminder email to p5p if no action has been taken in a month. please remember that the Perl 5 developers are all volunteers, and be polite. π«Ά
changes are always applied directly to the main development branch, called "blead". some patches may be backported to a maintenance branch. if you think your patch is appropriate for the maintenance branch (see "MAINTENANCE BRANCHES" in perlpolicy), please explain why when you submit it.
β Getting your patch accepted β
if you are submitting a code patch there are several things that you can do to help the Perl 5 Porters accept your patch.
π¨ Patch style π¨
using the GitHub Pull Request workflow, your patch will automatically be available in a suitable format. if you wish to submit a patch to the p5p list for review, make sure to create it appropriately.
if you used git to check out the Perl source, then using git format-patch will produce a patch in a style suitable for Perl. the format-patch command produces one patch file for each commit you made. if you prefer to send a single patch for all commits, you can use git diff.
% git checkout blead
% git pull
% git diff blead my-branch-name
this produces a patch based on the difference between blead and your current branch. it's important to make sure that blead is up to date before producing the diff β that's why we call git pull first. π
we strongly recommend that you use git if possible. it will make your life easier, and ours as well.
however, if you're not using git, you can still produce a suitable patch. you'll need a pristine copy of the Perl source to diff against. the porters prefer unified diffs. using GNU diff, you can produce a diff like this:
% diff -Npurd perl.pristine perl.mine
make sure that you make realclean in your copy of Perl to remove any build artifacts, or you may get a confusing result. π
π Commit message π
a commit message needs to answer these questions about the commit: "Who", "When", "What", "Where", "Why", and "How".
git automatically inserts the "Who" (you), and "When" (now), so you don't generally have to worry about these. but you definitely need to answer the other four. π
okay so a commit message has two parts: a title and a body. In rare instances the body can literally be omitted if the title describes the change well enough on its own. And when that happens, you can use a git shortcut to make the commit without git ever opening an editor on you:
% git commit -m'perlhack: Fix spelling error'
This keeps git from opening an editor where you'd have to compose your message, so you save yourself some keystrokes. π
In this case the title answers "What" (spelling error) and "Where" (pod/perlhacktips.pod). It skips "Why", because it correctly assumes the project's policy is that errors like this are always a bad thing that should be fixed. And it skips "How", because that answer is obvious here.
The title is extremely important. It's gonna get read over and over again far into the future β way more often than the body. It is genuinely unfair to the future maintainers of Perl to skimp on it now. π€
And the title has to be short, about 50 characters max, like the Subject: line of an email. Some tools will straight up refuse a longer title, and some will just truncate the display at or about the 50th character.
A title needs to carry enough info in that tiny space that someone doing git log can immediately decide if the body of the commit message is relevant to what they need rn, or if they can skip to the next commit without digging in. π
That means it needs to answer "What" and "Where" at a minimum, plus a hint of "Why" if there's room. "How" can generally be deferred to the message body.
"What" needs enough detail to actually be helpful, but not so much that it's meaningless noise. Like if you're fixing a spelling error β people do not need to know which word was misspelled. That info just distracts them from their real purpose. Do a git log yourself. It should mostly show you good examples of titles that answer this question, with the occasional one that leaves you wishing it had more. π
"Where" can look super different depending on the case. Sometimes it's a subsystem, like regex or mro (method resolution order). Sometimes it's a particular function:
% git commit -m'Use getentropy() for seeding PRNG in Perl_seed()'
In a few cases, a file:
% git commit -m'embed.fnc: Add ptr asserts for refcounted functions'
Sometimes, a module:
% git commit -m'Devel::PPPort: Add support for utf8_to_uv'
And rarely, it's entirely omitted:
% git commit -m'Add feature "class"'
Terseness is helpful in commit titles. Not only because of the 50-character limit, but because it biases you toward not adding unnecessary detail β which makes it faster for people skimming git log in the future. The style Where: rest-of-title tends to use the fewest characters for the "Where" answer, leaving more room for the "What". Sometimes you'll have to get creative to make things fit. For example, Devel:: in the example above could have been omitted if the message busted the character limit. You may have to spend a bit of time rewriting the title more concisely. Abbreviations are acceptable when needed. But keep in mind that this will be read by people whose first language is not English. π
The body of the commit message fills in the details, in plain English. And to actually get the commit merged, it needs to persuade someone with the authority to do that β convince them this change is desirable enough to outweigh the potential harm. It should not contain text tangential to the main point. π―
No convincing is generally necessary (and so nothing beyond the title needs to be included) for cases like this:
% git commit -m'"Where": Add/clarify comments"
% git commit -m'"Where": Use more mnemonic variable name"
% git commit -m'"Where": Move ARGS_ASSERT to top of function'
(That last one is because anyone who can merge commits would know such macros are best placed at the top of functions, and that many weren't simply because of C89 compiler limitations that got lifted when we moved to C99.)
The commit message should include a description of the problem the patch fixes, or the new functionality it adds. β¨
As a general rule of thumb, your commit message should help a programmer who knows the Perl core quickly understand what you were trying to do, how you were trying to do it, and why the change matters to Perl.
- Why
The message body should describe why the change you're making matters. When someone looks at your change in six months or six years, your intent should still be clear. π
If you're deprecating a feature with the intent of later simplifying another bit of code, say so. If you're fixing a performance problem or adding a new feature to support some other part of the core, mention that.
- What
The message body should amplify what's in the title, describing what part of the Perl core you're changing and what you expect your patch to do.
- How
While it's not necessary for documentation changes, new tests, or trivial patches, it's usually worth explaining how your change works. Even if it's clear to you today, it may not be clear to a porter next month or next year. π¦
The body is the place to explain why this particular implementation was chosen over the alternatives you considered. And if you're claiming performance gains, this is where you'd drop the supporting benchmarks. π
We're now using GitHub, and it will grep through your commit message for phrases of the form
m/Fixes\s+#(\d+)/
If it finds that, it takes the matched number and automatically closes the GitHub issue with that number when the PR gets merged β saving you some effort. (But beware it has to be exactly that form. If you instead say
Fixes GH #1234
nothing happens to #1234.) π
This also has the added benefit of cross-linking the issue and the pull request on GitHub, so it's easy to start with one and find the other, and to see what discussion has happened.
But this is not a substitute for an adequate commit message. We may not be on GitHub forever, and if we aren't, it might become hard to recover this info.
A commit message also isn't meant to take the place of comments in your code. Commit messages describe the change you made; code comments describe the current state of the code.
If you've just implemented a new feature β complete with docs, tests, and well-commented code β a brief commit message will often suffice. But if you've just changed a single character deep in the parser or lexer, you might need to write a small novel so future readers understand what you did and why you did it. ππ
π Comments, Comments, Comments π
Please, bestie, adequately comment your code. Commenting every single line is unnecessary, but anything that takes advantage of side effects of operators, or that creates changes felt outside the function being patched, or that others might find confusing, should be documented. And if you're gonna err? Err on the side of too many comments rather than too few. π«Ά
The best comments explain why the code does what it does, not what it does. periodt.
π Style π
In general, follow the particular style of the code you're patching, okay? Match the vibe of the file you're in.
And in particular, follow these general guidelines for patching Perl sources:
- 4-wide indents for code, 2-wide indents for nested CPP
"#define"s, with 8-wide tabstops. - Use spaces for indentation, not tab characters.
The codebase is a mixture of tabs and spaces for indentation, and we are moving to spaces only. Converting the lines you're patching from 8-wide tabs to spaces helps this migration. π«
- Try not to exceed 79 columns.
In general, we target 80 column lines. When sticking to 80 columns would lead to torturous code or rework, it's fine to go longer. Just try to keep your excess past 80 to a minimum.
- ANSI C prototypes
- Uncuddled
elses and "K&R" style for indenting control constructs - No C++ style (
//) comments - Mark places that need to be revisited with
XXX(and revisit often!) - Opening brace lines up with
ifwhen the conditional spans multiple lines; should be at end-of-line otherwise - In function definitions, name starts in column 0 (return value-type is on the previous line)
- Single space after keywords that are followed by parens, no space between function name and following paren
- Avoid assignments in conditionals, but if they're unavoidable, use an extra paren, e.g.
"if (a && (b = c)) ..." "return foo;"rather than"return(foo);""if (!foo) ..."rather than"if (foo == FALSE) ..."etc.- Do not declare variables using
"register". It may be counterproductive with modern compilers, and is deprecated in C++, under which the Perl source is regularly compiled. - In-line functions that are in headers accessible to XS code need to be able to compile without warnings with commonly used extra compilation flags β such as gcc's
"-Wswitch-default", which warns whenever aswitchstatement does not have a"default"case. The point of these extra flags is to catch potential problems in legal C code, and they're often used by Perl aggregators, like Linux distributors.
π§ͺ Test suite π§ͺ
If your patch changes code (rather than just changing documentation), you should also include one or more test cases that illustrate the bug you're fixing or validate the new functionality you're adding. In general, update an existing test file rather than creating a new one. π₯
Your test suite additions should generally follow these guidelines (courtesy of Gurusamy Sarathy <gsar@activestate.com>):
- Know what you're testing. Read the docs, and the source. π
- Tend to fail, not succeed.
- Interpret results strictly.
- Use unrelated features (this will flush out bizarre interactions).
- Use non-standard idioms (otherwise you are not testing TIMTOWTDI).
- Avoid using hardcoded test numbers whenever possible (the
EXPECTED/GOTfound int/op/tie.tis much more maintainable, and gives better failure reports). - Give meaningful error messages when a test fails. π
- Avoid using
qx//andsystem()unless you are testing for them. If you do use them, make sure you cover _all_ perl platforms. - Unlink any temporary files you create.
- Promote unforeseen warnings to errors with
$SIG{__WARN__}. - Be sure to use the libraries and modules shipped with the version being tested, not those that were already installed.
- Add comments to the code explaining what you are testing for.
- Make updating the <code>'1..42'</code> string unnecessary. Or, like, just actually remember to update it. Either vibe is fine, but the stale number is not the vibe.
- Test all the behaviors of a given operator, library, or function. All of them. No leaving the weird ones for someone else bestie.
- Test all optional arguments.
- Test return values in various contexts (boolean, scalar, list, lvalue).
- Use both global and lexical variables.
- Don't forget the exceptional, pathological cases. Yes, those cases. The cursed ones. Test them anyway. π
Patching a core module π
Okay so this works just like patching anything else, with one extra consideration. One. But it's a big one, so pay attention.
Modules in the <code>cpan/</code> directory of the source tree are maintained outside of the Perl core. When the author updates the module, the updates are simply copied into the core. So if you want info on reporting bugs and submitting patches, go check that module's own documentation, or its listing on <https://metacpan.org/>. That's where the real ones hang out.
In most cases, patches to modules in <code>cpan/</code> should be sent upstream and should not be applied to the Perl core individually. Like, don't just barge in. But if a patch to a file in <code>cpan/</code> absolutely cannot wait for the fix to be made upstream, released to CPAN and copied to blead, then you must add (or update) a CUSTOMIZED entry in the Porting/Maintainers.pl file to flag that a local modification has been made. See Porting/Maintainers.pl for more details, iykyk.
In contrast, modules in the <code>dist/</code> directory are maintained in the core. Different situation entirely. π«Ά
Updating perldelta β¨
For changes significant enough to warrant a pod/perldelta.pod entry, the porters will greatly appreciate it if you submit a delta entry along with your actual change. Like, they will love you for it. Significant changes include, but are not limited to:
- Adding, deprecating, or removing core features
- Adding, deprecating, removing, or upgrading core or dual-life modules
- Adding new core tests
- Fixing security issues and user-visible bugs in the core
- Changes that might break existing code, either on the perl or C level
- Significant performance improvements
- Adding, removing, or significantly changing documentation in the
pod/directory - Important platform-specific changes
Please make sure you add the perldelta entry to the right section within pod/perldelta.pod. Don't just dump it anywhere, that's chaos. More info on how to write good perldelta entries is available in the "Style" section of Porting/how_to_write_a_perldelta.pod.
What makes for a good patch? π
Okay bestie, real talk. New features and extensions to the language can be contentious. There's no specific set of criteria which determine what features get added, but here are some questions to consider when developing a patch:
Does the concept match the general goals of Perl?
Our goals include, but are not limited to:
- Keep it fast, simple, and useful.
- Keep features/concepts as orthogonal as possible.
- No arbitrary limits (platforms, data sizes, cultures).
- Keep it open and exciting to use/patch/advocate Perl everywhere.
- Either assimilate new technologies, or build bridges to them.
Where is the implementation?
All the talk in the world is useless without an implementation. In almost every case, the person or people who argue for a new feature will be expected to be the ones who implement it. Porters capable of coding new features have their own agendas, and are not available to implement your (possibly good) idea. Sorry babe, you gotta build it. π οΈ
Backwards compatibility
It's a cardinal sin to break existing Perl programs. Like, actual felony energy. New warnings can be contentious--some say that a program that emits warnings is not broken, while others say it is. Adding keywords has the potential to break programs, changing the meaning of existing token sequences or functions might break programs.
The Perl 5 core includes mechanisms to help porters make backwards incompatible changes more compatible such as the feature and deprecate modules. Please use them when appropriate, they're literally right there.
Could it be a module instead?
Perl 5 has extension mechanisms, modules and XS, specifically to avoid the need to keep changing the Perl interpreter. You can write modules that export functions, you can give those functions prototypes so they can be called like built-in functions, you can even write XS code to mess with the runtime data structures of the Perl interpreter if you want to implement really complicated things.
Whenever possible, new features should be prototyped in a CPAN module before they will be considered for the core.
Is the feature generic enough?
Is this something that only the submitter wants added to the language, or is it broadly useful? Sometimes, instead of adding a feature with a tight focus, the porters might decide to wait until someone implements the more generalized feature.
Does it potentially introduce new bugs?
Radical rewrites of large chunks of the Perl interpreter have the potential to introduce new bugs. π¬ Yeah. Them.
How big is it?
The smaller and more localized the change, the better. Similarly, a series of small patches is greatly preferred over a single large patch. Slay the small patch, bestie.
Does it preclude other desirable features?
A patch is likely to be rejected if it closes off future avenues of development. For instance, a patch that placed a true and final interpretation on prototypes is likely to be rejected because there are still options for the future of prototypes that haven't been addressed.
Is the implementation robust?
Good patches (tight code, complete, correct) stand more chance of going in. Sloppy or incorrect patches might be placed on the back burner until fixes can be made, or they might be discarded altogether without further notice. π
Is the implementation generic enough to be portable?
The worst patches make use of system-specific features. It's highly unlikely that non-portable additions to the Perl language will be accepted.
Is the implementation tested?
Patches which change behaviour (fixing bugs or introducing new features) must include regression tests to verify that everything works as expected.
Without tests provided by the original author, how can anyone else changing perl in the future be sure that they haven't unwittingly broken the behaviour the patch implements? And without tests, how can the patch's author be confident that his/her hard work put into the patch won't be accidentally thrown away by someone in the future? Like, imagine your work getting yeeted. No thanks. π
Is there enough documentation?
Patches without documentation are probably ill-thought out or incomplete. No features can be added or changed without documentation, so submitting a patch for the appropriate pod docs as well as the source code is important.
Is there another way to do it?
Larry said "Although the Perl Slogan is There's More Than One Way to Do It, I hesitate to make 10 ways to do something". This is a tricky heuristic to navigate, though--one man's essential addition is another man's pointless cruft.
Does it create too much work?
Work for the committers, work for Perl programmers, work for module authors, ... Perl is supposed to be easy.
Patches speak louder than words
Working code is always preferred to pie-in-the-sky ideas. A patch to add a feature stands a much higher chance of making it to the language than does a random feature request, no matter how fervently argued the request might be. This ties into "Will it be useful?", as the fact that someone took the time to make the patch demonstrates a strong desire for the feature.
π TESTING π
The core uses the same testing style as the rest of Perl, a simple "ok/not ok" run through Test::Harness, but there are a few special considerations. Just a few. Don't panic. π§
There are three ways to write a test in the core: Test::More, t/test.pl and ad hoc "print $test ? "ok 42\n" : "not ok 42\n"". The decision of which to use depends on what part of the test suite you're working on. This is a measure to prevent a high-level failure (such as Config.pm breaking) from causing basic functionality tests to fail.
The t/test.pl library provides some of the features of Test::More, but avoids loading most modules and uses as few core features as possible.
If you write your own test, use the Test Anything Protocol <https://testanything.org>.
t/base,t/compandt/opbasic
Since we don't know if "require" works, or even subroutines, use ad hoc tests for these three. Step carefully to avoid using the feature being tested. Tests in t/opbasic, for instance, have been placed there rather than in t/op because they test functionality which t/test.pl presumes has already been demonstrated to work.
- All other subdirectories of
t/
Now that basic require() and subroutines are tested, you can use the t/test.pl library.
You can also use certain libraries like Config conditionally, but be sure to skip the test gracefully if it's not there.
- Test files not found under
t/
This category includes .t files underneath directories such as dist, ext and lib. Since the core of Perl has now been tested, Test::More can and now should be used. You can also use the full suite of core modules in the tests. (As noted in "Patching a core module" above, changes to .t files found under cpan/ should be submitted to the upstream maintainers of those modules.)
When you say "make test", Perl uses the t/TEST program to run the test suite (except under Win32 where it uses t/harness instead). All tests are run from the t/ directory, not the directory which contains the test. This causes some problems with the tests in lib/, so here's some opportunity for some patching. π
You must be triply conscious of cross-platform concerns. This usually boils down to using File::Spec, avoiding things like fork() and system() unless absolutely necessary, and not assuming that a given character has a particular ordinal value (code point) or that its UTF-8 representation is composed of particular bytes.
There are several functions available to specify characters and code points portably in tests. The always-preloaded functions utf8::unicode_to_native() and its inverse utf8::native_to_unicode() take code points and translate appropriately. The file t/charset_tools.pl has several functions that can be useful. It has versions of the previous two functions that take strings as inputs -- not single numeric code points: uni_to_native() and native_to_uni(). If you must look at the individual bytes comprising a UTF-8 encoded string, byte_utf8a_to_utf8n() takes as input a string of those bytes encoded for an ASCII platform, and returns the equivalent string in the native platform. For example, byte_utf8a_to_utf8n("\xC2\xA0") returns the byte sequence on the current platform that form the UTF-8 for "U+00A0", since "\xC2\xA0" are the UTF-8 bytes on an ASCII platform for that code point. This function returns "\xC2\xA0" on an ASCII platform, and "\x80\x41" on an EBCDIC 1047 one. β¨
But honestly, the easiest move? If your character can just be written as a literal β like "A" or "%" β do that. And if it's not specifiable as a literal, you can reach for \N{}... if the side effects aren't gonna cause you trouble. The other option: just write all your chars in hex, using \N{U+ZZ} instead of \xZZ. Here's the thing: \N{} is the Unicode name, so it always hands you the Unicode character. \N{U+41} is the character whose Unicode code point is 0x41, which means it's 'A' on every single platform, no drama. π
So what are those side effects I keep mentioning? Buckle up, bestie:
- These select Unicode rules. Meaning: in double-quotish strings, the string is always converted to UTF-8 to force a Unicode interpretation (you can call
utf8::downgrade()afterwards to convert it back to non-UTF8, if that's even possible). In regular expression patterns, the conversion doesn't happen β but if the character set modifier would otherwise be/d, it gets changed to/u. - If you use the form
\N{character name}, thecharnamesmodule gets automatically loaded. β οΈ And that might not be suitable for the test level you're doing.
If you're testing locales (peep perllocale for that), there are helper functions hanging out in t/loc_tools.pl that let you see what locales exist on the current platform. Super handy. π¦
β¨ Special "make test" targets β¨
There are all these special make targets that let you test Perl a little differently from the standard "test" target. Heads up though: not all of them are expected to give you a 100% success rate, and not all of them are available on every operating system. Many of them have several aliases, too.
test_portingβ runs some basic sanity tests on the source tree and helps catch basic errors before you submit a patch. Do this one, bestie, trust. π«Άminitestβ runs miniperl on thet/base,t/comp,t/cmd,t/run,t/io,t/op,t/uniandt/mrotests.
Now, what even is miniperl? It's a minimalistic perl built to bootstrap building extensions, utilities, documentation and all that. It doesn't support dynamic loading, and depending on where you're at in the build process it'll only have access to a limited set of core modules. So yeah β miniperl is not intended for day to day use. It's the origin-story version of perl. π
test.valgrind check.valgrindβ (Linux only, babes) runs all the tests using that memory-leak + naughty-memory-access tool"valgrind". The log files get namedtestname.valgrind.test_harnessβ runs the test suite with thet/harnesscontrolling program instead oft/TEST. Andt/harnessis the more sophisticated one β it uses theTest::Harnessmodule, so using this target assumes perl mostly works. The big win for our purposes is that it prints a detailed summary of failed tests at the end. Also, unliket/TEST, it doesn't redirect stderr to stdout. π
Fun fact: under Win32, t/harness is always used instead of t/TEST, so there's literally no special "test_harness" target there.
Under the Unix build process you can use the TEST_ARGS and TEST_FILES parameters to pass arguments through to the underlying harness call. So like, you could do
make test_harness TEST_ARGS="-v -re pat"
which would make, and then run the test harness in verbose mode over files which contain "pat". Or you could do
make test_harness TEST_ARGS="-torture" TEST_FILES="op/*.t"
and run torture tests on files matching the glob "op/*.t".
Under Win32's "test" target you may use the TEST_SWITCHES and TEST_FILES environment variables to control the behaviour of t/harness. Which means you can say
nmake test TEST_FILES="op/*.t"
nmake test TEST_SWITCHES="-torture" TEST_FILES="op/*.t"
And note: for compatibility with the unix build process, TEST_ARGS may also be used instead of the traditional TEST_SWITCHES argument. π
test-notty test_nottyβ setsPERL_SKIP_TTY_TESTto true before running the normal test.
π Parallel tests π
The core distribution can now run its regression tests in parallel on Unix-like and Windows platforms. On Unix, instead of running "make test", you set "TEST_JOBS" in your environment to the number of tests you want to run in parallel, and then run "make test_harness". On a Bourne-like shell, it goes like this:
TEST_JOBS=3 make test_harness # Run 3 tests in parallel
Why an environment variable instead of just parallel make itself? Because TAP::Harness needs to be able to schedule individual non-conflicting test scripts all by itself, and there's no standard interface for "make" utilities to interact with their job schedulers. So env var it is. π
Tests normally run in a logical order: sanity tests first, then the main tests of the Perl core functionality, then the tests for the non-core modules. But on many-core systems, that ordering might not use your hardware as effectively as it possibly could. So by also specifying
TEST_JOBS=19 PERL_TEST_HARNESS_ASAP=1 make -j19 test_harness
you're signaling that you want the tests to finish in wall-clock time as short as absolutely possible. Once the sanity tests are done, this packs the remaining ones into the available cores as tightly as we know how. This has its greatest effect on slower, many-core systems. Throughput got sped up by 20% on an outmoded 24-core system β less on more recent, faster ones with fewer cores. β
Heads up! That command line added a "-j" parameter to make, so as to cause parallel compilation. This may or may not work on your platform. No promises. π
Normally, data on how long tests take is stored in t/test_state. But you can change that to a different filename by setting the "PERL_TEST_STATE_FILE" environment variable to something different β or set it to a false value (0 or the empty string) to disable use of the state mechanism entirely. And yeah, there are no protections against the format of the state file changing over time, so if you have any issues related to this file, it's up to you to delete it manually and then let the harness recreate it. That said, the file format doesn't change frequently, so this shouldn't be necessary very often. π
π§ Running tests by hand π§
You can run part of the test suite by hand using one of these commands, from the t/ directory:
./perl -I../lib TEST list-of-.t-files
or
./perl -I../lib harness list-of-.t-files
(And if you don't specify test scripts, the whole test suite will be run. All of it. Every last one. π)
π Using t/harness for testing π
If you use "harness" for testing, you've got several command line options available to you. The arguments are as follows, and they're in the order they must appear if you use them together:
harness -v -torture -re=pattern LIST OF FILES TO TEST
harness -v -torture -re LIST OF PATTERNS TO MATCH
If "LIST OF FILES TO TEST" is omitted, the file list is obtained from the manifest. And the file list may include shell wildcards, which will get expanded out.
-vβ run the tests under verbose mode so you can see what tests were run, plus debug output.-tortureβ run the torture tests as well as the normal set.-re=PATTERNβ filter the file list so that all the test files run match PATTERN. Note that this form is distinct from the-re LIST OF PATTERNSform below, in that it lets the file list be provided as well.-re LIST OF PATTERNSβ filter the file list so that all the test files run match/(LIST|OF|PATTERNS)/. Note that with this form the patterns are joined by'|'and you cannot supply a list of files β instead the test files are obtained from theMANIFEST.
You can run an individual test with a command similar to
./perl -I../lib path/to/foo.t
...except that the harnesses set up some environment variables that may affect the execution of the test:
PERL_CORE=1β indicates that we're running this test as part of the perl core test suite. This is useful for modules that have a dual life on CPAN.PERL_DESTRUCT_LEVEL=2β is set to 2 if it isn't set already (see"PERL_DESTRUCT_LEVEL"inperlhacktips).PERLβ (used only byt/TEST) if set, overrides the path to the perl executable that should be used to run the tests (the default being./perl).PERL_SKIP_TTY_TESTβ if set, tells it to skip the tests that need a terminal. It's actually set automatically by the Makefile, but you can also force it artificially by running'make test_notty'.
πΈ Other environment variables that may influence tests πΈ
PERL_TEST_Net_Pingβ setting this variable runs all theNet::Pingmodules tests. Otherwise, some tests that interact with the outside world get skipped. Seeperl58delta.PERL_TEST_NOVREXXβ setting this variable skips thevrexx.ttests forOS2::REXX.PERL_TEST_NUMCONVERTSβ this sets a variable inop/numconvert.t.PERL_TEST_MEMORYβ setting this variable includes the tests int/bigmem/. This should be set to the number of gigabytes of memory available for testing. So eg."PERL_TEST_MEMORY=4"indicates that tests requiring 4GiB of available memory can be run safely.
Also go read the documentation for the Test and Test::Harness modules for more environment variables that affect testing. There's always more. π
π₯ Performance testing π₯
The file t/perf/benchmarks contains snippets of perl code that are intended to be benchmarked across a range of perls by the Porting/bench.pl tool. So if you fix or enhance a performance issue, you may want to add a representative code sample to the file, then run bench.pl against the previous and current perls to see what difference it made β and whether anything else slowed down as a consequence. Rip to whatever got slower. π
The file t/perf/opcount.t is designed to test whether a particular code snippet has been compiled into an optree containing specified numbers of particular op types. This is great for testing whether optimisations that alter ops β like converting an "aelem" op into an "aelemfast" op β are really doing that.
The files t/perf/speed.t and t/re/speed.t are designed to test things that run thousands of times slower if a particular optimisation is broken (for example, the utf8 length cache on long utf8 strings). Add a test that'll take a fraction of a second normally β and minutes otherwise β causing the test file to time out on failure. Sneaky but genius. π
π Building perl at older commits π
In the course of hacking on the Perl core distribution, you may have occasion to configure, build and test perl at an old commit. And sometimes "make" will just... fail during this process. π If that happens, you may be able to salvage the whole situation by using the Devel::PatchPerl library from CPAN (not included in the core) to bring the source code at that commit to a buildable state. Saving the day, one patch at a time. π«Ά
okay so here's a real world example, taken from work done to resolve perl #10118 (https://github.com/Perl/perl5/issues/10118). Use of Porting/bisect.pl had identified commit ba77e4cc9d1ceebf472c9c5c18b2377ee47062e6 as the commit in which a bug was corrected. To confirm, a P5P developer wanted to configure and build perl at commit ba77e4c^ (presumably "bad") and then at ba77e4c (presumably "good"). Normal configuration and build was attempted:
$ sh ./Configure -des -Dusedevel
$ make test_prep
make, however, failed with output (excerpted) like this:
cc -fstack-protector -L/usr/local/lib -o miniperl \
gv.o toke.o perly.o pad.o regcomp.o dump.o util.o \
mg.o reentr.o mro.o hv.o av.o run.o pp_hot.o sv.o \
pp.o scope.o pp_ctl.o pp_sys.o doop.o doio.o regexec.o \
utf8.o taint.o deb.o universal.o globals.o perlio.o \
numeric.o mathoms.o locale.o pp_pack.o pp_sort.o \
miniperlmain.o opmini.o perlmini.o
pp.o: In function `Perl_pp_pow':
pp.c:(.text+0x2db9): undefined reference to `pow'
...
collect2: error: ld returned 1 exit status
makefile:348: recipe for target 'miniperl' failed
make: *** [miniperl] Error 1
Another P5P contributor recommended installation and use of Devel::PatchPerl for this situation, first to determine the version of perl at the commit in question, then to patch the source code at that point to facilitate a build.
$ perl -MDevel::PatchPerl -e \
'print Devel::PatchPerl->determine_version("/path/to/sourcecode"),
"\n";'
5.11.1
$ perl -MDevel::PatchPerl -e \
'Devel::PatchPerl->patch_source("5.11.1", "/path/to/sourcecode");'
Once the source was patched, ./Configure and make test_prep were called and completed successfully, enabling confirmation of the findings in RT #72414.
β¨ MORE READING FOR GUTS HACKERS β¨
To hack on the Perl guts, you'll need to read the following things:
perlsourceβ An overview of the Perl source tree. This will help you find the files you're looking for. πΊοΈperlinterpβ An overview of the Perl interpreter source code and some details on how Perl does what it does. π§perlhacktutβ This document walks through the creation of a small patch to Perl's C code. If you're just getting started with Perl core hacking, this will help you understand how it works. π£perlhacktipsβ More details on hacking the Perl core. This document focuses on lower level details such as how to write tests, compilation issues, portability, debugging, etc. If you plan on doing serious C hacking, make sure to read this. π₯perlgutsβ This is of paramount importance, since it's the documentation of what goes where in the Perl source. Read it over a couple of times and it might start to make sense - don't worry if it doesn't yet, because the best way to study it is to read it in conjunction with poking at Perl source, and we'll do that later on. Gisle Aas's "illustrated perlguts", also known as illguts, has very helpful pictures:
https://metacpan.org/release/RURBAN/illguts-0.49 πΈ
perlxstutandperlxsβ A working knowledge of XSUB programming is incredibly useful for core hacking; XSUBs use techniques drawn from the PP code, the portion of the guts that actually executes a Perl program. It's a lot gentler to learn those techniques from simple examples and explanation than from the core itself. π§΅perlapiβ The documentation for the Perl API explains what some of the internal functions do, as well as the many macros used in the source. πPorting/pumpkin.podβ This is a collection of words of wisdom for a Perl porter; some of it is only useful to the pumpkin holders, but most of it applies to anyone wanting to go about Perl development. π
π CPAN TESTERS AND PERL SMOKERS π
The CPAN testers ( https://cpantesters.org/ ) are a group of volunteers who test CPAN modules on a variety of platforms.
Perl Smokers ( https://www.nntp.perl.org/group/perl.daily-build/ and https://www.nntp.perl.org/group/perl.daily-build.reports/ ) automatically test Perl source releases on platforms with various configurations.
Both efforts welcome volunteers. In order to get involved in smoke testing of the perl itself visit https://metacpan.org/release/Test-Smoke. In order to start smoke testing CPAN modules visit https://metacpan.org/release/CPANPLUS-YACSmoke or https://metacpan.org/release/minismokebox or https://metacpan.org/release/CPAN-Reporter.
π WHAT NEXT? π
If you've read all the documentation in the document and the ones listed above, you're more than ready to hack on Perl.
Here's some more recommendations:
- Subscribe to perl5-porters, follow the patches and try and understand them; don't be afraid to ask if there's a portion you're not clear on - who knows, you may unearth a bug in the patch... π
- Do read the README associated with your operating system, e.g.
README.aixon the IBM AIX OS. Don't hesitate to supply patches to that README if you find anything missing or changed over a new OS release. π§ - Find an area of Perl that seems interesting to you, and see if you can work out how it works. Scan through the source, and step over it in the debugger. Play, poke, investigate, fiddle! You'll probably get to understand not just your chosen area but a much wider range of perl's activity as well, and probably sooner than you'd think. π΅οΈββοΈ
π£οΈ "The Road goes ever on and on, down from the door where it began." π£οΈ
If you can do these things, you've started on the long road to Perl porting. Thanks for wanting to help make Perl better - and happy hacking! π
π Metaphoric Quotations π
If you recognized the quote about the Road above, you're in luck.
Most software projects begin each file with a literal description of each file's purpose. Perl instead begins each with a literary allusion to that file's purpose.
Like chapters in many books, all top-level Perl source files (along with a few others here and there) begin with an epigrammatic inscription that alludes, indirectly and metaphorically, to the material you're about to read.
Quotations are taken from writings of J.R.R. Tolkien pertaining to his Legendarium, almost always from The Lord of the Rings. Chapters and page numbers are given using the following editions:
- The Hobbit, by J.R.R. Tolkien. The hardcover, 70th-anniversary edition of 2007 was used, published in the UK by Harper Collins Publishers and in the US by the Houghton Mifflin Company.
- The Lord of the Rings, by J.R.R. Tolkien. The hardcover, 50th-anniversary edition of 2004 was used, published in the UK by Harper Collins Publishers and in the US by the Houghton Mifflin Company.
- The Lays of Beleriand, by J.R.R. Tolkien and published posthumously by his son and literary executor, C.J.R. Tolkien, being the 3rd of the 12 volumes in Christopher's mammoth History of Middle Earth. Page numbers derive from the hardcover edition, first published in 1983 by George Allen & Unwin; no page numbers changed for the special 3-volume omnibus edition of 2002 or the various trade-paper editions, all again now by Harper Collins or Houghton Mifflin.
Other JRRT books fair game for quotes would thus include The Adventures of Tom Bombadil, The Silmarillion, Unfinished Tales, and The Tale of the Children of Hurin, all but the first posthumously assembled by CJRT. But The Lord of the Rings itself is perfectly fine and probably best to quote from, provided you can find a suitable quote there.
So if you were to supply a new, complete, top-level source file to add to Perl, you should conform to this peculiar practice by yourself selecting an appropriate quotation from Tolkien, retaining the original spelling and punctuation and using the same format the rest of the quotes are in. Indirect and oblique is just fine; remember, it's a metaphor, so being meta is, after all, what it's for. π«
π AUTHOR π
This document was originally written by Nathan Torkington, and is maintained by the perl5-porters mailing list.
and that's the whole page bestie! this one came from perl v5.44.0, dated 2026-10-17. happy hacking, ily πβ¨π¦
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms