Login
Corrected references to the Regexp::Common module.
[gknop/Perl-Critic.git] / lib / Perl / Critic / Policy / RegularExpressions / RequireLineBoundaryMatching.pm
CommitLineData
6036a254 1##############################################################################
dff08b70
JRT
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6036a254 6##############################################################################
dff08b70 7
59b05e08
JRT
8package Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching;
9
df6dee2b 10use 5.006001;
59b05e08
JRT
11use strict;
12use warnings;
c680a9c9
ES
13use Readonly;
14
bbf4108c 15use Perl::Critic::Utils qw{ :severities };
8b5a642f 16use Perl::Critic::Utils::PPIRegexp qw{ &get_modifiers };
59b05e08
JRT
17use base 'Perl::Critic::Policy';
18
fb1c69dd 19our $VERSION = '1.093_02';
59b05e08 20
6036a254 21#-----------------------------------------------------------------------------
7e86d49a 22
c680a9c9
ES
23Readonly::Scalar my $DESC => q{Regular expression without "/m" flag};
24Readonly::Scalar my $EXPL => [ 237 ];
59b05e08 25
6036a254 26#-----------------------------------------------------------------------------
59b05e08 27
c680a9c9
ES
28sub supported_parameters { return () }
29sub default_severity { return $SEVERITY_LOW }
30sub default_themes { return qw(core pbp cosmetic) }
31sub applies_to { return qw(PPI::Token::Regexp::Match
8b5a642f
CD
32 PPI::Token::Regexp::Substitute
33 PPI::Token::QuoteLike::Regexp) }
7e86d49a 34
6036a254 35#-----------------------------------------------------------------------------
bf159007 36
59b05e08 37sub violates {
e5f6c18d 38 my ( $self, $elem, undef ) = @_;
59b05e08 39
8b5a642f
CD
40 my %mods = get_modifiers($elem);
41 if ( ! $mods{m} ) {
c680a9c9 42 return $self->violation( $DESC, $EXPL, $elem );
59b05e08
JRT
43 }
44 return; #ok!;
45}
46
471;
48
49__END__
50
6036a254 51#-----------------------------------------------------------------------------
7e86d49a 52
59b05e08
JRT
53=pod
54
55=head1 NAME
56
2bd06403 57Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching - Always use the C</m> modifier with regular expressions.
59b05e08 58
11f53956 59
af93c316
ES
60=head1 AFFILIATION
61
11f53956
ES
62This Policy is part of the core L<Perl::Critic|Perl::Critic>
63distribution.
af93c316
ES
64
65
59b05e08
JRT
66=head1 DESCRIPTION
67
68Folks coming from a C<sed> or C<awk> background tend to assume that
69C<'$'> and C<'^'> match the beginning and and of the line, rather than
70then beginning and ed of the string. Adding the '/m' flag to your
71regex makes it behave as most people expect it should.
72
11f53956
ES
73 my $match = m{ ^ $pattern $ }x; #not ok
74 my $match = m{ ^ $pattern $ }xm; #ok
59b05e08 75
0cb729f0
ES
76
77=head1 CONFIGURATION
78
49860482 79This Policy is not configurable except for the standard options.
0cb729f0
ES
80
81
59b05e08
JRT
82=head1 NOTES
83
821d0eb5 84For common regular expressions like e-mail addresses, phone numbers,
50ee0dae 85dates, etc., have a look at the L<Regexp::Common|Regexp::Common> module.
11f53956 86Also, be cautions about slapping modifier flags onto existing regular
59b05e08
JRT
87expressions, as they can drastically alter their meaning. See
88L<http://www.perlmonks.org/?node_id=484238> for an interesting
89discussion on the effects of blindly modifying regular expression
90flags.
91
11f53956 92
59b05e08
JRT
93=head1 AUTHOR
94
95Jeffrey Ryan Thalhammer <thaljef@cpan.org>
96
11f53956 97
59b05e08
JRT
98=head1 COPYRIGHT
99
20dfddeb 100Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
59b05e08
JRT
101
102This program is free software; you can redistribute it and/or modify
103it under the same terms as Perl itself. The full text of this license
104can be found in the LICENSE file included with this module.
105
106=cut
737d3b65
CD
107
108# Local Variables:
109# mode: cperl
110# cperl-indent-level: 4
111# fill-column: 78
112# indent-tabs-mode: nil
113# c-indentation-style: bsd
114# End:
96fed375 115# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :