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