| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::RegularExpressions::RequireBracesForMultiline; |
|
2
|
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
25907
|
use 5.010001; |
|
|
40
|
|
|
|
|
280
|
|
|
4
|
40
|
|
|
40
|
|
326
|
use strict; |
|
|
40
|
|
|
|
|
135
|
|
|
|
40
|
|
|
|
|
852
|
|
|
5
|
40
|
|
|
40
|
|
265
|
use warnings; |
|
|
40
|
|
|
|
|
165
|
|
|
|
40
|
|
|
|
|
992
|
|
|
6
|
40
|
|
|
40
|
|
242
|
use Readonly; |
|
|
40
|
|
|
|
|
141
|
|
|
|
40
|
|
|
|
|
1932
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
285
|
use English qw(-no_match_vars); |
|
|
40
|
|
|
|
|
126
|
|
|
|
40
|
|
|
|
|
278
|
|
|
9
|
40
|
|
|
40
|
|
14957
|
use Carp; |
|
|
40
|
|
|
|
|
173
|
|
|
|
40
|
|
|
|
|
2728
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
40
|
|
|
40
|
|
337
|
use Perl::Critic::Utils qw{ :booleans :severities }; |
|
|
40
|
|
|
|
|
124
|
|
|
|
40
|
|
|
|
|
1905
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
40
|
|
|
40
|
|
6808
|
use parent 'Perl::Critic::Policy'; |
|
|
40
|
|
|
|
|
122
|
|
|
|
40
|
|
|
|
|
263
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '1.148'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q<Use '{' and '}' to delimit multi-line regexps>; |
|
20
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => [242]; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Readonly::Array my @EXTRA_BRACKETS => qw{ () [] <> }; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub supported_parameters { |
|
27
|
|
|
|
|
|
|
return ( |
|
28
|
|
|
|
|
|
|
{ |
|
29
|
94
|
|
|
94
|
0
|
1934
|
name => 'allow_all_brackets', |
|
30
|
|
|
|
|
|
|
description => |
|
31
|
|
|
|
|
|
|
q[In addition to allowing '{}', allow '()', '[]', and '{}'.], |
|
32
|
|
|
|
|
|
|
behavior => 'boolean', |
|
33
|
|
|
|
|
|
|
}, |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
78
|
|
|
78
|
1
|
353
|
sub default_severity { return $SEVERITY_LOWEST } |
|
38
|
84
|
|
|
84
|
1
|
382
|
sub default_themes { return qw( core pbp cosmetic ) } |
|
39
|
34
|
|
|
34
|
1
|
158
|
sub applies_to { return qw(PPI::Token::Regexp::Match |
|
40
|
|
|
|
|
|
|
PPI::Token::Regexp::Substitute |
|
41
|
|
|
|
|
|
|
PPI::Token::QuoteLike::Regexp) } |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub initialize_if_enabled { |
|
46
|
51
|
|
|
51
|
1
|
220
|
my ( $self, $config ) = @_; |
|
47
|
|
|
|
|
|
|
|
|
48
|
51
|
|
|
|
|
228
|
my %delimiters = ( q<{}> => 1 ); |
|
49
|
51
|
100
|
|
|
|
267
|
if ( $self->{_allow_all_brackets} ) { |
|
50
|
1
|
|
|
|
|
12
|
@delimiters{ @EXTRA_BRACKETS } = (1) x @EXTRA_BRACKETS; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
51
|
|
|
|
|
221
|
$self->{_allowed_delimiters} = \%delimiters; |
|
54
|
|
|
|
|
|
|
|
|
55
|
51
|
|
|
|
|
227
|
return $TRUE; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub violates { |
|
61
|
24
|
|
|
24
|
1
|
48
|
my ( $self, $elem, undef ) = @_; |
|
62
|
|
|
|
|
|
|
|
|
63
|
24
|
|
|
|
|
84
|
my $re = $elem->get_match_string(); |
|
64
|
24
|
100
|
|
|
|
378
|
return if $re !~ m/\n/xms; |
|
65
|
|
|
|
|
|
|
|
|
66
|
20
|
|
|
|
|
58
|
my ($match_delim) = $elem->get_delimiters(); |
|
67
|
20
|
100
|
|
|
|
374
|
return if $self->{_allowed_delimiters}{$match_delim}; |
|
68
|
|
|
|
|
|
|
|
|
69
|
4
|
|
|
|
|
20
|
return $self->violation( $DESC, $EXPL, $elem ); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=pod |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Perl::Critic::Policy::RegularExpressions::RequireBracesForMultiline - Use C<{> and C<}> to delimit multi-line regexps. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AFFILIATION |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
|
88
|
|
|
|
|
|
|
distribution. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Long regular expressions are hard to read. A good practice is to use |
|
94
|
|
|
|
|
|
|
the C<x> modifier and break the regex into multiple lines with |
|
95
|
|
|
|
|
|
|
comments explaining the parts. But, with the usual C<//> delimiters, |
|
96
|
|
|
|
|
|
|
the beginning and end can be hard to match, especially in a C<s///> |
|
97
|
|
|
|
|
|
|
regexp. Instead, try using C<{}> characters to delimit your |
|
98
|
|
|
|
|
|
|
expressions. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Compare these: |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
s/ |
|
103
|
|
|
|
|
|
|
<a \s+ href="([^"]+)"> |
|
104
|
|
|
|
|
|
|
(.*?) |
|
105
|
|
|
|
|
|
|
</a> |
|
106
|
|
|
|
|
|
|
/link=$1, text=$2/xms; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
vs. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
s{ |
|
111
|
|
|
|
|
|
|
<a \s+ href="([^"]+)"> |
|
112
|
|
|
|
|
|
|
(.*?) |
|
113
|
|
|
|
|
|
|
</a> |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
{link=$1, text=$2}xms; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Is that an improvement? Marginally, but yes. The curly braces lead |
|
118
|
|
|
|
|
|
|
the eye better. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
There is one option for this policy, C<allow_all_brackets>. If this |
|
124
|
|
|
|
|
|
|
is true, then, in addition to allowing C<{}>, the other matched pairs |
|
125
|
|
|
|
|
|
|
of C<()>, C<[]>, and C<< <> >> are allowed. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 CREDITS |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Initial development of this policy was supported by a grant from the |
|
131
|
|
|
|
|
|
|
Perl Foundation. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Chris Dolan <cdolan@cpan.org> |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Copyright (c) 2007-2011 Chris Dolan. Many rights reserved. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
144
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
|
145
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Local Variables: |
|
150
|
|
|
|
|
|
|
# mode: cperl |
|
151
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
|
152
|
|
|
|
|
|
|
# fill-column: 78 |
|
153
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
|
154
|
|
|
|
|
|
|
# c-indentation-style: bsd |
|
155
|
|
|
|
|
|
|
# End: |
|
156
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |