summaryrefslogtreecommitdiff
path: root/lib/VNDB/Func.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-11-11 12:55:28 +0100
committerYorhel <git@yorhel.nl>2020-11-11 13:24:37 +0100
commit7b6fcdbb00522e739c2e792e205b2ce2bbeae1a7 (patch)
treea21be41f262c658c62450161996b7a211fa6cbc4 /lib/VNDB/Func.pm
parent237193921509027c0168933f5eed4ae2d73c508a (diff)
AdvSearch: Fix using encoded form on pagination + abstraction changes
I was originally planning to have only two query encoding forms: Fully normalized JSON form and compact encoded form. But converting between the two is kind of annoying and requires lookup tables, which makes the normalized JSON form inconvenient for Elm. Hence I added a third form: compact JSON form, which has the same data type transformations applied as the compact encoded form, but still retains the JSON encoding and structure. Converting between compact JSON form and compact encoded form is fairly trivial. Downside is that this also implies that Query handling in Elm needs to be done through field numbers rather than names, which is more error prone - but this can be solved by generating an Elm module with a variable for each field numer. Another downside is that this makes it impossible to implement a normalized-form query viewer and editor in Elm without hitting the server for conversions - but such a feature is not very important anyway. Other abstraction change is that AdvSearch.pm now exposes an object-oriented interface, the object can keep track of the different query forms and seems like a more suitable solution in this case.
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r--lib/VNDB/Func.pm3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 508b2272..accf3df7 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -309,11 +309,12 @@ sub form_compare {
}
-# Encode query parameters. Takes a hash or hashref with key/values, supports array values.
+# Encode query parameters. Takes a hash or hashref with key/values, supports array values and objects that implement query_encode().
sub query_encode {
my $o = @_ == 1 ? $_[0] : {@_};
return join '&', map {
my($k, $v) = ($_, $o->{$_});
+ $v = $v->query_encode() if ref $v && ref $v ne 'ARRAY';
!defined $v ? () : ref $v ? map "$k=".uri_escape($_), sort @$v : "$k=".uri_escape($v)
} sort keys %$o;
}