Policy/Documentation/ProhibitVerbatimMarkup.pm

filter: Statementstmt 100% 63 / 63 Branchbran 85.7% 12 / 14 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 16 / 16 Podpod 100% 1 / 1 totaltotal 94.2% 98 / 104 CC 10 SCAR 11.0
CC
10
Cov
95%
verbatim
6.0
command
5.0
BEGIN
1.0
CRAP 3.0
« Policy/Modules/ProhibitUseQuotedVersion.pm ↑ Summary Policy/Documentation/RequireFilenameMarkup.pm »
1 # Copyright 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 # self:
20 # perlcritic -s ProhibitVerbatimMarkup ProhibitVerbatimMarkup.pm
21  
22 package Perl::Critic::Policy::Documentation::ProhibitVerbatimMarkup;
23 40 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 40 ▶use warnings;
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  
29 # uncomment this to run the ### lines
30 #use Smart::Comments;
31  
32 40 our $VERSION = 100;
33  
34 40 ▶use constant supported_parameters => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35 40 ▶use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 40 ▶use constant default_themes => qw(pulp cosmetic);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 40 ▶use constant applies_to => 'PPI::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 13 ▶sub violates {
Subroutine violates: called CC=1 SCAR=0.0
Pod documented
40 13 my ($self, $elem, $document) = @_;
41 ### ProhibitVerbatimMarkup on: $elem->content
42  
43 13 my $parser = Perl::Critic::PodParser::ProhibitVerbatimMarkup->new
44 (policy => $self);
45 13 $parser->parse_from_elem ($elem);
46 13 return $parser->violations;
47 }
48  
49 package Perl::Critic::PodParser::ProhibitVerbatimMarkup;
50 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 40 ▶use base 'Perl::Critic::Pulp::PodParser';
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 17 ▶sub command {
Subroutine command: called CC=5 SCAR=16.2
55 17 my $self = shift;
56 17 my ($command, $text, $linenum, $paraobj) = @_;
57 ### command: $command
58 ### $text
59 17 $self->SUPER::command(@_); # maintain 'in_begin'
60  
61 17 ▶ if ($command eq 'for'
Branch: 1 branch
BranchTrueFalseTotal
if ($command eq "for" and $text =~ /^ProhibitVerbatimMarkup\b\s*(.*)/) 4 13 17
Condition66%2/3
$command eq "for" and $text =~ /^ProhibitVerbatimMarkup\b\s*(.*)/
!ll&&!rl&&r
1304
MC/DC50%1/2
$command eq "for" and $text =~ /^ProhibitVerbatimMarkup\b\s*(.*)/
$command eq "for" $text =~ /^ProhibitVerbatimMarkup\b\s*(.*)/
Truth table66%2/3
A and B
A= $command eq "for"B= $text =~ /^ProhibitVerbatimMarkup\b\s*(.*)/
ABresult
0X0
100
111
62 && $text =~ /^ProhibitVerbatimMarkup\b\s*(.*)/) {
63 4 my $directive = $1;
64 ### $directive
65 4 ▶ if ($directive =~ /^allow next( (\d+))?/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($directive =~ /^allow next( (\d+))?/) 4 0 4
66 # numbered "allow next 5" means up to that many following verbatims
67 # unnumbered "allow next" means one following verbatim
68 4 ▶ $self->{'allow_next'} = (defined $2 ? $2 : 1);
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 2 2 4
69 }
70 }
71 17 return '';
72 }
73  
74 18 ▶sub verbatim {
Subroutine verbatim: called CC=6 SCAR=18.0
75 18 my ($self, $text, $linenum, $paraobj) = @_;
76 ### verbatim: $text
77  
78 18 ▶ if ($self->{'allow_next'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"allow_next"}) 4 14 18
79 ### allow next: $self->{'allow_next'}
80 4 $self->{'allow_next'}--;
81 4 return '';
82 }
83  
84 # process outside =begin, and inside =begin which is ":" markup
85 14 ▶ unless ($self->{'in_begin'} eq '' || $self->{'in_begin'} =~ /^:/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/) 1 13 14
Condition66%2/3
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/
l!l&&r!l&&!r
1301
MC/DC50%1/2
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/
$self->{"in_begin"} eq "" $self->{"in_begin"} =~ /^:/
Truth table66%2/3
A or B
A= $self->{"in_begin"} eq ""B= $self->{"in_begin"} =~ /^:/
ABresult
1X1
011
000
86 1 return '';
87 }
88  
89 # I<> italic
90 # B<> bold
91 # C<> code
92 # L<> link
93 # E<> escape
94 # F<> filename
95 # S<> no break
96 # X<> index
97 # Z<> empty
98 # J<> Pod::MultiLang
99 #
100 # DB<123> sample debugger output exempted
101 #
102 13 ▶ while ($text =~ /\bDB<\d+>|([IBCLEFSXZJ]<)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /\bDB<\d+>|([IBCLEFSXZJ]<)/g) 10 13 23
103 10 ▶ next unless $1;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 0 10 10
104 10 my $markup = "$1>";
105  
106 10 $self->violation_at_linenum_and_textpos
107 ("$markup markup in verbatim paragraph, is it meant to be so?",
108 $linenum, $text, pos($text));
109 }
110 13 return '';
111 }
112  
113 3 ▶sub textblock {
Subroutine textblock: called CC=1 SCAR=0.0
114 3 my ($self) = @_;
115 3 $self->{'allow_next'} = 0;
116 3 return '';
117 }
118  
119 40 1;
120 __END__
« Policy/Modules/ProhibitUseQuotedVersion.pm ↑ Summary Policy/Documentation/RequireFilenameMarkup.pm »