Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / Modules / RequireEndWithOne.pm
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) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::Modules::RequireEndWithOne;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities :classification };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
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;"};
24
25 #-----------------------------------------------------------------------------
26
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'     }
31
32 #-----------------------------------------------------------------------------
33
34 sub violates {
35     my ( $self, $elem, $doc ) = @_;
36     return if is_script($doc);   #Must be a library or module.
37
38     # Last statement should be just "1;"
39     my @significant = grep { _is_code($_) } $doc->schildren();
40     my $match = $significant[-1];
41     return if !$match;
42     return if ((ref $match) eq 'PPI::Statement' &&
43                $match =~  m{\A 1 \s* ; \z}mx );
44
45     # Must be a violation...
46     return $self->violation( $DESC, $EXPL, $match );
47 }
48
49 sub _is_code {
50     my $elem = shift;
51     return ! (    $elem->isa('PPI::Statement::End')
52                || $elem->isa('PPI::Statement::Data'));
53 }
54
55 1;
56
57 __END__
58
59 #-----------------------------------------------------------------------------
60
61 =pod
62
63 =head1 NAME
64
65 Perl::Critic::Policy::Modules::RequireEndWithOne - End each module with an explicitly C<1;> instead of some funky expression.
66
67 =head1 AFFILIATION
68
69 This Policy is part of the core L<Perl::Critic> distribution.
70
71
72 =head1 DESCRIPTION
73
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.
80
81
82 =head1 CONFIGURATION
83
84 This Policy is not configurable except for the standard options.
85
86
87 =head1 AUTHOR
88
89 Chris Dolan C<cdolan@cpan.org>
90
91 Some portions cribbed from
92 L<Perl::Critic::Policy::Modules::RequireExplicitPackage>.
93
94 =head1 COPYRIGHT
95
96 Copyright (c) 2005-2008 Chris Dolan and Jeffrey Ryan Thalhammer.  All
97 rights reserved.
98
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.
102
103 =cut
104
105 # Local Variables:
106 #   mode: cperl
107 #   cperl-indent-level: 4
108 #   fill-column: 78
109 #   indent-tabs-mode: nil
110 #   c-indentation-style: bsd
111 # End:
112 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :