| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::ToPerl6::TransformerParameter::Behavior::Enumeration; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14
|
use 5.006001; |
|
|
1
|
|
|
|
|
3
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
19
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
26
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Perl::ToPerl6::Exception::Fatal::TransformerDefinition |
|
8
|
1
|
|
|
1
|
|
6
|
qw{ &throw_transformer_definition }; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
84
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Perl::ToPerl6::Utils qw{ :characters &words_from_string &hashify }; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
45
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
217
|
use base qw{ Perl::ToPerl6::TransformerParameter::Behavior }; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
609
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub initialize_parameter { |
|
16
|
0
|
|
|
0
|
1
|
|
my ($self, $parameter, $specification) = @_; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $valid_values = $specification->{enumeration_values} |
|
19
|
0
|
0
|
|
|
|
|
or throw_transformer_definition( |
|
20
|
|
|
|
|
|
|
'No enumeration_values given for ' |
|
21
|
|
|
|
|
|
|
. $parameter->get_name() |
|
22
|
|
|
|
|
|
|
. $PERIOD); |
|
23
|
0
|
0
|
|
|
|
|
ref $valid_values eq 'ARRAY' |
|
24
|
|
|
|
|
|
|
or throw_transformer_definition( |
|
25
|
|
|
|
|
|
|
'The value given for enumeration_values for ' |
|
26
|
|
|
|
|
|
|
. $parameter->get_name() |
|
27
|
|
|
|
|
|
|
. ' is not an array reference.'); |
|
28
|
0
|
0
|
|
|
|
|
scalar @{$valid_values} > 1 |
|
|
0
|
|
|
|
|
|
|
|
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
|
0
|
|
|
|
|
|
my $value_lookup = { hashify( @{$valid_values} ) }; |
|
|
0
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$parameter->_get_behavior_values()->{enumeration_values} = $value_lookup; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $allow_multiple_values = |
|
43
|
0
|
|
|
|
|
|
$specification->{enumeration_allow_multiple_values}; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ($allow_multiple_values) { |
|
46
|
|
|
|
|
|
|
$parameter->_set_parser( |
|
47
|
|
|
|
|
|
|
sub { |
|
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
|
0
|
|
|
0
|
|
|
my ($transformer, $parameter, $config_string) = @_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my @potential_values; |
|
54
|
0
|
|
|
|
|
|
my $value_string = $parameter->get_default_string(); |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if (defined $config_string) { |
|
57
|
0
|
|
|
|
|
|
$value_string = $config_string; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if ( defined $value_string ) { |
|
61
|
0
|
|
|
|
|
|
@potential_values = words_from_string($value_string); |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my @bad_values = |
|
64
|
0
|
|
|
|
|
|
grep { not exists $value_lookup->{$_} } @potential_values; |
|
|
0
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if (@bad_values) { |
|
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
|
0
|
|
|
|
|
|
. join (q{, }, sort keys %{$value_lookup}) |
|
|
0
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
. qq{.\n}, |
|
75
|
|
|
|
|
|
|
); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my %actual_values = hashify(@potential_values); |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$transformer->__set_parameter_value($parameter, \%actual_values); |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
|
); |
|
86
|
|
|
|
|
|
|
} else { |
|
87
|
|
|
|
|
|
|
$parameter->_set_parser( |
|
88
|
|
|
|
|
|
|
sub { |
|
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
|
0
|
|
|
0
|
|
|
my ($transformer, $parameter, $config_string) = @_; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $value_string = $parameter->get_default_string(); |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
if (defined $config_string) { |
|
97
|
0
|
|
|
|
|
|
$value_string = $config_string; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
0
|
0
|
|
|
|
if ( |
|
|
|
|
0
|
|
|
|
|
|
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
|
0
|
|
|
|
|
|
. join (q{, }, sort keys %{$value_lookup}) |
|
|
0
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
. qq{.\n}, |
|
112
|
|
|
|
|
|
|
); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
$transformer->__set_parameter_value($parameter, $value_string); |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
0
|
|
|
|
|
|
); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
return; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub generate_parameter_description { |
|
128
|
0
|
|
|
0
|
1
|
|
my ($self, $parameter) = @_; |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my $description = $parameter->_get_description_with_trailing_period(); |
|
131
|
0
|
0
|
|
|
|
|
if ( $description ) { |
|
132
|
0
|
|
|
|
|
|
$description .= qq{\n}; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my %values = %{$parameter->_get_behavior_values()->{enumeration_values}}; |
|
|
0
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
return |
|
137
|
0
|
|
|
|
|
|
$description |
|
138
|
|
|
|
|
|
|
. 'Valid values: ' |
|
139
|
|
|
|
|
|
|
. join (', ', sort keys %values) |
|
140
|
|
|
|
|
|
|
. $PERIOD; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=pod |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=for stopwords |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 NAME |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Perl::ToPerl6::TransformerParameter::Behavior::Enumeration - Actions appropriate for an enumerated value. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Provides a standard set of functionality for an enumerated |
|
163
|
|
|
|
|
|
|
L<Perl::ToPerl6::TransformerParameter|Perl::ToPerl6::TransformerParameter> so that |
|
164
|
|
|
|
|
|
|
the developer of a transformer does not have to provide it her/himself. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
NOTE: Do not instantiate this class. Use the singleton instance held |
|
167
|
|
|
|
|
|
|
onto by |
|
168
|
|
|
|
|
|
|
L<Perl::ToPerl6::TransformerParameter|Perl::ToPerl6::TransformerParameter>. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 INTERFACE SUPPORT |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This is considered to be a non-public class. Its interface is subject |
|
174
|
|
|
|
|
|
|
to change without notice. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 METHODS |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=over |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item C<initialize_parameter( $parameter, $specification )> |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Plug in the functionality this behavior provides into the parameter, |
|
184
|
|
|
|
|
|
|
based upon the configuration provided by the specification. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This behavior looks for two configuration items: |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=over |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item enumeration_values |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Mandatory. The set of valid values for the parameter, as an array |
|
193
|
|
|
|
|
|
|
reference. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item enumeration_allow_multiple_values |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Optional, defaults to false. Should the parameter support a single |
|
199
|
|
|
|
|
|
|
value or accept multiple? |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=back |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item C<generate_parameter_description( $parameter )> |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Create a description of the parameter, based upon the description on |
|
208
|
|
|
|
|
|
|
the parameter itself, but enhancing it with information from this |
|
209
|
|
|
|
|
|
|
behavior. |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
In this specific case, the universe of values is added at the end. |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=back |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head1 AUTHOR |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Elliot Shank <perl@galumph.com> |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Copyright (c) 2006-2011 Elliot Shank. |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
227
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
|
228
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module. |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# Local Variables: |
|
233
|
|
|
|
|
|
|
# mode: cperl |
|
234
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
|
235
|
|
|
|
|
|
|
# fill-column: 78 |
|
236
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
|
237
|
|
|
|
|
|
|
# c-indentation-style: bsd |
|
238
|
|
|
|
|
|
|
# End: |
|
239
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |