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, you must use the perlbug command
113       line tool.  This tool will ensure that your bug report includes all the
114       relevant system and configuration information.
115
116       To browse existing Perl bugs and patches, you can use the web interface
117       at <http://rt.perl.org/>.
118
119       Please check the archive of the perl5-porters list (see below) and/or
120       the bug tracking system before submitting a bug report.  Often, you'll
121       find that the bug has been reported already.
122
123       You can log in to the bug tracking system and comment on existing bug
124       reports.  If you have additional information regarding an existing bug,
125       please add it.  This will help the porters fix the bug.
126

PERL 5 PORTERS

128       The perl5-porters (p5p) mailing list is where the Perl standard
129       distribution is maintained and developed.  The people who maintain Perl
130       are also referred to as the "Perl 5 Porters", "p5p" or just the
131       "porters".
132
133       A searchable archive of the list is available at
134       <http://markmail.org/search/?q=perl5-porters>.  There is also an
135       archive at <http://archive.develooper.com/perl5-porters@perl.org/>.
136
137   perl-changes mailing list
138       The perl5-changes mailing list receives a copy of each patch that gets
139       submitted to the maintenance and development branches of the perl
140       repository.  See <http://lists.perl.org/list/perl5-changes.html> for
141       subscription and archive information.
142
143   #p5p on IRC
144       Many porters are also active on the <irc://irc.perl.org/#p5p> channel.
145       Feel free to join the channel and ask questions about hacking on the
146       Perl core.
147

GETTING THE PERL SOURCE

149       All of Perl's source code is kept centrally in a Git repository at
150       github.com.  The repository contains many Perl revisions from Perl 1
151       onwards and all the revisions from Perforce, the previous version
152       control system.
153
154       For much more detail on using git with the Perl repository, please see
155       perlgit.
156
157   Read access via Git
158       You will need a copy of Git for your computer.  You can fetch a copy of
159       the repository using the git protocol:
160
161         % git clone git://github.com/Perl/perl5.git perl
162
163       This clones the repository and makes a local copy in the perl
164       directory.
165
166       If you cannot use the git protocol for firewall reasons, you can also
167       clone via http:
168
169         % git clone https://github.com/Perl/perl5.git perl
170
171   Read access via the web
172       You may access the repository over the web.  This allows you to browse
173       the tree, see recent commits, subscribe to repository notifications,
174       search for particular commits and more.  You may access it at
175       <https://github.com/Perl/perl5>.
176
177   Read access via rsync
178       You can also choose to use rsync to get a copy of the current source
179       tree for the bleadperl branch and all maintenance branches:
180
181         % rsync -avz rsync://perl5.git.perl.org/perl-current .
182         % rsync -avz rsync://perl5.git.perl.org/perl-5.12.x .
183         % rsync -avz rsync://perl5.git.perl.org/perl-5.10.x .
184         % rsync -avz rsync://perl5.git.perl.org/perl-5.8.x .
185         % rsync -avz rsync://perl5.git.perl.org/perl-5.6.x .
186         % rsync -avz rsync://perl5.git.perl.org/perl-5.005xx .
187
188       (Add the "--delete" option to remove leftover files.)
189
190       To get a full list of the available sync points:
191
192         % rsync perl5.git.perl.org::
193
194   Write access via git
195       If you have a commit bit, please see perlgit for more details on using
196       git.
197

PATCHING PERL

199       If you're planning to do more extensive work than a single small fix,
200       we encourage you to read the documentation below.  This will help you
201       focus your work and make your patches easier to incorporate into the
202       Perl source.
203
204   Submitting patches
205       If you have a small patch to submit, please submit it via the GitHub
206       Pull Request workflow.  You may also send patches to the p5p list.
207
208       Patches are reviewed and discussed on GitHub or the p5p list.  Simple,
209       uncontroversial patches will usually be applied without any discussion.
210       When the patch is applied, the ticket will be updated and you will
211       receive email.
212
213       In other cases, the patch will need more work or discussion.  You are
214       encouraged to participate in the discussion and advocate for your
215       patch.  Sometimes your patch may get lost in the shuffle.  It's
216       appropriate to send a reminder email to p5p if no action has been taken
217       in a month.  Please remember that the Perl 5 developers are all
218       volunteers, and be polite.
219
220       Changes are always applied directly to the main development branch,
221       called "blead".  Some patches may be backported to a maintenance
222       branch.  If you think your patch is appropriate for the maintenance
223       branch (see "MAINTENANCE BRANCHES" in perlpolicy), please explain why
224       when you submit it.
225
226   Getting your patch accepted
227       If you are submitting a code patch there are several things that you
228       can do to help the Perl 5 Porters accept your patch.
229
230       Patch style
231
232       Using the GitHub Pull Request workflow, your patch will automatically
233       be available in a suitable format.  If you wish to submit a patch to
234       the p5p list for review, make sure to create it appropriately.
235
236       If you used git to check out the Perl source, then using "git
237       format-patch" will produce a patch in a style suitable for Perl.  The
238       "format-patch" command produces one patch file for each commit you
239       made.  If you prefer to send a single patch for all commits, you can
240       use "git diff".
241
242         % git checkout blead
243         % git pull
244         % git diff blead my-branch-name
245
246       This produces a patch based on the difference between blead and your
247       current branch.  It's important to make sure that blead is up to date
248       before producing the diff, that's why we call "git pull" first.
249
250       We strongly recommend that you use git if possible.  It will make your
251       life easier, and ours as well.
252
253       However, if you're not using git, you can still produce a suitable
254       patch.  You'll need a pristine copy of the Perl source to diff against.
255       The porters prefer unified diffs.  Using GNU "diff", you can produce a
256       diff like this:
257
258         % diff -Npurd perl.pristine perl.mine
259
260       Make sure that you "make realclean" in your copy of Perl to remove any
261       build artifacts, or you may get a confusing result.
262
263       Commit message
264
265       As you craft each patch you intend to submit to the Perl core, it's
266       important to write a good commit message.  This is especially important
267       if your submission will consist of a series of commits.
268
269       The first line of the commit message should be a short description
270       without a period.  It should be no longer than the subject line of an
271       email, 50 characters being a good rule of thumb.
272
273       A lot of Git tools (Gitweb, GitHub, git log --pretty=oneline, ...) will
274       only display the first line (cut off at 50 characters) when presenting
275       commit summaries.
276
277       The commit message should include a description of the problem that the
278       patch corrects or new functionality that the patch adds.
279
280       As a general rule of thumb, your commit message should help a
281       programmer who knows the Perl core quickly understand what you were
282       trying to do, how you were trying to do it, and why the change matters
283       to Perl.
284
285       ·   Why
286
287           Your commit message should describe why the change you are making
288           is important.  When someone looks at your change in six months or
289           six years, your intent should be clear.
290
291           If you're deprecating a feature with the intent of later
292           simplifying another bit of code, say so.  If you're fixing a
293           performance problem or adding a new feature to support some other
294           bit of the core, mention that.
295
296       ·   What
297
298           Your commit message should describe what part of the Perl core
299           you're changing and what you expect your patch to do.
300
301       ·   How
302
303           While it's not necessary for documentation changes, new tests or
304           trivial patches, it's often worth explaining how your change works.
305           Even if it's clear to you today, it may not be clear to a porter
306           next month or next year.
307
308       A commit message isn't intended to take the place of comments in your
309       code.  Commit messages should describe the change you made, while code
310       comments should describe the current state of the code.
311
312       If you've just implemented a new feature, complete with doc, tests and
313       well-commented code, a brief commit message will often suffice.  If,
314       however, you've just changed a single character deep in the parser or
315       lexer, you might need to write a small novel to ensure that future
316       readers understand what you did and why you did it.
317
318       Comments, Comments, Comments
319
320       Be sure to adequately comment your code.  While commenting every line
321       is unnecessary, anything that takes advantage of side effects of
322       operators, that creates changes that will be felt outside of the
323       function being patched, or that others may find confusing should be
324       documented.  If you are going to err, it is better to err on the side
325       of adding too many comments than too few.
326
327       The best comments explain why the code does what it does, not what it
328       does.
329
330       Style
331
332       In general, please follow the particular style of the code you are
333       patching.
334
335       In particular, follow these general guidelines for patching Perl
336       sources:
337
338       ·   4-wide indents for code, 2-wide indents for nested CPP "#define"s,
339           with 8-wide tabstops.
340
341       ·   Use spaces for indentation, not tab characters.
342
343           The codebase is a mixture of tabs and spaces for indentation, and
344           we are moving to spaces only.  Converting lines you're patching
345           from 8-wide tabs to spaces will help this migration.
346
347       ·   Try hard not to exceed 79-columns
348
349       ·   ANSI C prototypes
350
351       ·   Uncuddled elses and "K&R" style for indenting control constructs
352
353       ·   No C++ style (//) comments
354
355       ·   Mark places that need to be revisited with XXX (and revisit often!)
356
357       ·   Opening brace lines up with "if" when conditional spans multiple
358           lines; should be at end-of-line otherwise
359
360       ·   In function definitions, name starts in column 0 (return value-type
361           is on previous line)
362
363       ·   Single space after keywords that are followed by parens, no space
364           between function name and following paren
365
366       ·   Avoid assignments in conditionals, but if they're unavoidable, use
367           extra paren, e.g. "if (a && (b = c)) ..."
368
369       ·   "return foo;" rather than "return(foo);"
370
371       ·   "if (!foo) ..." rather than "if (foo == FALSE) ..." etc.
372
373       ·   Do not declare variables using "register".  It may be
374           counterproductive with modern compilers, and is deprecated in C++,
375           under which the Perl source is regularly compiled.
376
377       ·   In-line functions that are in headers that are accessible to XS
378           code need to be able to compile without warnings with commonly used
379           extra compilation flags, such as gcc's "-Wswitch-default" which
380           warns whenever a switch statement does not have a "default" case.
381           The use of these extra flags is to catch potential problems in
382           legal C code, and is often used by Perl aggregators, such as Linux
383           distributors.
384
385       Test suite
386
387       If your patch changes code (rather than just changing documentation),
388       you should also include one or more test cases which illustrate the bug
389       you're fixing or validate the new functionality you're adding.  In
390       general, you should update an existing test file rather than create a
391       new one.
392
393       Your test suite additions should generally follow these guidelines
394       (courtesy of Gurusamy Sarathy <gsar@activestate.com>):
395
396       ·   Know what you're testing.  Read the docs, and the source.
397
398       ·   Tend to fail, not succeed.
399
400       ·   Interpret results strictly.
401
402       ·   Use unrelated features (this will flush out bizarre interactions).
403
404       ·   Use non-standard idioms (otherwise you are not testing TIMTOWTDI).
405
406       ·   Avoid using hardcoded test numbers whenever possible (the
407           EXPECTED/GOT found in t/op/tie.t is much more maintainable, and
408           gives better failure reports).
409
410       ·   Give meaningful error messages when a test fails.
411
412       ·   Avoid using qx// and system() unless you are testing for them.  If
413           you do use them, make sure that you cover _all_ perl platforms.
414
415       ·   Unlink any temporary files you create.
416
417       ·   Promote unforeseen warnings to errors with $SIG{__WARN__}.
418
419       ·   Be sure to use the libraries and modules shipped with the version
420           being tested, not those that were already installed.
421
422       ·   Add comments to the code explaining what you are testing for.
423
424       ·   Make updating the '1..42' string unnecessary.  Or make sure that
425           you update it.
426
427       ·   Test _all_ behaviors of a given operator, library, or function.
428
429           Test all optional arguments.
430
431           Test return values in various contexts (boolean, scalar, list,
432           lvalue).
433
434           Use both global and lexical variables.
435
436           Don't forget the exceptional, pathological cases.
437
438   Patching a core module
439       This works just like patching anything else, with one extra
440       consideration.
441
442       Modules in the cpan/ directory of the source tree are maintained
443       outside of the Perl core.  When the author updates the module, the
444       updates are simply copied into the core.  See that module's
445       documentation or its listing on <http://search.cpan.org/> for more
446       information on reporting bugs and submitting patches.
447
448       In most cases, patches to modules in cpan/ should be sent upstream and
449       should not be applied to the Perl core individually.  If a patch to a
450       file in cpan/ absolutely cannot wait for the fix to be made upstream,
451       released to CPAN and copied to blead, you must add (or update) a
452       "CUSTOMIZED" entry in the "Porting/Maintainers.pl" file to flag that a
453       local modification has been made.  See "Porting/Maintainers.pl" for
454       more details.
455
456       In contrast, modules in the dist/ directory are maintained in the core.
457
458   Updating perldelta
459       For changes significant enough to warrant a pod/perldelta.pod entry,
460       the porters will greatly appreciate it if you submit a delta entry
461       along with your actual change.  Significant changes include, but are
462       not limited to:
463
464       ·   Adding, deprecating, or removing core features
465
466       ·   Adding, deprecating, removing, or upgrading core or dual-life
467           modules
468
469       ·   Adding new core tests
470
471       ·   Fixing security issues and user-visible bugs in the core
472
473       ·   Changes that might break existing code, either on the perl or C
474           level
475
476       ·   Significant performance improvements
477
478       ·   Adding, removing, or significantly changing documentation in the
479           pod/ directory
480
481       ·   Important platform-specific changes
482
483       Please make sure you add the perldelta entry to the right section
484       within pod/perldelta.pod.  More information on how to write good
485       perldelta entries is available in the "Style" section of
486       Porting/how_to_write_a_perldelta.pod.
487
488   What makes for a good patch?
489       New features and extensions to the language can be contentious.  There
490       is no specific set of criteria which determine what features get added,
491       but here are some questions to consider when developing a patch:
492
493       Does the concept match the general goals of Perl?
494
495       Our goals include, but are not limited to:
496
497       1.  Keep it fast, simple, and useful.
498
499       2.  Keep features/concepts as orthogonal as possible.
500
501       3.  No arbitrary limits (platforms, data sizes, cultures).
502
503       4.  Keep it open and exciting to use/patch/advocate Perl everywhere.
504
505       5.  Either assimilate new technologies, or build bridges to them.
506
507       Where is the implementation?
508
509       All the talk in the world is useless without an implementation.  In
510       almost every case, the person or people who argue for a new feature
511       will be expected to be the ones who implement it.  Porters capable of
512       coding new features have their own agendas, and are not available to
513       implement your (possibly good) idea.
514
515       Backwards compatibility
516
517       It's a cardinal sin to break existing Perl programs.  New warnings can
518       be contentious--some say that a program that emits warnings is not
519       broken, while others say it is.  Adding keywords has the potential to
520       break programs, changing the meaning of existing token sequences or
521       functions might break programs.
522
523       The Perl 5 core includes mechanisms to help porters make backwards
524       incompatible changes more compatible such as the feature and deprecate
525       modules.  Please use them when appropriate.
526
527       Could it be a module instead?
528
529       Perl 5 has extension mechanisms, modules and XS, specifically to avoid
530       the need to keep changing the Perl interpreter.  You can write modules
531       that export functions, you can give those functions prototypes so they
532       can be called like built-in functions, you can even write XS code to
533       mess with the runtime data structures of the Perl interpreter if you
534       want to implement really complicated things.
535
536       Whenever possible, new features should be prototyped in a CPAN module
537       before they will be considered for the core.
538
539       Is the feature generic enough?
540
541       Is this something that only the submitter wants added to the language,
542       or is it broadly useful?  Sometimes, instead of adding a feature with a
543       tight focus, the porters might decide to wait until someone implements
544       the more generalized feature.
545
546       Does it potentially introduce new bugs?
547
548       Radical rewrites of large chunks of the Perl interpreter have the
549       potential to introduce new bugs.
550
551       How big is it?
552
553       The smaller and more localized the change, the better.  Similarly, a
554       series of small patches is greatly preferred over a single large patch.
555
556       Does it preclude other desirable features?
557
558       A patch is likely to be rejected if it closes off future avenues of
559       development.  For instance, a patch that placed a true and final
560       interpretation on prototypes is likely to be rejected because there are
561       still options for the future of prototypes that haven't been addressed.
562
563       Is the implementation robust?
564
565       Good patches (tight code, complete, correct) stand more chance of going
566       in.  Sloppy or incorrect patches might be placed on the back burner
567       until the pumpking has time to fix, or might be discarded altogether
568       without further notice.
569
570       Is the implementation generic enough to be portable?
571
572       The worst patches make use of system-specific features.  It's highly
573       unlikely that non-portable additions to the Perl language will be
574       accepted.
575
576       Is the implementation tested?
577
578       Patches which change behaviour (fixing bugs or introducing new
579       features) must include regression tests to verify that everything works
580       as expected.
581
582       Without tests provided by the original author, how can anyone else
583       changing perl in the future be sure that they haven't unwittingly
584       broken the behaviour the patch implements? And without tests, how can
585       the patch's author be confident that his/her hard work put into the
586       patch won't be accidentally thrown away by someone in the future?
587
588       Is there enough documentation?
589
590       Patches without documentation are probably ill-thought out or
591       incomplete.  No features can be added or changed without documentation,
592       so submitting a patch for the appropriate pod docs as well as the
593       source code is important.
594
595       Is there another way to do it?
596
597       Larry said "Although the Perl Slogan is There's More Than One Way to Do
598       It, I hesitate to make 10 ways to do something".  This is a tricky
599       heuristic to navigate, though--one man's essential addition is another
600       man's pointless cruft.
601
602       Does it create too much work?
603
604       Work for the pumpking, work for Perl programmers, work for module
605       authors, ... Perl is supposed to be easy.
606
607       Patches speak louder than words
608
609       Working code is always preferred to pie-in-the-sky ideas.  A patch to
610       add a feature stands a much higher chance of making it to the language
611       than does a random feature request, no matter how fervently argued the
612       request might be.  This ties into "Will it be useful?", as the fact
613       that someone took the time to make the patch demonstrates a strong
614       desire for the feature.
615

TESTING

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

MORE READING FOR GUTS HACKERS

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

CPAN TESTERS AND PERL SMOKERS

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

WHAT NEXT?

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

AUTHOR

1095       This document was originally written by Nathan Torkington, and is
1096       maintained by the perl5-porters mailing list.
1097
1098
1099
1100perl v5.30.1                      2019-11-29                       PERLHACK(1)
Impressum