blib/lib/Perl/Critic/PolicyConfig.pm

filter: Statementstmt 100% 83 / 83 Branchbran 81.2% 13 / 16 Conditioncond 75.0% 9 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 23 / 23 Podpod 92.3% 12 / 13 totaltotal 92.2% 142 / 154 CC 15 SCAR 10.9
CC
15
Cov
95%
handle_extra_parameters
7.4
is_maximum_violations_per_document_unlimited
4.0
new
4.0
CRAP 3.0
« blib/lib/Perl/Critic/Policy/Subroutines/ProhibitReturnSort.pm ↑ Summary blib/lib/Perl/Critic/Policy/Subroutines/ProhibitExplicitReturnUndef.pm »
1 package Perl::Critic::PolicyConfig;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 our $VERSION = '1.150';
10  
11 40 ▶use Perl::Critic::Exception::AggregateConfiguration;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 40 ▶use Perl::Critic::Exception::Configuration::Option::Policy::ParameterValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 40 ▶use Perl::Critic::Exception::Configuration::Option::Policy::ExtraParameter;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 40 ▶use Perl::Critic::Utils qw( :booleans :characters );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 40 ▶use Perl::Critic::Utils::Constants qw< :profile_strictness >;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 #-----------------------------------------------------------------------------
18  
19 40 Readonly::Scalar my $NON_PUBLIC_DATA => '_non_public_data';
20 40 Readonly::Scalar my $NO_LIMIT => 'no_limit';
21  
22 #-----------------------------------------------------------------------------
23  
24 sub new {
25 25756 ▶ my ($class, $policy_short_name, $specification) = @_;
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
26  
27 25756 ▶ my %self = $specification ? %{ $specification } : ();
Branch: 1 branch
BranchTrueFalseTotal
$specification ? : 25755 1 25756
28 25756 my %non_public_data;
29  
30 25756 $non_public_data{_policy_short_name} = $policy_short_name;
31 $non_public_data{_profile_strictness} =
32 25756 $self{$NON_PUBLIC_DATA}{_profile_strictness};
33  
34 25756 foreach my $standard_parameter (
35 qw< maximum_violations_per_document severity set_themes add_themes >
36 ) {
37 103024 ▶ if ( exists $self{$standard_parameter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self{$standard_parameter}) 1305 101719 103024
38 $non_public_data{"_$standard_parameter"} =
39 1305 delete $self{$standard_parameter};
40 }
41 }
42  
43 25756 $self{$NON_PUBLIC_DATA} = \%non_public_data;
44  
45  
46 25756 return bless \%self, $class;
47 }
48  
49 #-----------------------------------------------------------------------------
50  
51 sub _get_non_public_data {
52 50522 ▶ my $self = shift;
Subroutine _get_non_public_data: called CC=1 SCAR=0.0
53  
54 50522 return $self->{$NON_PUBLIC_DATA};
55 }
56  
57 #-----------------------------------------------------------------------------
58  
59 sub get_policy_short_name {
60 4 ▶ my $self = shift;
Subroutine get_policy_short_name: called CC=1 SCAR=0.0
Pod documented
61  
62 4 return $self->_get_non_public_data()->{_policy_short_name};
63 }
64  
65 #-----------------------------------------------------------------------------
66  
67 sub get_set_themes {
68 12628 ▶ my ($self) = @_;
Subroutine get_set_themes: called CC=1 SCAR=0.0
Pod documented
69  
70 12628 return $self->_get_non_public_data()->{_set_themes};
71 }
72  
73 #-----------------------------------------------------------------------------
74  
75 sub get_add_themes {
76 12628 ▶ my ($self) = @_;
Subroutine get_add_themes: called CC=1 SCAR=0.0
Pod documented
77  
78 12628 return $self->_get_non_public_data()->{_add_themes};
79 }
80  
81 #-----------------------------------------------------------------------------
82  
83 sub get_severity {
84 12629 ▶ my ($self) = @_;
Subroutine get_severity: called CC=1 SCAR=0.0
Pod documented
85  
86 12629 return $self->_get_non_public_data()->{_severity};
87 }
88  
89 #-----------------------------------------------------------------------------
90  
91 sub is_maximum_violations_per_document_unlimited {
92 12627 ▶ my ($self) = @_;
Subroutine is_maximum_violations_per_document_unlimited: called CC=4 SCAR=13.9
Pod documented
93  
94 12627 my $maximum_violations = $self->get_maximum_violations_per_document();
95 12627 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $maximum_violations or $maximum_violations eq $Perl::Critic::PolicyConfig::EMPTY or $maximum_violations =~ /\A $NO_LIMIT \z/imosx) 139 4 143
Condition83%5/6
not defined $maximum_violations or $maximum_violations eq $Perl::Critic::PolicyConfig::EMPTY or $maximum_violations =~ /\A $NO_LIMIT \z/imosx
l!l&&r!l&&!r
124841394
not defined $maximum_violations or $maximum_violations eq $Perl::Critic::PolicyConfig::EMPTY
l!l&&r!l&&!r
124840143
MC/DC66%2/3
not defined $maximum_violations or $maximum_violations eq $Perl::Critic::PolicyConfig::EMPTY or $maximum_violations =~ /\A $NO_LIMIT \z/imosx
not defined $maximum_violations $maximum_violations eq $Perl::Critic::PolicyConfig::EMPTY $maximum_violations =~ /\A $NO_LIMIT \z/imosx
Truth table75%3/4
not(A) or B or C
A= not defined $maximum_violationsB= $maximum_violations eq $Perl::Critic::PolicyConfig::EMPTYC= $maximum_violations =~ /\A $NO_LIMIT \z/imosx
ABCresult
1XX1
01X1
0011
0000
96 not defined $maximum_violations
97 or $maximum_violations eq $EMPTY
98 or $maximum_violations =~ m<\A $NO_LIMIT \z>xmsio
99 ) {
100 12623 return $TRUE;
101 }
102  
103 4 return $FALSE;
104 }
105  
106 #-----------------------------------------------------------------------------
107  
108 sub get_maximum_violations_per_document {
109 12633 ▶ my ($self) = @_;
Subroutine get_maximum_violations_per_document: called CC=1 SCAR=0.0
Pod documented
110  
111 12633 return $self->_get_non_public_data()->{_maximum_violations_per_document};
112 }
113  
114 #-----------------------------------------------------------------------------
115  
116 sub get {
117 11 ▶ my ($self, $parameter) = @_;
Subroutine get: called CC=2 SCAR=6.9
Pod documented
118  
119 11 ▶ return if $parameter eq $NON_PUBLIC_DATA;
Branch: 1 branch
BranchTrueFalseTotal
if $parameter eq $NON_PUBLIC_DATA 2 9 11
120  
121 9 return $self->{$parameter};
122 }
123  
124 #-----------------------------------------------------------------------------
125  
126 sub remove {
127 9710 ▶ my ($self, $parameter) = @_;
Subroutine remove: called CC=2 SCAR=7.0
Pod documented
128  
129 9710 ▶ return if $parameter eq $NON_PUBLIC_DATA;
Branch: 1 branch
BranchTrueFalseTotal
if $parameter eq $NON_PUBLIC_DATA 0 9710 9710
130  
131 9710 delete $self->{$parameter};
132  
133 9710 return;
134 }
135  
136 #-----------------------------------------------------------------------------
137  
138 sub is_empty {
139 3 ▶ my ($self) = @_;
Subroutine is_empty: called CC=1 SCAR=0.0
Pod documented
140  
141 3 return 1 >= keys %{$self};
142 }
143  
144 #-----------------------------------------------------------------------------
145  
146 sub get_parameter_names {
147 12922 ▶ my ($self) = @_;
Subroutine get_parameter_names: called CC=1 SCAR=0.0
Pod documented
148  
149 12922 return grep { $_ ne $NON_PUBLIC_DATA } keys %{$self};
150 }
151  
152 #-----------------------------------------------------------------------------
153  
154 sub handle_extra_parameters {
155 12919 ▶ my ($self, $policy, $errors) = @_;
Subroutine handle_extra_parameters: called CC=7 SCAR=20.0
Pod documented
156  
157 my $profile_strictness = $self->{$NON_PUBLIC_DATA}{_profile_strictness}
158 12919 ▶ // $PROFILE_STRICTNESS_DEFAULT;
Condition66%2/3
$self->{$NON_PUBLIC_DATA}{"_profile_strictness"} // $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_DEFAULT
l!l&&r!l&&!r
127731460
MC/DC0%0/2
$self->{$NON_PUBLIC_DATA}{"_profile_strictness"} // $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_DEFAULT
$self->{$NON_PUBLIC_DATA}{"_profile_strictness"} $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_DEFAULT
Truth table66%2/3
A // B
A= $self->{$NON_PUBLIC_DATA}{"_profile_strictness"}B= $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_DEFAULT
ABresult
1X1
011
000
159  
160 12919 ▶ return if $profile_strictness eq $PROFILE_STRICTNESS_QUIET;
Branch: 1 branch
BranchTrueFalseTotal
if $profile_strictness eq $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_QUIET 0 12919 12919
161  
162 12919 ▶ my $parameter_errors = $profile_strictness eq $PROFILE_STRICTNESS_WARN ?
Branch: 1 branch
BranchTrueFalseTotal
$profile_strictness eq $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_WARN ? : 12629 290 12919
163 Perl::Critic::Exception::AggregateConfiguration->new() : $errors;
164  
165 12919 foreach my $offered_param ( $self->get_parameter_names() ) {
166 145 $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 12919 ▶ warn qq<$parameter_errors\n>
Branch: 1 branch
BranchTrueFalseTotal
if $profile_strictness eq $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_WARN and $parameter_errors->has_exceptions 0 12919 12919
Condition66%2/3
$profile_strictness eq $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_WARN and $parameter_errors->has_exceptions
!ll&&!rl&&r
290126290
MC/DC0%0/2
$profile_strictness eq $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_WARN and $parameter_errors->has_exceptions
$profile_strictness eq $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_WARN $parameter_errors->has_exceptions
Truth table66%2/3
A and B
A= $profile_strictness eq $Perl::Critic::PolicyConfig::PROFILE_STRICTNESS_WARNB= $parameter_errors->has_exceptions
ABresult
0X0
100
111
176 if ($profile_strictness eq $PROFILE_STRICTNESS_WARN
177 && $parameter_errors->has_exceptions());
178  
179 12919 return;
180 }
181  
182 #-----------------------------------------------------------------------------
183  
184 sub set_profile_strictness {
185 12775 ▶ my ($self, $profile_strictness) = @_;
Subroutine set_profile_strictness: called CC=1 SCAR=0.0
Pod documented
186  
187 12775 $self->{$NON_PUBLIC_DATA}{_profile_strictness} = $profile_strictness;
188  
189 12775 return;
190 }
191  
192 #-----------------------------------------------------------------------------
193  
194 40 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 :
« blib/lib/Perl/Critic/Policy/Subroutines/ProhibitReturnSort.pm ↑ Summary blib/lib/Perl/Critic/Policy/Subroutines/ProhibitExplicitReturnUndef.pm »