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 / ValuesAndExpressions / ProhibitEscapedCharacters.pm
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) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitEscapedCharacters;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
22 Readonly::Scalar my $DESC     => q{Numeric escapes in interpolated string};
23 Readonly::Scalar my $EXPL     => [ 56 ];
24
25 #-----------------------------------------------------------------------------
26
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) }
32
33 #-----------------------------------------------------------------------------
34
35 sub violates {
36     my ( $self, $elem, undef ) = @_;
37
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 );
44     }
45     return;    #ok!
46 }
47
48 1;
49
50 __END__
51
52 #-----------------------------------------------------------------------------
53
54 =pod
55
56 =head1 NAME
57
58 Perl::Critic::Policy::ValuesAndExpressions::ProhibitEscapedCharacters - Write C<"\N{DELETE}"> instead of C<"\x7F">, etc.
59
60 =head1 AFFILIATION
61
62 This Policy is part of the core L<Perl::Critic> distribution.
63
64
65 =head1 DESCRIPTION
66
67 Escaped numeric values are hard to read and debug.  Instead, use named
68 values.  The syntax is less compact, but dramatically more readable.
69
70   $str = "\x7F\x06\x22Z";                         # not ok
71
72   use charnames ':full';
73   $str = "\N{DELETE}\N{ACKNOWLEDGE}\N{CANCEL}Z";  # ok
74
75
76 =head1 CONFIGURATION
77
78 This Policy is not configurable except for the standard options.
79
80
81 =head1 SEE ALSO
82
83
84 =head1 AUTHOR
85
86 Chris Dolan <cdolan@cpan.org>
87
88 =head1 COPYRIGHT
89
90 Copyright (c) 2006-2008 Chris Dolan.  All rights reserved.
91
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.
95
96 =cut
97
98 # Local Variables:
99 #   mode: cperl
100 #   cperl-indent-level: 4
101 #   fill-column: 78
102 #   indent-tabs-mode: nil
103 #   c-indentation-style: bsd
104 # End:
105 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :