|  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.017  | 
| 
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
  
 | 
 
 | 
462
 | 
 use strict;  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
174
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1729
 | 
    | 
| 
34
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
331
 | 
 use warnings;  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
151
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1714
 | 
    | 
| 
35
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
348
 | 
 use base qw(RDF::Trine::Serializer);  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
152
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4187
 | 
    | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
37
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
412
 | 
 use URI;  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
156
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1269
 | 
    | 
| 
38
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
559
 | 
 use Carp;  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
161
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3441
 | 
    | 
| 
39
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
479
 | 
 use JSON;  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
159
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
564
 | 
    | 
| 
40
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
6909
 | 
 use Data::Dumper;  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
149
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2820
 | 
    | 
| 
41
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
394
 | 
 use Scalar::Util qw(blessed);  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
151
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2557
 | 
    | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
43
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
393
 | 
 use RDF::Trine::Node;  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
152
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1906
 | 
    | 
| 
44
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
376
 | 
 use RDF::Trine::Statement;  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
589
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1425
 | 
    | 
| 
45
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
377
 | 
 use RDF::Trine::Error qw(:try);  | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
158
 | 
    | 
| 
 
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
395
 | 
    | 
| 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 ######################################################################  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our ($VERSION);  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 BEGIN {  | 
| 
51
 | 
68
 | 
 
 | 
 
 | 
  
68
  
 | 
 
 | 
10384
 | 
 	$VERSION	= '1.017';  | 
| 
52
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
204
 | 
 	$RDF::Trine::Serializer::serializer_names{ 'rdfjson' }	= __PACKAGE__;  | 
| 
53
 | 
68
 | 
 
 | 
 
 | 
 
 | 
 
 | 
182
 | 
 	foreach my $type (qw(application/json application/x-rdf+json)) {  | 
| 
54
 | 
136
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9251
 | 
 		$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
  
 | 
6
 | 
 	my $class	= shift;  | 
| 
68
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
 	my %args	= @_;  | 
| 
69
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
 	my $self = bless( {}, $class);  | 
| 
70
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
 	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
  
 | 
6
 | 
 	my $self	  = shift;  | 
| 
101
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
 	my $model  = shift;  | 
| 
102
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
 	my $opts   = shift;  | 
| 
103
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
 	my $string = to_json($model->as_hashref, $opts);  | 
| 
104
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
68
 | 
 	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
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    |