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 / CodeLayout / ProhibitHardTabs.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/CodeLayout/ProhibitHardTabs.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::ProhibitHardTabs;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :booleans :severities };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{Hard tabs used};
23 Readonly::Scalar my $EXPL => [ 20 ];
24
25 my $DEFAULT_ALLOW_LEADING_TABS = $TRUE;
26
27 #-----------------------------------------------------------------------------
28
29 sub supported_parameters {
30     return (
31         {
32             name           => 'allow_leading_tabs',
33             description    => 'Allow hard tabs before first non-whitespace character.',
34             default_string => '1',
35             behavior       => 'boolean',
36         },
37     );
38 }
39
40 sub default_severity { return $SEVERITY_MEDIUM    }
41 sub default_themes   { return qw( core cosmetic ) }
42 sub applies_to       { return 'PPI::Token'        }
43
44 #-----------------------------------------------------------------------------
45
46 sub violates {
47     my ( $self, $elem, undef ) = @_;
48     $elem =~ m{ \t }mx || return;
49
50     # The __DATA__ element is exempt
51     return if $elem->parent->isa('PPI::Statement::Data');
52
53     # Permit leading tabs, if allowed
54     return if $self->_allow_leading_tabs() && $elem->location->[1] == 1;
55
56     # Must be a violation...
57     return $self->violation( $DESC, $EXPL, $elem );
58 }
59
60 #-----------------------------------------------------------------------------
61
62 sub _allow_leading_tabs {
63     my ( $self ) = @_;
64
65     return $self->{_allow_leading_tabs};
66 }
67
68 1;
69
70 __END__
71
72 #-----------------------------------------------------------------------------
73
74 =head1 NAME
75
76 Perl::Critic::Policy::CodeLayout::ProhibitHardTabs - Use spaces instead of tabs.
77
78 =head1 AFFILIATION
79
80 This Policy is part of the core L<Perl::Critic> distribution.
81
82
83 =head1 DESCRIPTION
84
85 Putting hard tabs in your source code (or POD) is one of the worst
86 things you can do to your co-workers and colleagues, especially if
87 those tabs are anywhere other than a leading position.  Because
88 various applications and devices represent tabs differently, they can
89 cause you code to look vastly different to other people.  Any decent
90 editor can be configured to expand tabs into spaces.  L<Perl::Tidy>
91 also does this for you.
92
93 This Policy catches all tabs in your source code, including POD,
94 quotes, and HEREDOCs.  The contents of the C<__DATA__> section are not
95 examined.
96
97 =head1 CONFIGURATION
98
99 Tabs in a leading position are allowed, but if you want to forbid all tabs
100 everywhere, put this to your F<.perlcriticrc> file:
101
102     [CodeLayout::ProhibitHardTabs]
103     allow_leading_tabs = 0
104
105 =head1 NOTES
106
107 Beware that Perl::Critic may report the location of the string that
108 contains the tab, not the actual location of the tab, so you may need
109 to do some hunting.  I'll try and fix this in the future.
110
111 =head1 AUTHOR
112
113 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
114
115 =head1 COPYRIGHT
116
117 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
118
119 This program is free software; you can redistribute it and/or modify
120 it under the same terms as Perl itself.  The full text of this license
121 can be found in the LICENSE file included with this module.
122
123 =cut
124
125 ##############################################################################
126 # Local Variables:
127 #   mode: cperl
128 #   cperl-indent-level: 4
129 #   fill-column: 78
130 #   indent-tabs-mode: nil
131 #   c-indentation-style: bsd
132 # End:
133 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :