line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::PolicyConfig; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
1333
|
use 5.010001; |
|
40
|
|
|
|
|
146
|
|
4
|
40
|
|
|
40
|
|
264
|
use strict; |
|
40
|
|
|
|
|
91
|
|
|
40
|
|
|
|
|
851
|
|
5
|
40
|
|
|
40
|
|
196
|
use warnings; |
|
40
|
|
|
|
|
79
|
|
|
40
|
|
|
|
|
978
|
|
6
|
|
|
|
|
|
|
|
7
|
40
|
|
|
40
|
|
702
|
use Readonly; |
|
40
|
|
|
|
|
4316
|
|
|
40
|
|
|
|
|
2607
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.150'; |
10
|
|
|
|
|
|
|
|
11
|
40
|
|
|
40
|
|
4325
|
use Perl::Critic::Exception::AggregateConfiguration; |
|
40
|
|
|
|
|
117
|
|
|
40
|
|
|
|
|
1882
|
|
12
|
40
|
|
|
40
|
|
16468
|
use Perl::Critic::Exception::Configuration::Option::Policy::ParameterValue; |
|
40
|
|
|
|
|
117
|
|
|
40
|
|
|
|
|
2007
|
|
13
|
40
|
|
|
40
|
|
15144
|
use Perl::Critic::Exception::Configuration::Option::Policy::ExtraParameter; |
|
40
|
|
|
|
|
133
|
|
|
40
|
|
|
|
|
2003
|
|
14
|
40
|
|
|
40
|
|
293
|
use Perl::Critic::Utils qw( :booleans :characters ); |
|
40
|
|
|
|
|
82
|
|
|
40
|
|
|
|
|
1881
|
|
15
|
40
|
|
|
40
|
|
23304
|
use Perl::Critic::Utils::Constants qw< :profile_strictness >; |
|
40
|
|
|
|
|
113
|
|
|
40
|
|
|
|
|
39042
|
|
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
|
25466
|
|
|
25466
|
0
|
51459
|
my ($class, $policy_short_name, $specification) = @_; |
26
|
|
|
|
|
|
|
|
27
|
25466
|
100
|
|
|
|
47529
|
my %self = $specification ? %{ $specification } : (); |
|
25465
|
|
|
|
|
62017
|
|
28
|
25466
|
|
|
|
|
38557
|
my %non_public_data; |
29
|
|
|
|
|
|
|
|
30
|
25466
|
|
|
|
|
47757
|
$non_public_data{_policy_short_name} = $policy_short_name; |
31
|
|
|
|
|
|
|
$non_public_data{_profile_strictness} = |
32
|
25466
|
|
|
|
|
58525
|
$self{$NON_PUBLIC_DATA}{_profile_strictness}; |
33
|
|
|
|
|
|
|
|
34
|
25466
|
|
|
|
|
44042
|
foreach my $standard_parameter ( |
35
|
|
|
|
|
|
|
qw< maximum_violations_per_document severity set_themes add_themes > |
36
|
|
|
|
|
|
|
) { |
37
|
101864
|
100
|
|
|
|
187866
|
if ( exists $self{$standard_parameter} ) { |
38
|
|
|
|
|
|
|
$non_public_data{"_$standard_parameter"} = |
39
|
1305
|
|
|
|
|
4158
|
delete $self{$standard_parameter}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
25466
|
|
|
|
|
48735
|
$self{$NON_PUBLIC_DATA} = \%non_public_data; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
25466
|
|
|
|
|
72673
|
return bless \%self, $class; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _get_non_public_data { |
52
|
49942
|
|
|
49942
|
|
66014
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
49942
|
|
|
|
|
104050
|
return $self->{$NON_PUBLIC_DATA}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub get_policy_short_name { |
60
|
4
|
|
|
4
|
1
|
1632
|
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
|
12483
|
|
|
12483
|
1
|
19472
|
my ($self) = @_; |
69
|
|
|
|
|
|
|
|
70
|
12483
|
|
|
|
|
21677
|
return $self->_get_non_public_data()->{_set_themes}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get_add_themes { |
76
|
12483
|
|
|
12483
|
1
|
21866
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
|
78
|
12483
|
|
|
|
|
19445
|
return $self->_get_non_public_data()->{_add_themes}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub get_severity { |
84
|
12484
|
|
|
12484
|
1
|
19344
|
my ($self) = @_; |
85
|
|
|
|
|
|
|
|
86
|
12484
|
|
|
|
|
20581
|
return $self->_get_non_public_data()->{_severity}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub is_maximum_violations_per_document_unlimited { |
92
|
12482
|
|
|
12482
|
1
|
20408
|
my ($self) = @_; |
93
|
|
|
|
|
|
|
|
94
|
12482
|
|
|
|
|
22560
|
my $maximum_violations = $self->get_maximum_violations_per_document(); |
95
|
12482
|
100
|
66
|
|
|
37609
|
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
|
12478
|
|
|
|
|
40465
|
return $TRUE; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
4
|
|
|
|
|
24
|
return $FALSE; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub get_maximum_violations_per_document { |
109
|
12488
|
|
|
12488
|
1
|
19816
|
my ($self) = @_; |
110
|
|
|
|
|
|
|
|
111
|
12488
|
|
|
|
|
25103
|
return $self->_get_non_public_data()->{_maximum_violations_per_document}; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub get { |
117
|
11
|
|
|
11
|
1
|
3027
|
my ($self, $parameter) = @_; |
118
|
|
|
|
|
|
|
|
119
|
11
|
100
|
|
|
|
40
|
return if $parameter eq $NON_PUBLIC_DATA; |
120
|
|
|
|
|
|
|
|
121
|
9
|
|
|
|
|
40
|
return $self->{$parameter}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub remove { |
127
|
9605
|
|
|
9605
|
1
|
17138
|
my ($self, $parameter) = @_; |
128
|
|
|
|
|
|
|
|
129
|
9605
|
50
|
|
|
|
20495
|
return if $parameter eq $NON_PUBLIC_DATA; |
130
|
|
|
|
|
|
|
|
131
|
9605
|
|
|
|
|
15580
|
delete $self->{$parameter}; |
132
|
|
|
|
|
|
|
|
133
|
9605
|
|
|
|
|
21132
|
return; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub is_empty { |
139
|
3
|
|
|
3
|
1
|
10
|
my ($self) = @_; |
140
|
|
|
|
|
|
|
|
141
|
3
|
|
|
|
|
6
|
return 1 >= keys %{$self}; |
|
3
|
|
|
|
|
20
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub get_parameter_names { |
147
|
12777
|
|
|
12777
|
1
|
24294
|
my ($self) = @_; |
148
|
|
|
|
|
|
|
|
149
|
12777
|
|
|
|
|
19836
|
return grep { $_ ne $NON_PUBLIC_DATA } keys %{$self}; |
|
12923
|
|
|
|
|
49938
|
|
|
12777
|
|
|
|
|
35108
|
|
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub handle_extra_parameters { |
155
|
12774
|
|
|
12774
|
1
|
25625
|
my ($self, $policy, $errors) = @_; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $profile_strictness = $self->{$NON_PUBLIC_DATA}{_profile_strictness} |
158
|
12774
|
|
66
|
|
|
40360
|
// $PROFILE_STRICTNESS_DEFAULT; |
159
|
|
|
|
|
|
|
|
160
|
12774
|
50
|
|
|
|
28141
|
return if $profile_strictness eq $PROFILE_STRICTNESS_QUIET; |
161
|
|
|
|
|
|
|
|
162
|
12774
|
100
|
|
|
|
41394
|
my $parameter_errors = $profile_strictness eq $PROFILE_STRICTNESS_WARN ? |
163
|
|
|
|
|
|
|
Perl::Critic::Exception::AggregateConfiguration->new() : $errors; |
164
|
|
|
|
|
|
|
|
165
|
12774
|
|
|
|
|
12502021
|
foreach my $offered_param ( $self->get_parameter_names() ) { |
166
|
145
|
|
|
|
|
469
|
$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
|
12774
|
50
|
66
|
|
|
54857
|
warn qq<$parameter_errors\n> |
176
|
|
|
|
|
|
|
if ($profile_strictness eq $PROFILE_STRICTNESS_WARN |
177
|
|
|
|
|
|
|
&& $parameter_errors->has_exceptions()); |
178
|
|
|
|
|
|
|
|
179
|
12774
|
|
|
|
|
368057
|
return; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub set_profile_strictness { |
185
|
12630
|
|
|
12630
|
1
|
25053
|
my ($self, $profile_strictness) = @_; |
186
|
|
|
|
|
|
|
|
187
|
12630
|
|
|
|
|
25363
|
$self->{$NON_PUBLIC_DATA}{_profile_strictness} = $profile_strictness; |
188
|
|
|
|
|
|
|
|
189
|
12630
|
|
|
|
|
24048
|
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-2023 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 : |