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.018 |
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
|
|
14383
|
use strict; |
|
68
|
|
|
|
|
151
|
|
|
68
|
|
|
|
|
1632
|
|
34
|
68
|
|
|
68
|
|
318
|
use warnings; |
|
68
|
|
|
|
|
136
|
|
|
68
|
|
|
|
|
1659
|
|
35
|
68
|
|
|
68
|
|
340
|
use base qw(RDF::Trine::Serializer); |
|
68
|
|
|
|
|
141
|
|
|
68
|
|
|
|
|
4308
|
|
36
|
|
|
|
|
|
|
|
37
|
68
|
|
|
68
|
|
416
|
use URI; |
|
68
|
|
|
|
|
144
|
|
|
68
|
|
|
|
|
2569
|
|
38
|
68
|
|
|
68
|
|
348
|
use Carp; |
|
68
|
|
|
|
|
141
|
|
|
68
|
|
|
|
|
3227
|
|
39
|
68
|
|
|
68
|
|
377
|
use Data::Dumper; |
|
68
|
|
|
|
|
141
|
|
|
68
|
|
|
|
|
2590
|
|
40
|
68
|
|
|
68
|
|
402
|
use Scalar::Util qw(blessed); |
|
68
|
|
|
|
|
141
|
|
|
68
|
|
|
|
|
2628
|
|
41
|
68
|
|
|
68
|
|
376
|
use List::Util qw(min); |
|
68
|
|
|
|
|
146
|
|
|
68
|
|
|
|
|
3145
|
|
42
|
|
|
|
|
|
|
|
43
|
68
|
|
|
68
|
|
434
|
use RDF::Trine::Node; |
|
68
|
|
|
|
|
143
|
|
|
68
|
|
|
|
|
1822
|
|
44
|
68
|
|
|
68
|
|
356
|
use RDF::Trine::Statement; |
|
68
|
|
|
|
|
160
|
|
|
68
|
|
|
|
|
1337
|
|
45
|
68
|
|
|
68
|
|
320
|
use RDF::Trine::Error qw(:try); |
|
68
|
|
|
|
|
143
|
|
|
68
|
|
|
|
|
422
|
|
46
|
68
|
|
|
68
|
|
30611
|
use RDF::Trine::Exporter::RDFPatch; |
|
68
|
|
|
|
|
187
|
|
|
68
|
|
|
|
|
4068
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
###################################################################### |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
our ($VERSION); |
51
|
|
|
|
|
|
|
BEGIN { |
52
|
68
|
|
|
68
|
|
212
|
$VERSION = '1.018'; |
53
|
68
|
|
|
|
|
181
|
$RDF::Trine::Serializer::serializer_names{ 'rdfpatch' } = __PACKAGE__; |
54
|
|
|
|
|
|
|
# $RDF::Trine::Serializer::format_uris{ 'http://www.w3.org/ns/formats/RDF-Patch' } = __PACKAGE__; |
55
|
68
|
|
|
|
|
375
|
foreach my $type (qw(application/rdf-patch)) { |
56
|
68
|
|
|
|
|
28857
|
$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
|
624
|
my $class = shift; |
70
|
2
|
|
|
|
|
4
|
my %args; |
71
|
2
|
100
|
|
|
|
9
|
if (@_) { |
72
|
1
|
50
|
33
|
|
|
6
|
if (scalar(@_) == 1 and reftype($_[0]) eq 'HASH') { |
73
|
0
|
|
|
|
|
0
|
my $ns = shift; |
74
|
0
|
|
|
|
|
0
|
%args = ( namespaces => $ns ); |
75
|
|
|
|
|
|
|
} else { |
76
|
1
|
|
|
|
|
3
|
%args = @_; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
2
|
|
|
|
|
15
|
my $self = bless({ args => [ %args ] }, $class); |
80
|
2
|
|
|
|
|
8
|
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
|
10
|
my $self = shift; |
159
|
2
|
|
|
|
|
3
|
my $iter = shift; |
160
|
|
|
|
|
|
|
|
161
|
2
|
|
|
|
|
12
|
my $sink = RDF::Trine::Serializer::StringSink->new(); |
162
|
2
|
|
|
|
|
3
|
my $e = RDF::Trine::Exporter::RDFPatch->new( @{ $self->{args} }, sink => $sink ); |
|
2
|
|
|
|
|
17
|
|
163
|
|
|
|
|
|
|
|
164
|
2
|
|
|
|
|
8
|
while (my $st = $iter->next) { |
165
|
8
|
|
|
|
|
22
|
$e->add( $st ); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
2
|
|
|
|
|
8
|
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 |