« lib/Perl/Critic/Policy/InputOutput/ProhibitBacktickOperators.pm
↑ Summary
lib/Perl/Critic/Policy/ControlStructures/ProhibitYadaOperator.pm »
| 1 | package Perl::Critic::PolicyParameter::Behavior::Enumeration; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | use Perl::Critic::Exception::Fatal::PolicyDefinition | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 40 | ▶ | qw( throw_policy_definition ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use Perl::Critic::Utils qw( :characters words_from_string hashify ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 40 | ▶ | use parent qw{ Perl::Critic::PolicyParameter::Behavior }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 746 | ▶ | sub initialize_parameter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialize_parameter: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 746 | my (undef, $parameter, $specification) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | my $valid_values = $specification->{enumeration_values} | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 746 | ▶ | or throw_policy_definition | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 'No enumeration_values given for ' | ||||||||||||||||||||||||||||||||||||||||||
| 23 | . $parameter->get_name() | ||||||||||||||||||||||||||||||||||||||||||
| 24 | . $PERIOD; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 745 | ▶ | ref $valid_values eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | or throw_policy_definition | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 'The value given for enumeration_values for ' | ||||||||||||||||||||||||||||||||||||||||||
| 28 | . $parameter->get_name() | ||||||||||||||||||||||||||||||||||||||||||
| 29 | . ' is not an array reference.'; | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 744 | ▶ | scalar @{$valid_values} > 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | or throw_policy_definition | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 'There were not at least two valid values given for' | ||||||||||||||||||||||||||||||||||||||||||
| 33 | . ' enumeration_values for ' | ||||||||||||||||||||||||||||||||||||||||||
| 34 | . $parameter->get_name() | ||||||||||||||||||||||||||||||||||||||||||
| 35 | . $PERIOD; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | # Unfortunately, this has to be a reference, rather than a regular hash, | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # due to a problem in Devel::Cycle | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # (http://rt.cpan.org/Ticket/Display.html?id=25360) which causes | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # t/92_memory_leaks.t to fall over. | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 742 | my $value_lookup = { hashify( @{$valid_values} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 742 | $parameter->_get_behavior_values()->{enumeration_values} = $value_lookup; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | my $allow_multiple_values = | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 742 | $specification->{enumeration_allow_multiple_values}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 742 | ▶ | if ($allow_multiple_values) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | $parameter->_set_parser( | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 462 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Normally bad thing, obscuring a variable in an outer scope | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # with a variable with the same name is being done here in | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # order to remain consistent with the parser function interface. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 462 | my ($policy, $parameter, $config_string) = @_; ## no critic(Variables::ProhibitReusedNames) | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 462 | my @potential_values; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 462 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 462 | ▶ | if ( defined $value_string ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 461 | @potential_values = words_from_string($value_string); | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | my @bad_values = | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 461 | grep { not exists $value_lookup->{$_} } @potential_values; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 461 | ▶ | if (@bad_values) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | $policy->throw_parameter_value_exception( | ||||||||||||||||||||||||||||||||||||||||||
| 65 | $parameter->get_name(), | ||||||||||||||||||||||||||||||||||||||||||
| 66 | $value_string, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | q{contains invalid values: } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | . join (q{, }, @bad_values) | ||||||||||||||||||||||||||||||||||||||||||
| 70 | . q{. Allowed values are: } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | . join (q{, }, sort keys %{$value_lookup}) | |||||||||||||||||||||||||||||||||||||||||
| 72 | . qq{.\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 461 | my %actual_values = hashify(@potential_values); | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 461 | $policy->__set_parameter_value($parameter, \%actual_values); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 461 | return; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 462 | ); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | $parameter->_set_parser( | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 280 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | # Normally bad thing, obscuring a variable in an outer scope | ||||||||||||||||||||||||||||||||||||||||||
| 88 | # with a variable with the same name is being done here in | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # order to remain consistent with the parser function interface. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 280 | my ($policy, $parameter, $config_string) = @_; ## no critic(Variables::ProhibitReusedNames) | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 280 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 280 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $value_string and $Perl::Critic::PolicyParameter::Behavior::Enumeration::EMPTY ne $value_string and not defined $value_lookup->{$value_string}
defined $value_string and $Perl::Critic::PolicyParameter::Behavior::Enumeration::EMPTY ne $value_string
MC/DC100%3/3
defined $value_string and $Perl::Critic::PolicyParameter::Behavior::Enumeration::EMPTY ne $value_string and not defined $value_lookup->{$value_string}
defined $value_string
$Perl::Critic::PolicyParameter::Behavior::Enumeration::EMPTY ne $value_string
not defined $value_lookup->{$value_string}
Truth table100%4/4
A and B and not(C)
A= defined $value_stringB= $Perl::Critic::PolicyParameter::Behavior::Enumeration::EMPTY ne $value_stringC= not defined $value_lookup->{$value_string}
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | defined $value_string | ||||||||||||||||||||||||||||||||||||||||||
| 96 | and $EMPTY ne $value_string | ||||||||||||||||||||||||||||||||||||||||||
| 97 | and not defined $value_lookup->{$value_string} | ||||||||||||||||||||||||||||||||||||||||||
| 98 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | $policy->throw_parameter_value_exception( | ||||||||||||||||||||||||||||||||||||||||||
| 100 | $parameter->get_name(), | ||||||||||||||||||||||||||||||||||||||||||
| 101 | $value_string, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | undef, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | q{is not one of the allowed values: } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | . join (q{, }, sort keys %{$value_lookup}) | |||||||||||||||||||||||||||||||||||||||||
| 105 | . qq{.\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 278 | $policy->__set_parameter_value($parameter, $value_string); | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 278 | return; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 280 | ); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 742 | return; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 40 | ▶ | sub generate_parameter_description { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_parameter_description: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 40 | my (undef, $parameter) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 40 | my $description = $parameter->_get_description_with_trailing_period(); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 40 | ▶ | if ( $description ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 40 | $description .= qq{\n}; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 40 | my %values = %{$parameter->_get_behavior_values()->{enumeration_values}}; | |||||||||||||||||||||||||||||||||||||||||
| 130 | return | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 40 | $description | |||||||||||||||||||||||||||||||||||||||||
| 132 | . 'Valid values: ' | ||||||||||||||||||||||||||||||||||||||||||
| 133 | . join (', ', sort keys %values) | ||||||||||||||||||||||||||||||||||||||||||
| 134 | . $PERIOD; | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | __END__ | ||||||||||||||||||||||||||||||||||||||||||