« lib/Perl/Critic/Policy/BuiltinFunctions/RequireBlockMap.pm
↑ Summary
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.156'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1271 | ▶ | sub initialize_parameter { | ||||||||||||||||||||||||||
|
Subroutine
initialize_parameter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 1271 | my (undef, $parameter, $specification) = @_; | |||||||||||||||||||||||||||
| 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 | 1274 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 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) | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1274 | ▶ | my $value_string = $config_string // $parameter->get_default_string(); | ||||||||||||||||||||||||||
|
Condition100%3/3
$config_string // $parameter->get_default_string
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
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1274 | my $value; | |||||||||||||||||||||||||||
| 34 | 1274 | ▶ | if ( defined $value_string ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 1273 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $value_string =~ / \A [-+]? [1-9] [\d_]* \z /msx and $value_string ne 0
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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $minimum and $minimum > $value
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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $maximum and $maximum < $value
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
| |||||||||||||||||||||||||||||
| 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 | 70 | ▶ | sub generate_parameter_description { | ||||||||||||||||||||||||||
|
Subroutine
generate_parameter_description: called CC=6 SCAR=20.1
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 70 | my (undef, $parameter) = @_; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 70 | my $minimum = $parameter->_get_behavior_values()->{minimum}; | |||||||||||||||||||||||||||
| 83 | 70 | my $maximum = $parameter->_get_behavior_values()->{maximum}; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 70 | my $description = $parameter->_get_description_with_trailing_period(); | |||||||||||||||||||||||||||
| 86 | 70 | ▶ | if ( $description ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 70 | $description .= qq{\n}; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 70 | ▶ | if (defined $minimum or defined $maximum) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $minimum or defined $maximum
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
| |||||||||||||||||||||||||||||
| 91 | 70 | ▶ | if (defined $minimum) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 70 | $description .= "Minimum value $minimum. "; | |||||||||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||||||||||
| 94 | 0 | $description .= 'No minimum. '; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 70 | ▶ | if (defined $maximum) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | $description .= "Maximum value $maximum."; | |||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||
| 100 | 70 | $description .= 'No maximum.'; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||
| 103 | 0 | $description .= 'No limits.'; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 70 | return $description; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 40 | 1; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||