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 / RegularExpressions / RequireLineBoundaryMatching.pm
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) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities };
16 use Perl::Critic::Utils::PPIRegexp qw{ &get_modifiers };
17 use base 'Perl::Critic::Policy';
18
19 our $VERSION = '1.088';
20
21 #-----------------------------------------------------------------------------
22
23 Readonly::Scalar my $DESC => q{Regular expression without "/m" flag};
24 Readonly::Scalar my $EXPL => [ 237 ];
25
26 #-----------------------------------------------------------------------------
27
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) }
34
35 #-----------------------------------------------------------------------------
36
37 sub violates {
38     my ( $self, $elem, undef ) = @_;
39
40     my %mods = get_modifiers($elem);
41     if ( ! $mods{m} ) {
42         return $self->violation( $DESC, $EXPL, $elem );
43     }
44     return; #ok!;
45 }
46
47 1;
48
49 __END__
50
51 #-----------------------------------------------------------------------------
52
53 =pod
54
55 =head1 NAME
56
57 Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching - Always use the C</m> modifier with regular expressions.
58
59 =head1 AFFILIATION
60
61 This Policy is part of the core L<Perl::Critic> distribution.
62
63
64 =head1 DESCRIPTION
65
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.
70
71   my $match = m{ ^ $pattern $ }x;  #not ok
72   my $match = m{ ^ $pattern $ }xm; #ok
73
74
75 =head1 CONFIGURATION
76
77 This Policy is not configurable except for the standard options.
78
79
80 =head1 NOTES
81
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
88 flags.
89
90 =head1 AUTHOR
91
92 Jeffrey Ryan Thalhammer  <thaljef@cpan.org>
93
94 =head1 COPYRIGHT
95
96 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
97
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.
101
102 =cut
103
104 # Local Variables:
105 #   mode: cperl
106 #   cperl-indent-level: 4
107 #   fill-column: 78
108 #   indent-tabs-mode: nil
109 #   c-indentation-style: bsd
110 # End:
111 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :