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