1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitNoisyQuotes.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitNoisyQuotes;
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $NOISE_RX => qr{\A ["|'] [^ \w () {} [\] <> ]{1,2} ['|"] \z}mx;
23 Readonly::Scalar my $DESC => q{Quotes used with a noisy string};
24 Readonly::Scalar my $EXPL => [ 53 ];
26 #-----------------------------------------------------------------------------
28 sub supported_parameters { return () }
29 sub default_severity { return $SEVERITY_LOW }
30 sub default_themes { return qw(core pbp cosmetic) }
31 sub applies_to { return qw(PPI::Token::Quote::Double
32 PPI::Token::Quote::Single) }
34 #-----------------------------------------------------------------------------
37 my ( $self, $elem, undef ) = @_;
38 return if $elem !~ $NOISE_RX;
39 my $statement = $elem->statement;
41 && $statement->isa('PPI::Statement::Include')
42 && $statement->type eq 'use'
43 && $statement->module eq 'overload';
44 return $self->violation( $DESC, $EXPL, $elem );
51 #-----------------------------------------------------------------------------
57 Perl::Critic::Policy::ValuesAndExpressions::ProhibitNoisyQuotes - Use C<q{}> or C<qq{}> instead of quotes for awkward-looking strings.
61 This Policy is part of the core L<Perl::Critic> distribution.
66 Don't use quotes for one or two-character strings of non-alphanumeric
67 characters (i.e. noise). These tend to be hard to read. For
68 legibility, use C<q{}> or a named value. However, braces,
69 parentheses, and brackets tend do to look better in quotes, so those
72 $str = join ',', @list; #not ok
73 $str = join ",", @list; #not ok
74 $str = join q{,}, @list; #better
77 $str = join $COMMA, @list; #best
81 print '(', @list, ')'; #ok
86 This Policy is not configurable except for the standard options.
91 L<Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyQuotes>
95 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
99 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
101 This program is free software; you can redistribute it and/or modify
102 it under the same terms as Perl itself. The full text of this license
103 can be found in the LICENSE file included with this module.
109 # cperl-indent-level: 4
111 # indent-tabs-mode: nil
112 # c-indentation-style: bsd
114 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :