Policy/Documentation/RequireEndBeforeLastPod.pm

filter: Statementstmt 100% 44 / 44 Branchbran 100% 8 / 8 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 97.3% 73 / 75 CC 8 SCAR 14.1
CC
8
Cov
98%
violates
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.1
« Policy/CodeLayout/ProhibitFatCommaNewline.pm ↑ Summary Policy/Documentation/ProhibitParagraphEndComma.pm »
1 # Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Rydepod
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::RequireEndBeforeLastPod;
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 40 our $VERSION = 100;
27  
28 40 ▶use constant supported_parameters => ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29 40 ▶use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 40 ▶use constant default_themes => qw(pulp cosmetic);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 40 ▶use constant applies_to => 'PPI::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 # only ever gives one violation
34 40 ▶use constant default_maximum_violations_per_document => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 14 ▶sub violates {
Subroutine violates: called CC=8 SCAR=20.8
Pod documented
37 14 my ($self, $elem, $document) = @_;
38  
39 14 ▶ $elem = $elem->last_element
Condition50%1/2
$elem->last_element || (return)
l!l
140
MC/DC0%0/1
$elem->last_element || (return)
$elem->last_element
Truth table50%1/2
A
A= $elem->last_element
Aresult
11
00
40 || return; # empty file
41  
42 14 ▶ if ($elem->isa('PPI::Statement::End')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Statement::End") or $elem->isa("PPI::Statement::Data")) 5 9 14
Condition100%3/3
$elem->isa("PPI::Statement::End") or $elem->isa("PPI::Statement::Data")
l!l&&r!l&&!r
419
MC/DC100%2/2
$elem->isa("PPI::Statement::End") or $elem->isa("PPI::Statement::Data")
$elem->isa("PPI::Statement::End") $elem->isa("PPI::Statement::Data")
Truth table100%3/3
A or B
A= $elem->isa("PPI::Statement::End")B= $elem->isa("PPI::Statement::Data")
ABresult
1X1
011
000
43 || $elem->isa('PPI::Statement::Data')) {
44 # $document ends with __END__, ok
45 # or ends with __DATA__, in which case you can't use __END__ after last
46 # code, so ok
47 5 return;
48 }
49  
50 9 for (;;) {
51 17 ▶ if ($elem->significant) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->significant) 2 15 17
52 # document ends with code, ie. no pod after the last code, so ok
53 2 return;
54 }
55 15 ▶ if ($elem->isa('PPI::Token::Pod')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Pod")) 6 9 15
56 # found the last pod
57 6 last;
58 }
59 # otherwise skip PPI::Token::Comment and possibly PPI::Token::Whitespace
60 9 ▶ $elem = $elem->previous_sibling
Condition100%2/2
$elem->previous_sibling || (return)
l!l
81
MC/DC100%1/1
$elem->previous_sibling || (return)
$elem->previous_sibling
Truth table100%2/2
A
A= $elem->previous_sibling
Aresult
11
00
61 || return; # $document is empty, or only comments and whitespace, so ok
62 }
63  
64 6 ▶ if (! $elem->sprevious_sibling) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem->sprevious_sibling) 2 4 6
65 # there's no code before the last pod, either a pod-only file, or pod
66 # plus comments etc, so ok
67 2 return;
68 }
69  
70 4 return $self->violation
71 ('Put __END__ before POD at the end of a file.',
72 '',
73 $elem);
74 }
75  
76 40 1;
77 __END__
« Policy/CodeLayout/ProhibitFatCommaNewline.pm ↑ Summary Policy/Documentation/ProhibitParagraphEndComma.pm »