File Coverage

blib/lib/Perl/Critic/Policy/Documentation/RequirePodAtEnd.pm
Criterion Covered Total %
statement 38 38 100.0
branch 8 8 100.0
condition n/a
subroutine 13 13 100.0
pod 4 5 80.0
total 63 64 98.4


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Documentation::RequirePodAtEnd;
2              
3 40     40   26315 use 5.010001;
  40         163  
4 40     40   241 use strict;
  40         98  
  40         804  
5 40     40   1128 use warnings;
  40         116  
  40         966  
6 40     40   214 use Readonly;
  40         96  
  40         1922  
7              
8 40     40   314 use List::Util qw(first);
  40         89  
  40         3197  
9              
10 40     40   632 use Perl::Critic::Utils qw{ :severities };
  40         117  
  40         2121  
11 40     40   5195 use parent 'Perl::Critic::Policy';
  40         109  
  40         214  
12              
13             our $VERSION = '1.146';
14              
15             #-----------------------------------------------------------------------------
16              
17             Readonly::Scalar my $POD_RX => qr{\A = (?: for|begin|end ) }xms;
18             Readonly::Scalar my $DESC => q{POD before __END__};
19             Readonly::Scalar my $EXPL => [139, 140];
20              
21             #-----------------------------------------------------------------------------
22              
23 97     97 0 1693 sub supported_parameters { return () }
24 78     78 1 354 sub default_severity { return $SEVERITY_LOWEST }
25 84     84 1 401 sub default_themes { return qw( core cosmetic pbp ) }
26 38     38 1 120 sub applies_to { return 'PPI::Document' }
27              
28             #-----------------------------------------------------------------------------
29              
30             sub violates {
31 38     38 1 145 my ( $self, $elem, $doc ) = @_;
32              
33             # No POD means no violation
34 38         141 my $pods_ref = $doc->find('PPI::Token::Pod');
35 38 100       284 return if !$pods_ref;
36              
37             # Look for first POD tag that isn't =for, =begin, or =end
38 8     10   42 my $pod = first { $_ !~ $POD_RX} @{ $pods_ref };
  10         68  
  8         37  
39 8 100       91 return if !$pod;
40              
41 6         25 my $end = $doc->find_first('PPI::Statement::End');
42 6 100       29 if ($end) { # No __END__ means definite violation
43 3         12 my $pod_loc = $pod->location();
44 3         55 my $end_loc = $end->location();
45 3 100       66 if ( $pod_loc->[0] > $end_loc->[0] ) {
46             # POD is after __END__, or relative position couldn't be determined
47 2         11 return;
48             }
49             }
50              
51 4         27 return $self->violation( $DESC, $EXPL, $pod );
52             }
53              
54             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 :