Policy/Documentation/ProhibitParagraphTwoDots.pm

filter: Statementstmt 100% 62 / 62 Branchbran 100% 8 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 17 / 17 Podpod 100% 1 / 1 totaltotal 97.8% 91 / 93 CC 6 SCAR 6.0
CC
6
Cov
99%
textblock
4.0
interior_sequence
3.0
BEGIN
1.0
CRAP 1.8
« Policy/Documentation/ProhibitBadAproposMarkup.pm ↑ Summary Policy/ValuesAndExpressions/ProhibitFiletest_f.pm »
1 # Copyright 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 # perlcritic -s ProhibitParagraphTwoDots ProhibitParagraphTwoDots.pm
20 # perlcritic -s ProhibitParagraphTwoDots /usr/share/perl5/HTML/FormatText/WithLinks.pm
21  
22 # Maybe foo.Z<>. to disguise two dots?
23  
24  
25 package Perl::Critic::Policy::Documentation::ProhibitParagraphTwoDots;
26 40 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 40 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 40 ▶use Perl::Critic::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 # uncomment this to run the ### lines
33 #use Smart::Comments;
34  
35 40 our $VERSION = 100;
36  
37 40 ▶use constant supported_parameters => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
38 40 ▶use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOWEST;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 40 ▶use constant default_themes => qw(pulp cosmetic);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 40 ▶use constant applies_to => 'PPI::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 29 ▶sub violates {
Subroutine violates: called CC=1 SCAR=0.0
Pod documented
43 29 my ($self, $elem, $document) = @_;
44 ### ProhibitParagraphTwoDots on: $elem->content
45  
46 29 my $parser = Perl::Critic::Pulp::PodParser::ProhibitParagraphTwoDots->new
47 (policy => $self);
48 29 $parser->parse_from_elem ($elem);
49 29 return $parser->violations;
50 }
51  
52 package Perl::Critic::Pulp::PodParser::ProhibitParagraphTwoDots;
53 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 40 ▶use Pod::ParseLink;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 40 ▶use base 'Perl::Critic::Pulp::PodParser';
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 31 ▶sub command {
Subroutine command: called CC=1 SCAR=0.0
59 31 my $self = shift;
60 31 $self->SUPER::command(@_); # maintain 'in_begin'
61 31 return $self->command_as_textblock(@_);
62 }
63  
64 51 ▶sub textblock {
Subroutine textblock: called CC=4 SCAR=13.9
65 51 my ($self, $text, $linenum, $pod_para) = @_;
66 ### textblock: "linenum=$linenum"
67  
68 # "=begin :foo" is markup, check it. Other =begin is not markup.
69 51 ▶ unless ($self->{'in_begin'} eq '' || $self->{'in_begin'} =~ /^:/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/) 1 50 51
Condition66%2/3
$self->{"in_begin"} eq "" or $self->{"in_begin"} =~ /^:/
l!l&&r!l&&!r
5001
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
70 1 return '';
71 }
72  
73 50 my $str = $self->interpolate($text, $linenum);
74 ### $text
75 ### $str
76  
77 50 ▶ if ($str =~ /(?<!\.)(\.\.\s*)$/sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /(?<!\.)(\.\.\s*)$/gs) 13 37 50
78 13 $text =~ /(\s*)$/;
79 13 my $pos = length($text) - length($1); # end of $text
80 ### $pos
81 13 $self->violation_at_linenum_and_textpos
82 ("Paragraph ends with two dots (stray extra?)", $linenum, $text, $pos);
83 }
84 50 return '';
85 }
86 7 ▶sub interior_sequence {
Subroutine interior_sequence: called CC=3 SCAR=11.0
87 7 my ($self, $cmd, $text, $pod_seq) = @_;
88 7 ▶ if ($cmd eq 'X') {
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd eq 'X') { } 1 6 7
elsif ($cmd eq 'L') { } 3 3 6
89 # index entry, no text output, but keep newlines for linenum
90 1 $text =~ tr/\n//cd;
91  
92 } elsif ($cmd eq 'L') {
93 3 my ($display, $inferred, $name, $section, $type)
94 = Pod::ParseLink::parselink ($text);
95 ### $display
96 ### $inferred
97 ### $name
98 3 return $inferred; # the display part, or the name part if no display
99 }
100 4 return $text;
101 }
102  
103 40 1;
104 __END__
« Policy/Documentation/ProhibitBadAproposMarkup.pm ↑ Summary Policy/ValuesAndExpressions/ProhibitFiletest_f.pm »