Policy/Documentation/ProhibitBadAproposMarkup.pm

filter: Statementstmt 100% 57 / 57 Branchbran 100% 8 / 8 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 16 / 16 Podpod 100% 1 / 1 totaltotal 97.8% 90 / 92 SCAR 19.5
CC
7
Cov
99%
textblock
3.0
command
3.0
interior_sequence
3.0
CRAP 7.0
« Policy/Compatibility/PodMinimumVersion.pm ↑ Summary Policy/Modules/ProhibitModuleShebang.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::Documentation::ProhibitBadAproposMarkup;
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 40 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 40 ▶use Perl::Critic::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # uncomment this to run the ### lines
27 # use Smart::Comments;
28  
29 40 our $VERSION = 99;
30  
31 40 ▶use constant supported_parameters => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 40 ▶use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 40 ▶use constant default_themes => qw(pulp cosmetic);
Subroutine BEGIN: called CC=1 SCAR=0.0
34 40 ▶use constant applies_to => 'PPI::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 sub violates {
37 13 ▶ my ($self, $elem, $document) = @_;
Subroutine violates: called CC=1 SCAR=0.0
Pod documented
38 13 my $parser = Perl::Critic::Pulp::PodParser::ProhibitBadAproposMarkup->new
39 (policy => $self);
40 13 $parser->parse_from_elem ($elem);
41 13 return $parser->violations;
42 }
43  
44 package Perl::Critic::Pulp::PodParser::ProhibitBadAproposMarkup;
45 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 40 ▶use base 'Perl::Critic::Pulp::PodParser';
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 sub command {
50 23 ▶ my $self = shift;
Subroutine command: called CC=3 SCAR=11.0
51 23 my ($command, $text, $linenum, $paraobj) = @_;
52 ### command: $command
53 ### $text
54 23 $self->SUPER::command(@_); # maintain 'in_begin'
55  
56 23 ▶ if ($command eq 'head1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "head1") 14 9 23
57 14 ▶ $self->{'in_NAME'} = ($text =~ /^NAME\s*$/ ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /^NAME\s*$/ ? : 11 3 14
58 }
59 ### in_NAME now: $self->{'in_NAME'}
60 23 return '';
61 }
62  
63 sub textblock {
64 16 ▶ my ($self, $text, $linenum, $paraobj) = @_;
Subroutine textblock: called CC=3 SCAR=11.0
65 ### textblock ...
66 ### in_begin: $self->{'in_begin'}
67 ### $text
68  
69 # Pod::Man accept_targets() are man, MAN, roff, ROFF. Only those =begin
70 # bits are put through to the man page and therefore only those are bad.
71 16 ▶ unless ($self->{'in_begin'} eq '' || $self->{'in_begin'} =~ /^:(man|MAN|roff|ROFF)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:(man|MAN|roff|ROFF)$/) 3 13 16
Condition66%2/3
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:(man|MAN|roff|ROFF)$/
l!l&&r!l&&!r
1303
MC/DC50%1/2
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:(man|MAN|roff|ROFF)$/
$self->{"in_begin"} eq "" $self->{"in_begin"} =~ /^:(man|MAN|roff|ROFF)$/
Truth table66%2/3
A or B
A= $self->{"in_begin"} eq ""B= $self->{"in_begin"} =~ /^:(man|MAN|roff|ROFF)$/
ABresult
1X1
011
000
72 3 return '';
73 }
74  
75 13 $self->interpolate ($text, $linenum);
76 13 return '';
77 }
78  
79 sub interior_sequence {
80 12 ▶ my ($self, $command, $arg, $seq_obj) = @_;
Subroutine interior_sequence: called CC=3 SCAR=11.0
81 ### interior: $command
82 ### $arg
83 ### $seq_obj
84 ### seq raw_text: $seq_obj->raw_text
85 ### seq left_delimiter: $seq_obj->left_delimiter
86 ### seq outer: do {my $outer=$seq_obj->nested; $outer&&$outer->cmd_name}
87  
88 12 ▶ if ($self->{'in_NAME'} && $command eq 'C') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"in_NAME"} and $command eq "C") 8 4 12
Condition100%3/3
$self->{"in_NAME"} and $command eq "C"
!ll&&!rl&&r
318
MC/DC100%2/2
$self->{"in_NAME"} and $command eq "C"
$self->{"in_NAME"} $command eq "C"
Truth table100%3/3
A and B
A= $self->{"in_NAME"}B= $command eq "C"
ABresult
0X0
100
111
89 8 my ($filename, $linenum) = $seq_obj->file_line;
90  
91 8 $self->violation_at_linenum
92 ('C<> markup in NAME section is bad for "apropos".',
93 $linenum);
94 }
95 12 return '';
96 }
97  
98 40 1;
99 __END__
100  
101 =for stopwords builtin Ryde nroff
102  
103 =head1 NAME
104  
105 Perl::Critic::Policy::Documentation::ProhibitBadAproposMarkup - don't use CE<lt>E<gt> markup in a NAME section
106  
107 =head1 DESCRIPTION
108  
109 This policy is part of the L<C<Perl::Critic::Pulp>|Perl::Critic::Pulp>
110 add-on. It asks you not to write CE<lt>E<gt> markup in the NAME section of
111 the POD because it comes out badly in the man-db "apropos" database. For
112 example,
113  
114 =for ProhibitVerbatimMarkup allow next 2
115  
116 =head1 NAME
117  
118 foo - like the C<bar> program # bad
119  
120 C<pod2man> formats "CE<lt>E<gt>" using nroff macros which "man-db"'s
121 C<lexgrog> program doesn't expand, resulting in unattractive description
122 lines from C<apropos> like
123  
124 foo - like the *(C`bar*(C' program
125  
126 =for ProhibitUnbalancedParens allow next
127  
128 Man's actual formatted output is fine, and the desired text is in there,
129 just surrounded by C<*(C> bits. On that basis this policy is low severity
130 and under the "cosmetic" theme (see L<Perl::Critic/POLICY THEMES>).
131  
132 The NAME section is everything from C<=head1 NAME> to the next C<=head1>.
133 Other markup like "BE<lt>E<gt>", "IE<lt>E<gt>" and "FE<lt>E<gt>" is allowed
134 because C<pod2man> uses builtin C<\fB> etc directives for them, which
135 C<lexgrog> recognises.
136  
137 C<=begin :man> and C<=begin :roff> blocks are checked since C<Pod::Man>
138 processes those. Other C<=begin> blocks are ignored as they won't appear in
139 the roff output.
140  
141 =head2 Disabling
142  
143 If want markup in the NAME line, perhaps if printed output is more important
144 than C<apropos>, then you can always disable from your F<.perlcriticrc> in
145 the usual way (see L<Perl::Critic/CONFIGURATION>),
146  
147 [-Documentation::ProhibitBadAproposMarkup]
148  
149 Or in an individual file with the usual C<## no critic>
150  
151 ## no critic (ProhibitBadAproposMarkup)
152  
153 though if the NAME part is after an C<__END__> token then C<Perl::Critic>
154 1.112 or higher is required (and the annotation must be before the
155 C<__END__>).
156  
157 =head1 SEE ALSO
158  
159 L<Perl::Critic::Pulp>,
160 L<Perl::Critic>,
161 L<Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName>,
162 L<Perl::Critic::Policy::Documentation::RequirePodSections>,
163 L<Perl::Critic::Policy::Documentation::ProhibitVerbatimMarkup>
164  
165 L<man(1)>, L<apropos(1)>, L<lexgrog(1)>
166  
167 =head1 HOME PAGE
168  
169 L<http://user42.tuxfamily.org/perl-critic-pulp/index.html>
170  
171 =head1 COPYRIGHT
172  
173 Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
174  
175 Perl-Critic-Pulp is free software; you can redistribute it and/or modify it
176 under the terms of the GNU General Public License as published by the Free
177 Software Foundation; either version 3, or (at your option) any later
178 version.
179  
180 Perl-Critic-Pulp is distributed in the hope that it will be useful, but
181 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
182 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
183 more details.
184  
185 You should have received a copy of the GNU General Public License along with
186 Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
187  
188 =cut
« Policy/Compatibility/PodMinimumVersion.pm ↑ Summary Policy/Modules/ProhibitModuleShebang.pm »