Policy/Modules/PerlMinimumVersion.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 71.4% 10 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 80.0% 4 / 5 totaltotal 91.3% 74 / 81 CC 8 SCAR 9.8
CC
8
Cov
90%
violates
5.2
_parse_version
4.0
BEGIN
1.0
CRAP 2.7
« Policy/Editor/RequireEmacsFileVariables.pm ↑ Summary Policy/CodeLayout/RequireASCII.pm »
1 #######################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic-More/lib/Perl/Critic/Policy/Modules/PerlMinimumVersion.pm $
3 # $Date: 2013-10-29 09:39:11 -0700 (Tue, 29 Oct 2013) $
4 # $Author: thaljef $
5 # $Revision: 4222 $
6 ########################################################################
7  
8 package Perl::Critic::Policy::Modules::PerlMinimumVersion;
9  
10 7 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 7 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 7 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 7 our $VERSION = '1.003';
23  
24 #---------------------------------------------------------------------------
25  
26 7 Readonly::Scalar my $DESC =>
27 'Avoid Perl features newer than specified version';
28 7 Readonly::Scalar my $EXPL => 'Improve your backward compatibility';
29  
30 #---------------------------------------------------------------------------
31  
32 2 ▶sub default_severity { return $SEVERITY_LOWEST }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
33 1 ▶sub default_themes { return qw< more compatibility > }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
34 3 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
35  
36 5 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
37 return (
38 5 { name => 'version',
39 description => 'Version of perl to be compatible with.',
40 behavior => 'string',
41 parser => \&_parse_version,
42 },
43 );
44 }
45  
46 #---------------------------------------------------------------------------
47  
48 5 ▶sub _parse_version {
Subroutine _parse_version: called CC=4 SCAR=13.9
49 5 my ( $self, $parameter, $config_string ) = @_;
50  
51 5 my $version;
52 5 ▶ if ($config_string) {
Branch: 2 branches
BranchTrueFalseTotal
if ($config_string) { } 4 1 5
elsif (ref $Perl::Critic::Policy::Modules::PerlMinimumVersion::PERL_VERSION) { } 1 0 1
53 4 ▶ if ( $config_string =~ m<\A \s* (5 [.] [\d.]+) \s* \z>xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_string =~ /\A \s* (5 [.] [\d.]+) \s* \z/msx) { } 3 1 4
54 3 $version = $1;
55 } else {
56 1 $self->throw_parameter_value_exception( 'version', $config_string,
57 undef, "doesn't look like a perl version number.\n",
58 );
59 }
60 } elsif ( ref $PERL_VERSION ) {
61 1 $version = $PERL_VERSION->numify(); # It's an object as of 5.10.
62 } else {
63 0 $version = 0 + $PERL_VERSION; # numify to get away from version.pm
64 }
65  
66 4 $self->{_version} = $version;
67  
68 4 return;
69 }
70  
71 #---------------------------------------------------------------------------
72  
73 3 ▶sub violates {
Subroutine violates: called CC=5 SCAR=16.6
Pod documented
74 3 my ( $self, $elem, $doc ) = @_;
75  
76 3 ▶ return if not eval { require Perl::MinimumVersion; 1; };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require Perl::MinimumVersion; 1 } } 0 3 3
77  
78 3 my $checker = Perl::MinimumVersion->new($doc);
79  
80 # Workaround for Perl::Critic::Document instance in older P::C versions
81 # (pre-v0.22) that didn't have a custom isa() to masquerade as a
82 # PPI::Document
83 3 ▶ if ( !$checker ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($checker) 0 3 3
84 0 $checker = Perl::MinimumVersion->new( $doc->{_doc} );
85 }
86 3 ▶ return if !$checker; # bail out!
Branch: 1 branch
BranchTrueFalseTotal
unless $checker 0 3 3
87  
88 # this returns a version.pm instance
89 3 my $doc_version = $checker->minimum_version();
90  
91 #print "v$doc_version vs. $self->{_version}\n";
92 3 ▶ return if $doc_version <= $self->{_version};
Branch: 1 branch
BranchTrueFalseTotal
if $doc_version <= $self->{"_version"} 2 1 3
93  
94 1 return $self->violation( $DESC, $EXPL, $doc );
95 }
96  
97 7 1;
98  
99 __END__
« Policy/Editor/RequireEmacsFileVariables.pm ↑ Summary Policy/CodeLayout/RequireASCII.pm »