| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# RDF::Trine::Serializer::RDFPatch |
|
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Trine::Serializer::RDFPatch - RDF-Patch Serializer |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Trine::Serializer::RDFPatch version 1.017 |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use RDF::Trine::Serializer::RDFPatch; |
|
15
|
|
|
|
|
|
|
my $serializer = RDF::Trine::Serializer::RDFPatch->new(); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
The RDF::Trine::Serializer::RDFPatch class provides an API for serializing RDF |
|
20
|
|
|
|
|
|
|
graphs to the RDF-Patch 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::RDFPatch; |
|
32
|
|
|
|
|
|
|
|
|
33
|
68
|
|
|
68
|
|
18428
|
use strict; |
|
|
68
|
|
|
|
|
161
|
|
|
|
68
|
|
|
|
|
1858
|
|
|
34
|
68
|
|
|
68
|
|
342
|
use warnings; |
|
|
68
|
|
|
|
|
153
|
|
|
|
68
|
|
|
|
|
1672
|
|
|
35
|
68
|
|
|
68
|
|
332
|
use base qw(RDF::Trine::Serializer); |
|
|
68
|
|
|
|
|
147
|
|
|
|
68
|
|
|
|
|
4422
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
68
|
|
|
68
|
|
413
|
use URI; |
|
|
68
|
|
|
|
|
162
|
|
|
|
68
|
|
|
|
|
2630
|
|
|
38
|
68
|
|
|
68
|
|
477
|
use Carp; |
|
|
68
|
|
|
|
|
150
|
|
|
|
68
|
|
|
|
|
3290
|
|
|
39
|
68
|
|
|
68
|
|
408
|
use Data::Dumper; |
|
|
68
|
|
|
|
|
141
|
|
|
|
68
|
|
|
|
|
2690
|
|
|
40
|
68
|
|
|
68
|
|
395
|
use Scalar::Util qw(blessed); |
|
|
68
|
|
|
|
|
167
|
|
|
|
68
|
|
|
|
|
2859
|
|
|
41
|
68
|
|
|
68
|
|
390
|
use List::Util qw(min); |
|
|
68
|
|
|
|
|
171
|
|
|
|
68
|
|
|
|
|
3334
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
68
|
|
|
68
|
|
403
|
use RDF::Trine::Node; |
|
|
68
|
|
|
|
|
167
|
|
|
|
68
|
|
|
|
|
1876
|
|
|
44
|
68
|
|
|
68
|
|
360
|
use RDF::Trine::Statement; |
|
|
68
|
|
|
|
|
159
|
|
|
|
68
|
|
|
|
|
1367
|
|
|
45
|
68
|
|
|
68
|
|
324
|
use RDF::Trine::Error qw(:try); |
|
|
68
|
|
|
|
|
144
|
|
|
|
68
|
|
|
|
|
507
|
|
|
46
|
68
|
|
|
68
|
|
31062
|
use RDF::Trine::Exporter::RDFPatch; |
|
|
68
|
|
|
|
|
181
|
|
|
|
68
|
|
|
|
|
4197
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
###################################################################### |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
our ($VERSION); |
|
51
|
|
|
|
|
|
|
BEGIN { |
|
52
|
68
|
|
|
68
|
|
226
|
$VERSION = '1.017'; |
|
53
|
68
|
|
|
|
|
217
|
$RDF::Trine::Serializer::serializer_names{ 'rdfpatch' } = __PACKAGE__; |
|
54
|
|
|
|
|
|
|
# $RDF::Trine::Serializer::format_uris{ 'http://www.w3.org/ns/formats/RDF-Patch' } = __PACKAGE__; |
|
55
|
68
|
|
|
|
|
417
|
foreach my $type (qw(application/rdf-patch)) { |
|
56
|
68
|
|
|
|
|
29532
|
$RDF::Trine::Serializer::media_types{ $type } = __PACKAGE__; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
###################################################################### |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item C<< new >> |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Returns a new RDF-Patch serializer object. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub new { |
|
69
|
2
|
|
|
2
|
1
|
856
|
my $class = shift; |
|
70
|
2
|
|
|
|
|
4
|
my %args; |
|
71
|
2
|
100
|
|
|
|
10
|
if (@_) { |
|
72
|
1
|
50
|
33
|
|
|
7
|
if (scalar(@_) == 1 and reftype($_[0]) eq 'HASH') { |
|
73
|
0
|
|
|
|
|
0
|
my $ns = shift; |
|
74
|
0
|
|
|
|
|
0
|
%args = ( namespaces => $ns ); |
|
75
|
|
|
|
|
|
|
} else { |
|
76
|
1
|
|
|
|
|
4
|
%args = @_; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
2
|
|
|
|
|
7
|
my $self = bless({ args => [ %args ] }, $class); |
|
80
|
2
|
|
|
|
|
7
|
return $self; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item C<< serialize_model_to_file ( $fh, $model ) >> |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Serializes the C<$model> to RDF-Patch, printing the results to the supplied |
|
86
|
|
|
|
|
|
|
filehandle C<<$fh>>. |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub serialize_model_to_file { |
|
91
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
92
|
0
|
|
|
|
|
0
|
my $fh = shift; |
|
93
|
0
|
|
|
|
|
0
|
my $model = shift; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
my $sink = RDF::Trine::Serializer::FileSink->new( $fh ); |
|
96
|
0
|
|
|
|
|
0
|
my $e = RDF::Trine::Exporter::RDFPatch->new( @{ $self->{args} }, sink => $sink ); |
|
|
0
|
|
|
|
|
0
|
|
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
my $st = RDF::Trine::Statement->new( map { RDF::Trine::Node::Variable->new($_) } qw(s p o) ); |
|
|
0
|
|
|
|
|
0
|
|
|
99
|
0
|
|
|
|
|
0
|
my $pat = RDF::Trine::Pattern->new( $st ); |
|
100
|
0
|
|
|
|
|
0
|
my $stream = $model->get_pattern( $pat, undef, orderby => [ qw(s ASC p ASC o ASC) ] ); |
|
101
|
0
|
|
|
|
|
0
|
my $iter = $stream->as_statements( qw(s p o) ); |
|
102
|
0
|
|
|
|
|
0
|
while (my $st = $iter->next) { |
|
103
|
0
|
|
|
|
|
0
|
$e->add( $st ); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item C<< serialize_model_to_string ( $model ) >> |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Serializes the C<$model> to RDF-Patch, returning the result as a string. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub serialize_model_to_string { |
|
114
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
115
|
0
|
|
|
|
|
0
|
my $model = shift; |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
0
|
my $sink = RDF::Trine::Serializer::StringSink->new(); |
|
118
|
0
|
|
|
|
|
0
|
my $e = RDF::Trine::Exporter::RDFPatch->new( @{ $self->{args} }, sink => $sink ); |
|
|
0
|
|
|
|
|
0
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
0
|
my $st = RDF::Trine::Statement->new( map { RDF::Trine::Node::Variable->new($_) } qw(s p o) ); |
|
|
0
|
|
|
|
|
0
|
|
|
121
|
0
|
|
|
|
|
0
|
my $pat = RDF::Trine::Pattern->new( $st ); |
|
122
|
0
|
|
|
|
|
0
|
my $stream = $model->get_pattern( $pat, undef, orderby => [ qw(s ASC p ASC o ASC) ] ); |
|
123
|
0
|
|
|
|
|
0
|
my $iter = $stream->as_statements( qw(s p o) ); |
|
124
|
0
|
|
|
|
|
0
|
while (my $st = $iter->next) { |
|
125
|
0
|
|
|
|
|
0
|
$e->add( $st ); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
0
|
return $sink->string; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item C<< serialize_iterator_to_file ( $file, $iter ) >> |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Serializes the iterator to RDF-Patch, printing the results to the supplied |
|
134
|
|
|
|
|
|
|
filehandle C<<$fh>>. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub serialize_iterator_to_file { |
|
139
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
140
|
0
|
|
|
|
|
0
|
my $fh = shift; |
|
141
|
0
|
|
|
|
|
0
|
my $iter = shift; |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
0
|
my $sink = RDF::Trine::Serializer::FileSink->new( $fh ); |
|
144
|
0
|
|
|
|
|
0
|
my $e = RDF::Trine::Exporter::RDFPatch->new( @{ $self->{args} }, sink => $sink ); |
|
|
0
|
|
|
|
|
0
|
|
|
145
|
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
0
|
while (my $st = $iter->next) { |
|
147
|
0
|
|
|
|
|
0
|
$e->add( $st ); |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item C<< serialize_iterator_to_string ( $iter ) >> |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Serializes the iterator to RDF-Patch, returning the result as a string. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub serialize_iterator_to_string { |
|
158
|
2
|
|
|
2
|
1
|
12
|
my $self = shift; |
|
159
|
2
|
|
|
|
|
4
|
my $iter = shift; |
|
160
|
|
|
|
|
|
|
|
|
161
|
2
|
|
|
|
|
13
|
my $sink = RDF::Trine::Serializer::StringSink->new(); |
|
162
|
2
|
|
|
|
|
5
|
my $e = RDF::Trine::Exporter::RDFPatch->new( @{ $self->{args} }, sink => $sink ); |
|
|
2
|
|
|
|
|
18
|
|
|
163
|
|
|
|
|
|
|
|
|
164
|
2
|
|
|
|
|
8
|
while (my $st = $iter->next) { |
|
165
|
8
|
|
|
|
|
21
|
$e->add( $st ); |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
2
|
|
|
|
|
9
|
return $sink->string; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__ |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 NOTES |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
As described in L<RDF::Trine::Node::Resource/as_ntriples>, serialization will |
|
180
|
|
|
|
|
|
|
decode any L<punycode|http://www.ietf.org/rfc/rfc3492.txt> that is included in the IRI, |
|
181
|
|
|
|
|
|
|
and serialize it using unicode codepoint escapes. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 BUGS |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Please report any bugs or feature requests to through the GitHub web interface |
|
186
|
|
|
|
|
|
|
at L<https://github.com/kasei/perlrdf/issues>. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
L<http://afs.github.io/rdf-patch/> |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 AUTHOR |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Gregory Todd Williams C<< <gwilliams@cpan.org> >> |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Copyright (c) 2006-2012 Gregory Todd Williams. This |
|
199
|
|
|
|
|
|
|
program is free software; you can redistribute it and/or modify it under |
|
200
|
|
|
|
|
|
|
the same terms as Perl itself. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |