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