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