1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitEscapedCharacters.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitEscapedCharacters;
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $DESC => q{Numeric escapes in interpolated string};
23 Readonly::Scalar my $EXPL => [ 56 ];
25 #-----------------------------------------------------------------------------
27 sub supported_parameters { return () }
28 sub default_severity { return $SEVERITY_LOW }
29 sub default_themes { return qw(core pbp cosmetic) }
30 sub applies_to { return qw(PPI::Token::Quote::Double
31 PPI::Token::Quote::Interpolate) }
33 #-----------------------------------------------------------------------------
36 my ( $self, $elem, undef ) = @_;
38 my $not_escaped = qr/(?<!\\)(?:\\\\)*/mx;
39 my $hex = qr/\\x[\dA-Fa-f]{2}/mx;
40 my $widehex = qr/\\x[{][\dA-Fa-f]+[}]/mx;
41 my $oct = qr/\\[01][0-7]/mx;
42 if ($elem->content =~ m/$not_escaped (?:$hex|$widehex|$oct)/mxo) {
43 return $self->violation( $DESC, $EXPL, $elem );
52 #-----------------------------------------------------------------------------
58 Perl::Critic::Policy::ValuesAndExpressions::ProhibitEscapedCharacters - Write C<"\N{DELETE}"> instead of C<"\x7F">, etc.
62 This Policy is part of the core L<Perl::Critic> distribution.
67 Escaped numeric values are hard to read and debug. Instead, use named
68 values. The syntax is less compact, but dramatically more readable.
70 $str = "\x7F\x06\x22Z"; # not ok
72 use charnames ':full';
73 $str = "\N{DELETE}\N{ACKNOWLEDGE}\N{CANCEL}Z"; # ok
78 This Policy is not configurable except for the standard options.
86 Chris Dolan <cdolan@cpan.org>
90 Copyright (c) 2006-2008 Chris Dolan. All rights reserved.
92 This program is free software; you can redistribute it and/or modify
93 it under the same terms as Perl itself. The full text of this license
94 can be found in the LICENSE file included with this module.
100 # cperl-indent-level: 4
102 # indent-tabs-mode: nil
103 # c-indentation-style: bsd
105 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :