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) $
6 ##############################################################################
8 package Perl::Critic::Policy::Variables::ProhibitPunctuationVars;
15 use Perl::Critic::Utils qw{ :characters :severities :data_conversion };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $DESC => q{Magic punctuation variable used};
23 Readonly::Scalar my $EXPL => [ 79 ];
25 #-----------------------------------------------------------------------------
27 sub supported_parameters {
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 _ ) ],
40 sub default_severity { return $SEVERITY_LOW }
41 sub default_themes { return qw(core pbp cosmetic) }
42 sub applies_to { return 'PPI::Token::Magic' }
44 #-----------------------------------------------------------------------------
47 my ( $self, $elem, undef ) = @_;
48 if ( !exists $self->{_allow}->{$elem} ) {
49 return $self->violation( $DESC, $EXPL, $elem );
58 #-----------------------------------------------------------------------------
64 Perl::Critic::Policy::Variables::ProhibitPunctuationVars - Write C<$EVAL_ERROR> instead of C<$@>.
69 This Policy is part of the core L<Perl::Critic> distribution.
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.
81 use English qw(-no_match_vars);
82 local $OUTPUT_AUTOFLUSH = undef; #ok
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.
92 You can add more exceptions to your configuration. In your
93 perlcriticrc file, add a block like this:
95 [Variables::ProhibitPunctuationVars]
98 The C<allow> property should be a whitespace-delimited list of
99 punctuation variables.
104 This doesn't find punctuation variables in strings.
109 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
114 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
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.
124 # cperl-indent-level: 4
126 # indent-tabs-mode: nil
127 # c-indentation-style: bsd
129 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :