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