NAME
Perl::Critic::Policy::Compatibility::PerlMinimumVersionAndWhy - explicit Perl version for features used
DESCRIPTION
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.
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 only available in a newer Perl than you thought to support.
An explicit use 5.xxx in your code can be tedious, but makes it clear what you need (or think you need) and it gets a good error message if run on an older Perl. The config below lets you limit how far back you might 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]
MinimumVersion Mangling
Some mangling is applied to what Perl::MinimumVersion normally reports (as of its version 1.20).
Module requirements like
use Errnoare dropped, since you might get a back-port from CPAN etc and the need for a module is better expressed in your distribution "prereq".(The same doesn't normally apply to pragma type modules like
use warningssince they're normally an interface to a feature new in the Perl version it comes with.)A multi-constant hash with the
constantmodule is not reported, since that's covered better by Compatibility::ConstantPragmaHash.
MinimumVersion Extras
The following extra checks are added to what Perl::MinimumVersion normally reports.
qr//mrequires Perl 5.10, as the "m" modifier doesn't propagate correctly on aqruntil then.exists &subr,exists $array[0]ordelete $array[0]new in Perl 5.6.0b110011binary number literals new in Perl 5.6.Foo::Bar::double-colon package name new in Perl 5.005.use 5.005and similar Perl version check new in Perl 5.004. For earlier Perl it should beBEGIN { require 5.003 }or similar instead.__PACKAGE__special literal new in Perl 5.004.foreach my $foolexical loop variable new in Perl 5.004.packandunpackformat strings are checked for various new conversions in Perl 5.004 through 5.10.0. Currently this only works on literal strings or here-documents without interpolations, and.operator concats of those.
CONFIGURATION
above_version(version string, default none)-
Set a minimum version of Perl you always use, so reports are only about things both higher than this and higher than the document declares. The string is anything
version.pmunderstands. For example,[Compatibility::PerlMinimumVersionAndWhy] above_version = 5.006For example if you always use Perl 5.6 and set 5.006 like this then you can have
ourpackage variables without an explicituse 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 from
Perl::MinimumVersion::CHECKS. For example,[Compatibility::PerlMinimumVersionAndWhy] skip_checks = _some_thing _another_thingThis 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 silently ignored.
OTHER NOTES
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 run -w or not. (warnings::compat offers a use warnings for earlier versions, but it's not lexical and globally setting $^W from a module is probably not a good idea.)
SEE ALSO
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.
HOME PAGE
http://user42.tuxfamily.org/perl-critic-pulp/index.html
COPYRIGHT
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/>.