@@ -18,6 +18,8 @@ use YATT::Lite::MFields
18
18
dir_config_cache
19
19
_site_config_is_examined
20
20
21
+ _sigil_type_item
22
+
21
23
current_user
22
24
/ );
23
25
use YATT::Lite::Util qw( globref url_encode nonempty empty rootname lexpand) ;
@@ -139,6 +141,114 @@ sub multi_param {
139
141
}
140
142
}
141
143
144
+ # ========================================
145
+
146
+ sub sigil_type_item {
147
+ my PROP $prop = (my $glob = shift )-> prop;
148
+
149
+ @{$prop -> {_sigil_type_item } // []};
150
+ }
151
+
152
+ sub collect_request_sigil_by {
153
+ my ($glob , $cutter , @list ) = @_ ;
154
+ my %dict ;
155
+ foreach my $name (grep {defined } @list ) {
156
+ my ($sigil , $word ) = $name =~ / ^([~!])(\1 |\w *)$ /
157
+ or next ;
158
+ defined (my $value = $cutter -> ($name ))
159
+ or next ;
160
+ push @{$dict {$sigil }}, do {
161
+ if ($sigil eq $word ) {
162
+ $value ;
163
+ } else {
164
+ $word ;
165
+ }
166
+ };
167
+ };
168
+ \%dict ;
169
+ }
170
+
171
+ sub parse_request_sigil_psgi {
172
+ my PROP $prop = (my $glob = shift )-> prop;
173
+ my ($req ) = @_ ;
174
+
175
+
176
+ my Env $env = $prop -> {cf_env };
177
+
178
+ $prop -> {_sigil_type_item } = do {
179
+ if ($env -> {CONTENT_TYPE } and defined $env -> {CONTENT_LENGTH }) {
180
+ my @bodyParams = $glob -> extract_sigil_from_hmv($req -> body_parameters);
181
+ my @queryParams = $glob -> extract_sigil_from_hmv($req -> query_parameters);
182
+ if (@bodyParams ) {
183
+ \@bodyParams
184
+ } else {
185
+ \@queryParams
186
+ }
187
+ } else {
188
+ [$glob -> extract_sigil_from_hmv($req -> parameters)];
189
+ }
190
+ };
191
+ }
192
+
193
+ sub extract_sigil_from_hmv {
194
+ my ($glob , $hmv ) = @_ ;
195
+
196
+ my $sigilsDict = $glob -> collect_request_sigil_by(
197
+ sub {
198
+ my $value = $hmv -> {$_ [0]};
199
+ $hmv -> remove($_ [0]);
200
+ $value ;
201
+ }, $hmv -> keys );
202
+ $glob -> validate_request_sigils_dict($sigilsDict );
203
+ }
204
+
205
+ sub parse_request_sigil_cgi {
206
+ my PROP $prop = (my $glob = shift )-> prop;
207
+ my ($cgi ) = @_ ;
208
+ my $sigilsDict = $glob -> collect_request_sigil_by(
209
+ sub {
210
+ my $value = $cgi -> param($_ [0]);
211
+ $cgi -> delete ($_ [0]);
212
+ $value ;
213
+ }, $cgi -> param());
214
+ $prop -> {_sigil_type_item }
215
+ = [$glob -> validate_request_sigils_dict($sigilsDict )];
216
+ }
217
+
218
+ sub validate_request_sigils_dict {
219
+ my PROP $prop = (my $glob = shift )-> prop;
220
+ my ($sigilsDict ) = @_ ;
221
+
222
+ my ($subpage , $action );
223
+ if (my $names = $sigilsDict -> {' ~' }) {
224
+ if (@$names >= 2) {
225
+ $glob -> error(" Multiple subpage sigils in request!: %s "
226
+ , join (" , " , @$names ));
227
+ }
228
+ $subpage = $names -> [0];
229
+ }
230
+ if (my $names = $sigilsDict -> {' !' }) {
231
+ if (@$names >= 2) {
232
+ $glob -> error(" Multiple action sigils in request!: %s "
233
+ , join (" , " , @$names ));
234
+ }
235
+ $action = $names -> [0];
236
+ }
237
+ if (defined $subpage and defined $action ) {
238
+ # XXX: Reserved for future use.
239
+ $glob -> error(" Can't use subpage and action at one time: %s vs %s "
240
+ , $subpage , $action );
241
+ } elsif (defined $subpage ) {
242
+ (page => $subpage );
243
+ } elsif (defined $action ) {
244
+ (action => $action );
245
+ } else {
246
+ ();
247
+ }
248
+ }
249
+
250
+ # ========================================
251
+
142
252
sub queryobj {
143
253
my PROP $prop = (my $glob = shift )-> prop;
144
254
$prop -> {cf_parameters } || $prop -> {cf_hmv } || $prop -> {cf_cgi };
@@ -191,6 +301,16 @@ sub configure_cgi {
191
301
$prop -> {cf_cgi } = my $cgi = shift ;
192
302
return unless $glob -> is_form_content_type($cgi -> content_type);
193
303
return if $prop -> {cf_parameters };
304
+
305
+ #
306
+ # parse_request_sigil should be called before parse_nested_query.
307
+ #
308
+ if ($prop -> {cf_is_psgi }) {
309
+ $glob -> parse_request_sigil_psgi($cgi );
310
+ } else {
311
+ $glob -> parse_request_sigil_cgi($cgi );
312
+ }
313
+
194
314
unless ($prop -> {cf_no_nested_query }) {
195
315
if ($prop -> {cf_is_psgi }) {
196
316
$glob -> convert_array_param_psgi($cgi );
0 commit comments