1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/Modules/RequireEndWithOne.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::Modules::RequireEndWithOne;
15 use Perl::Critic::Utils qw{ :severities :classification };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $EXPL => q{Must end with a recognizable true value};
23 Readonly::Scalar my $DESC => q{Module does not end with "1;"};
25 #-----------------------------------------------------------------------------
27 sub supported_parameters { return () }
28 sub default_severity { return $SEVERITY_HIGH }
29 sub default_themes { return qw( core bugs pbp ) }
30 sub applies_to { return 'PPI::Document' }
32 #-----------------------------------------------------------------------------
35 my ( $self, $elem, $doc ) = @_;
36 return if is_script($doc); #Must be a library or module.
38 # Last statement should be just "1;"
39 my @significant = grep { _is_code($_) } $doc->schildren();
40 my $match = $significant[-1];
42 return if ((ref $match) eq 'PPI::Statement' &&
43 $match =~ m{\A 1 \s* ; \z}mx );
45 # Must be a violation...
46 return $self->violation( $DESC, $EXPL, $match );
51 return ! ( $elem->isa('PPI::Statement::End')
52 || $elem->isa('PPI::Statement::Data'));
59 #-----------------------------------------------------------------------------
65 Perl::Critic::Policy::Modules::RequireEndWithOne - End each module with an explicitly C<1;> instead of some funky expression.
69 This Policy is part of the core L<Perl::Critic> distribution.
74 All files included via C<use> or C<require> must end with a true value
75 to indicate to the caller that the include was successful. The
76 standard practice is to conclude your .pm files with C<1;>, but some
77 authors like to get clever and return some other true value like
78 C<return "Club sandwich";>. We cannot tolerate such frivolity! OK, we
79 can, but we don't recommend it since it confuses the newcomers.
84 This Policy is not configurable except for the standard options.
89 Chris Dolan C<cdolan@cpan.org>
91 Some portions cribbed from
92 L<Perl::Critic::Policy::Modules::RequireExplicitPackage>.
96 Copyright (c) 2005-2008 Chris Dolan and Jeffrey Ryan Thalhammer. All
99 This program is free software; you can redistribute it and/or modify
100 it under the same terms as Perl itself. The full text of this license
101 can be found in the LICENSE file included with this module.
107 # cperl-indent-level: 4
109 # indent-tabs-mode: nil
110 # c-indentation-style: bsd
112 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :