Perl::Critic::Policy::Compatibility::PerlMinimumVersionAndWhy - explicit Perl version for features used
This policy is part of the Perl::Critic::Pulp addon. It requires that you have an explicit use 5.XXX etc for the Perl syntax features you use, as determined by Perl::MinimumVersion.
Perl::Critic::Pulp
use 5.XXX
Perl::MinimumVersion
use 5.010; # the // operator is new in perl 5.010 print $x // $y; # ok
If you don't have Perl::MinimumVersion then nothing is reported. Certain nasty hacks are used to extract reasons and locations from Perl::MinimumVersion.
This policy is under the "compatibility" theme (see "POLICY THEMES" in Perl::Critic). Its best use is when it picks up things like // or qr which are only available in a newer Perl than you meant to target.
//
qr
An explicit use 5.xxx can be tedious, but makes it clear what's needed (or supposed to be needed) and it gives a good error message if run on an older Perl.
use 5.xxx
The config options below let you limit how far back to go. Or if you don't care at all about this sort of thing you can always disable the policy completely from you ~/.perlcriticrc file in the usual way,
[-Compatibility::PerlMinimumVersionAndWhy]
Some mangling is applied to what Perl::MinimumVersion normally reports (as of its version 1.20).
A multi-constant hash with the constant module is not reported, since that's covered better by Compatibility::ConstantPragmaHash.
constant
Module requirements like use Errno are dropped, since you might get a back-port from CPAN etc and any need for a module is better expressed in a distribution "prereq".
use Errno
The same rationale generally doesn't apply to pragma type modules like use warnings since they're normally an interface to a feature new in the Perl version it comes with and can't be back-ported.
use warnings
The following extra checks are added to what Perl::MinimumVersion normally reports.
5.10 for qr//m, since the "m" modifier doesn't propagate correctly on a qr until then.
qr//m
5.6 new exists &subr, exists $array[0] or delete $array[0] support.
exists &subr
exists $array[0]
delete $array[0]
5.6 new 0b110011 binary number literals.
0b110011
5.005 new Foo::Bar:: double-colon package name.
Foo::Bar::
5.004 new use 5.006 version check in a use. For earlier Perl it can be BEGIN { require 5.006 } etc.
use 5.006
use
BEGIN { require 5.006 }
5.004 new __PACKAGE__ special literal.
__PACKAGE__
5.004 new foreach my $foo lexical loop variable.
foreach my $foo
pack and unpack format strings are checked for various new conversions in Perl 5.004 through 5.10.0. Currently this only works on formats given as literal strings or here-documents, without interpolations, or . operator concats of those.
pack
unpack
.
above_version
Set a minimum version of Perl you always use, so that reports are only about things higher than this and higher than the document declares. The value is anything the version.pm module understands.
version.pm
[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.
our
skip_checks
Skip the given MinimumVersion checks (a space separated list). The check names are shown in the violation message and come from Perl::MinimumVersion::CHECKS. For example,
Perl::MinimumVersion::CHECKS
[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 bit of a moving target, especially the Pulp additions. Unknown checks in the list are quietly ignored.
use warnings is reported as a Perl 5.6.0 feature since the lexically-scoped fine grain warnings control is new in that version. If targeting earlier versions then it's often enough to make sure your code works under perl -w and leave it to applications to use -w (or set $^W) or not, as it might desire.
perl -w
-w
$^W
warnings::compat offers a use warnings for earlier versions, but it's not lexical, instead setting $^W globally. Doing that from a module is probably not a good idea, but in a script it could be an alternative to #!/usr/bin/perl -w (per perlrun).
warnings::compat
#!/usr/bin/perl -w
Perl::Critic::Pulp, Perl::Critic,
Perl::Critic::Policy::Modules::PerlMinimumVersion is similar, but compares against a Perl version configured in your ~/.perlcriticrc rather than a version in the document.
Perl::Critic::Policy::Modules::PerlMinimumVersion
http://user42.tuxfamily.org/perl-critic-pulp/index.html
Copyright 2008, 2009, 2010, 2011 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/>.
To install Perl::Critic::Pulp, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::Critic::Pulp
CPAN shell
perl -MCPAN -e shell install Perl::Critic::Pulp
For more information on module installation, please visit the detailed CPAN module installation guide.