line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Schema::AsType::Draft6::Types; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTRACT: JSON-schema v6 keywords as types |
4
|
|
|
|
|
|
|
$JSON::Schema::AsType::Draft6::Types::VERSION = '0.4.3'; |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1637
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
76
|
|
7
|
2
|
|
|
2
|
|
16
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
113
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
15
|
use Type::Utils -all; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
17
|
|
10
|
2
|
|
|
|
|
51
|
use Types::Standard qw/ |
11
|
|
|
|
|
|
|
Str StrictNum HashRef ArrayRef |
12
|
|
|
|
|
|
|
Int |
13
|
|
|
|
|
|
|
Dict slurpy Optional Any |
14
|
|
|
|
|
|
|
Tuple |
15
|
|
|
|
|
|
|
InstanceOf |
16
|
2
|
|
|
2
|
|
7072
|
/; |
|
2
|
|
|
|
|
6
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Type::Library |
19
|
2
|
|
|
|
|
15
|
-base, |
20
|
|
|
|
|
|
|
-declare => qw( |
21
|
|
|
|
|
|
|
PropertyNames |
22
|
|
|
|
|
|
|
Contains |
23
|
|
|
|
|
|
|
Schema |
24
|
2
|
|
|
2
|
|
3445
|
); |
|
2
|
|
|
|
|
5
|
|
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
2
|
|
1241
|
use List::MoreUtils qw/ all any zip none /; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
17
|
|
27
|
2
|
|
|
2
|
|
1583
|
use List::Util qw/ pairs pairmap reduce uniq /; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
189
|
|
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
2
|
|
13
|
use JSON::Schema::AsType; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
54
|
|
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
18
|
use JSON::Schema::AsType::Draft4::Types qw/ |
32
|
|
|
|
|
|
|
Integer Boolean Number String Null Object Array Items |
33
|
|
|
|
|
|
|
ExclusiveMinimum ExclusiveMaximum Dependencies Dependency |
34
|
|
|
|
|
|
|
Not MultipleOf |
35
|
2
|
|
|
2
|
|
11
|
/; |
|
2
|
|
|
|
|
4
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__PACKAGE__->meta->add_type( $_ ) for Integer, Boolean, Number, String, Null, Object, Array, Items, ExclusiveMaximum, ExclusiveMinimum; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
declare Contains, |
40
|
|
|
|
|
|
|
constraint_generator => sub{ |
41
|
|
|
|
|
|
|
my $type = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return sub { |
44
|
|
|
|
|
|
|
return 1 unless Array->check($_); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if( Boolean->check($type) ) { |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
return any { |
50
|
|
|
|
|
|
|
$type->check($_); |
51
|
|
|
|
|
|
|
} @$_; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
declare PropertyNames, |
56
|
|
|
|
|
|
|
constraint_generator => sub { |
57
|
|
|
|
|
|
|
my $type = shift; |
58
|
|
|
|
|
|
|
return sub { |
59
|
|
|
|
|
|
|
return 1 unless Object->check($_); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return 1 if $type eq Any; |
62
|
|
|
|
|
|
|
return !keys %$_ if $type eq ~Any; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
return all { $type->check($_) } keys %$_; |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
declare Dependencies, |
69
|
|
|
|
|
|
|
constraint_generator => sub { |
70
|
|
|
|
|
|
|
my %deps = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return reduce { $a & $b } pairmap { Dependency[$a => $b] } %deps; |
73
|
|
|
|
|
|
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
declare Dependency, |
76
|
|
|
|
|
|
|
constraint_generator => sub { |
77
|
|
|
|
|
|
|
my( $property, $dep) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub { |
80
|
|
|
|
|
|
|
return 1 unless Object->check($_); |
81
|
|
|
|
|
|
|
return 1 unless exists $_->{$property}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $obj = $_; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return all { exists $obj->{$_} } @$dep if ref $dep eq 'ARRAY'; |
86
|
|
|
|
|
|
|
return exists $obj->{$dep} unless ref $dep; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return $dep->check($_); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
declare Properties => |
93
|
|
|
|
|
|
|
constraint_generator => sub { |
94
|
|
|
|
|
|
|
my $type = Dict[@_, slurpy Any]; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub { |
97
|
|
|
|
|
|
|
! Object->check($_) or $type->check($_) |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
declare Disallow => |
102
|
|
|
|
|
|
|
constraint_generator => sub { |
103
|
|
|
|
|
|
|
Not[ shift ]; |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
declare Extends => |
107
|
|
|
|
|
|
|
constraint_generator => sub { |
108
|
|
|
|
|
|
|
reduce { $a & $b } @_; |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
declare DivisibleBy => |
112
|
|
|
|
|
|
|
constraint_generator => sub { |
113
|
|
|
|
|
|
|
MultipleOf[shift]; |
114
|
|
|
|
|
|
|
}; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
declare Schema, as InstanceOf['Type::Tiny']; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
coerce Schema, |
119
|
|
|
|
|
|
|
from HashRef, |
120
|
|
|
|
|
|
|
via { |
121
|
|
|
|
|
|
|
my $schema = JSON::Schema::AsType->new( draft_version => 6, schema => $_ ); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
if ( $schema->validate_schema ) { |
124
|
|
|
|
|
|
|
die "not a valid draft6 json schema\n"; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
$schema->type |
128
|
|
|
|
|
|
|
}; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=pod |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=encoding UTF-8 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 NAME |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
JSON::Schema::AsType::Draft6::Types - JSON-schema v6 keywords as types |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 VERSION |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
version 0.4.3 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 SYNOPSIS |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
use JSON::Schema::AsType::Draft6::Types '-all'; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $type = Object & |
151
|
|
|
|
|
|
|
Properties[ |
152
|
|
|
|
|
|
|
foo => Minimum[3] |
153
|
|
|
|
|
|
|
]; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$type->check({ foo => 5 }); # => 1 |
156
|
|
|
|
|
|
|
$type->check({ foo => 1 }); # => 0 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 EXPORTED TYPES |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Null Boolean Array Object String Integer Pattern Number Enum |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
OneOf AllOf AnyOf |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Not |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Minimum ExclusiveMinimum Maximum ExclusiveMaximum MultipleOf |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
MaxLength MinLength |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Items AdditionalItems MaxItems MinItems UniqueItems |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
PatternProperties AdditionalProperties MaxProperties MinProperties |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Dependencies Dependency |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 Schema |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Only verifies that the variable is a L<Type::Tiny>. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Can coerce the value from a hashref defining the schema. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
my $schema = Schema->coerce( \%schema ); |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# equivalent to |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
$schema = JSON::Schema::AsType::Draft4->new( |
187
|
|
|
|
|
|
|
draft_version => 6, |
188
|
|
|
|
|
|
|
schema => \%schema; |
189
|
|
|
|
|
|
|
)->type; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 AUTHOR |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Yanick Champoux <yanick@babyl.dyndns.org> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This software is copyright (c) 2017, 2015 by Yanick Champoux. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
200
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |