1PERLHACK(1)            Perl Programmers Reference Guide            PERLHACK(1)
2
3
4

NAME

6       perlhack - How to hack on Perl
7

DESCRIPTION

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

SUPER QUICK PATCH GUIDE

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 donXt 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

BUG REPORTING

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

PERL 5 PORTERS

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

GETTING THE PERL SOURCE

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

PATCHING PERL

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

TESTING

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
629t/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
673       "native_to_uni()".  If you must look at the individual bytes comprising
674       a UTF-8 encoded string, "byte_utf8a_to_utf8n()" takes as input a string
675       of those bytes encoded for an ASCII platform, and returns the
676       equivalent string in the native platform.  For example,
677       "byte_utf8a_to_utf8n("\xC2\xA0")" returns the byte sequence on the
678       current platform that form the UTF-8 for "U+00A0", since "\xC2\xA0" are
679       the UTF-8 bytes on an ASCII platform for that code point.  This
680       function returns "\xC2\xA0" on an ASCII platform, and "\x80\x41" on an
681       EBCDIC 1047 one.
682
683       But easiest is, if the character is specifiable as a literal, like "A"
684       or "%", to use that; if not so specificable, you can use "\N{}" , if
685       the side effects aren't troublesome.  Simply specify all your
686       characters in hex, using "\N{U+ZZ}" instead of "\xZZ".  "\N{}" is the
687       Unicode name, and so it always gives you the Unicode character.
688       "\N{U+41}" is the character whose Unicode code point is 0x41, hence is
689       'A' on all platforms.  The side effects are:
690
691       •   These select Unicode rules.  That means that in double-quotish
692           strings, the string is always converted to UTF-8 to force a Unicode
693           interpretation (you can "utf8::downgrade()" afterwards to convert
694           back to non-UTF8, if possible).  In regular expression patterns,
695           the conversion isn't done, but if the character set modifier would
696           otherwise be "/d", it is changed to "/u".
697
698       •   If you use the form "\N{character name}", the charnames module gets
699           automatically loaded.  This may not be suitable for the test level
700           you are doing.
701
702       If you are testing locales (see perllocale), there are helper functions
703       in t/loc_tools.pl to enable you to see what locales there are on the
704       current platform.
705
706   Special "make test" targets
707       There are various special make targets that can be used to test Perl
708       slightly differently than the standard "test" target.  Not all them are
709       expected to give a 100% success rate.  Many of them have several
710       aliases, and many of them are not available on certain operating
711       systems.
712
713       •   test_porting
714
715           This runs some basic sanity tests on the source tree and helps
716           catch basic errors before you submit a patch.
717
718       •   minitest
719
720           Run miniperl on t/base, t/comp, t/cmd, t/run, t/io, t/op, t/uni and
721           t/mro tests.
722
723           miniperl is a minimalistic perl built to bootstrap building
724           extensions, utilties, documentation etc.  It doesn't support
725           dynamic loading and depending on the point in the build process
726           will only have access to a limited set of core modules.  miniperl
727           is not intended for day to day use.
728
729       •   test.valgrind check.valgrind
730
731           (Only in Linux) Run all the tests using the memory leak + naughty
732           memory access tool "valgrind".  The log files will be named
733           testname.valgrind.
734
735       •   test_harness
736
737           Run the test suite with the t/harness controlling program, instead
738           of t/TEST.  t/harness is more sophisticated, and uses the
739           Test::Harness module, thus using this test target supposes that
740           perl mostly works.  The main advantage for our purposes is that it
741           prints a detailed summary of failed tests at the end.  Also, unlike
742           t/TEST, it doesn't redirect stderr to stdout.
743
744           Note that under Win32 t/harness is always used instead of t/TEST,
745           so there is no special "test_harness" target.
746
747           Under Win32's "test" target you may use the TEST_SWITCHES and
748           TEST_FILES environment variables to control the behaviour of
749           t/harness.  This means you can say
750
751               nmake test TEST_FILES="op/*.t"
752               nmake test TEST_SWITCHES="-torture" TEST_FILES="op/*.t"
753
754       •   test-notty test_notty
755
756           Sets PERL_SKIP_TTY_TEST to true before running normal test.
757
758   Parallel tests
759       The core distribution can now run its regression tests in parallel on
760       Unix-like and Windows platforms.  On Unix, instead of running "make
761       test", set "TEST_JOBS" in your environment to the number of tests to
762       run in parallel, and run "make test_harness".  On a Bourne-like shell,
763       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       Tests are normally run in a logical order, with the sanity tests first,
773       then the main tests of the Perl core functionality, then the tests for
774       the non-core modules.  On many-core systems, this may not use the
775       hardware as effectively as possible.  By also specifying
776
777        TEST_JOBS=19 PERL_TEST_HARNESS_ASAP=1 make -j19 test_harness
778
779       you signal that you want the tests to finish in wall-clock time as
780       short as possible.  After the sanity tests are completed, this causes
781       the remaining ones to be packed into the available cores as tightly as
782       we know how.  This has its greatest effect on slower, many-core
783       systems.  Throughput was sped up by 20% on an outmoded 24-core system;
784       less on more recent faster ones with fewer cores.
785
786       Note that the command line above added a "-j" parameter to make, so as
787       to cause parallel compilation.  This may or may not work on your
788       platform.
789
790   Running tests by hand
791       You can run part of the test suite by hand by using one of the
792       following commands from the t/ directory:
793
794           ./perl -I../lib TEST list-of-.t-files
795
796       or
797
798           ./perl -I../lib harness list-of-.t-files
799
800       (If you don't specify test scripts, the whole test suite will be run.)
801
802   Using t/harness for testing
803       If you use "harness" for testing, you have several command line options
804       available to you.  The arguments are as follows, and are in the order
805       that they must appear if used together.
806
807           harness -v -torture -re=pattern LIST OF FILES TO TEST
808           harness -v -torture -re LIST OF PATTERNS TO MATCH
809
810       If "LIST OF FILES TO TEST" is omitted, the file list is obtained from
811       the manifest.  The file list may include shell wildcards which will be
812       expanded out.
813
814       •   -v
815
816           Run the tests under verbose mode so you can see what tests were
817           run, and debug output.
818
819       •   -torture
820
821           Run the torture tests as well as the normal set.
822
823       •   -re=PATTERN
824
825           Filter the file list so that all the test files run match PATTERN.
826           Note that this form is distinct from the -re LIST OF PATTERNS form
827           below in that it allows the file list to be provided as well.
828
829       •   -re LIST OF PATTERNS
830
831           Filter the file list so that all the test files run match
832           /(LIST|OF|PATTERNS)/.  Note that with this form the patterns are
833           joined by '|' and you cannot supply a list of files, instead the
834           test files are obtained from the MANIFEST.
835
836       You can run an individual test by a command similar to
837
838           ./perl -I../lib path/to/foo.t
839
840       except that the harnesses set up some environment variables that may
841       affect the execution of the test:
842
843       •   PERL_CORE=1
844
845           indicates that we're running this test as part of the perl core
846           test suite.  This is useful for modules that have a dual life on
847           CPAN.
848
849       •   PERL_DESTRUCT_LEVEL=2
850
851           is set to 2 if it isn't set already (see "PERL_DESTRUCT_LEVEL" in
852           perlhacktips).
853
854       •   PERL
855
856           (used only by t/TEST) if set, overrides the path to the perl
857           executable that should be used to run the tests (the default being
858           ./perl).
859
860       •   PERL_SKIP_TTY_TEST
861
862           if set, tells to skip the tests that need a terminal.  It's
863           actually set automatically by the Makefile, but can also be forced
864           artificially by running 'make test_notty'.
865
866       Other environment variables that may influence tests
867
868       •   PERL_TEST_Net_Ping
869
870           Setting this variable runs all the Net::Ping modules tests,
871           otherwise some tests that interact with the outside world are
872           skipped.  See perl58delta.
873
874       •   PERL_TEST_NOVREXX
875
876           Setting this variable skips the vrexx.t tests for OS2::REXX.
877
878       •   PERL_TEST_NUMCONVERTS
879
880           This sets a variable in op/numconvert.t.
881
882       •   PERL_TEST_MEMORY
883
884           Setting this variable includes the tests in t/bigmem/.  This should
885           be set to the number of gigabytes of memory available for testing,
886           eg.  "PERL_TEST_MEMORY=4" indicates that tests that require 4GiB of
887           available memory can be run safely.
888
889       See also the documentation for the Test and Test::Harness modules, for
890       more environment variables that affect testing.
891
892   Performance testing
893       The file t/perf/benchmarks contains snippets of perl code which are
894       intended to be benchmarked across a range of perls by the
895       Porting/bench.pl tool. If you fix or enhance a performance issue, you
896       may want to add a representative code sample to the file, then run
897       bench.pl against the previous and current perls to see what difference
898       it has made, and whether anything else has slowed down as a
899       consequence.
900
901       The file t/perf/opcount.t is designed to test whether a particular code
902       snippet has been compiled into an optree containing specified numbers
903       of particular op types. This is good for testing whether optimisations
904       which alter ops, such as converting an "aelem" op into an "aelemfast"
905       op, are really doing that.
906
907       The files t/perf/speed.t and t/re/speed.t are designed to test things
908       that run thousands of times slower if a particular optimisation is
909       broken (for example, the utf8 length cache on long utf8 strings).  Add
910       a test that will take a fraction of a second normally, and minutes
911       otherwise, causing the test file to time out on failure.
912
913   Building perl at older commits
914       In the course of hacking on the Perl core distribution, you may have
915       occasion to configure, build and test perl at an old commit.  Sometimes
916       "make" will fail during this process.  If that happens, you may be able
917       to salvage the situation by using the Devel::PatchPerl library from
918       CPAN (not included in the core) to bring the source code at that commit
919       to a buildable state.
920
921       Here's a real world example, taken from work done to resolve perl
922       #10118 <https://github.com/Perl/perl5/issues/10118>.  Use of
923       Porting/bisect.pl had identified commit
924       "ba77e4cc9d1ceebf472c9c5c18b2377ee47062e6" as the commit in which a bug
925       was corrected.  To confirm, a P5P developer wanted to configure and
926       build perl at commit "ba77e4c^" (presumably "bad") and then at
927       "ba77e4c" (presumably "good").  Normal configuration and build was
928       attempted:
929
930           $ sh ./Configure -des -Dusedevel
931           $ make test_prep
932
933       "make", however, failed with output (excerpted) like this:
934
935           cc -fstack-protector -L/usr/local/lib -o miniperl \
936             gv.o toke.o perly.o pad.o regcomp.o dump.o util.o \
937             mg.o reentr.o mro.o hv.o av.o run.o pp_hot.o sv.o \
938             pp.o scope.o pp_ctl.o pp_sys.o doop.o doio.o regexec.o \
939             utf8.o taint.o deb.o universal.o globals.o perlio.o \
940             numeric.o mathoms.o locale.o pp_pack.o pp_sort.o  \
941             miniperlmain.o opmini.o perlmini.o
942           pp.o: In function `Perl_pp_pow':
943           pp.c:(.text+0x2db9): undefined reference to `pow'
944           ...
945           collect2: error: ld returned 1 exit status
946           makefile:348: recipe for target 'miniperl' failed
947           make: *** [miniperl] Error 1
948
949       Another P5P contributor recommended installation and use of
950       Devel::PatchPerl for this situation, first to determine the version of
951       perl at the commit in question, then to patch the source code at that
952       point to facilitate a build.
953
954        $ perl -MDevel::PatchPerl -e \
955            'print Devel::PatchPerl->determine_version("/path/to/sourcecode"),
956                   "\n";'
957        5.11.1
958        $ perl -MDevel::PatchPerl -e \
959            'Devel::PatchPerl->patch_source("5.11.1", "/path/to/sourcecode");'
960
961       Once the source was patched, "./Configure" and "make test_prep" were
962       called and completed successfully, enabling confirmation of the
963       findings in RT #72414.
964

MORE READING FOR GUTS HACKERS

966       To hack on the Perl guts, you'll need to read the following things:
967
968       •   perlsource
969
970           An overview of the Perl source tree.  This will help you find the
971           files you're looking for.
972
973       •   perlinterp
974
975           An overview of the Perl interpreter source code and some details on
976           how Perl does what it does.
977
978       •   perlhacktut
979
980           This document walks through the creation of a small patch to Perl's
981           C code.  If you're just getting started with Perl core hacking,
982           this will help you understand how it works.
983
984       •   perlhacktips
985
986           More details on hacking the Perl core.  This document focuses on
987           lower level details such as how to write tests, compilation issues,
988           portability, debugging, etc.
989
990           If you plan on doing serious C hacking, make sure to read this.
991
992       •   perlguts
993
994           This is of paramount importance, since it's the documentation of
995           what goes where in the Perl source.  Read it over a couple of times
996           and it might start to make sense - don't worry if it doesn't yet,
997           because the best way to study it is to read it in conjunction with
998           poking at Perl source, and we'll do that later on.
999
1000           Gisle Aas's "illustrated perlguts", also known as illguts, has very
1001           helpful pictures:
1002
1003           <https://metacpan.org/release/RURBAN/illguts-0.49>
1004
1005       •   perlxstut and perlxs
1006
1007           A working knowledge of XSUB programming is incredibly useful for
1008           core hacking; XSUBs use techniques drawn from the PP code, the
1009           portion of the guts that actually executes a Perl program.  It's a
1010           lot gentler to learn those techniques from simple examples and
1011           explanation than from the core itself.
1012
1013       •   perlapi
1014
1015           The documentation for the Perl API explains what some of the
1016           internal functions do, as well as the many macros used in the
1017           source.
1018
1019Porting/pumpkin.pod
1020
1021           This is a collection of words of wisdom for a Perl porter; some of
1022           it is only useful to the pumpkin holders, but most of it applies to
1023           anyone wanting to go about Perl development.
1024

CPAN TESTERS AND PERL SMOKERS

1026       The CPAN testers ( <http://cpantesters.org/> ) are a group of
1027       volunteers who test CPAN modules on a variety of platforms.
1028
1029       Perl Smokers ( <https://www.nntp.perl.org/group/perl.daily-build/> and
1030       <https://www.nntp.perl.org/group/perl.daily-build.reports/> )
1031       automatically test Perl source releases on platforms with various
1032       configurations.
1033
1034       Both efforts welcome volunteers.  In order to get involved in smoke
1035       testing of the perl itself visit
1036       <https://metacpan.org/release/Test-Smoke>.  In order to start smoke
1037       testing CPAN modules visit
1038       <https://metacpan.org/release/CPANPLUS-YACSmoke> or
1039       <https://metacpan.org/release/minismokebox> or
1040       <https://metacpan.org/release/CPAN-Reporter>.
1041

WHAT NEXT?

1043       If you've read all the documentation in the document and the ones
1044       listed above, you're more than ready to hack on Perl.
1045
1046       Here's some more recommendations
1047
1048       •   Subscribe to perl5-porters, follow the patches and try and
1049           understand them; don't be afraid to ask if there's a portion you're
1050           not clear on - who knows, you may unearth a bug in the patch...
1051
1052       •   Do read the README associated with your operating system, e.g.
1053           README.aix on the IBM AIX OS.  Don't hesitate to supply patches to
1054           that README if you find anything missing or changed over a new OS
1055           release.
1056
1057       •   Find an area of Perl that seems interesting to you, and see if you
1058           can work out how it works.  Scan through the source, and step over
1059           it in the debugger.  Play, poke, investigate, fiddle! You'll
1060           probably get to understand not just your chosen area but a much
1061           wider range of perl's activity as well, and probably sooner than
1062           you'd think.
1063
1064   "The Road goes ever on and on, down from the door where it began."
1065       If you can do these things, you've started on the long road to Perl
1066       porting.  Thanks for wanting to help make Perl better - and happy
1067       hacking!
1068
1069   Metaphoric Quotations
1070       If you recognized the quote about the Road above, you're in luck.
1071
1072       Most software projects begin each file with a literal description of
1073       each file's purpose.  Perl instead begins each with a literary allusion
1074       to that file's purpose.
1075
1076       Like chapters in many books, all top-level Perl source files (along
1077       with a few others here and there) begin with an epigrammatic
1078       inscription that alludes, indirectly and metaphorically, to the
1079       material you're about to read.
1080
1081       Quotations are taken from writings of J.R.R. Tolkien pertaining to his
1082       Legendarium, almost always from The Lord of the Rings.  Chapters and
1083       page numbers are given using the following editions:
1084
1085The Hobbit, by J.R.R. Tolkien.  The hardcover, 70th-anniversary
1086           edition of 2007 was used, published in the UK by Harper Collins
1087           Publishers and in the US by the Houghton Mifflin Company.
1088
1089The Lord of the Rings, by J.R.R. Tolkien.  The hardcover,
1090           50th-anniversary edition of 2004 was used, published in the UK by
1091           Harper Collins Publishers and in the US by the Houghton Mifflin
1092           Company.
1093
1094The Lays of Beleriand, by J.R.R. Tolkien and published posthumously
1095           by his son and literary executor, C.J.R. Tolkien, being the 3rd of
1096           the 12 volumes in Christopher's mammoth History of Middle Earth.
1097           Page numbers derive from the hardcover edition, first published in
1098           1983 by George Allen & Unwin; no page numbers changed for the
1099           special 3-volume omnibus edition of 2002 or the various trade-paper
1100           editions, all again now by Harper Collins or Houghton Mifflin.
1101
1102       Other JRRT books fair game for quotes would thus include The Adventures
1103       of Tom Bombadil, The Silmarillion, Unfinished Tales, and The Tale of
1104       the Children of Hurin, all but the first posthumously assembled by
1105       CJRT.  But The Lord of the Rings itself is perfectly fine and probably
1106       best to quote from, provided you can find a suitable quote there.
1107
1108       So if you were to supply a new, complete, top-level source file to add
1109       to Perl, you should conform to this peculiar practice by yourself
1110       selecting an appropriate quotation from Tolkien, retaining the original
1111       spelling and punctuation and using the same format the rest of the
1112       quotes are in.  Indirect and oblique is just fine; remember, it's a
1113       metaphor, so being meta is, after all, what it's for.
1114

AUTHOR

1116       This document was originally written by Nathan Torkington, and is
1117       maintained by the perl5-porters mailing list.
1118
1119
1120
1121perl v5.36.0                      2022-08-30                       PERLHACK(1)
Impressum