KV/Patch.pm

filter: Statementstmt 33.7% 62 / 184 Branchbran 19.4% 23 / 118 Conditioncond 30.7% 8 / 26 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 44.4% 12 / 27 Podpod 100% 9 / 9 totaltotal 30.1% 114 / 378 CC 78 SCAR 53.2
CC
78
Cov
28%
_validate
528.1
_traverse
132.0
affected_subjects
30.0
CRAP 204.4
« KV.pm ↑ Summary
1 package RDF::KV::Patch;
2  
3 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use RDF::Trine qw(iri blank literal);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use URI::BNode;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 RDF::KV::Patch - Representation of RDF statements to be added or removed
17  
18 =head1 VERSION
19  
20 Version 0.14
21  
22 =cut
23  
24 3 our $VERSION = '0.14';
25  
26 =head1 SYNOPSIS
27  
28 my $patch = RDF::KV::Patch->new;
29  
30 $patch->add_this($s, $p, $o, $g);
31 $patch->remove_this($s, $p, undef, $g); # a wildcard
32  
33 $patch->apply($model); # an RDF::Trine::Model instance
34  
35 =head1 DESCRIPTION
36  
37 This module is designed to represent a I<diff> for RDF graphs. You add
38 statements to its I<add> or I<remove> sides, then you L</apply> them
39 to a L<RDF::Trine::Model> object. This should probably be part of
40 L<RDF::Trine> if there isn't something like this in there already.
41  
42 =cut
43  
44 # positive statements
45 has _pos => (
46 is => 'ro',
47 isa => 'HashRef',
48 1 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 3 );
50  
51 # negative statements/wildcards
52 has _neg => (
53 is => 'ro',
54 isa => 'HashRef',
55 1 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
56 3 );
57  
58 =head1 METHODS
59  
60 =head2 new
61  
62 Stub constructor, nothing of interest.
63  
64 =cut
65  
66 =head2 add_this { $S, $P, $O | $statement } [, $graph ]
67  
68 Add a statement, or set of terms, to the I<add> side of the patch.
69  
70 This method and its siblings are fairly robust, and can take a wide
71 variety of inputs, from triple and quad statements, to individual
72 subject/predicate/object/graph objects, to string literals, to
73 variable nodes, to undef. They are processed by the following scheme:
74  
75 =over 4
76  
77 =item
78  
79 If passed a L<RDF::Trine::Statement>, it will be unwound into its
80 respective components. The C<graph> attribute of a L<quad
81 statement|RDF::Trine::Statement::Quad> supersedes any given graph
82 parameter.
83  
84 =item
85  
86 The empty string, C<undef>, and L<RDF::Trine::Node::Variable> objects
87 are considered to be wildcards, which are only legal in the
88 I<negative> side of the patch, since they don't make sense on the
89 positive side. Placing wildcards in all three of the subject,
90 predicate and object positions will raise an exception, because if
91 carried out it would completely empty the graph. If you're sure you
92 want to do that, you should use another mechanism.
93  
94 =item
95  
96 I<Subjects> are coerced from string literals to L<URI> and
97 L<URI::BNode> instances and from there to
98 L<RDF::Trine::Node::Resource> and L<RDF::Trine::Node::Blank>
99 instances, respectively.
100  
101 =item
102  
103 I<Predicates> are always coerced from string literals or L<URI> objects
104 into L<RDF::Trine::Node::Resource> objects.
105  
106 =item
107  
108 I<Objects> are coerced from either string literals or C<ARRAY>
109 references into L<RDF::Trine::Node::Literal> instances, the latter
110 case mimicking L<that class's
111 constructor|RDF::Trine::Node::Literal/new>. URIs or blank nodes must
112 already be at least instances of L<URI> or L<URI::BNode>, if not
113 L<RDF::Trine::Node::Resource> or L<RDF::Trine::Node::Blank>. Note: the
114 empty string is considered a wildcard, so if you want an actual empty
115 string, you will need to pass in an L<RDF::Trine::Node::Literal> with
116 that value.
117  
118 =back
119  
120 =cut
121  
122 1 ▶sub _validate {
Subroutine _validate: called CC=36 SCAR=62.7
123 # oh undef vs empty string, you're so cute.
124 my ($s, $p, $o, $g) =
125 1 ▶ map { defined $_ && !ref $_ && $_ eq '' ? undef : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && !ref($_) && $_ eq '' ? : 0 3 3
Condition66%4/6
defined $_ and not ref $_ and $_ eq ""
!ll&&!rl&&r
120
defined $_ and not ref $_
!ll&&!rl&&r
012
MC/DC0%0/3
defined $_ and not ref $_ and $_ eq ""
defined $_ not ref $_ $_ eq ""
Truth table50%2/4
A and not(B) and C
A= defined $_B= not ref $_C= $_ eq ""
ABCresult
0XX0
10X0
1100
1111
126  
127 1 ▶ if (defined $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s) 1 0 1
128 1 ▶ if (Scalar::Util::blessed($s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($s)) { } 0 1 1
129 0 ▶ if ($s->isa('RDF::Trine::Statement')) {
Branch: 4 branches
BranchTrueFalseTotal
if ($s->isa('RDF::Trine::Statement')) { } 0 0 0
elsif ($s->isa('URI::BNode')) { } 0 0 0
elsif ($s->isa('URI')) { } 0 0 0
elsif ($s->isa('RDF::Trine::Node::Variable')) { } 0 0 0
130 # move $p to $g
131 0 ▶ if (defined $p) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p) 0 0 0
132 0 $g = $p;
133 0 undef $p;
134 }
135  
136 # unpack statement
137 0 ▶ if ($s->isa('RDF::Trine::Statement::Quad')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->isa('RDF::Trine::Statement::Quad')) { } 0 0 0
138 ($s, $p, $o, $g) =
139 0 map { $s->$_ } qw(subject predicate object graph);
140 }
141 else {
142 0 ($s, $p, $o) = map { $s->$_ } qw(subject predicate object);
143 }
144 }
145 elsif ($s->isa('URI::BNode')) {
146 0 $s = blank($s->opaque);
147 }
148 elsif ($s->isa('URI')) {
149 0 $s = iri($s->as_string);
150 }
151 elsif ($s->isa('RDF::Trine::Node::Variable')) {
152 0 $s = undef;
153 }
154 else {
155 # dunno
156 }
157 }
158 else {
159 # dunno
160 1 $s = URI::BNode->new($s);
161 1 ▶ $s = $s->scheme eq '_' ? blank($s->opaque) : iri($s->as_string);
Branch: 1 branch
BranchTrueFalseTotal
$s->scheme eq '_' ? : 1 0 1
162 }
163 }
164  
165 # predicate will always be an iri
166 1 ▶ if (defined $p) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p) 1 0 1
167 1 ▶ if (Scalar::Util::blessed($p)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($p)) { } 0 1 1
168 0 ▶ if ($p->isa('URI')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($p->isa('URI')) { } 0 0 0
elsif ($p->isa('RDF::Trine::Node::Variable')) { } 0 0 0
169 0 $p = iri($p->as_string);
170 }
171 elsif ($p->isa('RDF::Trine::Node::Variable')) {
172 0 $p = undef;
173 }
174 else {
175 # dunno
176 }
177 }
178 else {
179 1 $p = iri("$p");
180 }
181 }
182  
183 1 ▶ if (defined $o) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o) 1 0 1
184 1 ▶ if (my $ref = ref $o) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = ref $o) { } 1 0 1
185 1 ▶ if (Scalar::Util::blessed($o)) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($o)) { } 1 0 1
elsif ($ref eq 'ARRAY') { } 0 0 0
186 1 ▶ if ($o->isa('URI::BNode')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($o->isa('URI::BNode')) { } 0 1 1
elsif ($o->isa('URI')) { } 0 1 1
elsif ($o->isa('RDF::Trine::Node::Variable')) { } 0 1 1
187 0 $o = blank($o->opaque);
188 }
189 elsif ($o->isa('URI')) {
190 0 $o = iri($o->as_string);
191 }
192 elsif ($o->isa('RDF::Trine::Node::Variable')) {
193 0 $o = undef;
194 }
195 else {
196 # dunno
197 }
198 }
199 elsif ($ref eq 'ARRAY') {
200 0 my ($lv, $lang, $dt) = @$o;
201 0 ▶ if (ref $dt and Scalar::Util::blessed($dt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dt and builtin::blessed($dt)) 0 0 0
Condition0%0/3
ref $dt and builtin::blessed($dt)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $dt and builtin::blessed($dt)
ref $dt builtin::blessed($dt)
Truth table0%0/3
A and B
A= ref $dtB= builtin::blessed($dt)
ABresult
0X0
100
111
202 0 ▶ $dt = $dt->can('uri_value') ? $dt->uri_value :
Branch: 2 branches
BranchTrueFalseTotal
$dt->can('uri_value') ? : 0 0 0
$dt->can('as_string') ? : 0 0 0
203 $dt->can('as_string') ? $dt->as_string : "$dt";
204 }
205 0 $o = literal($lv, $lang, $dt);
206 }
207 else {
208 # dunno
209 }
210 }
211 else {
212 0 $o = literal($o);
213 }
214 }
215  
216 1 ▶ if (defined $g) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $g) 0 1 1
217 0 ▶ if (Scalar::Util::blessed($g)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($g)) { } 0 0 0
218 0 ▶ if ($g->isa('RDF::Trine::Node')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($g->isa('RDF::Trine::Node')) { } 0 0 0
elsif ($g->isa('URI')) { } 0 0 0
219 # do nothing
220 }
221 elsif ($g->isa('URI')) {
222 # scheme is not guaranteed to be present
223 0 ▶ $g = ($g->scheme || '') eq '_' ?
Branch: 1 branch
BranchTrueFalseTotal
($g->scheme || '') eq '_' ? : 0 0 0
Condition0%0/2
$g->scheme || ''
l!l
00
MC/DC0%0/1
$g->scheme || ''
$g->scheme
Truth table0%0/2
A
A= $g->scheme
Aresult
11
00
224 blank($g->opaque) : iri($g->as_string);
225 }
226 else {
227 # dunno
228 }
229 }
230 else {
231 # apparently rdf 1.1 graph identifiers can be bnodes
232 0 $g = URI::BNode->new($g);
233 # ditto scheme
234 0 ▶ $g = ($g->scheme || '') eq '_' ?
Branch: 1 branch
BranchTrueFalseTotal
($g->scheme || '') eq '_' ? : 0 0 0
Condition0%0/2
$g->scheme || ''
l!l
00
MC/DC0%0/1
$g->scheme || ''
$g->scheme
Truth table0%0/2
A
A= $g->scheme
Aresult
11
00
235 blank($g->opaque) : iri($g->as_string);
236 }
237 }
238  
239 1 return ($s, $p, $o, $g);
240 }
241  
242 1 ▶sub _add_either {
Subroutine _add_either: called CC=14 SCAR=33.5
243 1 my ($set, $s, $p, $o, $g) = @_;
244 # clobber graph, subject and predicate to strings; bnode will be _:
245 ($g, $s, $p) = map {
246 1 ▶ defined $_ ? $_->isa('RDF::Trine::Node::Blank') ?
Branch: 3 branches
BranchTrueFalseTotal
defined $_ ? : 2 1 3
$_->isa('RDF::Trine::Node::Blank') ? : 1 1 2
ref $_ ? : 1 0 1
247 $_->sse : ref $_ ? $_->uri_value : $_ : '' } ($g, $s, $p);
248  
249 1 ▶ $set->{$g} ||= {};
Condition50%1/2
$set->{$g} ||= {}
l!l
01
MC/DC0%0/1
$set->{$g} ||= {}
$set->{$g}
Truth table50%1/2
A
A= $set->{$g}
Aresult
11
00
250 1 ▶ $set->{$g}{$s} ||= {};
Condition50%1/2
$set->{$g}{$s} ||= {}
l!l
01
MC/DC0%0/1
$set->{$g}{$s} ||= {}
$set->{$g}{$s}
Truth table50%1/2
A
A= $set->{$g}{$s}
Aresult
11
00
251 1 ▶ $set->{$g}{$s}{$p} ||= [{}, {}];
Condition50%1/2
$set->{$g}{$s}{$p} ||= [{}, {}]
l!l
01
MC/DC0%0/1
$set->{$g}{$s}{$p} ||= [{}, {}]
$set->{$g}{$s}{$p}
Truth table50%1/2
A
A= $set->{$g}{$s}{$p}
Aresult
11
00
252  
253 1 ▶ if ($o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o) { } 1 0 1
254 1 ▶ if ($o->isa('RDF::Trine::Node::Literal')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o->isa('RDF::Trine::Node::Literal')) { } 1 0 1
elsif ($o->isa('RDF::Trine::Node::Variable')) { } 0 0 0
255 1 my $l = $o->literal_value_language;
256 1 my $d = $o->literal_datatype;
257 1 ▶ my $ld = $d ? "^$d" : $l ? "\@$l" : '';
Branch: 2 branches
BranchTrueFalseTotal
$d ? : 1 0 1
$l ? : 0 0 0
258 1 ▶ my $x = $set->{$g}{$s}{$p}[1]{$ld} ||= {};
Condition50%1/2
$set->{$g}{$s}{$p}[1]{$ld} ||= {}
l!l
01
MC/DC0%0/1
$set->{$g}{$s}{$p}[1]{$ld} ||= {}
$set->{$g}{$s}{$p}[1]{$ld}
Truth table50%1/2
A
A= $set->{$g}{$s}{$p}[1]{$ld}
Aresult
11
00
259 1 $x->{$o->literal_value} = 1;
260 }
261 elsif ($o->isa('RDF::Trine::Node::Variable')) {
262 0 $set->{$g}{$s}{$p} = 1;
263 }
264 else {
265 0 ▶ $o = $o->isa('RDF::Trine::Node::Blank') ? $o->sse : $o->uri_value;
Branch: 1 branch
BranchTrueFalseTotal
$o->isa('RDF::Trine::Node::Blank') ? : 0 0 0
266 0 $set->{$g}{$s}{$p}[0]{$o} = 1;
267 }
268 }
269 else {
270 0 $set->{$g}{$s}{$p} = 1;
271 }
272 }
273  
274 1 ▶sub add_this {
Subroutine add_this: called CC=3 SCAR=11.2
Pod documented
275 1 my $self = shift;
276 1 my ($s, $p, $o, $g) = _validate(@_);
277 Carp::croak('It makes no sense in this context to add a partial statement')
278 1 ▶ unless 3 == grep { ref $_ } ($s, $p, $o);
Branch: 1 branch
BranchTrueFalseTotal
unless 3 == grep({ref $_;} $s, $p, $o) 0 1 1
279  
280 1 ▶ my $ret = $g ? RDF::Trine::Statement::Quad->new($s, $p, $o, $g) :
Branch: 1 branch
BranchTrueFalseTotal
$g ? : 0 1 1
281 RDF::Trine::Statement->new($s, $p, $o);
282 #warn $ret;
283  
284 1 _add_either($self->_pos, $s, $p, $o, $g);
285  
286 1 $ret;
287 }
288  
289 =head2 dont_add_this { $S, $P, $O | $statement } [, $graph ]
290  
291 Remove a statement, or set of terms, from the I<add> side of the patch.
292  
293 =cut
294  
295 0 ▶sub dont_add_this {
Subroutine dont_add_this: not called CC=1 SCAR=6.9
Pod documented
296 0 my $self = shift;
297 0 my ($s, $p, $o, $g) = _validate(@_);
298 }
299  
300 =head2 remove_this { $S, $P, $O | $statement } [, $graph ]
301  
302 Add a statement, or set of terms, to the I<remove> side of the patch.
303  
304 =cut
305  
306 0 ▶sub remove_this {
Subroutine remove_this: not called CC=3 SCAR=24.8
Pod documented
307 0 my $self = shift;
308 0 my ($s, $p, $o, $g) = _validate(@_);
309  
310 #warn Data::Dumper::Dumper([$s, $p, $o, $g]);
311  
312 Carp::croak('If you want to nuke the whole graph, just do that directly')
313 0 ▶ unless 1 <= grep { ref $_ } ($s, $p, $o);
Branch: 1 branch
BranchTrueFalseTotal
unless 1 <= grep({ref $_;} $s, $p, $o) 0 0 0
314  
315 0 ▶ my $ret = $g ? RDF::Trine::Statement::Quad->new($s, $p, $o, $g) :
Branch: 1 branch
BranchTrueFalseTotal
$g ? : 0 0 0
316 RDF::Trine::Statement->new($s, $p, $o);
317  
318 0 _add_either($self->_neg, $s, $p, $o, $g);
319  
320 0 $ret;
321 }
322  
323 =head2 dont_remove_this { $S, $P, $O | $statement } [, $graph ]
324  
325 Remove a statement, or set of terms, from the I<remove> side of the
326 patch.
327  
328 =cut
329  
330 0 ▶sub dont_remove_this {
Subroutine dont_remove_this: not called CC=1 SCAR=6.9
Pod documented
331 0 my $self = shift;
332 0 my ($s, $p, $o, $g) = _validate(@_);
333 }
334  
335 =head2 affected_graphs
336  
337 Return the set of graph identifiers affected by the patch, including
338 C<undef> for the null graph.
339  
340 =cut
341  
342 0 ▶sub affected_graphs {
Subroutine affected_graphs: not called CC=1 SCAR=6.9
Pod documented
343 0 my $self = shift;
344 0 my %seen;
345  
346 0 map { $seen{$_} = 1 } (keys %{$self->_pos}, keys %{$self->_neg});
347  
348 0 map { _node($_) } keys %seen;
349 }
350  
351 =head2 affected_subjects [$use_graphs]
352  
353 Return the set of subjects that are affected by the patch,
354 irrespective of graph.
355  
356 =cut
357  
358 0 ▶sub affected_subjects {
Subroutine affected_subjects: not called CC=5 SCAR=34.0
Pod documented
359 0 my ($self, $use_graphs) = @_;
360 0 my %seen;
361  
362 0 for my $stmt ($self->to_add, $self->to_remove) {
363 0 my $g = $stmt->graph;
364 0 ▶ my $x = $seen{$g ? $g->value : ''} ||= {};
Branch: 1 branch
BranchTrueFalseTotal
$g ? : 0 0 0
Condition0%0/2
$seen{$g ? $g->value : ""} ||= {}
l!l
00
MC/DC0%0/1
$seen{$g ? $g->value : ""} ||= {}
$seen{$g ? $g->value : ""}
Truth table0%0/2
A
A= $seen{$g ? $g->value : ""}
Aresult
11
00
365 0 $x->{$stmt->subject->value} = $stmt->subject;
366 }
367  
368 0 ▶ unless ($use_graphs) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($use_graphs) 0 0 0
369 my %out = map {
370 0 map { $_->value => $_ } values %{$seen{$_}} } keys %seen;
371 0 return values %out;
372 }
373  
374 0 map { [_node($_), [values %{$seen{$_}} ] ] } keys %seen;
375 }
376  
377 =head2 to_add
378  
379 In list context, returns an array of statements to add to the
380 graph. In scalar context, returns an L<RDF::Trine::Iterator>.
381  
382 =cut
383  
384 0 ▶sub to_add {
Subroutine to_add: not called CC=2 SCAR=17.9
Pod documented
385 0 my $self = shift;
386 0 my @out;
387 0 ▶ _traverse($self->_pos, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
388 0 ▶ my $stmt = defined $_[3] ?
Branch: 1 branch
BranchTrueFalseTotal
defined $_[3] ? : 0 0 0
389 RDF::Trine::Statement::Quad->new(@_)
390 : RDF::Trine::Statement->new(@_[0..2]);
391 0 push @out, $stmt;
392 0 });
393 0 ▶ wantarray ? @out : RDF::Trine::Iterator->new(\@out, 'graph');
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
394 }
395  
396 =head2 to_remove
397  
398 In list context, returns an array of statements to remove from the
399 graph. In scalar context, returns an L<RDF::Trine::Iterator>.
400  
401 =cut
402  
403 0 ▶sub to_remove {
Subroutine to_remove: not called CC=2 SCAR=17.9
Pod documented
404 0 my $self = shift;
405 0 my @out;
406 0 ▶ _traverse($self->_neg, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
407 0 ▶ my $stmt = defined $_[3] ?
Branch: 1 branch
BranchTrueFalseTotal
defined $_[3] ? : 0 0 0
408 RDF::Trine::Statement::Quad->new(@_)
409 : RDF::Trine::Statement->new(@_[0..2]);
410 0 push @out, $stmt;
411 0 });
412 0 ▶ wantarray ? @out : RDF::Trine::Iterator->new(\@out, 'bindings');
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
413 }
414  
415 =head2 apply { $model | $remove, $add }
416  
417 Apply the patch to an L<RDF::Trine::Model> object. Statements are
418 removed first, then added. Transactions
419 (i.e. L<RDF::Trine::Model/begin_bulk_ops>) are your responsibility.
420  
421 Alternatively, supply the C<remove> and C<add> functions directly:
422  
423 sub _remove_or_add {
424 my ($subject, $predicate, $object, $graph) = @_;
425  
426 # do stuff ...
427  
428 # return value is ignored
429 }
430  
431 Inputs will be either L<RDF::Trine::Node> objects, or C<undef>, in the
432 case of C<remove>.
433  
434 =cut
435  
436 0 ▶sub _node {
Subroutine _node: not called CC=3 SCAR=24.8
437 0 my $x = shift;
438 0 ▶ return $x eq '' ? undef : $x =~ /^_:(.*)/ ? bnode($1) : iri($x);
Branch: 2 branches
BranchTrueFalseTotal
$x eq '' ? : 0 0 0
$x =~ /^_:(.*)/ ? : 0 0 0
439 }
440  
441 # holy lol @ this
442 0 ▶sub _traverse {
Subroutine _traverse: not called CC=11 SCAR=48.8
443 0 my ($structure, $callback) = @_;
444  
445 0 for my $gg (keys %{$structure}) {
446 0 my $g = _node($gg);
447 0 for my $ss (keys %{$structure->{$gg}}) {
448 0 my $s = _node($ss);
449 0 for my $pp (keys %{$structure->{$gg}{$ss}}) {
450 0 my $gsp = $structure->{$gg}{$ss}{$pp};
451 0 my $p = _node($pp);
452 0 ▶ if (!ref $gsp or $gsp->[0]{''}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $gsp or $gsp->[0]{''}) { } 0 0 0
Condition0%0/3
not ref $gsp or $gsp->[0]{""}
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $gsp or $gsp->[0]{""}
not ref $gsp $gsp->[0]{""}
Truth table0%0/3
not(A) or B
A= not ref $gspB= $gsp->[0]{""}
ABresult
1X1
011
000
453 #warn 'lul';
454 0 $callback->($s, $p, undef, $g);
455 }
456 else {
457 0 for my $oo (keys %{$gsp->[0]}) {
458 0 my $o = _node($oo);
459 #warn "lul $o";
460 0 $callback->($s, $p, $o, $g);
461 }
462 0 for my $ld (keys %{$gsp->[1]}) {
463 0 my ($t, $v) = ($ld =~ /^(.)(.*)$/);
464 0 ▶ my @args = $t ? $t eq '@' ?
Branch: 2 branches
BranchTrueFalseTotal
$t ? : 0 0 0
$t eq '@' ? : 0 0 0
465 ($v, undef) : (undef, $v) : ();
466 # of course the datatype is always a string
467 # here so no need to check it for blessedness
468 0 for my $ll (keys %{$gsp->[1]{$ld}}) {
469 0 my $o = literal($ll, @args);
470 #warn 'lul';
471 0 $callback->($s, $p, $o, $g);
472 }
473 }
474 }
475 }
476 }
477 }
478 }
479  
480 0 ▶sub _apply {
Subroutine _apply: not called CC=1 SCAR=6.9
481 0 my ($self, $model) = @_;
482  
483 0 $model->begin_bulk_ops;
484  
485 0 ▶ _traverse($self->_neg, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
486 #warn join(' ', map { defined $_ ? $_ : '(undef)' } @_);
487 # fuuuuuuck this quad semantics shit
488 0 my @n = map { $_[$_] } (0..3);
489  
490 #warn "found context $n[3]" if defined $n[3];
491  
492 0 ▶ $model->remove_statements
Branch: 1 branch
BranchTrueFalseTotal
defined $n[3] ? : 0 0 0
493 0 (defined $n[3] ? @n[0..3] : @n[0..2]) });
494 _traverse($self->_pos,
495 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
496 #warn "found context $_[3]" if defined $_[3];
497 0 ▶ my $stmt = defined $_[3] ?
Branch: 1 branch
BranchTrueFalseTotal
defined $_[3] ? : 0 0 0
498 RDF::Trine::Statement::Quad->new(@_)
499 : RDF::Trine::Statement->new(@_[0..2]);
500 #warn $stmt->sse;
501 0 $model->add_statement($stmt);
502 0 });
503  
504 0 $model->end_bulk_ops;
505  
506 0 1;
507 }
508  
509 0 ▶sub apply {
Subroutine apply: not called CC=4 SCAR=30.0
Pod documented
510 0 my ($self, $remove, $add) = @_;
511  
512 # note remove may be a coderef or a model
513 0 ▶ if (ref $remove eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $remove eq "CODE") 0 0 0
514 0 _traverse($self->_neg, $remove);
515 0 ▶ _traverse($self->_pos, $add) if $add;
Branch: 1 branch
BranchTrueFalseTotal
if $add 0 0 0
516 0 return 1;
517 }
518 0 ▶ $self->_apply($remove) if Scalar::Util::blessed($remove);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($remove) 0 0 0
519 }
520  
521 =head1 SEE ALSO
522  
523 =over 4
524  
525 =item L<RDF::KV>
526  
527 =item L<RDF::Trine::Model>
528  
529 =item L<RDF::Trine::Statement>
530  
531 =item L<RDF::Trine::Node>
532  
533 =back
534  
535 =head1 LICENSE AND COPYRIGHT
536  
537 Copyright 2013 Dorian Taylor.
538  
539 Licensed under the Apache License, Version 2.0 (the "License"); you
540 may not use this file except in compliance with the License. You may
541 obtain a copy of the License at
542 L<http://www.apache.org/licenses/LICENSE-2.0>.
543  
544 Unless required by applicable law or agreed to in writing, software
545 distributed under the License is distributed on an "AS IS" BASIS,
546 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
547 implied. See the License for the specific language governing
548 permissions and limitations under the License.
549  
550 =cut
551  
552 3 __PACKAGE__->meta->make_immutable;
553  
554 3 1;
« KV.pm ↑ Summary