Giter Site home page Giter Site logo

thaischema's Introduction

NAME

ThaiSchema - Lightweight schema validator

SYNOPSIS

use ThaiSchema;

match_schema({x => 3}, {x => type_int});

DESCRIPTION

ThaiSchema is a lightweight schema validator.

FUNCTIONS

  • type_int()

    Is it a int value?

  • type_str()

    Is it a str value?

  • type_maybe($child)

    Is it maybe a $child value?

  • type_hash(\%schema)

      type_hash(
          {
              x => type_str,
              y => type_int,
          }
      );
    

    Is it a hash contains valid keys?

  • type_array()

      type_array(
          type_hash({
              x => type_str,
              y => type_int,
          })
      );
    
  • type_bool()

    Is it a boolean value?

    This function allows only JSON::true, JSON::false, \1, and \0.

OPTIONS

  • $STRICT

    You can check a type more strictly.

    This option is useful for checking JSON types.

  • $ALLOW_EXTRA

    You can allow extra key in hashref.

AUTHOR

Tokuhiro Matsuno [email protected]

SEE ALSO

LICENSE

Copyright (C) Tokuhiro Matsuno

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

thaischema's People

Contributors

tokuhirom avatar neilb avatar

Stargazers

Patrick Cho avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

neilb

thaischema's Issues

type_maybe + type_hash doesn't work

use strict;
use warnings;
use utf8;

use Test::More;
use ThaiSchema::JSON;
use ThaiSchema;

my $json = q/{"prop": {"subprop": 1}}/;
my $null_json = q/{"prop": null}/;

my $schema = +{
    prop => type_maybe(type_hash(+{
        subprop => type_int
    }))
};

my $j = ThaiSchema::JSON->new();

{
    # This test will pass.
    my ($ok, $errors) = $j->validate($null_json, $schema);
    ok($ok);
    diag($_) for @$errors;
}

{
    # This test case will fail.
    # at ThaiSchema.t line 32.
    # Can't locate object method "schema" via package "ThaiSchema::Maybe"
    #   at /Library/Perl/5.18/ThaiSchema/JSON.pm line 190.
    # でこける。
    my ($ok, $errors) = $j->validate($json, $schema);
    ok($ok);
    diag($_) for @$errors;
}
done_testing;

Minimal Perl version is wrong

ThaiSchema.pm uses "package block syntax" such as ThaiSchema::Array.
But minimal Perl version of this package is 5.10.
"package block syntax" is introduced Perl 5.14.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.