1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/Documentation/RequirePodAtEnd.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::Documentation::RequirePodAtEnd;
15 use List::Util qw(first);
17 use Perl::Critic::Utils qw{ :severities };
18 use base 'Perl::Critic::Policy';
20 our $VERSION = '1.088';
22 #-----------------------------------------------------------------------------
24 Readonly::Scalar my $POD_RX => qr{\A = (?: for|begin|end ) }mx;
25 Readonly::Scalar my $DESC => q{POD before __END__};
26 Readonly::Scalar my $EXPL => [139, 140];
28 #-----------------------------------------------------------------------------
30 sub supported_parameters { return () }
31 sub default_severity { return $SEVERITY_LOWEST }
32 sub default_themes { return qw( core cosmetic pbp ) }
33 sub applies_to { return 'PPI::Document' }
35 #-----------------------------------------------------------------------------
38 my ( $self, $elem, $doc ) = @_;
40 # No POD means no violation
41 my $pods_ref = $doc->find('PPI::Token::Pod');
44 # Look for first POD tag that isn't =for, =begin, or =end
45 my $pod = first { $_ !~ $POD_RX} @{ $pods_ref };
48 my $end = $doc->find_first('PPI::Statement::End');
49 if ($end) { # No __END__ means definite violation
50 my $pod_loc = $pod->location();
51 my $end_loc = $end->location();
52 if ( $pod_loc->[0] > $end_loc->[0] ) {
53 # POD is after __END__, or relative position couldn't be determined
58 return $self->violation( $DESC, $EXPL, $pod );
65 #-----------------------------------------------------------------------------
71 Perl::Critic::Policy::Documentation::RequirePodAtEnd - All POD should be after C<__END__>.
75 This Policy is part of the core L<Perl::Critic> distribution.
80 Perl stops processing code when it sees an C<__END__> statement. So,
81 to save processing time, it's faster to put
82 documentation after the C<__END__>. Also, writing all the POD in one
83 place usually leads to a more cohesive document, rather than being
84 forced to follow the layout of your code. This policy issues
85 violations if any POD is found before an C<__END__>.
90 This Policy is not configurable except for the standard options.
95 Some folks like to use C<=for>, and C<=begin>, and C<=end> tags to
96 create block comments in-line with their code. Since those tags aren't
97 usually part of the documentation, this Policy does allows them to
98 appear before the C<__END__> statement.
103 Accepts: A list of things to frobulate
104 Returns: True if succesful
108 sub frobulate { ... }
112 Chris Dolan <cdolan@cpan.org>
116 Copyright (c) 2006-2008 Chris Dolan. All rights reserved.
118 This program is free software; you can redistribute it and/or modify
119 it under the same terms as Perl itself. The full text of this license
120 can be found in the LICENSE file included with this module
126 # cperl-indent-level: 4
128 # indent-tabs-mode: nil
129 # c-indentation-style: bsd
131 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :