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