Grinnz / Perl-Critic-Community

Perl::Critic::Community - Community-inspired Perl::Critic policies
https://metacpan.org/pod/Perl::Critic::Community
Other
8 stars 10 forks source link

StrictWarnings cant deal with use 5.xx.y #13

Closed Tux closed 9 years ago

Tux commented 9 years ago
#!/usr/bin/perl
use 5.14.2;
use warnings;
our $VERSION = "0.00";
say "hello";

Here 'use 5.14.2' implies 'use strict' (plus a bit more), and that would be the exception to the "version string used" warning.

$ perlcritic -1 xx.pl
Argument "^E^N^B" isn't numeric in numeric gt (>) at /pro/lib/perl5/site_perl/5.22.0/Perl/Critic/Policy/Freenode/StrictWarnings.pm line 57.
xx.pl#1.1:      [4 - Freenode::StrictWarnings]  Missing strict or warnings      :#!/usr/bin/perl
xx.pl#2.1:      [3 - ValuesAndExpressions::ProhibitVersionStrings]      Version string used     :use 5.14.2;
Tux commented 9 years ago
--- Perl/Critic/Policy/Freenode/StrictWarnings.pm   2015-07-31 04:34:33.000000000 +0200
+++ Perl/Critic/Policy/Freenode/StrictWarnings.pm       2015-08-14 11:07:59.355095463 +0200
@@ -54,9 +54,14 @@ sub violates {
                        $has_warnings = 1 if $include->pragma eq 'warnings';
                }
                if ($include->type//'' eq 'use') {
-                       $has_strict = 1 if $include->version and $include->version_literal > 5.012;
-                       $has_strict = 1 if defined $include->module and exists $strict_importers{$include->module};
-                       $has_warnings = 1 if defined $include->module and exists $warnings_importers{$include->module};
+                       my $version = $include->version_literal || 0;
+                       $version =~ m/^\x05([\x00-\x63])([\x00-\x63])$/ and
+                           $version = sprintf "5.%03d%03d", ord $1, ord $2;
+                       $version =~ m/^5\.([0-9][0-9])\.([0-9][0-9]?)$/ and
+                           $version = sprintf "5.%03d%03d", $1, $2;
+                       $has_strict   = 1 if defined $include->version and $version > 5.012;
+                       $has_strict   = 1 if defined $include->module  and exists $strict_importers{$include->module};
+                       $has_warnings = 1 if defined $include->module  and exists $warnings_importers{$include->module};
                }
                return () if $has_strict and $has_warnings;
        }