1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/RegularExpressions/RequireExtendedFormatting.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::RegularExpressions::RequireExtendedFormatting;
15 use Perl::Critic::Utils qw{ :severities };
16 use Perl::Critic::Utils::PPIRegexp qw{ &get_modifiers };
17 use base 'Perl::Critic::Policy';
19 our $VERSION = '1.088';
21 #-----------------------------------------------------------------------------
23 Readonly::Scalar my $DESC => q{Regular expression without "/x" flag};
24 Readonly::Scalar my $EXPL => [ 236 ];
26 #-----------------------------------------------------------------------------
28 sub supported_parameters { return () }
29 sub default_severity { return $SEVERITY_MEDIUM }
30 sub default_themes { return qw(core pbp maintenance) }
31 sub applies_to { return qw(PPI::Token::Regexp::Match
32 PPI::Token::Regexp::Substitute
33 PPI::Token::QuoteLike::Regexp) }
35 #-----------------------------------------------------------------------------
38 my ( $self, $elem, undef ) = @_;
40 my %mods = get_modifiers($elem);
42 return $self->violation( $DESC, $EXPL, $elem );
51 #-----------------------------------------------------------------------------
57 Perl::Critic::Policy::RegularExpressions::RequireExtendedFormatting - Always use the C</x> modifier with regular expressions.
61 This Policy is part of the core L<Perl::Critic> distribution.
66 Extended regular expression formatting allows you mix whitespace and
67 comments into the pattern, thus making them much more readable.
69 # Match a single-quoted string efficiently...
71 m{'[^\\']*(?:\\.[^\\']*)*'}; #Huh?
73 #Same thing with extended format...
75 m{ ' #an opening single quote
76 [^\\'] #any non-special chars (i.e. not backslash or single quote)
78 \\ . # any explicitly backslashed char
79 [^\\']* # followed by an non-special chars
80 )* #...repeated zero or more times
81 ' # a closing single quote
87 This Policy is not configurable except for the standard options.
92 For common regular expressions like e-mail addresses, phone numbers,
93 dates, etc., have a look at the L<Regex::Common> module. Also, be
94 cautions about slapping modifier flags onto existing regular
95 expressions, as they can drastically alter their meaning. See
96 L<http://www.perlmonks.org/?node_id=484238> for an interesting
97 discussion on the effects of blindly modifying regular expression
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 :