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 / Variables / ProhibitPunctuationVars.pm
1 ##############################################################################
2 #      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/Variables/ProhibitPunctuationVars.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::Variables::ProhibitPunctuationVars;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :characters :severities :data_conversion };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC => q{Magic punctuation variable used};
23 Readonly::Scalar my $EXPL => [ 79 ];
24
25 #-----------------------------------------------------------------------------
26
27 sub supported_parameters {
28     return (
29         {
30             name            => 'allow',
31             description     => 'The additional variables to allow.',
32             default_string  => $EMPTY,
33             behavior        => 'string list',
34             list_always_present_values =>
35                                  [ qw( $_ @_ $1 $2 $3 $4 $5 $6 $7 $8 $9 _ ) ],
36         },
37     );
38 }
39
40 sub default_severity { return $SEVERITY_LOW         }
41 sub default_themes   { return qw(core pbp cosmetic) }
42 sub applies_to       { return 'PPI::Token::Magic'   }
43
44 #-----------------------------------------------------------------------------
45
46 sub violates {
47     my ( $self, $elem, undef ) = @_;
48     if ( !exists $self->{_allow}->{$elem} ) {
49         return $self->violation( $DESC, $EXPL, $elem );
50     }
51     return;  #ok!
52 }
53
54 1;
55
56 __END__
57
58 #-----------------------------------------------------------------------------
59
60 =pod
61
62 =head1 NAME
63
64 Perl::Critic::Policy::Variables::ProhibitPunctuationVars - Write C<$EVAL_ERROR> instead of C<$@>.
65
66
67 =head1 AFFILIATION
68
69 This Policy is part of the core L<Perl::Critic> distribution.
70
71
72 =head1 DESCRIPTION
73
74 Perl's vocabulary of punctuation variables such as C<$!>, C<$.>, and
75 C<$^> are perhaps the leading cause of its reputation as inscrutable
76 line noise.  The simple alternative is to use the L<English> module to
77 give them clear names.
78
79   $| = undef;                      #not ok
80
81   use English qw(-no_match_vars);
82   local $OUTPUT_AUTOFLUSH = undef;        #ok
83
84
85 =head1 CONFIGURATION
86
87 The scratch variables C<$_> and C<@_> are very common and are pretty
88 well understood, so they are exempt from this policy.  The same goes
89 for the less-frequently-used default filehandle C<_> used by stat().
90 All the regexp capture variables (C<$1>, C<$2>, ...) are exempt too.
91
92 You can add more exceptions to your configuration.  In your
93 perlcriticrc file, add a block like this:
94
95   [Variables::ProhibitPunctuationVars]
96   allow = $@ $!
97
98 The C<allow> property should be a whitespace-delimited list of
99 punctuation variables.
100
101
102 =head1 BUGS
103
104 This doesn't find punctuation variables in strings.
105
106
107 =head1 AUTHOR
108
109 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
110
111
112 =head1 COPYRIGHT
113
114 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer.  All rights reserved.
115
116 This program is free software; you can redistribute it and/or modify
117 it under the same terms as Perl itself.  The full text of this license
118 can be found in the LICENSE file included with this module.
119
120 =cut
121
122 # Local Variables:
123 #   mode: cperl
124 #   cperl-indent-level: 4
125 #   fill-column: 78
126 #   indent-tabs-mode: nil
127 #   c-indentation-style: bsd
128 # End:
129 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :