GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Kwalify(3) User Contributed Perl Documentation Kwalify(3)

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 <https://web.archive.org/web/20190718083758/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:

The name of the schema.
The description for the rule. It is not used for validation.
A pattern matching the valid values.

Perl regular expressions are used for patterns. This may or may not be compatible with other Kwalify validators, so restrict to "simple" regular expression constructs to be compatible with other validators.

A list of the valid values.
A hash with the valid value ranges for types other than seq, map, bool and any.
The maximum inclusive.
The minimum inclusive.
The maximum exclusive.
The minimum exclusive.
Like range but for str and text.
A constraint to denote the value is required when true. The default is false.
The default type if omitted is str.
Any defined value which is not a number. Most probably you will want to use text instead of str.
A possibly signed integer. Note that scientific notation is not supported, and it is also not clear whether it should be supported.
A possibly signed floating value with a mandatory decimal point. Note that scientific notation is also not supported here.
A possibly signed floating value with an optional decimal point (so either int or float). Note that scientific notation is also not supported here.
Any defined value which is either a str or a number.
The values yes, true, and 1 for true values and the values no, false, and 0 for false values are allowed. The ruby implementation possibly allows more values, but this is not documented.

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]
    
A string matching "/^\d{4}-\d{2}-\d{2}$/" (i.e. YYYY-MM-DD). Note that no date range checks are done (yet).
A string matching "/^\d{2}:\d{2}:\d{2}$/" (i.e. HH:MM:SS). Note that no time range checks are done (yet).
Not supported --- it is not clear what this is supposed to be.
A sequence (list) of rules.
A mapping (hash) of rules.

The name "=" can be used to apply rules to any key.

Currently the same as text, but it's not clear if this is correct. Originally defined as all but seq and map.
Any data type.
The value is unique for a seq or a map.
Currently not supported by the Perl implementation.
Previously defined what is now class, see <https://web.archive.org/web/20190718083758/http://www.kuwata-lab.com/kwalify/ruby/users-guide.01.html>.
Currently not used, as there's no genclass action.
Currently not used, as there's no genclass action.

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/>

2024-07-21 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.