On Sun, Jun 6, 2021, at 7:09 PM, Neil Bowers wrote:
>> In other words, "use vX" turns on strict if X is at least 5.12.0, unless it was preceded by "no strict".
> 1. What happens if "use vX" is preceded by "no strict 'refs'" – do you get strict vars and subs?
> 2. Is this documented anywhere (other than the perldelta that introduced it, which was presumably 5.12?
> 3. Seems like this should be mentioned in the doc for strict (that was the first place I looked)
> 4. If the answer to #1 is "Yes", then the doc for `use` should probably be updated too.
I'm not sure what you mean by "this" in "Is this documented." The enabling-strict behavior of "use v5.12" happens when you "use", and so is documented under "use". Adding a cross-reference in strict is perfectly reasonable.
"use VERSION" also lexically enables all features available in
the requested version as defined by the feature pragma,
disabling any features not in the requested version's feature
bundle. See feature. Similarly, if the specified Perl version is
greater than or equal to 5.12.0, strictures are enabled
lexically as with "use strict". Any explicit use of "use strict"
or "no strict" overrides "use VERSION", even if it comes before
it. Later use of "use VERSION" will override all behavior of a
previous "use VERSION", possibly removing the "strict" and
"feature" added by "use VERSION". "use VERSION" does not load
the feature.pm or strict.pm files.
So, "overrides" is perhaps vague, but easy to test:
~$ perl -e 'no strict; use v5.12.0; $x = 1'
(no error)
~$ perl -e 'no strict "refs"; use v5.12.0; $x = 1'
Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at -e line 1.
Execution of -e aborted due to compilation errors.
~$ perl -e 'no strict "vars"; use v5.12.0; $x = 1'
(no error)
> This behaviour seems surprising.
Here's one post about it from 2011:
https://markmail.org/message/jvktz6zayls4okez …but that mostly defers to advice provided by Father C. in an earlier post. Also, note that this discussion is late 2011, which is over a year after v5.12.0 shipped with "enables strict." So when did this change? It changed in v5.16.0, noted as follows in perl5160delta:
"use *VERSION*"
As of this release, version declarations like "use v5.16" now disable
all features before enabling the new feature bundle. This means that the
following holds true:
use 5.016;
# only 5.16 features enabled here
use 5.014;
# only 5.14 features enabled here (not 5.16)
"use v5.12" and higher continue to enable strict, but explicit "use
strict" and "no strict" now override the version declaration, even when
they come first:
no strict;
use 5.012;
# no strict here
This was changed in b50b20584a1 <
https://github.com/Perl/perl5/commit/b50b20584a1>. It took me ages to track down the original thread to which I made reference, but I finally did it:
https://markmail.org/message/homuy7tspk3sgkag I think I need to give it a big think, but here's the reasoning as I was able to quickly swap it back in:
* imagine that "use v5.34" turns on "switch", but "use v5.36" does not
* your program says: { use v5.34; use v5.36; EXPR }
* is switch enabled at EXPR?
* the goal was to make every "use" statement configure everything to its specification, not to layer atop the previous environment
…at which point somebody (Eric Brine) said: If we apply that logic to the way that use v5.12.0 affects strict, then saying use v5.10.0 should turn strict back off, and what about people who have already written this program:
use strict;
use warnings;
use 5.010;
This left us with the question of how to not break that code, but be consistent, which got us to where we are today.
At ten years' remove, I'm not sure what I think of this decision anymore, but I urge you to read the reasoning behind it before coming to a conclusion.
--
rjbs