Skip to content

Instantly share code, notes, and snippets.

@jef-sure
Created November 25, 2019 18:48
Show Gist options
  • Save jef-sure/496e1242548a1226e05b9308cb8d4eb0 to your computer and use it in GitHub Desktop.
Save jef-sure/496e1242548a1226e05b9308cb8d4eb0 to your computer and use it in GitHub Desktop.
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