wanna_code_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

It's been a good long while since I've put out a new CPAN module, containing entirely new code. Feels good, except I'm very much overthinking which use 5.0xx; Perl version to require. I'm well aware that the overly reductive answer is generally "the lowest Perl version that runs your code," but that logic falls apart when the code hasn't all been written yet. I certainly could make it work on good ol' 5.005_03, but only after making several uncomfortable SCM concessions in style, testing, core modules, CPAN dependencies, security, and generally not having very much fun in the process. And, no, I'm not actually planning on supporting 20+ year old Perls in brand new code.

Are there recent stats or census data on Perl versions in use in the wild? Devs integrating my code may well be using a recent Perl(s) via perlbrew, but my target deployment audience will very likely either be using system Perl on one Linux/BSD distro or another (probably mostly on "long term support" releases that run older, stable versions), or one of the Windows Perls, so I guess I could look up the system Perl versions of the top 5 Linux distros, figure out which system Perl version they're running, and go with the minimum, for a reasonable start. But has anyone already gathered similar data in the past couple of years or so? I couldn't find anything close (or recent) but my Google-fu might be off today.

But that's just my vaguely specific case. I'm also interested in general perspectives on how you've all chosen min Perl versions for your modules, even if your situation differed from mine.

Replies are listed 'Best First'.
Re: Determining minimum Perl version for new module
by Your Mother (Archbishop) on Sep 12, 2019 at 01:47 UTC

    This just came. up a few days ago: How to determine what code is limiting needed perl version for a module. I installed it to play around with it and it seems to work well though I’ve only tried it on a couple of things: Perl::MinimumVersion. Here’s some output from it suggesting that I’ve likely set the version much too high in some of my own code.

    perlver lib/MuhCodes.pm ---------------------------------------------- | file | explicit | syntax | external | | ---------------------------------------------- | | lib/MuhCodes.pm | v5.16.0 | v5.8.0 | n/a | | ---------------------------------------------- | | Minimum explicit version : v5.16.0. | | Minimum syntax version : v5.8.0. | | Minimum version of perl : v5.16.0. | ----------------------------------------------

    Update: I agree with stevieb’s advice. Leave it out unless you actually need it to block a test runner or something from trying a Perl that’s too low.

Re: Determining minimum Perl version for new module
by choroba (Cardinal) on Sep 12, 2019 at 09:09 UTC
    My Syntax::Construct provides another viewpoint: if you know what features were introduced, you don't have to remember in which version it happened. Just list the features you use in the code and the module will require the appropriate version. It will also tell a user why exactly their version can't be used if it's too old.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: Determining minimum Perl version for new module
by haukex (Archbishop) on Sep 12, 2019 at 18:14 UTC

    Personally, the lowest I go is 5.6, because that introduced:

    • Three-argument open
    • Lexical filehandles
    • Lexical warnings
    • our
    • omitting -> between dereferences

    However, sometimes I require 5.8, because that improved the Unicode support and had some changes to I/O, i.e. PerlIO (plus it has safe signals).

    As for what the lowest version you should support for a new module, IMHO: I think good reasons to support the versions above might be: because your module is providing some feature that users of the above Perls might not otherwise have, or because you happen to know that some people who are stuck on 5.6 and 5.8 might need your module. Otherwise, I'd suggest starting with 5.10, since that introduced // and several regex improvements, such as named capture buffers.

    Newer versions of course have nice features, just some examples:

    • 5.12 changed length undef to return undef, without throwing a warning
    • 5.14 introduced s///r and package NAME BLOCK
    • 5.16 introduced __SUB__ and fc
    • ... and so on.

    However, personally I find that for libraries I release, I'm ok with sticking to the 5.10 feature set (excluding smart matching, of course). For scripts that I write, I'll often go with 5.26 and up.

    Update: Added an item to the list, thanks Discipulus!

Re: Determining minimum Perl version for new module
by stevieb (Canon) on Sep 12, 2019 at 00:42 UTC

    You're the only person who has made decisions on what features of Perl you require. That directly relates to what version of Perl your software needs.

    If you go non-core in your prerequisites, then that software will take care of the requisite perl you need (generally).

    Leave the requirement blank, unless you need a specific version. If you do require something specific, ensure you put it both in the file you're needing it, as well as in your Makefile.PL or equivalent.

    Personally, I would say no statement at all, but if anything, 5.10 "for a reasonable start", only for the defined-or operator.

      You're the only person who has made decisions on what features of Perl you require.

      Agree! But sometimes a little outside discussion can help refine those decisions, so thank you for entertaining said discussion. :-)

        If that's the case, I say require 5.10. For me personally, it'd cover my 5.8 standard, and any requirement above that.

        The CPAN Testers will ensure things work correctly against your required version of Perl, as should your local testing. If not, might I suggest the following:

        • test against numerous versions of perl via perlbrew or berrybrew
        • ensure that your software works against any custom libraries you have locally
        • verify that any local security validation is either workable or bypassed in testing
        • document and criticize any client data that you've tested against, sanitize after digesting it, and request client feedback on its handling

        Beyond that, just have numerous test platforms to run against that you can reset on every test run. There's no way to validate everything every time, so use your best judgement. If your platform is useful and there's an issue found, make sure you have very accessible contact information.

Re: Determining minimum Perl version for new module
by jcb (Parson) on Sep 12, 2019 at 19:17 UTC

    I see backwards compatibility as a major pillar of the Perl community, so I would suggest aiming to support whatever version provides the features your API needs, within reason. For example, I am currently working on a WARC library for Perl and the API uses tied lexical filehandles — and there were bugs in 5.8.0 that resulted in leaking lexical filehandles, so 5.8.1 is the minimum for my project, even though some versions of 5.6 might be able to run my code.

    That said, there is still at least one 5.8.5 smoker out there, (and my non-broken tests have passed on it) so as a practical matter I would be more inclined to bump the required version rather than work around bugs in perl releases even more ancient than that.

    My philosophy is generally to let older versions run the tests and see if I get failure reports, but to go ahead and exclude versions known to have bugs that would cause disaster if the code were put into production. I am up to "alpha-5" as I call v0.0.0_5 currently. I follow release early, release often, as long as the tests exist and pass: the very first "alpha-1" release had no actual code, just empty subs and stub unit tests to ensure that the modules parse OK and verify the embedded POD. Each subsequent release has been a step along the way to building the library, while rolling in bug fixes for previously-failing tests.

    The CPAN smokers seem to all run various Unix-like systems but are still an impressive variety of configurations. If your distribution has a version with an underscore instead of a dot ahead of the last number, the smokers will test it but it will only be installed for users if specifically requested.

      The CPAN smokers seem to all run various Unix-like systems

      My modest stable of modules has seen tests from some MSWin32 smokers recently. Previously there were also tests coming from Haiku which I wouldn't consider Unix-like although no doubt it could be argued as such. It would be nice to see even greater diversity of course but it is what it is.

Re: Determining minimum Perl version for new module
by Anonymous Monk on Sep 12, 2019 at 19:44 UTC
    My opinion would be: If it's toolchain, support 5.8.1. Otherwise support 5.10.1 if reasonable, or 5.14.0 to be able to use keywords. 5.10.1 is by far the biggest user base due to RHEL6, but it's shrinking. There is a useful chart maintained of versions reported by cpanm, just remember it's a subsection of the community: http://cpanmetadb.plackperl.org/versions/ -Grinnz
Re: Determining minimum Perl version for new module
by Anonymous Monk on Sep 12, 2019 at 02:17 UTC
    Are there recent stats or census data on Perl versions in use in the wild?

    One way to see what people are supporting is to watch the CPAN. Most modules have a use VERSION or use feature 'VERSION' line. The MetaCPAN API provides a lot of information about modules but I couldn't find anything about the supported Perl version (which is found in the source code):

    https://metacpan.org/feed/recent
    https://metacpan.org/recent?f=n
    https://metacpan.org/favorite/leaderboard
    
    Whip up a bot that checks what versions of Perl are supported by which CPAN upload/new dist/fav/etc and plot a graph of CPAN's most supported Perl versions so you can upload it to cool uses?

      Another good measure is to look at what version of Perl the long term editions of popular Linux distributions and Apple distribute (and thus, support). Currently, I think these are

      • RHEL 6 - Perl 5.10, EOL 2020
      • RHEL 7 - Perl 5.18 (I think?), Perl 5.24 available as package, EOL 2024
      • Debian 9 - Perl 5.18, EOL 2022
      • Debian 10 - Perl 5.28, EOL 2022
      • Ubuntu Xenial - Perl 5.20
      • OSX (Yosemite upwards) - Perl 5.18

      Also see Which version of perl comes with ...?.

        RHEL 7 - Perl 5.18 (I think?)

        Actually it's only 5.16.3 on RHEL7. RHEL8 has 5.26.3. That's quite a jump but then it has been almost 5 years between their major releases.

        On distrowatch you can dig through the Linux distributions to make a list of which distro comes with what perl version. (I try to keep a CSV list up-to-date for System::Info).

        A summary:

        5.6 54 # .0: 16, .1: 38 5.8 372 # .0: 39, .1: 7, .2: 11, .3: 11, .4: 42, .5: 26, .6: 21, .7 +: 29, .8:184, .9: 2 5.10 270 # .0:105, .1:165 5.12 110 # .1: 10, .2: 24, .3: 36, .4: 40 5.14 166 # .0: 3, .1: 4, .2:156, .3: 1, .4: 2 5.16 59 # .0: 1, .1: 15, .2: 7, .3: 36 5.18 119 # .0: 8, .1: 31, .2: 77, .4: 3 5.20 145 # .0: 15, .1: 23, .2: 98, .3: 9 5.22 128 # .0: 12, .1: 74, .2: 36, .3: 6 5.24 137 # .0: 19, .1: 95, .2: 3, .3: 19, .4: 1 5.26 135 # .0: 19, .1: 72, .2: 41, .3: 3 5.28 117 # .0: 23, .1: 80, .2: 14 5.30 28 # .0: 28

        If I limit that list to dists that got a release since 2017-01-01, I get:

        5.8 2 # .8: 2 5.10 10 # .1: 10 5.12 4 # .3: 4 5.14 7 # .2: 6, .3: 1 5.16 15 # .3: 15 5.18 11 # .0: 2, .1: 1, .2: 8 5.20 44 # .0: 2, .2: 38, .3: 4 5.22 60 # .0: 1, .1: 44, .2: 9, .3: 6 5.24 121 # .0: 8, .1: 90, .2: 3, .3: 19, .4: 1 5.26 135 # .0: 19, .1: 72, .2: 41, .3: 3 5.28 117 # .0: 23, .1: 80, .2: 14 5.30 28 # .0: 28

        and limiting to 2018 and 2019:

        5.8 1 # .8: 1 5.10 4 # .1: 4 5.12 3 # .3: 3 5.14 5 # .2: 4, .3: 1 5.16 12 # .3: 12 5.18 4 # .0: 1, .2: 3 5.20 12 # .0: 1, .2: 10, .3: 1 5.22 30 # .1: 22, .2: 5, .3: 3 5.24 71 # .0: 2, .1: 54, .3: 14, .4: 1 5.26 108 # .0: 2, .1: 62, .2: 41, .3: 3 5.28 117 # .0: 23, .1: 80, .2: 14 5.30 28 # .0: 28

        With just one dist (openwall-3.1, which is the most recent openwall distributeded with perl on 2018-07-03) shipping with perl-5.8.8, I'd say having a minimum of 5.10.1 is a very safe choice.

        If you however really want to use a feature like s{}{}r, perlver tells me you'd need 5.14.0.


        Enjoy, Have FUN! H.Merijn