summaryrefslogtreecommitdiff
path: root/lib/VNDB/Func.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r--lib/VNDB/Func.pm28
1 files changed, 1 insertions, 27 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 40af8e73..02489980 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -11,7 +11,7 @@ use VNDBUtil;
our @EXPORT = (@VNDBUtil::EXPORT, qw|
clearfloat cssicon tagscore mt minage fil_parse fil_serialize parenttags
childtags charspoil imgpath imgurl fmtvote
- json_encode json_decode script_json json_validate
+ json_encode json_decode script_json
mtvoiced mtani mtvnlen mtrlstat mtvnlstat mtbloodt
|);
@@ -228,32 +228,6 @@ sub script_json {
}
-# Special validation function for simple JSON structures as form fields. It can
-# only validate arrays of key-value objects. The key-value objects are then
-# validated using kv_validate.
-# Returns the parsed json object on success, undef on error and sets $frm->{_err}.
-# Doesn't provide a user-friendly error message if validation fails. It's the
-# responsibility of the JS code to handle the interface with the user.
-sub json_validate {
- my($frm, $name, @fields) = @_;
- my $data = eval { json_decode $frm->{$name} };
- goto error if $@ || ref $data ne 'ARRAY';
- my %known_fields = map +($_->{field},1), @fields;
- for my $i (0..$#$data) {
- goto error if ref $data->[$i] ne 'HASH';
- # Require that all keys are known and have a scalar value.
- goto error if grep !$known_fields{$_} || ref($data->[$i]{$_}), keys %{$data->[$i]};
- $data->[$i] = kv_validate({ field => sub { $data->[$i]{shift()} } }, $TUWF::OBJ->{_TUWF}{validate_templates}, \@fields);
- goto error if $data->[$i]{_err};
- }
-
- return $data;
-error:
- push @{$frm->{_err}}, [ 'aliases', 'template', 'json' ] ;
- return undef;
-}
-
-
# mt() wrappers for data-dependent translation strings that have a special
# value for 'unknown'.
sub mtvoiced { !$_[0] ? mt '_unknown' : mt '_voiced_'.$_[0]; }