Policy/Compatibility/PodMinimumVersion.pm

filter: Statementstmt 100% 63 / 63 Branchbran 83.3% 5 / 6 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 15 / 15 Podpod 100% 2 / 2 totaltotal 96.9% 94 / 97 CC 7 SCAR 6.7
CC
7
Cov
97%
violates
4.0
location
3.0
initialize_if_enabled
2.0
CRAP 2.0
« Policy/Documentation/ProhibitDuplicateSeeAlso.pm ↑ Summary Policy/Documentation/ProhibitBadAproposMarkup.pm »
1 # Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
2  
3 # This file is part of Perl-Critic-Pulp.
4  
5 # Perl-Critic-Pulp is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Perl-Critic-Pulp is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
17  
18  
19 package Perl::Critic::Policy::Compatibility::PodMinimumVersion;
20 40 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # 1.084 for Perl::Critic::Document highest_explicit_perl_version()
25 40 ▶use Perl::Critic::Policy 1.084;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 40 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 40 ▶use Perl::Critic::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 40 ▶use Perl::Critic::Pulp::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # uncomment this to run the ### lines
31 # use Smart::Comments;
32  
33 40 our $VERSION = 100;
34  
35 40 ▶use constant supported_parameters =>
Subroutine BEGIN: called CC=1 SCAR=0.0
36 ({ name => 'above_version',
37 description => 'Check only things above this version of Perl.',
38 behavior => 'string',
39 parser => \&Perl::Critic::Pulp::Utils::parameter_parse_version,
40 40 });
41 40 ▶use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 40 ▶use constant default_themes => qw(pulp compatibility);
Subroutine BEGIN: called CC=1 SCAR=0.0
43 40 ▶use constant applies_to => 'PPI::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45  
46 # but actually Pod::MinimumVersion is a hard dependency at the moment ...
47 1 ▶sub initialize_if_enabled {
Subroutine initialize_if_enabled: called CC=2 SCAR=7.0
Pod documented
48 1 my ($self, $config) = @_;
49 # when Pod::MinimumVersion is available
50 1 ▶ return (eval { require Pod::MinimumVersion; 1 } || 0);
Condition50%1/2
eval { do { require Pod::MinimumVersion; 1 } } || 0
l!l
10
MC/DC0%0/1
eval { do { require Pod::MinimumVersion; 1 } } || 0
eval { do { require Pod::MinimumVersion; 1 } }
Truth table50%1/2
A
A= eval { do { require Pod::MinimumVersion; 1 } }
Aresult
11
00
51 }
52  
53 19 ▶sub violates {
Subroutine violates: called CC=4 SCAR=13.9
Pod documented
54 19 my ($self, $document) = @_;
55 ### $self
56  
57 # whichever of highest_explicit_perl_version() or "above_version" is greater
58 19 my $above_version = $self->{'_above_version'};
59 19 ▶ if (defined (my $doc_version = $document->highest_explicit_perl_version)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $doc_version = $document->highest_explicit_perl_version)) 7 12 19
60 7 ▶ if (! defined $above_version || $doc_version > $above_version) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $above_version or $doc_version > $above_version) 4 3 7
Condition100%3/3
not defined $above_version or $doc_version > $above_version
l!l&&r!l&&!r
313
MC/DC100%2/2
not defined $above_version or $doc_version > $above_version
not defined $above_version $doc_version > $above_version
Truth table100%3/3
not(A) or B
A= not defined $above_versionB= $doc_version > $above_version
ABresult
1X1
011
000
61 4 $above_version = $doc_version;
62 }
63 }
64  
65 19 my $str = $document->serialize;
66 19 my $pmv = Pod::MinimumVersion->new (string => $str,
67 above_version => $above_version,
68 one_report_per_version => 1,
69 );
70 19 my @reports = $pmv->reports;
71 19 @reports = sort {$a->{'version'} <=> $b->{'version'}} @reports;
72 return map {
73 19 my $report = $_;
74 11 my $violation = $self->violation
75 ("Pod requires perl $report->{'version'} due to: $report->{'why'}.",
76 '',
77 $document);
78 Perl::Critic::Pulp::Utils::_violation_override_linenum
79 11 ($violation, $str, $report->{'linenum'});
80  
81 } @reports;
82 }
83  
84 package Perl::Critic::Pulp::PodMinimumVersionViolation;
85 40 ▶use base 'Perl::Critic::Violation';
Subroutine BEGIN: called CC=1 SCAR=0.0
86 637 ▶sub location {
Subroutine location: called CC=3 SCAR=11.0
87 637 my ($self) = @_;
88 637 ▶ my $offset = ($self->{_Pulp_linenum_offset} || 0);
Condition100%2/2
$self->{'_Pulp_linenum_offset'} || 0
l!l
61918
MC/DC100%1/1
$self->{'_Pulp_linenum_offset'} || 0
$self->{'_Pulp_linenum_offset'}
Truth table100%2/2
A
A= $self->{'_Pulp_linenum_offset'}
Aresult
11
00
89  
90 637 my @location = @{$self->SUPER::location()};
91 637 $location[0] += $offset; # line
92 637 ▶ if ($#location >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#location >= 3) 637 0 637
93 637 $location[3] += $offset; # logical line, new in ppi 1.205
94 }
95 637 return \@location;
96 }
97  
98 40 1;
99 __END__
« Policy/Documentation/ProhibitDuplicateSeeAlso.pm ↑ Summary Policy/Documentation/ProhibitBadAproposMarkup.pm »