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

BUG REPORTING

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

PERL 5 PORTERS

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       <http://markmail.org/search/?q=perl5-porters>.  There is also an
132       archive at <http://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 <http://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

GETTING THE PERL SOURCE

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

PATCHING PERL

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 <http://search.cpan.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 the pumpking has time to fix, or might be discarded altogether
565       without 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 pumpking, 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

TESTING

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

MORE READING FOR GUTS HACKERS

942       To hack on the Perl guts, you'll need to read the following things:
943
944       ·   perlsource
945
946           An overview of the Perl source tree.  This will help you find the
947           files you're looking for.
948
949       ·   perlinterp
950
951           An overview of the Perl interpreter source code and some details on
952           how Perl does what it does.
953
954       ·   perlhacktut
955
956           This document walks through the creation of a small patch to Perl's
957           C code.  If you're just getting started with Perl core hacking,
958           this will help you understand how it works.
959
960       ·   perlhacktips
961
962           More details on hacking the Perl core.  This document focuses on
963           lower level details such as how to write tests, compilation issues,
964           portability, debugging, etc.
965
966           If you plan on doing serious C hacking, make sure to read this.
967
968       ·   perlguts
969
970           This is of paramount importance, since it's the documentation of
971           what goes where in the Perl source.  Read it over a couple of times
972           and it might start to make sense - don't worry if it doesn't yet,
973           because the best way to study it is to read it in conjunction with
974           poking at Perl source, and we'll do that later on.
975
976           Gisle Aas's "illustrated perlguts", also known as illguts, has very
977           helpful pictures:
978
979           <http://search.cpan.org/dist/illguts/>
980
981       ·   perlxstut and perlxs
982
983           A working knowledge of XSUB programming is incredibly useful for
984           core hacking; XSUBs use techniques drawn from the PP code, the
985           portion of the guts that actually executes a Perl program.  It's a
986           lot gentler to learn those techniques from simple examples and
987           explanation than from the core itself.
988
989       ·   perlapi
990
991           The documentation for the Perl API explains what some of the
992           internal functions do, as well as the many macros used in the
993           source.
994
995       ·   Porting/pumpkin.pod
996
997           This is a collection of words of wisdom for a Perl porter; some of
998           it is only useful to the pumpkin holder, but most of it applies to
999           anyone wanting to go about Perl development.
1000

CPAN TESTERS AND PERL SMOKERS

1002       The CPAN testers ( <http://testers.cpan.org/> ) are a group of
1003       volunteers who test CPAN modules on a variety of platforms.
1004
1005       Perl Smokers ( <http://www.nntp.perl.org/group/perl.daily-build/> and
1006       <http://www.nntp.perl.org/group/perl.daily-build.reports/> )
1007       automatically test Perl source releases on platforms with various
1008       configurations.
1009
1010       Both efforts welcome volunteers.  In order to get involved in smoke
1011       testing of the perl itself visit
1012       <https://metacpan.org/release/Test-Smoke>.  In order to start smoke
1013       testing CPAN modules visit
1014       <https://metacpan.org/release/CPANPLUS-YACSmoke> or
1015       <https://metacpan.org/release/minismokebox> or
1016       <https://metacpan.org/release/CPAN-Reporter>.
1017

WHAT NEXT?

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

AUTHOR

1092       This document was originally written by Nathan Torkington, and is
1093       maintained by the perl5-porters mailing list.
1094
1095
1096
1097perl v5.30.2                      2020-03-27                       PERLHACK(1)
Impressum