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