Perl::...nAndWhy(3pm)
π Perl::Critic::Policy::Compatibility::PerlMinimumVersionAndWhy π
okay bestie, gather round, because this one is literally about making you say which Perl you're on. like, out loud. in the code. π
β¨ NAME β¨
Perl::Critic::Policy::Compatibility::PerlMinimumVersionAndWhy β explicit Perl version for features used
πΈ DESCRIPTION πΈ
so this policy lives inside the Perl::Critic::Pulp add-on (yes, the whole vibe is Pulp). what it wants from you is an explicit use 5.XXX (or whatever flavour of that) for every Perl syntax feature you're actually using β and it figures out which features those are via Perl::MinimumVersion. π§
use 5.010; # the // operator is new in perl 5.010
print $x // $y; # ok
if you don't even have the Perl::MinimumVersion module installed? then literally nothing gets reported. silence. no notes. π (apparently there are "certain nasty hacks" used under the hood to pull the reasons and locations out of Perl::MinimumVersion, which, iconic behaviour honestly.)
this policy hangs out under the compatibility theme (peep "POLICY THEMES" in Perl::Critic). where it truly shines is catching stuff like // or qr β things that only exist in a newer Perl than the one you thought you were targeting. it's giving "surprise, your target version is a lie." π
yes, an explicit use 5.xxx is a tiny bit tedious, but the glow-up is real: it makes it super clear what's needed (or what's supposed to be needed), and it hands you a genuinely good error message if someone runs it on an older Perl. periodt.
π Disabling π
the config options down below let you limit how far back the checking goes. or, if you simply do not care about any of this, you can always disable the policy entirely from your ~/.perlcriticrc file the usual way (see "CONFIGURATION" in Perl::Critic),
[-Compatibility::PerlMinimumVersionAndWhy]
π MinimumVersion Mangling π
some mangling gets applied to whatever Perl::MinimumVersion would normally report (as of its version 1.28). it's a whole thing.
- A multi-constant hash with the
constantmodule is not reported, since that's covered better by Compatibility::ConstantPragmaHash. - Module requirements for things like
use Errnoare dropped, since you might get a back-port from CPAN etc and the need for a module is better expressed in a distributionprereq.
But pragma modules like use warnings are still reported. They're normally an interface to a feature new in the Perl version it comes with and can't be back-ported. (See "OTHER NOTES" below too.) π
π MinimumVersion Extras π
the following extra checks get added on top of Perl::MinimumVersion. little bonus rounds, we love to see it.
5.12 for
- new
keys @array,values @arrayandeach @array
5.10 for
qr//m, sincemmodifier doesn't propagate correctly on aqruntil 5.10-e -f -xstacked filetest operators.- pack() new
<and>endianness. - new
UNIVERSAL.pmmethod DOES()
5.8 for
- new
word [newline] =>fat comma quoting across a newline
For earlier Perl word ended up a function call. It's presumed such code is meant to quote in the 5.8 style, and thus requires 5.8 or higher.
eval '#line ...'with#linethe very first thing
In earlier Perl a #line as the very first thing in an eval doesn't take effect. Adding a blank line so it's not first is enough.
- pack() new
Fnative NV,Dlong double,iIV,jUV,()group,[]repeat count
5.6 for
- new
exists &subr,exists $array[0]anddelete $array[0] - new
0b110011binary number literals - new
open(my $fh,...)etc auto-creation of filehandle - syswrite() length parameter optional
Foo->$methodno-args call without parens
For earlier Perl a no-args call to a method named in a variable must be Foo->$method(). The parens are optional in 5.6 up.
- pack() new
Zasciz,q,Qquads,!native size,/counted string,#comment
5.005 for
- new
Foo::Bar::double-colon package name quoting - new
my ($x, undef, $y) = @values, usingundefas a dummy in amylist
5.004 for
- new
use 5.xxxPerl version check throughuse. For earlier Perl it can beBEGIN { require 5.000 }etc - new
__PACKAGE__special literal - new
foreach my $foolexical loop variable - new $coderef->() call with
-> - new sysseek() builtin function
- pack() new
wBER integer - new
UNIVERSAL.pmwith VERSION(), isa() and can() methods
pack() and unpack() format strings are only checked if they're literal strings or here-documents without interpolations, or . operator concats of those. no vibes-based guessing here, only the literal stuff. β¨
the qr//m report concerns a misfeature fixed in perl 5.10.0 (see perl5101delta). In earlier versions a regexp like $re = qr/^x/m within another regexp like /zz|$re/ loses the /m attribute from $re, changing the interpretation of the ^ (and $ similarly). Forms like (\A|\n) are a possible workaround, though are uncommon so may be a little obscure. RegularExpressions::RequireLineBoundaryMatching asks for /m in all cases so if think you want that then you probably want Perl 5.10 or up for the fix too.
π¦ "Modern::Perl" π¦
use Modern::Perl is taken to mean Perl 5.10. this is slightly experimental, and in principle the actual minimum it implies is forever rising, and even now could be more, or depends on it date argument scheme. Maybe if could say its actual current desire then an installed version could be queried. (that's the original's wording and honestly same, bestie, the vibes are immaculate and the certainty is not lol.) π
β CONFIGURATION β
above_version(version string, default none) Set a minimum version of Perl you always use, so that reports are only about things higher than this and higher than what the document declares. The value is anything theversion.pmmodule can parse.
[Compatibility::PerlMinimumVersionAndWhy]
above_version = 5.006
For example if you always use Perl 5.6 and set 5.006 like this then you can have our package variables without an explicit use 5.006. β¨
skip_checks(list of check names, default none) Skip the given MinimumVersion checks (a space separated list). The check names are shown in the violation message and come fromPerl::MinimumVersion::CHECKS. For example,
[Compatibility::PerlMinimumVersionAndWhy]
skip_checks = _some_thing _another_thing
This can be used for checks you believe are wrong, or where the compatibility matter only affects limited circumstances which you understand.
The check names are likely to be a moving target, especially the Pulp additions. Unknown checks in the list are quietly ignored. π
π OTHER NOTES π
use warnings is reported as a Perl 5.6 feature since the lexically-scoped fine grain warnings control it gives is new in that version. If targeting earlier versions then it's often enough to drop use warnings, ensure your code runs cleanly under perl -w, and leave it to applications to use -w (or set $^W) if they desire.
warnings::compat offers a use warnings for earlier Perl, but it's not lexical, instead setting $^W globally. In a script this might be an alternative to #!/usr/bin/perl -w (per perlrun), but in a module it's probably not a good idea to change global settings. π
The UNIVERSAL.pm methods VERSION(), isa(), can() or DOES() might in principle be implemented explicitly by a particular class, but it's assumed that's not so and that any call to those requires the respective minimum Perl version.
π SEE ALSO π
Perl::Critic::Pulp, Perl::Critic
Perl::Critic::Policy::Modules::PerlMinimumVersion, which is similar, but compares against a Perl version configured in your ~/.perlcriticrc rather than a version in the document.
Perl::Critic::Policy::Modules::RequirePerlVersion
π HOME PAGE π
<http://user42.tuxfamily.org/perl-critic-pulp/index.html>
π COPYRIGHT π
Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
and that's the whole page, bestie π«Ά this beauty came out of the User Contributed Perl Documentation collection, sitting at perl v5.40.1, dated 2025-10-21 β go forth and declare your Perl version explicitly, the linter believes in you πβ¨
π¦ where this page comes from
- ubuntu resolute: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- ubuntu stonking: libperl-critic-pulp-perl 100-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms