1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/RegularExpressions/RequireLineBoundaryMatching.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching;
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 "/m" flag};
24 Readonly::Scalar my $EXPL => [ 237 ];
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::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::RequireLineBoundaryMatching - Always use the C</m> modifier with regular expressions.
61 This Policy is part of the core L<Perl::Critic> distribution.
66 Folks coming from a C<sed> or C<awk> background tend to assume that
67 C<'$'> and C<'^'> match the beginning and and of the line, rather than
68 then beginning and ed of the string. Adding the '/m' flag to your
69 regex makes it behave as most people expect it should.
71 my $match = m{ ^ $pattern $ }x; #not ok
72 my $match = m{ ^ $pattern $ }xm; #ok
77 This Policy is not configurable except for the standard options.
82 For common regular expressions like e-mail addresses, phone numbers,
83 dates, etc., have a look at the L<Regex::Common> module. Also, be
84 cautions about slapping modifier flags onto existing regular
85 expressions, as they can drastically alter their meaning. See
86 L<http://www.perlmonks.org/?node_id=484238> for an interesting
87 discussion on the effects of blindly modifying regular expression
92 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
96 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
98 This program is free software; you can redistribute it and/or modify
99 it under the same terms as Perl itself. The full text of this license
100 can be found in the LICENSE file included with this module.
106 # cperl-indent-level: 4
108 # indent-tabs-mode: nil
109 # c-indentation-style: bsd
111 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :