line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: JSON schema base class. Used as a dispatcher for loading JSON schema objects used by JsonSQL::Validator. |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
74
|
|
5
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
59
|
|
6
|
3
|
|
|
3
|
|
53
|
use 5.014; |
|
3
|
|
|
|
|
9
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package JsonSQL::Schemas::Schema; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.41'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
769
|
use Class::Load qw( try_load_class ); |
|
3
|
|
|
|
|
35469
|
|
|
3
|
|
|
|
|
174
|
|
13
|
3
|
|
|
3
|
|
20
|
use JSON::Parse qw( parse_json ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
92
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
682
|
use JsonSQL::Error; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
398
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
14
|
|
|
14
|
1
|
27
|
my $class = shift; |
21
|
|
|
|
|
|
|
|
22
|
14
|
|
|
|
|
24
|
my $self = {}; |
23
|
|
|
|
|
|
|
|
24
|
14
|
|
|
|
|
28
|
bless $self, $class; |
25
|
14
|
|
|
|
|
33
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub load_schema { |
30
|
14
|
|
|
14
|
1
|
38
|
my ( $caller, $jsonSchema ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
14
|
|
|
|
|
48
|
my $class = "JsonSQL::Schemas::" . $jsonSchema; |
33
|
|
|
|
|
|
|
|
34
|
14
|
|
|
|
|
59
|
my ( $success, $err ) = try_load_class($class); |
35
|
14
|
50
|
|
|
|
915
|
if ( $success ) { |
36
|
14
|
|
|
|
|
54
|
my $schema = $class->new; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# When parsing JSON, need to trap parsing errors. |
39
|
14
|
|
|
|
|
27
|
my $schemaObj = eval { |
40
|
14
|
|
|
|
|
1129
|
return parse_json($schema->{_json}); |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
|
43
|
14
|
50
|
|
|
|
48
|
if ( $@ ) { |
44
|
0
|
|
|
|
|
0
|
return JsonSQL::Error->new("json_schema", "Schema is invalid JSON at: $@"); |
45
|
|
|
|
|
|
|
} else { |
46
|
14
|
|
|
|
|
67
|
return $schemaObj; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
|
|
|
|
|
return JsonSQL::Error->new("json_schema", $err); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=pod |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=encoding UTF-8 |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
JsonSQL::Schemas::Schema - JSON schema base class. Used as a dispatcher for loading JSON schema objects used by JsonSQL::Validator. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 VERSION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
version 0.41 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SYNOPSIS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This is a supporting module used by L<JsonSQL::Validator> for loading JSON schemas. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
To use this: |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $schema = JsonSQL::Schemas::Schema->load_schema(<schema_name>); |
77
|
|
|
|
|
|
|
if ( eval { $schema->is_error } ) { |
78
|
|
|
|
|
|
|
return "Could not load JSON schema: $schema->{message}"; |
79
|
|
|
|
|
|
|
} else { |
80
|
|
|
|
|
|
|
... |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
<schemaname> must be a module residing in JsonSQL::Schemas that is a subclass of this one. See, for example, |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item * L<JsonSQL::Schemas::select> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item * L<JsonSQL::Schemas::insert> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
If you desire other JSON schemas you can create your own... |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 METHODS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 Constructor new -> JsonSQL::Schemas::Schema |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
An inherited constructor for creating the blessed object reference. This should not be called directly. Instead use load_schema. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 Dispatcher load_schema($jsonSchema) -> JsonSQL::Schemas<schema> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Serves as a dispatcher method to load the appropriate subclass for the specified $jsonSchema. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$jsonSchema => The name of the JSON schema to load. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 AUTHOR |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Chris Hoefler <bhoefler@draper.com> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Chris Hoefler. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
116
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |