line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::PolicyConfig; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
1285
|
use 5.010001; |
|
40
|
|
|
|
|
159
|
|
4
|
40
|
|
|
40
|
|
230
|
use strict; |
|
40
|
|
|
|
|
312
|
|
|
40
|
|
|
|
|
859
|
|
5
|
40
|
|
|
40
|
|
229
|
use warnings; |
|
40
|
|
|
|
|
90
|
|
|
40
|
|
|
|
|
1201
|
|
6
|
|
|
|
|
|
|
|
7
|
40
|
|
|
40
|
|
1229
|
use Readonly; |
|
40
|
|
|
|
|
4113
|
|
|
40
|
|
|
|
|
3192
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.148'; |
10
|
|
|
|
|
|
|
|
11
|
40
|
|
|
40
|
|
4124
|
use Perl::Critic::Exception::AggregateConfiguration; |
|
40
|
|
|
|
|
97
|
|
|
40
|
|
|
|
|
1690
|
|
12
|
40
|
|
|
40
|
|
16739
|
use Perl::Critic::Exception::Configuration::Option::Policy::ParameterValue; |
|
40
|
|
|
|
|
117
|
|
|
40
|
|
|
|
|
2024
|
|
13
|
40
|
|
|
40
|
|
15388
|
use Perl::Critic::Exception::Configuration::Option::Policy::ExtraParameter; |
|
40
|
|
|
|
|
110
|
|
|
40
|
|
|
|
|
2104
|
|
14
|
40
|
|
|
40
|
|
302
|
use Perl::Critic::Utils qw< :booleans :characters severity_to_number >; |
|
40
|
|
|
|
|
89
|
|
|
40
|
|
|
|
|
1967
|
|
15
|
40
|
|
|
40
|
|
23508
|
use Perl::Critic::Utils::Constants qw< :profile_strictness >; |
|
40
|
|
|
|
|
162
|
|
|
40
|
|
|
|
|
40847
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Readonly::Scalar my $NON_PUBLIC_DATA => '_non_public_data'; |
20
|
|
|
|
|
|
|
Readonly::Scalar my $NO_LIMIT => 'no_limit'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
30750
|
|
|
30750
|
0
|
68850
|
my ($class, $policy_short_name, $specification) = @_; |
26
|
|
|
|
|
|
|
|
27
|
30750
|
100
|
|
|
|
58981
|
my %self = $specification ? %{ $specification } : (); |
|
30749
|
|
|
|
|
86576
|
|
28
|
30750
|
|
|
|
|
52598
|
my %non_public_data; |
29
|
|
|
|
|
|
|
|
30
|
30750
|
|
|
|
|
62768
|
$non_public_data{_policy_short_name} = $policy_short_name; |
31
|
|
|
|
|
|
|
$non_public_data{_profile_strictness} = |
32
|
30750
|
|
|
|
|
75826
|
$self{$NON_PUBLIC_DATA}{_profile_strictness}; |
33
|
|
|
|
|
|
|
|
34
|
30750
|
|
|
|
|
56340
|
foreach my $standard_parameter ( |
35
|
|
|
|
|
|
|
qw< maximum_violations_per_document severity set_themes add_themes > |
36
|
|
|
|
|
|
|
) { |
37
|
123000
|
100
|
|
|
|
244755
|
if ( exists $self{$standard_parameter} ) { |
38
|
|
|
|
|
|
|
$non_public_data{"_$standard_parameter"} = |
39
|
1307
|
|
|
|
|
4120
|
delete $self{$standard_parameter}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
30750
|
|
|
|
|
64209
|
$self{$NON_PUBLIC_DATA} = \%non_public_data; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
30750
|
|
|
|
|
94796
|
return bless \%self, $class; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _get_non_public_data { |
52
|
60504
|
|
|
60504
|
|
86087
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
60504
|
|
|
|
|
136292
|
return $self->{$NON_PUBLIC_DATA}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub get_policy_short_name { |
60
|
4
|
|
|
4
|
1
|
1659
|
my $self = shift; |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
13
|
return $self->_get_non_public_data()->{_policy_short_name}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub get_set_themes { |
68
|
15123
|
|
|
15123
|
1
|
26067
|
my ($self) = @_; |
69
|
|
|
|
|
|
|
|
70
|
15123
|
|
|
|
|
27070
|
return $self->_get_non_public_data()->{_set_themes}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get_add_themes { |
76
|
15123
|
|
|
15123
|
1
|
25840
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
|
78
|
15123
|
|
|
|
|
26295
|
return $self->_get_non_public_data()->{_add_themes}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub get_severity { |
84
|
15124
|
|
|
15124
|
1
|
25913
|
my ($self) = @_; |
85
|
|
|
|
|
|
|
|
86
|
15124
|
|
|
|
|
27171
|
return $self->_get_non_public_data()->{_severity}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub is_maximum_violations_per_document_unlimited { |
92
|
15122
|
|
|
15122
|
1
|
27555
|
my ($self) = @_; |
93
|
|
|
|
|
|
|
|
94
|
15122
|
|
|
|
|
33162
|
my $maximum_violations = $self->get_maximum_violations_per_document(); |
95
|
15122
|
100
|
66
|
|
|
49966
|
if ( |
|
|
|
100
|
|
|
|
|
96
|
|
|
|
|
|
|
not defined $maximum_violations |
97
|
|
|
|
|
|
|
or $maximum_violations eq $EMPTY |
98
|
|
|
|
|
|
|
or $maximum_violations =~ m<\A $NO_LIMIT \z>xmsio |
99
|
|
|
|
|
|
|
) { |
100
|
15116
|
|
|
|
|
52894
|
return $TRUE; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
6
|
|
|
|
|
31
|
return $FALSE; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub get_maximum_violations_per_document { |
109
|
15130
|
|
|
15130
|
1
|
26790
|
my ($self) = @_; |
110
|
|
|
|
|
|
|
|
111
|
15130
|
|
|
|
|
33721
|
return $self->_get_non_public_data()->{_maximum_violations_per_document}; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub get { |
117
|
11
|
|
|
11
|
1
|
2901
|
my ($self, $parameter) = @_; |
118
|
|
|
|
|
|
|
|
119
|
11
|
100
|
|
|
|
51
|
return if $parameter eq $NON_PUBLIC_DATA; |
120
|
|
|
|
|
|
|
|
121
|
9
|
|
|
|
|
43
|
return $self->{$parameter}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub remove { |
127
|
28901
|
|
|
28901
|
1
|
53417
|
my ($self, $parameter) = @_; |
128
|
|
|
|
|
|
|
|
129
|
28901
|
50
|
|
|
|
60851
|
return if $parameter eq $NON_PUBLIC_DATA; |
130
|
|
|
|
|
|
|
|
131
|
28901
|
|
|
|
|
47147
|
delete $self->{$parameter}; |
132
|
|
|
|
|
|
|
|
133
|
28901
|
|
|
|
|
63051
|
return; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub is_empty { |
139
|
3
|
|
|
3
|
1
|
11
|
my ($self) = @_; |
140
|
|
|
|
|
|
|
|
141
|
3
|
|
|
|
|
7
|
return 1 >= keys %{$self}; |
|
3
|
|
|
|
|
19
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub get_parameter_names { |
147
|
15419
|
|
|
15419
|
1
|
32272
|
my ($self) = @_; |
148
|
|
|
|
|
|
|
|
149
|
15419
|
|
|
|
|
24832
|
return grep { $_ ne $NON_PUBLIC_DATA } keys %{$self}; |
|
15565
|
|
|
|
|
67751
|
|
|
15419
|
|
|
|
|
46314
|
|
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub handle_extra_parameters { |
155
|
15416
|
|
|
15416
|
1
|
34115
|
my ($self, $policy, $errors) = @_; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $profile_strictness = $self->{$NON_PUBLIC_DATA}{_profile_strictness} |
158
|
15416
|
|
66
|
|
|
51990
|
// $PROFILE_STRICTNESS_DEFAULT; |
159
|
|
|
|
|
|
|
|
160
|
15416
|
50
|
|
|
|
38531
|
return if $profile_strictness eq $PROFILE_STRICTNESS_QUIET; |
161
|
|
|
|
|
|
|
|
162
|
15416
|
100
|
|
|
|
55607
|
my $parameter_errors = $profile_strictness eq $PROFILE_STRICTNESS_WARN ? |
163
|
|
|
|
|
|
|
Perl::Critic::Exception::AggregateConfiguration->new() : $errors; |
164
|
|
|
|
|
|
|
|
165
|
15416
|
|
|
|
|
16100652
|
foreach my $offered_param ( $self->get_parameter_names() ) { |
166
|
145
|
|
|
|
|
452
|
$parameter_errors->add_exception( |
167
|
|
|
|
|
|
|
Perl::Critic::Exception::Configuration::Option::Policy::ExtraParameter->new( |
168
|
|
|
|
|
|
|
policy => $policy->get_short_name(), |
169
|
|
|
|
|
|
|
option_name => $offered_param, |
170
|
|
|
|
|
|
|
source => undef, |
171
|
|
|
|
|
|
|
) |
172
|
|
|
|
|
|
|
); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
15416
|
50
|
66
|
|
|
68307
|
warn qq<$parameter_errors\n> |
176
|
|
|
|
|
|
|
if ($profile_strictness eq $PROFILE_STRICTNESS_WARN |
177
|
|
|
|
|
|
|
&& $parameter_errors->has_exceptions()); |
178
|
|
|
|
|
|
|
|
179
|
15416
|
|
|
|
|
476357
|
return; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub set_profile_strictness { |
185
|
15272
|
|
|
15272
|
1
|
32479
|
my ($self, $profile_strictness) = @_; |
186
|
|
|
|
|
|
|
|
187
|
15272
|
|
|
|
|
32072
|
$self->{$NON_PUBLIC_DATA}{_profile_strictness} = $profile_strictness; |
188
|
|
|
|
|
|
|
|
189
|
15272
|
|
|
|
|
30908
|
return; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
__END__ |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=pod |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=for stopwords |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 NAME |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Perl::Critic::PolicyConfig - Configuration data for a Policy. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 DESCRIPTION |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
A container for the configuration of a Policy. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 INTERFACE SUPPORT |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
This is considered to be a non-public class. Its interface is subject |
218
|
|
|
|
|
|
|
to change without notice. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 METHODS |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=over |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item C<get_policy_short_name()> |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
The name of the policy this configuration is for. Primarily here for |
228
|
|
|
|
|
|
|
the sake of debugging. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item C< get_set_themes() > |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
The value of C<set_themes> in the user's F<.perlcriticrc>. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item C< get_add_themes() > |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
The value of C<add_themes> in the user's F<.perlcriticrc>. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item C< get_severity() > |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
The value of C<severity> in the user's F<.perlcriticrc>. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item C< is_maximum_violations_per_document_unlimited() > |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Answer whether the value of C<maximum_violations_per_document> should |
249
|
|
|
|
|
|
|
be considered to be unlimited. |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item C< get_maximum_violations_per_document() > |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
The value of C<maximum_violations_per_document> in the user's |
255
|
|
|
|
|
|
|
F<.perlcriticrc>. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item C< get($parameter) > |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Retrieve the value of the specified parameter in the user's |
261
|
|
|
|
|
|
|
F<.perlcriticrc>. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=item C< remove($parameter) > |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Delete the value of the specified parameter. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=item C< is_empty() > |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Answer whether there is any non-standard configuration information |
272
|
|
|
|
|
|
|
left. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item C< get_parameter_names() > |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Retrieve the names of the parameters in this object. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=item C< set_profile_strictness($profile_strictness) > |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
Sets the profile strictness associated with the configuration. |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item C< handle_extra_parameters($policy,$errors) > |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
Deals with any extra parameters according to the profile_strictness |
288
|
|
|
|
|
|
|
setting. To be called by Perl::Critic::Policy->new() once all valid |
289
|
|
|
|
|
|
|
policies have been processed and removed from the configuration. |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
If profile_strictness is $PROFILE_STRICTNESS_QUIET, extra policy |
292
|
|
|
|
|
|
|
parameters are ignored. |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
If profile_strictness is $PROFILE_STRICTNESS_WARN, extra policy |
295
|
|
|
|
|
|
|
parameters generate a warning. |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
If profile_strictness is $PROFILE_STRICTNESS_FATAL, extra policy |
298
|
|
|
|
|
|
|
parameters generate a fatal error. |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
If no profile_strictness was set, the behavior is that specified by |
301
|
|
|
|
|
|
|
$PROFILE_STRICTNESS_DEFAULT. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=back |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head1 SEE ALSO |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
L<Perl::Critic::DEVELOPER/"MAKING YOUR POLICY CONFIGURABLE"> |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=head1 AUTHOR |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
Elliot Shank <perl@galumph.com> |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=head1 COPYRIGHT |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
Copyright (c) 2008-2011 Elliot Shank. |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
322
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
323
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module. |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=cut |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
# Local Variables: |
328
|
|
|
|
|
|
|
# mode: cperl |
329
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
330
|
|
|
|
|
|
|
# fill-column: 78 |
331
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
332
|
|
|
|
|
|
|
# c-indentation-style: bsd |
333
|
|
|
|
|
|
|
# End: |
334
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |