Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Finding when a feature or keyword was introduced

by Bod (Parson)
on Sep 26, 2023 at 17:12 UTC ( [id://11154668] : perlquestion . print w/replies, xml ) Need Help??

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

Is there an easy way to find out when a feature or keyword was introduced to Perl?
In other words, which version introduced it...

I have a module that uses pos, a keyword I infrequently use. How can I find out when this, or any other keyword, was introduced so I can set the minimum required Perl version?

Obviously I could go through each delta until I find it but that seems rather tedious...

  • Comment on Finding when a feature or keyword was introduced

Replies are listed 'Best First'.
Re: Finding when a feature or keyword was introduced
by SankoR (Prior) on Sep 26, 2023 at 17:57 UTC
Re: Finding when a feature or keyword was introduced
by choroba (Cardinal) on Sep 26, 2023 at 18:00 UTC
    Regarding features, the documentation of feature lists the minimal Perl version for each feature.

    Regarding keywords, the ones not covered by features (i.e. everything but fc and say) are as old as I remember, so probably pre-5.6. There's no need to bother with so ancient versions.

    There are some things that were introduced over the years that weren't mentioned in the deltas or they were but the required version isn't mentioned in their documentation. That's why I created Syntax::Construct.

    Update: Reformulated. fc and say are examples of keywords covered by features.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      say is enabled with use v5.10 which implies it was introduced in that version.

      Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

      It doesn't list the versions for try (5.34) and defer (5.38) features. Both are still experimental as of 5.38.

Perl named operators and builtin subs introduced since 5.6
by ikegami (Patriarch) on Sep 27, 2023 at 06:18 UTC

    Perl named operators and builtin subs introduced since 5.6

    NameAvailabilityExperimentalIn CORE::Enabling
    pragma
    Enabling
    feature set
    __SUB__Since 5.16Since 5.16use feature qw( current_sub );5.16 and up
    blessedSince 5.36Since 5.36use builtin qw( blessed );
    breakFrom 5.10
    until 5.42
    Since 5.16[1]
    Deprecated since 5.38
    From 5.16[4]
    until 5.42
    use feature qw( switch );From 5.10
    up to 5.36
    catchSince 5.34Since 5.34Since 5.34use feature qw( try );
    ceilSince 5.36Since 5.36use builtin qw( ceil );
    classSince 5.38Since 5.38Since 5.38use feature qw( class );
    continueFrom 5.10
    until 5.42
    Since 5.16[1]
    Deprecated since 5.38
    From 5.16[4]
    until 5.42
    use feature qw( switch );From 5.10
    up to 5.36
    created_as_numberSince 5.36Since 5.36use builtin qw( created_as_number );
    created_as_stringSince 5.36Since 5.36use builtin qw( created_as_string );
    defaultFrom 5.10
    until 5.42
    Since 5.16[1]
    Deprecated since 5.38
    From 5.16[4]
    until 5.42
    use feature qw( switch );From 5.10
    up to 5.36
    deferSince 5.36Since 5.36Since 5.36use feature qw( defer );
    falseSince 5.36Since 5.36use builtin qw( false );
    fc Since 5.16Since 5.16use feature qw( fc );5.16 and up
    fieldSince 5.38Since 5.38Since 5.38use feature qw( class );
    floorSince 5.36Since 5.36use builtin qw( floor );
    finallySince 5.36[3]Since 5.36Since 5.36use feature qw( try );
    givenFrom 5.10
    until 5.42
    Since 5.16[1]
    Deprecated since 5.38
    From 5.16[4]
    until 5.42
    use feature qw( switch );From 5.10
    up to 5.36
    indexedSince 5.36Since 5.36use builtin qw( indexed );
    is_boolSince 5.36Since 5.36use builtin qw( is_bool );
    is_weakSince 5.36Since 5.36use builtin qw( is_weak );
    isaSince 5.32From 5.32 until 5.34Since 5.32use feature qw( isa );5.36 and up[2]
    methodSince 5.38Since 5.38Since 5.38use feature qw( class );
    refaddrSince 5.36Since 5.36use builtin qw( refaddr );
    reftypeSince 5.36Since 5.36use builtin qw( reftype );
    saySince 5.10Since 5.16[4]use feature qw( say );5.10 and up
    stateSince 5.10Since 5.16[4]use feature qw( state );5.10 and up
    trimSince 5.36Since 5.36use builtin qw( trim );
    trueSince 5.36Since 5.36use builtin qw( true );
    trySince 5.34Since 5.34Since 5.34use feature qw( try );
    unweakenSince 5.36Since 5.36use builtin qw( unweaken );
    weakenSince 5.36Since 5.36use builtin qw( weaken );
    whenFrom 5.10
    until 5.42
    Since 5.16[1]
    Deprecated since 5.38
    From 5.16[4]
    until 5.42
    use feature qw( switch );From 5.10
    up to 5.36
     
    builtin::blessedSince 5.36Since 5.36Always available
    builtin::ceilSince 5.36Since 5.36Always available
    builtin::created_as_numberSince 5.36Since 5.36Always available
    builtin::created_as_stringSince 5.36Since 5.36Always available
    builtin::falseSince 5.36Since 5.36Always available
    builtin::floorSince 5.36Since 5.36Always available
    builtin::indexedSince 5.36Since 5.36Always available
    builtin::is_boolSince 5.36Since 5.36Always available
    builtin::is_weakSince 5.36Since 5.36Always available
    builtin::refaddrSince 5.36Since 5.36Always available
    builtin::reftypeSince 5.36Since 5.36Always available
    builtin::trimSince 5.36Since 5.36Always available
    builtin::trueSince 5.36Since 5.36Always available
    builtin::unweakenSince 5.36Since 5.36Always available
    builtin::weakenSince 5.36Since 5.36Always available
     
    utf8::decodeSince 5.8Always available
    utf8::downgradeSince 5.8Always available
    utf8::encodeSince 5.8Always available
    utf8::is_utf8Since 5.8.1Always available
    utf8::native_to_unicodeSince 5.8[5]Always available
    utf8::unicode_to_nativeSince 5.8[5]Always available
    utf8::upgradeSince 5.8Always available
    utf8::validSince 5.8Always available

    Notes

    • Current as of 5.38.
    • Perl provides other builtin subs which are meant to be used as methods, which aren't documented to be available at all times, or which aren't documented at all. (These are found in in constant::, Internals::, PerlIO::, re::, Tie::Hash::NamedCapture, UNIVERSAL:: and version::). These are deliberately omitted.
    • The existence of dev versions is ignored.
    • "Until 5.xx" and "up to 5.xx" are exclusive, meaning they don't include 5.xx.

    Footnotes

    1. Experimental warnings were only added in 5.18, but the switch feature was flagged as experimental in the documentation since 5.16.
    2. Although the isa feature stopped being experimental in 5.34, use v5.34; does not activate the feature.
    3. Although try and catch first appeared in 5.34, finally only appeared in 5.36.
    4. Although these were added as keywords in 5.10, they were only added to CORE:: in 5.16.
    5. While utf8::native_to_unicode and utf8::unicode_to_native have only been documented since 5.22, they've been available since 5.8.

    Updates

    1. Added the keywords from the class feature.
    2. Fixed versions for defer.
    3. Fixed versions for finally.
    4. Added CORE::.

      Good table, but maybe it doesn't need to list everything from builtin twice? Better to just make a note that they can always be used by their fully-qualified name or imported lexically.

        I've mistakenly said the feature became experimental in 5.18 in the past too. But while the experimental warnings were added in 5.18, it was flagged as experimental in 5.16.

        Quote 5.16's perlsyn,

        you can say use feature "switch"; to enable an experimental switch feature.

        Also,

        Under the "switch" feature, Perl gains the experimental keywords given, when, default, continue, and break.

        Added break, default and continue to the table.

      Great table - thanks :)

      I would have expected to see class in there as that's new in 5.36 isn't it? I've not used it or investigated it as 5.32 is the latest version I have.

        I would have expected to see class in there as that's new in 5.36 isn't it?

        Good point. I just checked perlclass, and I see keywords: class, field and method. Not sure if attributes :isa and :param qualify.

        5.38. Overlooked. Fixed. Thanks.

Re: Finding when a feature or keyword was introduced (perlver)
by Anonymous Monk on Sep 27, 2023 at 09:41 UTC
      Perl::MinimumVersion Find a minimum required version of perl for Perl code

      WoW!!!
      Good find - thanks for sharing...

      Frok the documentation - Future plans are to also add support for tracing module dependencies

      It will be an essential tool as and when that comes to pass. I always struggle to know which version of modules to declare as necessary.

        I don't think that means what you think it does. I read it as meaning that it will be extended to report the minimum perl version required by the modules on which the originally examined code depends. ie. it will do the same checks but descend recursively into the dependency tree.


        🦛

Re: Finding when a feature or keyword was introduced
by ikegami (Patriarch) on Sep 27, 2023 at 05:35 UTC

    I don't believe any named operators ("functions") have been added since 5.6, except 1) those that need a pragma to enable, and 2) those that are in a namespace other than main::.