in reply to Re: Exposing minimum required perl version ('use x.y.z') to Perl code during runtime?
in thread Exposing minimum required perl version ('use x.y.z') to Perl code during runtime?

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.

  • Comment on Re^2: Exposing minimum required perl version ('use x.y.z') to Perl code during runtime?

Replies are listed 'Best First'.
Re^3: Exposing minimum required perl version ('use x.y.z') to Perl code during runtime?
by tobyink (Canon) on Apr 01, 2014 at 12:08 UTC

    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

      Yeah, I suspect so. Would be nice (for me) if Perl did.

      As for 'good default value', I was referring to "the highest Perl version I can use in the user's environment", so picking a globally safe value like 5.8.x is not good enough. Also, I refuse to go lower than 5.10.1 :)

        Yes, I know what you meant by a good default value. My point is that as Data::Sah allows the user to generate strings of Perl code, it's reasonable user behaviour to be able to expect to output those strings of code to files, and possibly evaluate those files under a different version of Perl.

        So the best default would be to output code which will run on the widest possible range of Perl versions that you're willing to support.

        (I do something similar with Type::Tiny which generates code that runs successfully on Perl 5.6.1 through to the latest blead.)

        use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
        5.8.8 is still common, as many still use RHEL5.