1PERLHACK(1) Perl Programmers Reference Guide PERLHACK(1)
2
3
4
6 perlhack - How to hack on Perl
7
9 This document explains how Perl development works. It includes details
10 about the Perl 5 Porters email list, the Perl repository, the Perl bug
11 tracker, patch guidelines, and commentary on Perl development
12 philosophy.
13
15 If you just want to submit a single small patch like a pod fix, a test
16 for a bug, comment fixes, etc., it's easy! Here's how:
17
18 • Check out the source repository
19
20 The perl source is in a git repository. You can clone the
21 repository with the following command:
22
23 % git clone https://github.com/Perl/perl5.git perl
24
25 • Ensure you're following the latest advice
26
27 In case the advice in this guide has been updated recently, read
28 the latest version directly from the perl source:
29
30 % perldoc pod/perlhack.pod
31
32 • Create a branch for your change
33
34 Create a branch based on blead to commit your change to, which will
35 later be used to send it to the Perl issue tracker.
36
37 % git checkout -b mychange
38
39 • Make your change
40
41 Hack, hack, hack. Keep in mind that Perl runs on many different
42 platforms, with different operating systems that have different
43 capabilities, different filesystem organizations, and even
44 different character sets. perlhacktips gives advice on this.
45
46 • Test your change
47
48 You can run all the tests with the following commands:
49
50 % ./Configure -des -Dusedevel
51 % make test
52
53 Keep hacking until the tests pass.
54
55 • Commit your change
56
57 Committing your work will save the change on your local system:
58
59 % git commit -a -m 'Commit message goes here'
60
61 Make sure the commit message describes your change in a single
62 sentence. For example, "Fixed spelling errors in perlhack.pod".
63
64 • Send your change to the Perl issue tracker
65
66 The next step is to submit your patch to the Perl core ticket
67 system.
68
69 Create a GitHub fork of the perl5 repository and add it as a
70 remote, if you haven't already, as described in the GitHub
71 documentation at
72 <https://help.github.com/en/articles/working-with-forks>.
73
74 % git remote add fork git@github.com:MyUser/perl5.git
75
76 For more information, see "Connecting to GitHub with SSH"
77 <https://docs.github.com/en/free-pro-
78 team@latest/github/authenticating-to-github/connecting-to-github-
79 with-ssh>.
80
81 If you'd rather use an HTTPS URL for your "git push" see "Cloning
82 with HTTPS URLs" <https://docs.github.com/en/free-pro-
83 team@latest/github/using-git/which-remote-url-should-i-use#cloning-
84 with-https-urls>.
85
86 % git remote add fork https://github.com/MyUser/perl5.git
87
88 Then, push your new branch to your fork.
89
90 % git push -u fork mychange
91
92 Finally, create a Pull Request on GitHub from your branch to blead
93 as described in the GitHub documentation at
94 <https://help.github.com/en/articles/creating-a-pull-request-from-a-fork>.
95
96 • Thank you
97
98 The porters appreciate the time you spent helping to make Perl
99 better. Thank you!
100
101 • Acknowledgement
102
103 All contributors are credited (by name and email address) in the
104 AUTHORS file, which is part of the perl distribution, as well as
105 the Git commit history.
106
107 If you don’t want to be included in the AUTHORS file, just let us
108 know. Otherwise we will take your submission of a patch as
109 permission to credit you in the AUTHORS file.
110
111 • Next time
112
113 The next time you wish to make a patch, you need to start from the
114 latest perl in a pristine state. Check you don't have any local
115 changes or added files in your perl check-out which you wish to
116 keep, then run these commands:
117
118 % git checkout blead
119 % git pull
120 % git reset --hard origin/blead
121 % git clean -dxf
122
124 If you want to report a bug in Perl, or browse existing Perl bugs and
125 patches, use the GitHub issue tracker at
126 <https://github.com/perl/perl5/issues>.
127
128 Please check the archive of the perl5-porters list (see below) and/or
129 the bug tracking system before submitting a bug report. Often, you'll
130 find that the bug has been reported already.
131
132 You can log in to the bug tracking system and comment on existing bug
133 reports. If you have additional information regarding an existing bug,
134 please add it. This will help the porters fix the bug.
135
137 The perl5-porters (p5p) mailing list is where the Perl standard
138 distribution is maintained and developed. The people who maintain Perl
139 are also referred to as the "Perl 5 Porters", "p5p" or just the
140 "porters".
141
142 A searchable archive of the list is available at
143 <https://markmail.org/search/?q=perl5-porters>. There is also an
144 archive at <https://archive.develooper.com/perl5-porters@perl.org/>.
145
146 perl-changes mailing list
147 The perl5-changes mailing list receives a copy of each patch that gets
148 submitted to the maintenance and development branches of the perl
149 repository. See <https://lists.perl.org/list/perl5-changes.html> for
150 subscription and archive information.
151
152 #p5p on IRC
153 Many porters are also active on the <irc://irc.perl.org/#p5p> channel.
154 Feel free to join the channel and ask questions about hacking on the
155 Perl core.
156
158 All of Perl's source code is kept centrally in a Git repository at
159 github.com. The repository contains many Perl revisions from Perl 1
160 onwards and all the revisions from Perforce, the previous version
161 control system.
162
163 For much more detail on using git with the Perl repository, please see
164 perlgit.
165
166 Read access via Git
167 You will need a copy of Git for your computer. You can fetch a copy of
168 the repository using the git protocol:
169
170 % git clone git@github.com:Perl/perl5.git perl
171
172 This clones the repository and makes a local copy in the perl
173 directory.
174
175 If you cannot use the git protocol for firewall reasons, you can also
176 clone via http:
177
178 % git clone https://github.com/Perl/perl5.git perl
179
180 Read access via the web
181 You may access the repository over the web. This allows you to browse
182 the tree, see recent commits, subscribe to repository notifications,
183 search for particular commits and more. You may access it at
184 <https://github.com/Perl/perl5>.
185
186 Write access via git
187 If you have a commit bit, please see perlgit for more details on using
188 git.
189
191 If you're planning to do more extensive work than a single small fix,
192 we encourage you to read the documentation below. This will help you
193 focus your work and make your patches easier to incorporate into the
194 Perl source.
195
196 Submitting patches
197 If you have a small patch to submit, please submit it via the GitHub
198 Pull Request workflow. You may also send patches to the p5p list.
199
200 Patches are reviewed and discussed on GitHub or the p5p list. Simple,
201 uncontroversial patches will usually be applied without any discussion.
202 When the patch is applied, the ticket will be updated and you will
203 receive email.
204
205 In other cases, the patch will need more work or discussion. You are
206 encouraged to participate in the discussion and advocate for your
207 patch. Sometimes your patch may get lost in the shuffle. It's
208 appropriate to send a reminder email to p5p if no action has been taken
209 in a month. Please remember that the Perl 5 developers are all
210 volunteers, and be polite.
211
212 Changes are always applied directly to the main development branch,
213 called "blead". Some patches may be backported to a maintenance
214 branch. If you think your patch is appropriate for the maintenance
215 branch (see "MAINTENANCE BRANCHES" in perlpolicy), please explain why
216 when you submit it.
217
218 Getting your patch accepted
219 If you are submitting a code patch there are several things that you
220 can do to help the Perl 5 Porters accept your patch.
221
222 Patch style
223
224 Using the GitHub Pull Request workflow, your patch will automatically
225 be available in a suitable format. If you wish to submit a patch to
226 the p5p list for review, make sure to create it appropriately.
227
228 If you used git to check out the Perl source, then using "git
229 format-patch" will produce a patch in a style suitable for Perl. The
230 "format-patch" command produces one patch file for each commit you
231 made. If you prefer to send a single patch for all commits, you can
232 use "git diff".
233
234 % git checkout blead
235 % git pull
236 % git diff blead my-branch-name
237
238 This produces a patch based on the difference between blead and your
239 current branch. It's important to make sure that blead is up to date
240 before producing the diff, that's why we call "git pull" first.
241
242 We strongly recommend that you use git if possible. It will make your
243 life easier, and ours as well.
244
245 However, if you're not using git, you can still produce a suitable
246 patch. You'll need a pristine copy of the Perl source to diff against.
247 The porters prefer unified diffs. Using GNU "diff", you can produce a
248 diff like this:
249
250 % diff -Npurd perl.pristine perl.mine
251
252 Make sure that you "make realclean" in your copy of Perl to remove any
253 build artifacts, or you may get a confusing result.
254
255 Commit message
256
257 As you craft each patch you intend to submit to the Perl core, it's
258 important to write a good commit message. This is especially important
259 if your submission will consist of a series of commits.
260
261 The first line of the commit message should be a short description
262 without a period. It should be no longer than the subject line of an
263 email, 50 characters being a good rule of thumb.
264
265 A lot of Git tools (Gitweb, GitHub, git log --pretty=oneline, ...) will
266 only display the first line (cut off at 50 characters) when presenting
267 commit summaries.
268
269 The commit message should include a description of the problem that the
270 patch corrects or new functionality that the patch adds.
271
272 As a general rule of thumb, your commit message should help a
273 programmer who knows the Perl core quickly understand what you were
274 trying to do, how you were trying to do it, and why the change matters
275 to Perl.
276
277 • Why
278
279 Your commit message should describe why the change you are making
280 is important. When someone looks at your change in six months or
281 six years, your intent should be clear.
282
283 If you're deprecating a feature with the intent of later
284 simplifying another bit of code, say so. If you're fixing a
285 performance problem or adding a new feature to support some other
286 bit of the core, mention that.
287
288 • What
289
290 Your commit message should describe what part of the Perl core
291 you're changing and what you expect your patch to do.
292
293 • How
294
295 While it's not necessary for documentation changes, new tests or
296 trivial patches, it's often worth explaining how your change works.
297 Even if it's clear to you today, it may not be clear to a porter
298 next month or next year.
299
300 A commit message isn't intended to take the place of comments in your
301 code. Commit messages should describe the change you made, while code
302 comments should describe the current state of the code.
303
304 If you've just implemented a new feature, complete with doc, tests and
305 well-commented code, a brief commit message will often suffice. If,
306 however, you've just changed a single character deep in the parser or
307 lexer, you might need to write a small novel to ensure that future
308 readers understand what you did and why you did it.
309
310 Comments, Comments, Comments
311
312 Be sure to adequately comment your code. While commenting every line
313 is unnecessary, anything that takes advantage of side effects of
314 operators, that creates changes that will be felt outside of the
315 function being patched, or that others may find confusing should be
316 documented. If you are going to err, it is better to err on the side
317 of adding too many comments than too few.
318
319 The best comments explain why the code does what it does, not what it
320 does.
321
322 Style
323
324 In general, please follow the particular style of the code you are
325 patching.
326
327 In particular, follow these general guidelines for patching Perl
328 sources:
329
330 • 4-wide indents for code, 2-wide indents for nested CPP "#define"s,
331 with 8-wide tabstops.
332
333 • Use spaces for indentation, not tab characters.
334
335 The codebase is a mixture of tabs and spaces for indentation, and
336 we are moving to spaces only. Converting lines you're patching
337 from 8-wide tabs to spaces will help this migration.
338
339 • Try not to exceed 79 columns
340
341 In general, we target 80 column lines. When sticking to 80 columns
342 would lead to torturous code or rework, it's fine to go longer.
343 Try to keep your excess past 80 to a minimum.
344
345 • ANSI C prototypes
346
347 • Uncuddled elses and "K&R" style for indenting control constructs
348
349 • No C++ style (//) comments
350
351 • Mark places that need to be revisited with XXX (and revisit often!)
352
353 • Opening brace lines up with "if" when conditional spans multiple
354 lines; should be at end-of-line otherwise
355
356 • In function definitions, name starts in column 0 (return value-type
357 is on previous line)
358
359 • Single space after keywords that are followed by parens, no space
360 between function name and following paren
361
362 • Avoid assignments in conditionals, but if they're unavoidable, use
363 extra paren, e.g. "if (a && (b = c)) ..."
364
365 • "return foo;" rather than "return(foo);"
366
367 • "if (!foo) ..." rather than "if (foo == FALSE) ..." etc.
368
369 • Do not declare variables using "register". It may be
370 counterproductive with modern compilers, and is deprecated in C++,
371 under which the Perl source is regularly compiled.
372
373 • In-line functions that are in headers that are accessible to XS
374 code need to be able to compile without warnings with commonly used
375 extra compilation flags, such as gcc's "-Wswitch-default" which
376 warns whenever a switch statement does not have a "default" case.
377 The use of these extra flags is to catch potential problems in
378 legal C code, and is often used by Perl aggregators, such as Linux
379 distributors.
380
381 Test suite
382
383 If your patch changes code (rather than just changing documentation),
384 you should also include one or more test cases which illustrate the bug
385 you're fixing or validate the new functionality you're adding. In
386 general, you should update an existing test file rather than create a
387 new one.
388
389 Your test suite additions should generally follow these guidelines
390 (courtesy of Gurusamy Sarathy <gsar@activestate.com>):
391
392 • Know what you're testing. Read the docs, and the source.
393
394 • Tend to fail, not succeed.
395
396 • Interpret results strictly.
397
398 • Use unrelated features (this will flush out bizarre interactions).
399
400 • Use non-standard idioms (otherwise you are not testing TIMTOWTDI).
401
402 • Avoid using hardcoded test numbers whenever possible (the
403 EXPECTED/GOT found in t/op/tie.t is much more maintainable, and
404 gives better failure reports).
405
406 • Give meaningful error messages when a test fails.
407
408 • Avoid using qx// and system() unless you are testing for them. If
409 you do use them, make sure that you cover _all_ perl platforms.
410
411 • Unlink any temporary files you create.
412
413 • Promote unforeseen warnings to errors with $SIG{__WARN__}.
414
415 • Be sure to use the libraries and modules shipped with the version
416 being tested, not those that were already installed.
417
418 • Add comments to the code explaining what you are testing for.
419
420 • Make updating the '1..42' string unnecessary. Or make sure that
421 you update it.
422
423 • Test _all_ behaviors of a given operator, library, or function.
424
425 Test all optional arguments.
426
427 Test return values in various contexts (boolean, scalar, list,
428 lvalue).
429
430 Use both global and lexical variables.
431
432 Don't forget the exceptional, pathological cases.
433
434 Patching a core module
435 This works just like patching anything else, with one extra
436 consideration.
437
438 Modules in the cpan/ directory of the source tree are maintained
439 outside of the Perl core. When the author updates the module, the
440 updates are simply copied into the core. See that module's
441 documentation or its listing on <https://metacpan.org/> for more
442 information on reporting bugs and submitting patches.
443
444 In most cases, patches to modules in cpan/ should be sent upstream and
445 should not be applied to the Perl core individually. If a patch to a
446 file in cpan/ absolutely cannot wait for the fix to be made upstream,
447 released to CPAN and copied to blead, you must add (or update) a
448 "CUSTOMIZED" entry in the Porting/Maintainers.pl file to flag that a
449 local modification has been made. See Porting/Maintainers.pl for more
450 details.
451
452 In contrast, modules in the dist/ directory are maintained in the core.
453
454 Updating perldelta
455 For changes significant enough to warrant a pod/perldelta.pod entry,
456 the porters will greatly appreciate it if you submit a delta entry
457 along with your actual change. Significant changes include, but are
458 not limited to:
459
460 • Adding, deprecating, or removing core features
461
462 • Adding, deprecating, removing, or upgrading core or dual-life
463 modules
464
465 • Adding new core tests
466
467 • Fixing security issues and user-visible bugs in the core
468
469 • Changes that might break existing code, either on the perl or C
470 level
471
472 • Significant performance improvements
473
474 • Adding, removing, or significantly changing documentation in the
475 pod/ directory
476
477 • Important platform-specific changes
478
479 Please make sure you add the perldelta entry to the right section
480 within pod/perldelta.pod. More information on how to write good
481 perldelta entries is available in the "Style" section of
482 Porting/how_to_write_a_perldelta.pod.
483
484 What makes for a good patch?
485 New features and extensions to the language can be contentious. There
486 is no specific set of criteria which determine what features get added,
487 but here are some questions to consider when developing a patch:
488
489 Does the concept match the general goals of Perl?
490
491 Our goals include, but are not limited to:
492
493 1. Keep it fast, simple, and useful.
494
495 2. Keep features/concepts as orthogonal as possible.
496
497 3. No arbitrary limits (platforms, data sizes, cultures).
498
499 4. Keep it open and exciting to use/patch/advocate Perl everywhere.
500
501 5. Either assimilate new technologies, or build bridges to them.
502
503 Where is the implementation?
504
505 All the talk in the world is useless without an implementation. In
506 almost every case, the person or people who argue for a new feature
507 will be expected to be the ones who implement it. Porters capable of
508 coding new features have their own agendas, and are not available to
509 implement your (possibly good) idea.
510
511 Backwards compatibility
512
513 It's a cardinal sin to break existing Perl programs. New warnings can
514 be contentious--some say that a program that emits warnings is not
515 broken, while others say it is. Adding keywords has the potential to
516 break programs, changing the meaning of existing token sequences or
517 functions might break programs.
518
519 The Perl 5 core includes mechanisms to help porters make backwards
520 incompatible changes more compatible such as the feature and deprecate
521 modules. Please use them when appropriate.
522
523 Could it be a module instead?
524
525 Perl 5 has extension mechanisms, modules and XS, specifically to avoid
526 the need to keep changing the Perl interpreter. You can write modules
527 that export functions, you can give those functions prototypes so they
528 can be called like built-in functions, you can even write XS code to
529 mess with the runtime data structures of the Perl interpreter if you
530 want to implement really complicated things.
531
532 Whenever possible, new features should be prototyped in a CPAN module
533 before they will be considered for the core.
534
535 Is the feature generic enough?
536
537 Is this something that only the submitter wants added to the language,
538 or is it broadly useful? Sometimes, instead of adding a feature with a
539 tight focus, the porters might decide to wait until someone implements
540 the more generalized feature.
541
542 Does it potentially introduce new bugs?
543
544 Radical rewrites of large chunks of the Perl interpreter have the
545 potential to introduce new bugs.
546
547 How big is it?
548
549 The smaller and more localized the change, the better. Similarly, a
550 series of small patches is greatly preferred over a single large patch.
551
552 Does it preclude other desirable features?
553
554 A patch is likely to be rejected if it closes off future avenues of
555 development. For instance, a patch that placed a true and final
556 interpretation on prototypes is likely to be rejected because there are
557 still options for the future of prototypes that haven't been addressed.
558
559 Is the implementation robust?
560
561 Good patches (tight code, complete, correct) stand more chance of going
562 in. Sloppy or incorrect patches might be placed on the back burner
563 until fixes can be made, or they might be discarded altogether without
564 further notice.
565
566 Is the implementation generic enough to be portable?
567
568 The worst patches make use of system-specific features. It's highly
569 unlikely that non-portable additions to the Perl language will be
570 accepted.
571
572 Is the implementation tested?
573
574 Patches which change behaviour (fixing bugs or introducing new
575 features) must include regression tests to verify that everything works
576 as expected.
577
578 Without tests provided by the original author, how can anyone else
579 changing perl in the future be sure that they haven't unwittingly
580 broken the behaviour the patch implements? And without tests, how can
581 the patch's author be confident that his/her hard work put into the
582 patch won't be accidentally thrown away by someone in the future?
583
584 Is there enough documentation?
585
586 Patches without documentation are probably ill-thought out or
587 incomplete. No features can be added or changed without documentation,
588 so submitting a patch for the appropriate pod docs as well as the
589 source code is important.
590
591 Is there another way to do it?
592
593 Larry said "Although the Perl Slogan is There's More Than One Way to Do
594 It, I hesitate to make 10 ways to do something". This is a tricky
595 heuristic to navigate, though--one man's essential addition is another
596 man's pointless cruft.
597
598 Does it create too much work?
599
600 Work for the committers, work for Perl programmers, work for module
601 authors, ... Perl is supposed to be easy.
602
603 Patches speak louder than words
604
605 Working code is always preferred to pie-in-the-sky ideas. A patch to
606 add a feature stands a much higher chance of making it to the language
607 than does a random feature request, no matter how fervently argued the
608 request might be. This ties into "Will it be useful?", as the fact
609 that someone took the time to make the patch demonstrates a strong
610 desire for the feature.
611
613 The core uses the same testing style as the rest of Perl, a simple
614 "ok/not ok" run through Test::Harness, but there are a few special
615 considerations.
616
617 There are three ways to write a test in the core: Test::More, t/test.pl
618 and ad hoc "print $test ? "ok 42\n" : "not ok 42\n"". The decision of
619 which to use depends on what part of the test suite you're working on.
620 This is a measure to prevent a high-level failure (such as Config.pm
621 breaking) from causing basic functionality tests to fail.
622
623 The t/test.pl library provides some of the features of Test::More, but
624 avoids loading most modules and uses as few core features as possible.
625
626 If you write your own test, use the Test Anything Protocol
627 <https://testanything.org>.
628
629 • t/base, t/comp and t/opbasic
630
631 Since we don't know if "require" works, or even subroutines, use ad
632 hoc tests for these three. Step carefully to avoid using the
633 feature being tested. Tests in t/opbasic, for instance, have been
634 placed there rather than in t/op because they test functionality
635 which t/test.pl presumes has already been demonstrated to work.
636
637 • All other subdirectories of t/
638
639 Now that basic require() and subroutines are tested, you can use
640 the t/test.pl library.
641
642 You can also use certain libraries like Config conditionally, but
643 be sure to skip the test gracefully if it's not there.
644
645 • Test files not found under t/
646
647 This category includes .t files underneath directories such as
648 dist, ext and lib. Since the core of Perl has now been tested,
649 Test::More can and now should be used. You can also use the full
650 suite of core modules in the tests. (As noted in "Patching a core
651 module" above, changes to .t files found under cpan/ should be
652 submitted to the upstream maintainers of those modules.)
653
654 When you say "make test", Perl uses the t/TEST program to run the test
655 suite (except under Win32 where it uses t/harness instead). All tests
656 are run from the t/ directory, not the directory which contains the
657 test. This causes some problems with the tests in lib/, so here's some
658 opportunity for some patching.
659
660 You must be triply conscious of cross-platform concerns. This usually
661 boils down to using File::Spec, avoiding things like fork() and
662 system() unless absolutely necessary, and not assuming that a given
663 character has a particular ordinal value (code point) or that its UTF-8
664 representation is composed of particular bytes.
665
666 There are several functions available to specify characters and code
667 points portably in tests. The always-preloaded functions
668 utf8::unicode_to_native() and its inverse utf8::native_to_unicode()
669 take code points and translate appropriately. The file
670 t/charset_tools.pl has several functions that can be useful. It has
671 versions of the previous two functions that take strings as inputs --
672 not single numeric code points: uni_to_native() and native_to_uni().
673 If you must look at the individual bytes comprising a UTF-8 encoded
674 string, byte_utf8a_to_utf8n() takes as input a string of those bytes
675 encoded for an ASCII platform, and returns the equivalent string in the
676 native platform. For example, byte_utf8a_to_utf8n("\xC2\xA0") returns
677 the byte sequence on the current platform that form the UTF-8 for
678 "U+00A0", since "\xC2\xA0" are the UTF-8 bytes on an ASCII platform for
679 that code point. This function returns "\xC2\xA0" on an ASCII
680 platform, and "\x80\x41" on an EBCDIC 1047 one.
681
682 But easiest is, if the character is specifiable as a literal, like "A"
683 or "%", to use that; if not so specificable, you can use "\N{}" , if
684 the side effects aren't troublesome. Simply specify all your
685 characters in hex, using "\N{U+ZZ}" instead of "\xZZ". "\N{}" is the
686 Unicode name, and so it always gives you the Unicode character.
687 "\N{U+41}" is the character whose Unicode code point is 0x41, hence is
688 'A' on all platforms. The side effects are:
689
690 • These select Unicode rules. That means that in double-quotish
691 strings, the string is always converted to UTF-8 to force a Unicode
692 interpretation (you can utf8::downgrade() afterwards to convert
693 back to non-UTF8, if possible). In regular expression patterns,
694 the conversion isn't done, but if the character set modifier would
695 otherwise be "/d", it is changed to "/u".
696
697 • If you use the form "\N{character name}", the charnames module gets
698 automatically loaded. This may not be suitable for the test level
699 you are doing.
700
701 If you are testing locales (see perllocale), there are helper functions
702 in t/loc_tools.pl to enable you to see what locales there are on the
703 current platform.
704
705 Special "make test" targets
706 There are various special make targets that can be used to test Perl
707 slightly differently than the standard "test" target. Not all them are
708 expected to give a 100% success rate. Many of them have several
709 aliases, and many of them are not available on certain operating
710 systems.
711
712 • test_porting
713
714 This runs some basic sanity tests on the source tree and helps
715 catch basic errors before you submit a patch.
716
717 • minitest
718
719 Run miniperl on t/base, t/comp, t/cmd, t/run, t/io, t/op, t/uni and
720 t/mro tests.
721
722 miniperl is a minimalistic perl built to bootstrap building
723 extensions, utilties, documentation etc. It doesn't support
724 dynamic loading and depending on the point in the build process
725 will only have access to a limited set of core modules. miniperl
726 is not intended for day to day use.
727
728 • test.valgrind check.valgrind
729
730 (Only in Linux) Run all the tests using the memory leak + naughty
731 memory access tool "valgrind". The log files will be named
732 testname.valgrind.
733
734 • test_harness
735
736 Run the test suite with the t/harness controlling program, instead
737 of t/TEST. t/harness is more sophisticated, and uses the
738 Test::Harness module, thus using this test target supposes that
739 perl mostly works. The main advantage for our purposes is that it
740 prints a detailed summary of failed tests at the end. Also, unlike
741 t/TEST, it doesn't redirect stderr to stdout.
742
743 Note that under Win32 t/harness is always used instead of t/TEST,
744 so there is no special "test_harness" target.
745
746 Under the Unix build process you may use the TEST_ARGS and
747 TEST_FILES parameters to pass arguments through to the underlying
748 harness call. This means that for instance you could do
749
750 make test_harness TEST_ARGS="-v -re pat"
751
752 which would make, and then run the test harness in verbose mode
753 over files which contain "pat". Or you could do
754
755 make test_harness TEST_ARGS="-torture" TEST_FILES="op/*.t"
756
757 and run torture tests on files matching the glob "op/*.t".
758
759 Under Win32's "test" target you may use the TEST_SWITCHES and
760 TEST_FILES environment variables to control the behaviour of
761 t/harness. This means you can say
762
763 nmake test TEST_FILES="op/*.t"
764 nmake test TEST_SWITCHES="-torture" TEST_FILES="op/*.t"
765
766 Note that for compatibility with the unix build process TEST_ARGS
767 may also be used instead of the traditional TEST_SWITCHES argument.
768
769 • test-notty test_notty
770
771 Sets PERL_SKIP_TTY_TEST to true before running normal test.
772
773 Parallel tests
774 The core distribution can now run its regression tests in parallel on
775 Unix-like and Windows platforms. On Unix, instead of running "make
776 test", set "TEST_JOBS" in your environment to the number of tests to
777 run in parallel, and run "make test_harness". On a Bourne-like shell,
778 this can be done as
779
780 TEST_JOBS=3 make test_harness # Run 3 tests in parallel
781
782 An environment variable is used, rather than parallel make itself,
783 because TAP::Harness needs to be able to schedule individual non-
784 conflicting test scripts itself, and there is no standard interface to
785 "make" utilities to interact with their job schedulers.
786
787 Tests are normally run in a logical order, with the sanity tests first,
788 then the main tests of the Perl core functionality, then the tests for
789 the non-core modules. On many-core systems, this may not use the
790 hardware as effectively as possible. By also specifying
791
792 TEST_JOBS=19 PERL_TEST_HARNESS_ASAP=1 make -j19 test_harness
793
794 you signal that you want the tests to finish in wall-clock time as
795 short as possible. After the sanity tests are completed, this causes
796 the remaining ones to be packed into the available cores as tightly as
797 we know how. This has its greatest effect on slower, many-core
798 systems. Throughput was sped up by 20% on an outmoded 24-core system;
799 less on more recent faster ones with fewer cores.
800
801 Note that the command line above added a "-j" parameter to make, so as
802 to cause parallel compilation. This may or may not work on your
803 platform.
804
805 Normally data on how long tests take is stored in t/test_state, however
806 you can change this to use a different filename by setting the
807 "PERL_TEST_STATE_FILE" environment variable to something different, or
808 to a false value (0 or the empty string) to disable use of the state
809 mechanism entirely. There are no protections against the format of the
810 state file changing over time, so if you have any issues related to
811 this file it is up to you to delete the file manually and then let the
812 harness recreate it, although the file format does not change
813 frequently so this should not be necessary very often.
814
815 Running tests by hand
816 You can run part of the test suite by hand by using one of the
817 following commands from the t/ directory:
818
819 ./perl -I../lib TEST list-of-.t-files
820
821 or
822
823 ./perl -I../lib harness list-of-.t-files
824
825 (If you don't specify test scripts, the whole test suite will be run.)
826
827 Using t/harness for testing
828 If you use "harness" for testing, you have several command line options
829 available to you. The arguments are as follows, and are in the order
830 that they must appear if used together.
831
832 harness -v -torture -re=pattern LIST OF FILES TO TEST
833 harness -v -torture -re LIST OF PATTERNS TO MATCH
834
835 If "LIST OF FILES TO TEST" is omitted, the file list is obtained from
836 the manifest. The file list may include shell wildcards which will be
837 expanded out.
838
839 • -v
840
841 Run the tests under verbose mode so you can see what tests were
842 run, and debug output.
843
844 • -torture
845
846 Run the torture tests as well as the normal set.
847
848 • -re=PATTERN
849
850 Filter the file list so that all the test files run match PATTERN.
851 Note that this form is distinct from the -re LIST OF PATTERNS form
852 below in that it allows the file list to be provided as well.
853
854 • -re LIST OF PATTERNS
855
856 Filter the file list so that all the test files run match
857 /(LIST|OF|PATTERNS)/. Note that with this form the patterns are
858 joined by '|' and you cannot supply a list of files, instead the
859 test files are obtained from the MANIFEST.
860
861 You can run an individual test by a command similar to
862
863 ./perl -I../lib path/to/foo.t
864
865 except that the harnesses set up some environment variables that may
866 affect the execution of the test:
867
868 • PERL_CORE=1
869
870 indicates that we're running this test as part of the perl core
871 test suite. This is useful for modules that have a dual life on
872 CPAN.
873
874 • PERL_DESTRUCT_LEVEL=2
875
876 is set to 2 if it isn't set already (see "PERL_DESTRUCT_LEVEL" in
877 perlhacktips).
878
879 • PERL
880
881 (used only by t/TEST) if set, overrides the path to the perl
882 executable that should be used to run the tests (the default being
883 ./perl).
884
885 • PERL_SKIP_TTY_TEST
886
887 if set, tells to skip the tests that need a terminal. It's
888 actually set automatically by the Makefile, but can also be forced
889 artificially by running 'make test_notty'.
890
891 Other environment variables that may influence tests
892
893 • PERL_TEST_Net_Ping
894
895 Setting this variable runs all the Net::Ping modules tests,
896 otherwise some tests that interact with the outside world are
897 skipped. See perl58delta.
898
899 • PERL_TEST_NOVREXX
900
901 Setting this variable skips the vrexx.t tests for OS2::REXX.
902
903 • PERL_TEST_NUMCONVERTS
904
905 This sets a variable in op/numconvert.t.
906
907 • PERL_TEST_MEMORY
908
909 Setting this variable includes the tests in t/bigmem/. This should
910 be set to the number of gigabytes of memory available for testing,
911 eg. "PERL_TEST_MEMORY=4" indicates that tests that require 4GiB of
912 available memory can be run safely.
913
914 See also the documentation for the Test and Test::Harness modules, for
915 more environment variables that affect testing.
916
917 Performance testing
918 The file t/perf/benchmarks contains snippets of perl code which are
919 intended to be benchmarked across a range of perls by the
920 Porting/bench.pl tool. If you fix or enhance a performance issue, you
921 may want to add a representative code sample to the file, then run
922 bench.pl against the previous and current perls to see what difference
923 it has made, and whether anything else has slowed down as a
924 consequence.
925
926 The file t/perf/opcount.t is designed to test whether a particular code
927 snippet has been compiled into an optree containing specified numbers
928 of particular op types. This is good for testing whether optimisations
929 which alter ops, such as converting an "aelem" op into an "aelemfast"
930 op, are really doing that.
931
932 The files t/perf/speed.t and t/re/speed.t are designed to test things
933 that run thousands of times slower if a particular optimisation is
934 broken (for example, the utf8 length cache on long utf8 strings). Add
935 a test that will take a fraction of a second normally, and minutes
936 otherwise, causing the test file to time out on failure.
937
938 Building perl at older commits
939 In the course of hacking on the Perl core distribution, you may have
940 occasion to configure, build and test perl at an old commit. Sometimes
941 "make" will fail during this process. If that happens, you may be able
942 to salvage the situation by using the Devel::PatchPerl library from
943 CPAN (not included in the core) to bring the source code at that commit
944 to a buildable state.
945
946 Here's a real world example, taken from work done to resolve perl
947 #10118 <https://github.com/Perl/perl5/issues/10118>. Use of
948 Porting/bisect.pl had identified commit
949 "ba77e4cc9d1ceebf472c9c5c18b2377ee47062e6" as the commit in which a bug
950 was corrected. To confirm, a P5P developer wanted to configure and
951 build perl at commit "ba77e4c^" (presumably "bad") and then at
952 "ba77e4c" (presumably "good"). Normal configuration and build was
953 attempted:
954
955 $ sh ./Configure -des -Dusedevel
956 $ make test_prep
957
958 "make", however, failed with output (excerpted) like this:
959
960 cc -fstack-protector -L/usr/local/lib -o miniperl \
961 gv.o toke.o perly.o pad.o regcomp.o dump.o util.o \
962 mg.o reentr.o mro.o hv.o av.o run.o pp_hot.o sv.o \
963 pp.o scope.o pp_ctl.o pp_sys.o doop.o doio.o regexec.o \
964 utf8.o taint.o deb.o universal.o globals.o perlio.o \
965 numeric.o mathoms.o locale.o pp_pack.o pp_sort.o \
966 miniperlmain.o opmini.o perlmini.o
967 pp.o: In function `Perl_pp_pow':
968 pp.c:(.text+0x2db9): undefined reference to `pow'
969 ...
970 collect2: error: ld returned 1 exit status
971 makefile:348: recipe for target 'miniperl' failed
972 make: *** [miniperl] Error 1
973
974 Another P5P contributor recommended installation and use of
975 Devel::PatchPerl for this situation, first to determine the version of
976 perl at the commit in question, then to patch the source code at that
977 point to facilitate a build.
978
979 $ perl -MDevel::PatchPerl -e \
980 'print Devel::PatchPerl->determine_version("/path/to/sourcecode"),
981 "\n";'
982 5.11.1
983 $ perl -MDevel::PatchPerl -e \
984 'Devel::PatchPerl->patch_source("5.11.1", "/path/to/sourcecode");'
985
986 Once the source was patched, "./Configure" and "make test_prep" were
987 called and completed successfully, enabling confirmation of the
988 findings in RT #72414.
989
991 To hack on the Perl guts, you'll need to read the following things:
992
993 • perlsource
994
995 An overview of the Perl source tree. This will help you find the
996 files you're looking for.
997
998 • perlinterp
999
1000 An overview of the Perl interpreter source code and some details on
1001 how Perl does what it does.
1002
1003 • perlhacktut
1004
1005 This document walks through the creation of a small patch to Perl's
1006 C code. If you're just getting started with Perl core hacking,
1007 this will help you understand how it works.
1008
1009 • perlhacktips
1010
1011 More details on hacking the Perl core. This document focuses on
1012 lower level details such as how to write tests, compilation issues,
1013 portability, debugging, etc.
1014
1015 If you plan on doing serious C hacking, make sure to read this.
1016
1017 • perlguts
1018
1019 This is of paramount importance, since it's the documentation of
1020 what goes where in the Perl source. Read it over a couple of times
1021 and it might start to make sense - don't worry if it doesn't yet,
1022 because the best way to study it is to read it in conjunction with
1023 poking at Perl source, and we'll do that later on.
1024
1025 Gisle Aas's "illustrated perlguts", also known as illguts, has very
1026 helpful pictures:
1027
1028 <https://metacpan.org/release/RURBAN/illguts-0.49>
1029
1030 • perlxstut and perlxs
1031
1032 A working knowledge of XSUB programming is incredibly useful for
1033 core hacking; XSUBs use techniques drawn from the PP code, the
1034 portion of the guts that actually executes a Perl program. It's a
1035 lot gentler to learn those techniques from simple examples and
1036 explanation than from the core itself.
1037
1038 • perlapi
1039
1040 The documentation for the Perl API explains what some of the
1041 internal functions do, as well as the many macros used in the
1042 source.
1043
1044 • Porting/pumpkin.pod
1045
1046 This is a collection of words of wisdom for a Perl porter; some of
1047 it is only useful to the pumpkin holders, but most of it applies to
1048 anyone wanting to go about Perl development.
1049
1051 The CPAN testers ( <http://cpantesters.org/> ) are a group of
1052 volunteers who test CPAN modules on a variety of platforms.
1053
1054 Perl Smokers ( <https://www.nntp.perl.org/group/perl.daily-build/> and
1055 <https://www.nntp.perl.org/group/perl.daily-build.reports/> )
1056 automatically test Perl source releases on platforms with various
1057 configurations.
1058
1059 Both efforts welcome volunteers. In order to get involved in smoke
1060 testing of the perl itself visit
1061 <https://metacpan.org/release/Test-Smoke>. In order to start smoke
1062 testing CPAN modules visit
1063 <https://metacpan.org/release/CPANPLUS-YACSmoke> or
1064 <https://metacpan.org/release/minismokebox> or
1065 <https://metacpan.org/release/CPAN-Reporter>.
1066
1068 If you've read all the documentation in the document and the ones
1069 listed above, you're more than ready to hack on Perl.
1070
1071 Here's some more recommendations
1072
1073 • Subscribe to perl5-porters, follow the patches and try and
1074 understand them; don't be afraid to ask if there's a portion you're
1075 not clear on - who knows, you may unearth a bug in the patch...
1076
1077 • Do read the README associated with your operating system, e.g.
1078 README.aix on the IBM AIX OS. Don't hesitate to supply patches to
1079 that README if you find anything missing or changed over a new OS
1080 release.
1081
1082 • Find an area of Perl that seems interesting to you, and see if you
1083 can work out how it works. Scan through the source, and step over
1084 it in the debugger. Play, poke, investigate, fiddle! You'll
1085 probably get to understand not just your chosen area but a much
1086 wider range of perl's activity as well, and probably sooner than
1087 you'd think.
1088
1089 "The Road goes ever on and on, down from the door where it began."
1090 If you can do these things, you've started on the long road to Perl
1091 porting. Thanks for wanting to help make Perl better - and happy
1092 hacking!
1093
1094 Metaphoric Quotations
1095 If you recognized the quote about the Road above, you're in luck.
1096
1097 Most software projects begin each file with a literal description of
1098 each file's purpose. Perl instead begins each with a literary allusion
1099 to that file's purpose.
1100
1101 Like chapters in many books, all top-level Perl source files (along
1102 with a few others here and there) begin with an epigrammatic
1103 inscription that alludes, indirectly and metaphorically, to the
1104 material you're about to read.
1105
1106 Quotations are taken from writings of J.R.R. Tolkien pertaining to his
1107 Legendarium, almost always from The Lord of the Rings. Chapters and
1108 page numbers are given using the following editions:
1109
1110 • The Hobbit, by J.R.R. Tolkien. The hardcover, 70th-anniversary
1111 edition of 2007 was used, published in the UK by Harper Collins
1112 Publishers and in the US by the Houghton Mifflin Company.
1113
1114 • The Lord of the Rings, by J.R.R. Tolkien. The hardcover,
1115 50th-anniversary edition of 2004 was used, published in the UK by
1116 Harper Collins Publishers and in the US by the Houghton Mifflin
1117 Company.
1118
1119 • The Lays of Beleriand, by J.R.R. Tolkien and published posthumously
1120 by his son and literary executor, C.J.R. Tolkien, being the 3rd of
1121 the 12 volumes in Christopher's mammoth History of Middle Earth.
1122 Page numbers derive from the hardcover edition, first published in
1123 1983 by George Allen & Unwin; no page numbers changed for the
1124 special 3-volume omnibus edition of 2002 or the various trade-paper
1125 editions, all again now by Harper Collins or Houghton Mifflin.
1126
1127 Other JRRT books fair game for quotes would thus include The Adventures
1128 of Tom Bombadil, The Silmarillion, Unfinished Tales, and The Tale of
1129 the Children of Hurin, all but the first posthumously assembled by
1130 CJRT. But The Lord of the Rings itself is perfectly fine and probably
1131 best to quote from, provided you can find a suitable quote there.
1132
1133 So if you were to supply a new, complete, top-level source file to add
1134 to Perl, you should conform to this peculiar practice by yourself
1135 selecting an appropriate quotation from Tolkien, retaining the original
1136 spelling and punctuation and using the same format the rest of the
1137 quotes are in. Indirect and oblique is just fine; remember, it's a
1138 metaphor, so being meta is, after all, what it's for.
1139
1141 This document was originally written by Nathan Torkington, and is
1142 maintained by the perl5-porters mailing list.
1143
1144
1145
1146perl v5.38.2 2023-11-30 PERLHACK(1)