1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ValuesAndExpressions/RequireInterpolationOfMetachars.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars;
15 use Perl::Critic::Utils qw{ :severities };
16 use base 'Perl::Critic::Policy';
18 #-----------------------------------------------------------------------------
20 our $VERSION = '1.088';
22 #-----------------------------------------------------------------------------
24 Readonly::Scalar my $DESC => q{String *may* require interpolation};
25 Readonly::Scalar my $EXPL => [ 51 ];
27 #-----------------------------------------------------------------------------
29 sub supported_parameters { return () }
30 sub default_severity { return $SEVERITY_LOWEST }
31 sub default_themes { return qw(core pbp cosmetic) }
32 sub applies_to { return qw(PPI::Token::Quote::Single
33 PPI::Token::Quote::Literal) }
35 #-----------------------------------------------------------------------------
38 my ( $self, $elem, undef ) = @_;
39 # The string() method strips off the quotes
40 return if not _needs_interpolation( $elem->string() );
41 return if _looks_like_email_address( $elem->string() );
42 return $self->violation( $DESC, $EXPL, $elem );
45 #-----------------------------------------------------------------------------
47 sub _needs_interpolation {
49 return $string =~ m{ [\$\@] \S+ }mxo #Contains a $ or @
50 || $string =~ m{ \\[tnrfae0xcNLuLUEQ] }mxo; #Contains metachars
53 #-----------------------------------------------------------------------------
55 sub _looks_like_email_address {
57 return $string =~ m{\A [^\@\s]+ \@ [\w\-.]+ \z}mxo;
64 #-----------------------------------------------------------------------------
70 Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars - Warns that you might have used single quotes when you really wanted double-quotes.
74 This Policy is part of the core L<Perl::Critic> distribution.
79 This policy warns you if you use single-quotes or C<q//> with a string
80 that has unescaped metacharacters that may need interpolation. Its hard
81 to know for sure if a string really should be interpolated without
82 looking into the symbol table. This policy just makes an educated
83 guess by looking for metacharacters and sigils which usually indicate that
84 the string should be interpolated.
89 This Policy is not configurable except for the standard options.
94 Perl's own C<warnings> pragma also warns you about this.
98 L<Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals>
102 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
106 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
108 This program is free software; you can redistribute it and/or modify
109 it under the same terms as Perl itself. The full text of this license
110 can be found in the LICENSE file included with this module.
116 # cperl-indent-level: 4
118 # indent-tabs-mode: nil
119 # c-indentation-style: bsd
121 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :