line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
27246
|
use 5.010001; |
|
40
|
|
|
|
|
196
|
|
4
|
40
|
|
|
40
|
|
284
|
use strict; |
|
40
|
|
|
|
|
115
|
|
|
40
|
|
|
|
|
856
|
|
5
|
40
|
|
|
40
|
|
222
|
use warnings; |
|
40
|
|
|
|
|
125
|
|
|
40
|
|
|
|
|
963
|
|
6
|
40
|
|
|
40
|
|
262
|
use Readonly; |
|
40
|
|
|
|
|
127
|
|
|
40
|
|
|
|
|
2189
|
|
7
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
330
|
use Perl::Critic::Utils qw{ :severities }; |
|
40
|
|
|
|
|
139
|
|
|
40
|
|
|
|
|
2065
|
|
9
|
|
|
|
|
|
|
|
10
|
40
|
|
|
40
|
|
5501
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
155
|
|
|
40
|
|
|
|
|
263
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '1.146'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{Regular expression without "/m" flag}; |
17
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => [ 237 ]; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
20
|
|
|
|
|
|
|
|
21
|
96
|
|
|
96
|
0
|
1690
|
sub supported_parameters { return () } |
22
|
93
|
|
|
93
|
1
|
417
|
sub default_severity { return $SEVERITY_LOW } |
23
|
84
|
|
|
84
|
1
|
340
|
sub default_themes { return qw(core pbp cosmetic) } |
24
|
37
|
|
|
37
|
1
|
143
|
sub applies_to { return qw(PPI::Token::Regexp::Match |
25
|
|
|
|
|
|
|
PPI::Token::Regexp::Substitute |
26
|
|
|
|
|
|
|
PPI::Token::QuoteLike::Regexp) } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub violates { |
31
|
38
|
|
|
38
|
1
|
93
|
my ( $self, $elem, $doc ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
38
|
50
|
|
|
|
117
|
my $re = $doc->ppix_regexp_from_element( $elem ) |
34
|
|
|
|
|
|
|
or return; |
35
|
38
|
100
|
|
|
|
165625
|
$re->modifier_asserted( 'm' ) |
36
|
|
|
|
|
|
|
or return $self->violation( $DESC, $EXPL, $elem ); |
37
|
|
|
|
|
|
|
|
38
|
19
|
|
|
|
|
465
|
return; #ok!; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=pod |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Perl::Critic::Policy::RegularExpressions::RequireLineBoundaryMatching - Always use the C</m> modifier with regular expressions. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 AFFILIATION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
57
|
|
|
|
|
|
|
distribution. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Folks coming from a C<sed> or C<awk> background tend to assume that |
63
|
|
|
|
|
|
|
C<'$'> and C<'^'> match the beginning and end of the line, rather than |
64
|
|
|
|
|
|
|
then beginning and end of the string. Adding the '/m' flag to your |
65
|
|
|
|
|
|
|
regex makes it behave as most people expect it should. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $match = m{ ^ $pattern $ }x; #not ok |
68
|
|
|
|
|
|
|
my $match = m{ ^ $pattern $ }xm; #ok |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 CONFIGURATION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NOTES |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
For common regular expressions like e-mail addresses, phone numbers, |
79
|
|
|
|
|
|
|
dates, etc., have a look at the L<Regexp::Common|Regexp::Common> module. |
80
|
|
|
|
|
|
|
Also, be cautions about slapping modifier flags onto existing regular |
81
|
|
|
|
|
|
|
expressions, as they can drastically alter their meaning. See |
82
|
|
|
|
|
|
|
L<http://www.perlmonks.org/?node_id=484238> for an interesting |
83
|
|
|
|
|
|
|
discussion on the effects of blindly modifying regular expression |
84
|
|
|
|
|
|
|
flags. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 COPYRIGHT |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
97
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
98
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Local Variables: |
103
|
|
|
|
|
|
|
# mode: cperl |
104
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
105
|
|
|
|
|
|
|
# fill-column: 78 |
106
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
107
|
|
|
|
|
|
|
# c-indentation-style: bsd |
108
|
|
|
|
|
|
|
# End: |
109
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |