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