-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsf-demo.pl
More file actions
50 lines (42 loc) · 722 Bytes
/
sf-demo.pl
File metadata and controls
50 lines (42 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!perl
use strict;
use warnings;
use 5.10.1;
use lib 'perl/lib';
use Data::Rx;
use YAML::XS;
my $rx = Data::Rx->new;
my $schema_yaml = <<'END_YAML';
---
type: //all
of:
- //def
- type: //seq
contents:
- //int
- //nil
- type: //rec
required:
foo: //int
bar: //int
optional:
baz:
type: //arr
contents:
type: //all
of : [ //def, //num, //int ]
END_YAML
my ($schema_def) = YAML::XS::Load($schema_yaml);
my $schema = $rx->make_schema($schema_def);
my $input = [
1,
undef,
{
foo => 1,
bar => 2.2,
baz => [ 3, 4, 5, 6.2, 7 ],
},
];
eval { $schema->assert_valid($input); };
my $fail = $@;
say $fail;