Build all packages removed dependencies of libtest-exception-perl libtest-warn-perl...
[dh-make-perl] / dev / i386 / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / CodeLayout / ProhibitTrailingWhitespace.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/CodeLayout/ProhibitTrailingWhitespace.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::CodeLayout::ProhibitTrailingWhitespace;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use English qw(-no_match_vars);
14 use Readonly;
15
16 use charnames qw{};
17
18 use PPI::Token::Whitespace;
19 use Perl::Critic::Utils qw{ :characters :severities };
20
21 use base 'Perl::Critic::Policy';
22
23 our $VERSION = '1.088';
24
25 #-----------------------------------------------------------------------------
26
27 Readonly::Scalar my $EXPL => q{Don't use whitespace at the end of lines};
28
29 ## no critic (RequireInterpolationOfMetachars)
30 Readonly::Hash my %C_STYLE_ESCAPES =>
31     (
32         ord "\t" => q{\t},
33         ord "\n" => q{\n},
34         ord "\r" => q{\r},
35         ord "\f" => q{\f},
36         ord "\b" => q{\b},
37         ord "\a" => q{\a},
38         ord "\e" => q{\e},
39     );
40 ## use critic
41
42 #-----------------------------------------------------------------------------
43
44 sub supported_parameters { return qw{ }                    }
45 sub default_severity     { return $SEVERITY_LOWEST         }
46 sub default_themes       { return qw( core maintenance )   }
47 sub applies_to           { return 'PPI::Token::Whitespace' }
48
49 #-----------------------------------------------------------------------------
50
51 sub violates {
52     my ( $self, $token, undef ) = @_;
53
54     # There is at most one linefeed per Whitespace token, and it will always
55     # be the last character, if present.  If the code has two consecutive
56     # blank lines, PPI will produce two Whitespace tokens, each consisting
57     # of a single linefeed.  Thus, any Whitespace token consisting of a single
58     # character cannot contain trailing whitespace.
59     my $content = $token->content();
60     return if length($content) < 2;
61     return if qq{\n} ne chop $content;
62
63     my $description = q{Found "};
64     $description .= join $EMPTY, map { _escape($_) } split $EMPTY, $content;
65     $description .= q{" at the end of the line};
66
67     return $self->violation( $description, $EXPL, $token );
68 }
69
70 sub _escape {
71     my $character = shift;
72     my $ordinal = ord $character;
73
74     if (my $c_escape = $C_STYLE_ESCAPES{$ordinal}) {
75         return $c_escape;
76     }
77
78
79     # Apparently, the charnames.pm that ships with older perls does not
80     # support the C<viacode> function, and newer versions of the module are
81     # not distributed separately from perl itself So if the C<viacode> method
82     # is not supported, then just substitute something.
83
84
85     ## no critic (RequireInterpolationOfMetachars)
86     if ( charnames->can( 'viacode' ) ) {
87         return q/\N{/ . charnames::viacode($ordinal) . q/}/;
88     }
89     else {
90         return '\N{WHITESPACE CHAR}';
91     }
92 }
93
94 1;
95
96 #-----------------------------------------------------------------------------
97
98 __END__
99
100 =pod
101
102 =for stopwords
103
104 =head1 NAME
105
106 Perl::Critic::Policy::CodeLayout::ProhibitTrailingWhitespace - Don't use whitespace at the end of lines.
107
108 =head1 AFFILIATION
109
110 This Policy is part of the core L<Perl::Critic> distribution.
111
112
113 =head1 DESCRIPTION
114
115 Anything that is not readily visually detectable is a bad thing in
116 general, and more specifically, as different people edit the same
117 code, their editors may automatically strip out trailing whitespace,
118 causing spurious differences between different versions of the same
119 file (i.e. code in a source control system).
120
121
122 =head1 CONFIGURATION
123
124 This Policy is not configurable except for the standard options.
125
126
127 =head1 AUTHOR
128
129 Elliot Shank C<< <perl@galumph.com> >>
130
131 =head1 COPYRIGHT
132
133 Copyright (c) 2007-2008 Elliot Shank.  All rights reserved.
134
135 This program is free software; you can redistribute it and/or modify
136 it under the same terms as Perl itself.  The full text of this license
137 can be found in the LICENSE file included with this module.
138
139 =cut
140
141 # Local Variables:
142 #   mode: cperl
143 #   cperl-indent-level: 4
144 #   fill-column: 78
145 #   indent-tabs-mode: nil
146 #   c-indentation-style: bsd
147 # End:
148 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :