« 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 = 99; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 40 | use constant supported_parameters => | |||||||||||||||||||||||||||
| 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 | ▶ | }); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | sub initialize_if_enabled { | ||||||||||||||||||||||||||||
| 48 | 1 | ▶ | my ($self, $config) = @_; | ||||||||||||||||||||||||||
|
Subroutine
initialize_if_enabled: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | # when Pod::MinimumVersion is available | ||||||||||||||||||||||||||||
| 50 | 1 | ▶ | return (eval { require Pod::MinimumVersion; 1 } || 0); | ||||||||||||||||||||||||||
|
Condition50%1/2
eval { || 0
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
}
}
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub violates { | ||||||||||||||||||||||||||||
| 54 | 19 | ▶ | my ($self, $document) = @_; | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 60 | 7 | ▶ | if (! defined $above_version || $doc_version > $above_version) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $above_version or $doc_version > $above_version
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
| |||||||||||||||||||||||||||||
| 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 | sub location { | ||||||||||||||||||||||||||||
| 87 | 637 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
location: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 88 | 637 | ▶ | my $offset = ($self->{_Pulp_linenum_offset} || 0); | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'_Pulp_linenum_offset'} || 0
MC/DC100%1/1
$self->{'_Pulp_linenum_offset'} || 0
$self->{'_Pulp_linenum_offset'}
Truth table100%2/2
A
A= $self->{'_Pulp_linenum_offset'}
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 637 | my @location = @{$self->SUPER::location()}; | |||||||||||||||||||||||||||
| 91 | 637 | $location[0] += $offset; # line | |||||||||||||||||||||||||||
| 92 | 637 | ▶ | if ($#location >= 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 637 | $location[3] += $offset; # logical line, new in ppi 1.205 | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 637 | return \@location; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 40 | 1; | |||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =for stopwords CPAN config Ryde | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 NAME | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | Perl::Critic::Policy::Compatibility::PodMinimumVersion - check Perl version declared against POD features used | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | This policy is part of the L<C<Perl::Critic::Pulp>|Perl::Critic::Pulp> | ||||||||||||||||||||||||||||
| 110 | add-on. It checks that the POD features you use don't exceed your target | ||||||||||||||||||||||||||||
| 111 | Perl version as indicated by C<use 5.008> etc. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =for ProhibitVerbatimMarkup allow next 3 | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | use 5.005; | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =pod | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | C<< something >> # bad, double angles needs 5.006 | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | POD doesn't affect how the code runs, so this policy is low severity, and | ||||||||||||||||||||||||||||
| 122 | under the "compatibility" theme (see L<Perl::Critic/POLICY THEMES>). | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | See L<C<Pod::MinimumVersion>|Pod::MinimumVersion> for the POD version checks | ||||||||||||||||||||||||||||
| 125 | applied. The key idea is for example when targeting Perl 5.005 you avoid | ||||||||||||||||||||||||||||
| 126 | things like double-angles S<C<CE<lt>E<lt> E<gt>E<gt>>>, since C<pod2man> in | ||||||||||||||||||||||||||||
| 127 | 5.005 didn't support them. It may be possible to get newer versions of the | ||||||||||||||||||||||||||||
| 128 | POD translators from CPAN, but whether they run on an older Perl and whether | ||||||||||||||||||||||||||||
| 129 | you want to require that of users is another matter. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | Adding the sort of C<use 5.006> etc to declare a target Perl can be a bit | ||||||||||||||||||||||||||||
| 132 | tedious. The config option below lets you set a base version you use. As | ||||||||||||||||||||||||||||
| 133 | always if you don't care at all about this sort of thing you can disable the | ||||||||||||||||||||||||||||
| 134 | policy from your F<.perlcriticrc> in the usual way (see | ||||||||||||||||||||||||||||
| 135 | L<Perl::Critic/CONFIGURATION>), | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | [-Compatibility::PodMinimumVersion] | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =head2 C<RequirePodLinksIncludeText> Policy | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | The C<Documentation::RequirePodLinksIncludeText> policy asks you to use the | ||||||||||||||||||||||||||||
| 142 | C<LE<lt>target|displayE<gt>> style always. That feature is new in Perl | ||||||||||||||||||||||||||||
| 143 | 5.005 and will be reported by C<PodMinimumVersion> unless you've got C<use | ||||||||||||||||||||||||||||
| 144 | 5.005> or higher or set C<above_version> below. | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =over 4 | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =item C<above_version> (version string, default none) | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | Report only things about Perl versions above this. The string is anything | ||||||||||||||||||||||||||||
| 153 | the L<C<version.pm>|version> module understands. For example if you always | ||||||||||||||||||||||||||||
| 154 | use Perl 5.6 or higher then set | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | [Compatibility::PodMinimumVersion] | ||||||||||||||||||||||||||||
| 157 | above_version = 5.006 | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | The effect is that all POD features up to and including Perl 5.6 are | ||||||||||||||||||||||||||||
| 160 | allowed, only things above that will be reported (and still only those | ||||||||||||||||||||||||||||
| 161 | exceeding any C<use 5.xxx> in the file). | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =back | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | L<Perl::Critic::Pulp>, L<Pod::MinimumVersion>, L<Perl::Critic> | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | L<Perl::Critic::Policy::Documentation::RequirePodLinksIncludeText>, | ||||||||||||||||||||||||||||
| 170 | L<Perl::Critic::Policy::Compatibility::PerlMinimumVersionAndWhy>, | ||||||||||||||||||||||||||||
| 171 | L<Perl::Critic::Policy::Modules::PerlMinimumVersion> | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =head1 HOME PAGE | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | L<http://user42.tuxfamily.org/perl-critic-pulp/index.html> | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | Perl-Critic-Pulp is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 182 | under the terms of the GNU General Public License as published by the Free | ||||||||||||||||||||||||||||
| 183 | Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||
| 184 | version. | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | Perl-Critic-Pulp is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||
| 187 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||
| 188 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||||||||||||||||||||||||||||
| 189 | more details. | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | You should have received a copy of the GNU General Public License along with | ||||||||||||||||||||||||||||
| 192 | Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||