Created
November 25, 2019 18:48
-
-
Save jef-sure/496e1242548a1226e05b9308cb8d4eb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use JSON; | |
use JSV::Compiler; | |
use v5.10; | |
my $s = JSV::Compiler->new; | |
$s->load_schema({minimum => 4}); | |
my $code = $s->compile(coercion => 1, input_symbole => "\$iv"); | |
my $tsub = <<EOS; | |
sub { | |
my \$iv=\$_[0]; | |
my \$errors; | |
$code; | |
die \"\@{[\@\$errors]}\" if \$errors; | |
\$iv; | |
} | |
EOS | |
my $test = eval $tsub; | |
say encode_json({result => "ok", value => $test->("5")}); | |
say "not ok" if $test->(3); | |
__END__ | |
{"value":5,"result":"ok"} | |
must be not less than 4 at (eval 49) line 11. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment