blib/lib/Perl/Critic/Policy/Documentation/RequirePodAtEnd.pm

filter: Statementstmt 90.7% 39 / 43 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 80.0% 4 / 5 totaltotal 86.9% 60 / 69 CC 5 SCAR 9.3
CC
5
Cov
84%
violates
6.2
BEGIN
1.0
BEGIN
1.0
CRAP 2.5
« blib/lib/Perl/Critic/Policy/Miscellanea/ProhibitUselessNoCritic.pm ↑ Summary blib/lib/Perl/Critic/Policy/Miscellanea/ProhibitUnrestrictedNoCritic.pm »
1 package Perl::Critic::Policy::Documentation::RequirePodAtEnd;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 40 ▶use Perl::Critic::Utils qw{ :severities };
Subroutine BEGIN: called CC=1 SCAR=0.0
11 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 40 our $VERSION = '1.150';
14  
15 #-----------------------------------------------------------------------------
16  
17 40 Readonly::Scalar my $POD_RX => qr{\A = (?: for|begin|end ) }xms;
18 40 Readonly::Scalar my $DESC => q{POD before __END__};
19 40 Readonly::Scalar my $EXPL => [139, 140];
20  
21 #-----------------------------------------------------------------------------
22  
23 90 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
24 77 ▶sub default_severity { return $SEVERITY_LOWEST }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
25 84 ▶sub default_themes { return qw( core cosmetic pbp ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
26 31 ▶sub applies_to { return 'PPI::Document' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
27  
28 #-----------------------------------------------------------------------------
29  
30 sub violates {
31 31 ▶ my ( $self, $elem, $doc ) = @_;
Subroutine violates: called CC=5 SCAR=18.2
Pod documented
32  
33 # No POD means no violation
34 31 my $pods_ref = $doc->find('PPI::Token::Pod');
35 31 ▶ return if !$pods_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $pods_ref 29 2 31
36  
37 # Look for first POD tag that isn't =for, =begin, or =end
38 2 ▶ my $pod = first { $_ !~ $POD_RX} @{ $pods_ref };
Subroutine __ANON__: called CC=1 SCAR=0.0
39 2 ▶ return if !$pod;
Branch: 1 branch
BranchTrueFalseTotal
unless $pod 0 2 2
40  
41 2 my $end = $doc->find_first('PPI::Statement::End');
42 2 ▶ if ($end) { # No __END__ means definite violation
Branch: 1 branch
BranchTrueFalseTotal
if ($end) 0 2 2
43 0 my $pod_loc = $pod->location();
44 0 my $end_loc = $end->location();
45 0 ▶ if ( $pod_loc->[0] > $end_loc->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pod_loc->[0] > $end_loc->[0]) 0 0 0
46 # POD is after __END__, or relative position couldn't be determined
47 0 return;
48 }
49 }
50  
51 2 return $self->violation( $DESC, $EXPL, $pod );
52 }
53  
54 40 1;
55  
56 __END__
57  
58 #-----------------------------------------------------------------------------
59  
60 =pod
61  
62 =head1 NAME
63  
64 Perl::Critic::Policy::Documentation::RequirePodAtEnd - All POD should be after C<__END__>.
65  
66  
67 =head1 AFFILIATION
68  
69 This Policy is part of the core L<Perl::Critic|Perl::Critic>
70 distribution.
71  
72  
73 =head1 DESCRIPTION
74  
75 Perl stops processing code when it sees an C<__END__> statement. So,
76 to save processing time, it's faster to put documentation after the
77 C<__END__>. Also, writing all the POD in one place usually leads to a
78 more cohesive document, rather than being forced to follow the layout
79 of your code. This policy issues violations if any POD is found
80 before an C<__END__>.
81  
82  
83 =head1 CONFIGURATION
84  
85 This Policy is not configurable except for the standard options.
86  
87  
88 =head1 NOTES
89  
90 Some folks like to use C<=for>, and C<=begin>, and C<=end> tags to
91 create block comments in-line with their code. Since those tags
92 aren't usually part of the documentation, this Policy does allows them
93 to appear before the C<__END__> statement.
94  
95 =begin comments
96  
97 frobulate()
98 Accepts: A list of things to frobulate
99 Returns: True if successful
100  
101 =end comments
102  
103 sub frobulate { ... }
104  
105 =head1 AUTHOR
106  
107 Chris Dolan <cdolan@cpan.org>
108  
109  
110 =head1 COPYRIGHT
111  
112 Copyright (c) 2006-2011 Chris Dolan.
113  
114 This program is free software; you can redistribute it and/or modify
115 it under the same terms as Perl itself. The full text of this license
116 can be found in the LICENSE file included with this module
117  
118 =cut
119  
120 # Local Variables:
121 # mode: cperl
122 # cperl-indent-level: 4
123 # fill-column: 78
124 # indent-tabs-mode: nil
125 # c-indentation-style: bsd
126 # End:
127 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
« blib/lib/Perl/Critic/Policy/Miscellanea/ProhibitUselessNoCritic.pm ↑ Summary blib/lib/Perl/Critic/Policy/Miscellanea/ProhibitUnrestrictedNoCritic.pm »