line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# RDF::Trine::Serializer::RDFJSON |
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Trine::Serializer::RDFJSON - RDF/JSON Serializer |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Trine::Serializer::RDF/JSON version 1.018 |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use RDF::Trine::Serializer::RDFJSON; |
15
|
|
|
|
|
|
|
my $serializer = RDF::Trine::Serializer::RDFJSON->new(); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
The RDF::Trine::Serializer::Turtle class provides an API for serializing RDF |
20
|
|
|
|
|
|
|
graphs to the RDF/JSON syntax. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 METHODS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
25
|
|
|
|
|
|
|
L<RDF::Trine::Serializer> class. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over 4 |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package RDF::Trine::Serializer::RDFJSON; |
32
|
|
|
|
|
|
|
|
33
|
68
|
|
|
68
|
|
426
|
use strict; |
|
68
|
|
|
|
|
191
|
|
|
68
|
|
|
|
|
1695
|
|
34
|
68
|
|
|
68
|
|
342
|
use warnings; |
|
68
|
|
|
|
|
143
|
|
|
68
|
|
|
|
|
1633
|
|
35
|
68
|
|
|
68
|
|
329
|
use base qw(RDF::Trine::Serializer); |
|
68
|
|
|
|
|
146
|
|
|
68
|
|
|
|
|
4129
|
|
36
|
|
|
|
|
|
|
|
37
|
68
|
|
|
68
|
|
394
|
use URI; |
|
68
|
|
|
|
|
181
|
|
|
68
|
|
|
|
|
1160
|
|
38
|
68
|
|
|
68
|
|
432
|
use Carp; |
|
68
|
|
|
|
|
144
|
|
|
68
|
|
|
|
|
3302
|
|
39
|
68
|
|
|
68
|
|
454
|
use JSON; |
|
68
|
|
|
|
|
156
|
|
|
68
|
|
|
|
|
495
|
|
40
|
68
|
|
|
68
|
|
6508
|
use Data::Dumper; |
|
68
|
|
|
|
|
157
|
|
|
68
|
|
|
|
|
2742
|
|
41
|
68
|
|
|
68
|
|
366
|
use Scalar::Util qw(blessed); |
|
68
|
|
|
|
|
150
|
|
|
68
|
|
|
|
|
2466
|
|
42
|
|
|
|
|
|
|
|
43
|
68
|
|
|
68
|
|
371
|
use RDF::Trine::Node; |
|
68
|
|
|
|
|
151
|
|
|
68
|
|
|
|
|
1996
|
|
44
|
68
|
|
|
68
|
|
362
|
use RDF::Trine::Statement; |
|
68
|
|
|
|
|
584
|
|
|
68
|
|
|
|
|
1440
|
|
45
|
68
|
|
|
68
|
|
334
|
use RDF::Trine::Error qw(:try); |
|
68
|
|
|
|
|
149
|
|
|
68
|
|
|
|
|
380
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
###################################################################### |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our ($VERSION); |
50
|
|
|
|
|
|
|
BEGIN { |
51
|
68
|
|
|
68
|
|
9927
|
$VERSION = '1.018'; |
52
|
68
|
|
|
|
|
191
|
$RDF::Trine::Serializer::serializer_names{ 'rdfjson' } = __PACKAGE__; |
53
|
68
|
|
|
|
|
174
|
foreach my $type (qw(application/json application/x-rdf+json)) { |
54
|
136
|
|
|
|
|
9218
|
$RDF::Trine::Serializer::media_types{ $type } = __PACKAGE__; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
###################################################################### |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item C<< new >> |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Returns a new serializer object. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub new { |
67
|
2
|
|
|
2
|
1
|
5
|
my $class = shift; |
68
|
2
|
|
|
|
|
7
|
my %args = @_; |
69
|
2
|
|
|
|
|
7
|
my $self = bless( {}, $class); |
70
|
2
|
|
|
|
|
6
|
return $self; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item C<< serialize_model_to_file ( $file, $model [,\%json_options] ) >> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Serializes the C<$model> to RDF/JSON, printing the results to the supplied |
76
|
|
|
|
|
|
|
C<$file> handle. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
C<%json_options> is an options hash suitable for JSON::to_json. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub serialize_model_to_file { |
83
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
84
|
0
|
|
|
|
|
0
|
my $file = shift; |
85
|
0
|
|
|
|
|
0
|
my $model = shift; |
86
|
0
|
|
|
|
|
0
|
my $opts = shift; |
87
|
0
|
|
|
|
|
0
|
my $string = to_json($model->as_hashref, $opts); |
88
|
0
|
|
|
|
|
0
|
print {$file} $string; |
|
0
|
|
|
|
|
0
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item C<< serialize_model_to_string ( $model [,\%json_options] ) >> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Serializes the C<$model> to RDF/JSON, returning the result as a string. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
C<%json_options> is an options hash suitable for JSON::to_json. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub serialize_model_to_string { |
100
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
101
|
1
|
|
|
|
|
3
|
my $model = shift; |
102
|
1
|
|
|
|
|
2
|
my $opts = shift; |
103
|
1
|
|
|
|
|
10
|
my $string = to_json($model->as_hashref, $opts); |
104
|
1
|
|
|
|
|
51
|
return $string; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=back |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 BUGS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Please report any bugs or feature requests to through the GitHub web interface |
116
|
|
|
|
|
|
|
at L<https://github.com/kasei/perlrdf/issues>. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SEE ALSO |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L<http://n2.talis.com/wiki/RDF_JSON_Specification> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Toby Inkster <tobyink@cpan.org> |
125
|
|
|
|
|
|
|
Gregory Williams <gwilliams@cpan.org> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 COPYRIGHT |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Copyright (c) 2010 Toby Inkster. This program is free |
130
|
|
|
|
|
|
|
software; you can redistribute it and/or modify it under the same terms as Perl |
131
|
|
|
|
|
|
|
itself. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|