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