Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Exposing minimum required perl version ('use x.y.z') to Perl code during runtime?

by sedusedan (Monk)
on Apr 01, 2014 at 10:18 UTC ( [id://1080525]=perlquestion: print w/replies, xml ) Need Help??

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

Is there currently a way to do this? For 'use MODULE VERSION', Perl already gives us the VERSION() mechanism. I'm thinking feature.pm could be made to provide this (or has it already done so?)
  • Comment on Exposing minimum required perl version ('use x.y.z') to Perl code during runtime?

Replies are listed 'Best First'.
Re: Exposing minimum required perl version ('use x.y.z') to Perl code during runtime?
by hippo (Bishop) on Apr 01, 2014 at 10:43 UTC

    Do you mean/want something like this?

    use strict; use warnings; eval { require 5.10.1; print "Newish\n"; }; eval { require 5.18.0; print "Newer\n"; };
      Nope :) See my reply to AM.
Re: Exposing minimum required perl version ('use x.y.z') to Perl code during runtime?
by Anonymous Monk on Apr 01, 2014 at 10:30 UTC

      The current running Perl version is at $^V (or $]). But how about the minimum Perl version that is currently requested via 'use VERSION'?

      % perl -e'use 5.014; say $^V'; # -> prints v5.18.2, but I also want to get v5.14.0 via something

      An example use case: my module Data::Sah generates Perl code. It'd be nice if Data::Sah can adjust the kind of Perl code it outputs automatically via detecting the minimum Perl version that the user requests (and not the running Perl interpreter version). This means, even when running under Perl 5.18.2, Data::Sah won't emit code that uses s///r if the user code only says 'use 5.010' and not 'use 5.14' or 'use 5.18'.

      I can of course add a configuration to Data::Sah for this, but I'm aiming for a nice default value.

        Perl doesn't keep track of that - it checks the version number supplied against the current version of Perl and dies if the current Perl is too old. If it doesn't die though, it doesn't save the checked version number anywhere. (The file that does this is pp_ctl.c.)

        A good default value would be 5.8.1.

        use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re: Exposing minimum required perl version ('use x.y.z') to Perl code during runtime?
by CountZero (Bishop) on Apr 01, 2014 at 17:19 UTC
    I'm afraid that is a problem that cannot be reliably solved.

    What would you do if one of the modules somewhere in the dependency chain also asks for a (different) minimum version of Perl? Which version will win?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      Well, feature.pm could just store the last request. That would be good enough for most cases.

        Well, feature.pm could just store the last request. That would be good enough for most cases.

        Or the user could simply tell your module what he wants :)

        on the one hand, there is no performance benefit between s///r and and the older syntax

        on the other hand catering to multiple perl versions seems like busywork

        on the other hand ...

        perlver - The Perl Minimum Version Analyzer / Perl::MinimumVersion

        ha ha :)

Re: Exposing minimum required perl version ('use x.y.z') to Perl code during runtime?
by boftx (Deacon) on Apr 02, 2014 at 00:08 UTC

    Instead of resorting to a config file, is it reasonable to have a custom import function that accepts the minimum version to generate code for?

    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1080525]
Approved by Happy-the-monk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-20 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found