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.1'; |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
57599
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
159
|
|
7
|
5
|
|
|
5
|
|
20
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
159
|
|
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
3028
|
use Type::Utils -all; |
|
5
|
|
|
|
|
62517
|
|
|
5
|
|
|
|
|
38
|
|
10
|
5
|
|
|
|
|
51
|
use Types::Standard qw/ |
11
|
|
|
|
|
|
|
InstanceOf |
12
|
|
|
|
|
|
|
Str StrictNum HashRef ArrayRef |
13
|
|
|
|
|
|
|
Int |
14
|
|
|
|
|
|
|
Dict slurpy Optional Any |
15
|
|
|
|
|
|
|
Tuple |
16
|
5
|
|
|
5
|
|
13384
|
/; |
|
5
|
|
|
|
|
71499
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Type::Library |
19
|
5
|
|
|
|
|
23
|
-base, |
20
|
|
|
|
|
|
|
-declare => qw( |
21
|
|
|
|
|
|
|
Disallow |
22
|
|
|
|
|
|
|
Extends |
23
|
|
|
|
|
|
|
DivisibleBy |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Properties |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Dependencies Dependency |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Schema |
30
|
5
|
|
|
5
|
|
6378
|
); |
|
5
|
|
|
|
|
10
|
|
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
5
|
|
4273
|
use List::MoreUtils qw/ all any zip none /; |
|
5
|
|
|
|
|
8253
|
|
|
5
|
|
|
|
|
39
|
|
33
|
5
|
|
|
5
|
|
2784
|
use List::Util qw/ pairs pairmap reduce uniq /; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
418
|
|
34
|
|
|
|
|
|
|
|
35
|
5
|
|
|
5
|
|
611
|
use JSON qw/ to_json from_json /; |
|
5
|
|
|
|
|
9503
|
|
|
5
|
|
|
|
|
65
|
|
36
|
|
|
|
|
|
|
|
37
|
5
|
|
|
5
|
|
1551
|
use JSON::Schema::AsType; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
185
|
|
38
|
|
|
|
|
|
|
|
39
|
5
|
|
|
|
|
80
|
use JSON::Schema::AsType::Draft4::Types 'Not', 'Integer', 'MultipleOf', |
40
|
5
|
|
|
5
|
|
2393
|
'Boolean', 'Number', 'String', 'Null', 'Object', 'Array', 'LaxNumber', 'LaxInteger', 'LaxString'; |
|
5
|
|
|
|
|
15
|
|
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.1 |
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 |