Policy/Documentation/RequireFinalCut.pm

filter: Statementstmt 94.8% 74 / 78 Branchbran 81.2% 13 / 16 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 21 / 21 Podpod 100% 1 / 1 totaltotal 94.4% 119 / 126 CC 11 SCAR 10.0
CC
11
Cov
93%
verbatim
6.1
command
6.0
end_input
3.0
CRAP 2.7
« Policy/Documentation/RequireFilenameMarkup.pm ↑ Summary Policy/Modules/ProhibitModuleShebang.pm »
1 # Copyright 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 RequireFinalCut RequireFinalCut.pm
20 # perlcritic -s RequireFinalCut /usr/share/perl5/Class/InsideOut.pm
21 # perlcritic -s RequireFinalCut /usr/share/perl5/Lingua/Any/Numbers.pm
22  
23  
24 package Perl::Critic::Policy::Documentation::RequireFinalCut;
25 40 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 40 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 40 ▶use Perl::Critic::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 # uncomment this to run the ### lines
32 # use Smart::Comments;
33  
34 40 our $VERSION = 100;
35  
36 40 ▶use constant supported_parameters => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
37 40 ▶use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOWEST;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 40 ▶use constant default_themes => qw(pulp cosmetic);
Subroutine BEGIN: called CC=1 SCAR=0.0
39 40 ▶use constant applies_to => 'PPI::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 31 ▶sub violates {
Subroutine violates: called CC=1 SCAR=0.0
Pod documented
42 31 my ($self, $elem, $document) = @_;
43 ### RequireFinalCut on: $elem->content
44  
45 31 my $parser = Perl::Critic::Pulp::PodParser::RequireFinalCut->new
46 (policy => $self);
47 31 $parser->parse_from_elem ($elem);
48 31 return $parser->violations;
49 }
50  
51 package Perl::Critic::Pulp::PodParser::RequireFinalCut;
52 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 40 ▶use base 'Perl::Critic::Pulp::PodParser';
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 31 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
57 31 my $class = shift;
58 31 my $self = $class->SUPER::new (@_);
59 31 $self->parseopts(-process_cut_cmd => 1);
60 31 return $self;
61 }
62  
63 # Pod::Parser doesn't hold the current line number except in a local
64 # variable, so have to note it here for use in end_input().
65 #
66 28 ▶sub begin_input {
Subroutine begin_input: called CC=1 SCAR=0.0
67 28 my $self = shift;
68 28 $self->SUPER::begin_input(@_);
69 28 $self->{'last_linenum'} = 0;
70 }
71 113 ▶sub preprocess_line {
Subroutine preprocess_line: called CC=1 SCAR=0.0
72 113 my ($self, $line, $linenum) = @_;
73 ### preprocess_line(): "linenum=$linenum"
74 113 $self->{'last_linenum'} = $linenum;
75 113 return $line;
76 }
77  
78 28 ▶sub end_input {
Subroutine end_input: called CC=3 SCAR=11.0
79 28 my $self = shift;
80 28 $self->SUPER::begin_input(@_);
81 28 ▶ if ($self->{'in_pod'}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"in_pod"} and not $self->{"saw_cut_in_text"}) 7 21 28
Condition100%3/3
$self->{"in_pod"} and not $self->{"saw_cut_in_text"}
!ll&&!rl&&r
1477
MC/DC100%2/2
$self->{"in_pod"} and not $self->{"saw_cut_in_text"}
$self->{"in_pod"} not $self->{"saw_cut_in_text"}
Truth table100%3/3
A and not(B)
A= $self->{"in_pod"}B= not $self->{"saw_cut_in_text"}
ABresult
0X0
100
111
82 && ! $self->{'saw_cut_in_text'}) {
83 $self->violation_at_linenum_and_textpos
84 ("POD doesn't end with =cut directive",
85 7 $self->{'last_linenum'} + 1, # end of file as the position
86 '',
87 0);
88 }
89 }
90  
91 49 ▶sub command {
Subroutine command: called CC=6 SCAR=17.9
92 49 my $self = shift;
93 49 $self->SUPER::command(@_);
94 49 my ($command, $text, $linenum, $paraobj) = @_;
95 ### $command
96 ### $text
97  
98 49 ▶ if ($command eq 'cut') {
Branch: 3 branches
BranchTrueFalseTotal
if ($command eq 'cut') { } 10 39 49
elsif ($command eq 'end' or $command eq 'for') { } 11 28 39
elsif ($command eq 'pod') { } 15 13 28
99 10 $self->{'in_pod'} = 0;
100  
101 ▶ } elsif ($command eq 'end' || $command eq 'for') {
Condition100%3/3
$command eq "end" or $command eq "for"
l!l&&r!l&&!r
9228
MC/DC100%2/2
$command eq "end" or $command eq "for"
$command eq "end" $command eq "for"
Truth table100%3/3
A or B
A= $command eq "end"B= $command eq "for"
ABresult
1X1
011
000
102  
103 } elsif ($command eq 'pod') {
104 15 $self->{'in_pod'} = 1;
105  
106 } else {
107 13 ▶ unless ($self->{'in_begin'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"in_begin"}) 3 10 13
108 3 $self->{'in_pod'} = 1;
109 }
110 }
111 ### now in_pod: $self->{'in_pod'}
112  
113 49 $self->my_notice_cut($text);
114 49 return '';
115 }
116  
117 4 ▶sub verbatim {
Subroutine verbatim: called CC=3 SCAR=18.1
118 4 my ($self, $text, $linenum, $paraobj) = @_;
119 ### verbatim ...
120  
121 # ignore entirely whitespace runs of blank lines
122 4 ▶ return '' if $text =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /^\s*$/ 4 0 4
123  
124 0 ▶ unless ($self->{'in_begin'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"in_begin"}) 0 0 0
125 0 $self->{'in_pod'} = 1;
126 }
127 0 $self->my_notice_cut($text);
128 0 return '';
129 }
130  
131 13 ▶sub textblock {
Subroutine textblock: called CC=2 SCAR=6.9
132 13 my ($self, $text, $linenum, $paraobj) = @_;
133 ### textblock ...
134 ### $text
135  
136 13 ▶ unless ($self->{'in_begin'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"in_begin"}) 5 8 13
137 5 $self->{'in_pod'} = 1;
138 }
139 13 $self->my_notice_cut($text);
140 13 return '';
141 }
142  
143 62 ▶sub my_notice_cut {
Subroutine my_notice_cut: called CC=1 SCAR=0.0
144 62 my ($self, $text) = @_;
145 62 $self->{'saw_cut_in_text'} = ($text =~ /\n=cut\b[^\n]*/);
146 }
147  
148 40 1;
149 __END__
« Policy/Documentation/RequireFilenameMarkup.pm ↑ Summary Policy/Modules/ProhibitModuleShebang.pm »