blib/lib/Perl/Critic/PolicyParameter/Behavior/Integer.pm

filter: Statementstmt 94.2% 49 / 52 Branchbran 75.0% 12 / 16 Conditioncond 86.6% 13 / 15 MC/DCmcdc 80.0% 8 / 10 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 89.3% 92 / 103 CC 14 SCAR 18.4
CC
14
Cov
89%
__ANON__
9.0
generate_parameter_description
7.5
BEGIN
1.0
CRAP 6.3
« blib/lib/Perl/Critic/Policy/BuiltinFunctions/RequireBlockMap.pm ↑ Summary blib/lib/Perl/Critic/Policy/TestingAndDebugging/RequireUseWarnings.pm »
1 package Perl::Critic::PolicyParameter::Behavior::Integer;
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 Perl::Critic::Utils qw{ :characters };
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 40 ▶use parent qw{ Perl::Critic::PolicyParameter::Behavior };
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 40 our $VERSION = '1.150';
12  
13 #-----------------------------------------------------------------------------
14  
15 sub initialize_parameter {
16 1271 ▶ my ($self, $parameter, $specification) = @_;
Subroutine initialize_parameter: called CC=1 SCAR=0.0
Pod documented
17  
18 1271 my $minimum = $specification->{integer_minimum};
19 1271 my $maximum = $specification->{integer_maximum};
20  
21 1271 $parameter->_get_behavior_values()->{minimum} = $minimum;
22 1271 $parameter->_get_behavior_values()->{maximum} = $maximum;
23  
24 $parameter->_set_parser(
25 sub {
26 # Normally bad thing, obscuring a variable in an outer scope
27 # with a variable with the same name is being done here in
28 # order to remain consistent with the parser function interface.
29 1274 ▶ my ($policy, $parameter, $config_string) = @_; ## no critic(Variables::ProhibitReusedNames)
Subroutine __ANON__: called CC=9 SCAR=22.0
30  
31 1274 ▶ my $value_string = $config_string // $parameter->get_default_string();
Condition100%3/3
$config_string // $parameter->get_default_string
l!l&&r!l&&!r
481046180
MC/DC100%2/2
$config_string // $parameter->get_default_string
$config_string $parameter->get_default_string
Truth table100%3/3
A // B
A= $config_stringB= $parameter->get_default_string
ABresult
1X1
011
000
32  
33 1274 my $value;
34 1274 ▶ if ( defined $value_string ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value_string) 1273 1 1274
35 1273 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $value_string =~ / \A [-+]? [1-9] [\d_]* \z /msx and $value_string ne 0) 1 1272 1273
Condition100%3/3
not $value_string =~ / \A [-+]? [1-9] [\d_]* \z /msx and $value_string ne 0
!ll&&!rl&&r
10851871
MC/DC100%2/2
not $value_string =~ / \A [-+]? [1-9] [\d_]* \z /msx and $value_string ne 0
not $value_string =~ / \A [-+]? [1-9] [\d_]* \z /msx $value_string ne 0
Truth table100%3/3
not(A) and B
A= not $value_string =~ / \A [-+]? [1-9] [\d_]* \z /msxB= $value_string ne 0
ABresult
0X0
100
111
36 $value_string !~ m/ \A [-+]? [1-9] [\d_]* \z /xms
37 and $value_string ne '0'
38 ) {
39 1 $policy->throw_parameter_value_exception(
40 $parameter->get_name(),
41 $value_string,
42 undef,
43 'does not look like an integer.',
44 );
45 }
46  
47 1272 $value_string =~ tr/_//d;
48 1272 $value = $value_string + 0;
49  
50 1272 ▶ if ( defined $minimum and $minimum > $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $minimum and $minimum > $value) 2 1270 1272
Condition100%3/3
defined $minimum and $minimum > $value
!ll&&!rl&&r
1212582
MC/DC100%2/2
defined $minimum and $minimum > $value
defined $minimum $minimum > $value
Truth table100%3/3
A and B
A= defined $minimumB= $minimum > $value
ABresult
0X0
100
111
51 2 $policy->throw_parameter_value_exception(
52 $parameter->get_name(),
53 $value_string,
54 undef,
55 qq{is less than $minimum.},
56 );
57 }
58  
59 1270 ▶ if ( defined $maximum and $maximum < $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maximum and $maximum < $value) 2 1268 1270
Condition100%3/3
defined $maximum and $maximum < $value
!ll&&!rl&&r
126352
MC/DC100%2/2
defined $maximum and $maximum < $value
defined $maximum $maximum < $value
Truth table100%3/3
A and B
A= defined $maximumB= $maximum < $value
ABresult
0X0
100
111
60 2 $policy->throw_parameter_value_exception(
61 $parameter->get_name(),
62 $value_string,
63 undef,
64 qq{is greater than $maximum.},
65 );
66 }
67 }
68  
69 1269 $policy->__set_parameter_value($parameter, $value);
70 1269 return;
71 }
72 1271 );
73  
74 1271 return;
75 }
76  
77 #-----------------------------------------------------------------------------
78  
79 sub generate_parameter_description {
80 126 ▶ my ($self, $parameter) = @_;
Subroutine generate_parameter_description: called CC=6 SCAR=20.1
Pod documented
81  
82 126 my $minimum = $parameter->_get_behavior_values()->{minimum};
83 126 my $maximum = $parameter->_get_behavior_values()->{maximum};
84  
85 126 my $description = $parameter->_get_description_with_trailing_period();
86 126 ▶ if ( $description ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($description) 126 0 126
87 126 $description .= qq{\n};
88 }
89  
90 126 ▶ if (defined $minimum or defined $maximum) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $minimum or defined $maximum) { } 126 0 126
Condition33%1/3
defined $minimum or defined $maximum
l!l&&r!l&&!r
12600
MC/DC0%0/2
defined $minimum or defined $maximum
defined $minimum defined $maximum
Truth table33%1/3
A or B
A= defined $minimumB= defined $maximum
ABresult
1X1
011
000
91 126 ▶ if (defined $minimum) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $minimum) { } 126 0 126
92 126 $description .= "Minimum value $minimum. ";
93 } else {
94 0 $description .= 'No minimum. ';
95 }
96  
97 126 ▶ if (defined $maximum) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maximum) { } 0 126 126
98 0 $description .= "Maximum value $maximum.";
99 } else {
100 126 $description .= 'No maximum.';
101 }
102 } else {
103 0 $description .= 'No limits.';
104 }
105  
106 126 return $description;
107 }
108  
109 #-----------------------------------------------------------------------------
110  
111 40 1;
112  
113 __END__
114  
115 #-----------------------------------------------------------------------------
116  
117 =pod
118  
119 =for stopwords
120  
121 =head1 NAME
122  
123 Perl::Critic::PolicyParameter::Behavior::Integer - Actions appropriate for an integer parameter.
124  
125  
126 =head1 DESCRIPTION
127  
128 Provides a standard set of functionality for an integer
129 L<Perl::Critic::PolicyParameter|Perl::Critic::PolicyParameter> so that
130 the developer of a policy does not have to provide it her/himself.
131  
132 The parser provided by this behavior allows underscores ("_") in input
133 values as in a Perl numeric literal.
134  
135 NOTE: Do not instantiate this class. Use the singleton instance held
136 onto by
137 L<Perl::Critic::PolicyParameter|Perl::Critic::PolicyParameter>.
138  
139  
140 =head1 INTERFACE SUPPORT
141  
142 This is considered to be a non-public class. Its interface is subject
143 to change without notice.
144  
145  
146 =head1 METHODS
147  
148 =over
149  
150 =item C<initialize_parameter( $parameter, $specification )>
151  
152 Plug in the functionality this behavior provides into the parameter,
153 based upon the configuration provided by the specification.
154  
155 This behavior looks for two configuration items:
156  
157 =over
158  
159 =item integer_minimum
160  
161 Optional. The minimum acceptable value. Inclusive.
162  
163  
164 =item integer_maximum
165  
166 Optional. The maximum acceptable value. Inclusive.
167  
168  
169 =back
170  
171  
172 =item C<generate_parameter_description( $parameter )>
173  
174 Create a description of the parameter, based upon the description on
175 the parameter itself, but enhancing it with information from this
176 behavior.
177  
178 In this case, this means including the minimum and maximum values.
179  
180  
181 =back
182  
183  
184 =head1 AUTHOR
185  
186 Elliot Shank <perl@galumph.com>
187  
188  
189 =head1 COPYRIGHT
190  
191 Copyright (c) 2007-2011 Elliot Shank.
192  
193 This program is free software; you can redistribute it and/or modify
194 it under the same terms as Perl itself. The full text of this license
195 can be found in the LICENSE file included with this module.
196  
197 =cut
198  
199 # Local Variables:
200 # mode: cperl
201 # cperl-indent-level: 4
202 # fill-column: 78
203 # indent-tabs-mode: nil
204 # c-indentation-style: bsd
205 # End:
206 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
« blib/lib/Perl/Critic/Policy/BuiltinFunctions/RequireBlockMap.pm ↑ Summary blib/lib/Perl/Critic/Policy/TestingAndDebugging/RequireUseWarnings.pm »