Kwalify(3pm) | User Contributed Perl Documentation | Kwalify(3pm) |
Kwalify - Kwalify schema for data structures
use Kwalify qw(validate); validate($schema, $data);
Typically used together with YAML or JSON:
use YAML; validate(YAML::LoadFile($schema_file), YAML::LoadFile($data_file)); use JSON; validate(decode_json($schema_data), decode_json($data));
Kwalify is a Perl implementation for validating data structures against the Kwalify schema. For a schema definition, see <http://www.kuwata-lab.com/kwalify/ruby/users-guide.01.html>, but see also below "SCHEMA DEFINITION".
Validate $data according to Kwalify schema specified in $schema_data. Dies if the validation fails.
validate may be exported.
The original schema definition document is not very specific about types and behaviour. Here's how Kwalify.pm implements things:
Note that this definition is problematic, because for example the string no is a true boolean value in Perl. So one should stick to 0 and 1 as data values, and probably define an additional pattern or enum to ensure this:
type: bool enum: [0, 1]
As Kwalify.pm is a pure validator and de-coupled from a parser (in fact, it does not need to deal with YAML at all, but just with pure perl data structures), there's no connection to the original validated document. This means that no line numbers are available to the validator. In case of validation errors the validator is only able to show a path-like expression to the data causing the error.
Slaven Rezić, <srezic@cpan.org>
Copyright (C) 2006,2007,2008,2009,2010,2015 by Slaven Rezić
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
pkwalify, kwalify(1).
Other non-XML schema languages: <http://rx.codesimply.com/>
2022-11-11 | perl v5.36.0 |