AtteanX/Store/Memory.pm

filter: Statementstmt 97.7% 298 / 305 Branchbran 88.5% 62 / 70 Conditioncond 83.3% 10 / 12 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 100% 43 / 43 Podpod 100% 14 / 14 totaltotal 95.5% 432 / 452 CC 52 SCAR 18.4
CC
52
Cov
96%
_get_quads
16.1
_count_quads
13.0
_statement_id
6.1
CRAP 6.3
« AtteanX/Parser/SPARQLJSON.pm ↑ Summary Attean/QuadModel.pm »
1 =head1 NAME
2  
3 AtteanX::Store::Memory - Simple in-memory RDF store
4  
5 =head1 VERSION
6  
7 This document describes AtteanX::Store::Memory version 0.040
8  
9 =head1 SYNOPSIS
10  
11 use AtteanX::Store::Memory;
12  
13 =head1 DESCRIPTION
14  
15 AtteanX::Store::Memory provides an in-memory quad-store.
16  
17 =cut
18  
19 14 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 11 package AtteanX::Store::Memory 0.040 {
23 14 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 14 ▶use Type::Tiny::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 14 ▶use Types::Standard qw(Int ArrayRef HashRef ConsumerOf InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 14 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 14 ▶use Set::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 14 ▶use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 14 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 14 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 14 ▶use Scalar::Util qw(refaddr reftype blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 14 ▶use Math::Cartesian::Product;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 14 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 11 with 'Attean::API::RDFStarStore';
36 11 with 'Attean::API::MutableQuadStore';
37 11 with 'Attean::API::QuadStore';
38 11 with 'Attean::API::ETagCacheableQuadStore';
39 11 with 'Attean::API::TimeCacheableQuadStore';
40 11 with 'Attean::API::CostPlanner';
41  
42 11 my @pos_names = Attean::API::Quad->variables;
43  
44 =head1 ATTRIBUTES
45  
46 =over 4
47  
48 =item C<< subject >>
49  
50 =item C<< predicate >>
51  
52 =item C<< object >>
53  
54 =item C<< graph >>
55  
56 =back
57  
58 =head1 METHODS
59  
60 Beyond the methods documented below, this class inherits methods from the
61 L<Attean::API::QuadStore> class.
62  
63 =over 4
64  
65 =item C<< new () >>
66  
67 Returns a new memory-backed storage object.
68  
69 =cut
70  
71 11 has _size => (is => 'rw', isa => Int, init_arg => undef, default => 0);
72 60 ▶has statements => (is => 'rw', isa => ArrayRef[ConsumerOf['Attean::API::Quad']], init_arg => undef, default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
73 60 ▶has subject => (is => 'ro', isa => HashRef[InstanceOf['Set::Scalar']], init_arg => undef, default => sub { +{} });
Subroutine __ANON__: called CC=1 SCAR=0.0
74 60 ▶has predicate => (is => 'ro', isa => HashRef[InstanceOf['Set::Scalar']], init_arg => undef, default => sub { +{} });
Subroutine __ANON__: called CC=1 SCAR=0.0
75 60 ▶has object => (is => 'ro', isa => HashRef[InstanceOf['Set::Scalar']], init_arg => undef, default => sub { +{} });
Subroutine __ANON__: called CC=1 SCAR=0.0
76 60 ▶has graph => (is => 'ro', isa => HashRef[InstanceOf['Set::Scalar']], init_arg => undef, default => sub { +{} });
Subroutine __ANON__: called CC=1 SCAR=0.0
77 60 ▶has graph_nodes => (is => 'rw', isa => HashRef[ConsumerOf['Attean::API::IRI']], init_arg => undef, default => sub { +{} });
Subroutine __ANON__: called CC=1 SCAR=0.0
78 60 ▶has hash => (is => 'rw', isa => InstanceOf['Digest::SHA'], default => sub { Digest::SHA->new });
Subroutine __ANON__: called CC=1 SCAR=0.0
79 60 ▶has mtime => (is => 'rw', isa => Int, default => sub { return time() });
Subroutine __ANON__: called CC=1 SCAR=0.0
80  
81 =item C<< size >>
82  
83 Returns the number of quads in the store.
84  
85 =cut
86  
87 25 ▶sub size {
Subroutine size: called CC=1 SCAR=0.0
Pod documented
88 shift->_size()
89 25 }
90  
91 =item C<< get_quads ( $subject, $predicate, $object, $graph ) >>
92  
93 Returns a stream object of all statements matching the specified subject,
94 predicate and objects. Any of the arguments may be undef to match any value.
95  
96 =cut
97  
98 107 ▶sub get_quads {
Subroutine get_quads: called CC=2 SCAR=7.0
Pod documented
99 107 my $self = shift;
100 107 ▶ my @nodes = map { ref($_) eq 'ARRAY' ? $_ : [$_] } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 402 402
101 107 my @iters;
102 107 cartesian { push(@iters, $self->_get_quads(@_)) } @nodes;
103 107 return Attean::IteratorSequence->new( iterators => \@iters, item_type => 'Attean::API::Quad' );
104 }
105  
106 107 ▶sub _get_quads {
Subroutine _get_quads: called CC=16 SCAR=27.8
107 107 my $self = shift;
108 107 my @nodes = @_;
109 107 my @pos_names = Attean::QuadPattern->variables;
110
111 107 my %pattern_bound;
112 107 foreach my $pos (0 .. 3) {
113 428 my $n = $nodes[ $pos ];
114 428 $pattern_bound{ $pos_names[$pos] } = $n;
115 }
116
117 # create a quadpattern that includes any embedded triple patterns (RDF-star)
118 107 my $pattern = Attean::QuadPattern->new(%pattern_bound);
119  
120 107 my %bound;
121 107 my $bound = 0;
122 107 my %embedded_triple_vars;
123 107 my $seen_embedded_triple = 0;
124 107 foreach my $pos (0 .. 3) {
125 428 my $n = $nodes[ $pos ];
126 428 ▶ if (blessed($n) and $n->does('Attean::API::TriplePattern')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($n) and $n->does("Attean::API::TriplePattern")) 0 428 428
Condition66%2/3
builtin::blessed($n) and $n->does("Attean::API::TriplePattern")
!ll&&!rl&&r
1772510
MC/DC0%0/2
builtin::blessed($n) and $n->does("Attean::API::TriplePattern")
builtin::blessed($n) $n->does("Attean::API::TriplePattern")
Truth table66%2/3
A and B
A= builtin::blessed($n)B= $n->does("Attean::API::TriplePattern")
ABresult
0X0
100
111
127 # replace embedded triple patterns with variables.
128 # the quads that match with the new variables will be filtered
129 # in post-processing below to ensure that they also match the
130 # embedded triple patterns.
131 0 $seen_embedded_triple = 1;
132 0 my $v = Attean::Variable->new();
133 0 $embedded_triple_vars{$v->value} = $n;
134 0 $nodes[$pos] = $v;
135 0 $n = $v;
136 }
137
138 428 ▶ if (blessed($n) and $n->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($n) and $n->does("Attean::API::Variable")) 86 342 428
Condition100%3/3
builtin::blessed($n) and $n->does("Attean::API::Variable")
!ll&&!rl&&r
17716586
MC/DC100%2/2
builtin::blessed($n) and $n->does("Attean::API::Variable")
builtin::blessed($n) $n->does("Attean::API::Variable")
Truth table100%3/3
A and B
A= builtin::blessed($n)B= $n->does("Attean::API::Variable")
ABresult
0X0
100
111
139 86 $n = undef;
140 86 $nodes[$pos] = undef;
141 }
142 428 ▶ if (blessed($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($n)) 165 263 428
143 165 $bound++;
144 165 $bound{ $pos } = $n;
145 }
146 }
147
148 107 ▶ if ($bound == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bound == 0) 23 84 107
149 23 my $i = 0;
150 71 ▶ my $sub = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
151 71 ▶ return unless ($i <= $#{ $self->statements });
Branch: 1 branch
BranchTrueFalseTotal
unless $i <= $#{$self->statements;} 21 50 71
152 50 my $st = $self->statements->[ $i ];
153 50 ▶ while (not(blessed($st)) and ($i <= $#{ $self->statements })) {
Branch: 1 branch
BranchTrueFalseTotal
if (not builtin::blessed($st) and $i <= $#{$self->statements;}) 1 50 51
Condition66%2/3
not builtin::blessed($st) and $i <= $#{$self->statements;}
!ll&&!rl&&r
5001
MC/DC50%1/2
not builtin::blessed($st) and $i <= $#{$self->statements;}
not builtin::blessed($st) $i <= $#{$self->statements;}
Truth table66%2/3
not(A) and B
A= not builtin::blessed($st)B= $i <= $#{$self->statements;}
ABresult
0X0
100
111
154 1 $i++;
155 1 $st = $self->statements->[ $i ];
156 }
157 50 $i++;
158 50 return $st;
159 23 };
160 23 return Attean::CodeIterator->new( generator => $sub, item_type => 'Attean::API::Quad' )->matching_pattern($pattern);
161 }
162
163 84 my $match_set;
164 84 ▶ if ($bound == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bound == 1) { } 32 52 84
165 32 my ($pos) = keys %bound;
166 32 my $name = $pos_names[ $pos ];
167 32 my $node = $bound{ $pos };
168 32 my $string = $node->as_string;
169 32 $match_set = $self->$name()->{ $string };
170 32 ▶ unless (blessed($match_set)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($match_set)) 1 31 32
171 1 return Attean::ListIterator->new( values => [], item_type => 'Attean::API::Quad' );
172 }
173 } else {
174 52 my @pos = keys %bound;
175 52 my @names = @pos_names[ @pos ];
176
177 52 my @sets;
178 52 foreach my $i (0 .. $#pos) {
179 133 my $pos = $pos[ $i ];
180 133 my $node = $bound{ $pos };
181 133 ▶ Carp::confess unless ($node->can('as_string'));
Branch: 1 branch
BranchTrueFalseTotal
unless $node->can("as_string") 0 133 133
182 133 my $string = $node->as_string;
183 133 my $name = $names[$i];
184 133 my $hash = $self->$name();
185 133 my $set = $hash->{ $string };
186 133 push(@sets, $set);
187 }
188
189 52 foreach my $s (@sets) {
190 127 ▶ unless (blessed($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($s)) 5 122 127
191 5 return Attean::ListIterator->new( values => [], item_type => 'Attean::API::Quad' );
192 }
193 }
194 47 my $i = shift(@sets);
195 47 ▶ while (@sets) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sets) 72 47 119
196 72 my $s = shift(@sets);
197 72 $i = $i->intersection($s);
198 }
199 47 $match_set = $i;
200 }
201
202 78 my @e = $match_set->elements;
203 199 ▶ my $sub = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
204 199 ▶ return unless (scalar(@e));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @e 70 129 199
205 129 my $e = shift(@e);
206 129 my $st = $self->statements->[ $e ];
207 129 return $st;
208 78 };
209 78 return Attean::CodeIterator->new( generator => $sub, item_type => 'Attean::API::Quad' )->matching_pattern($pattern);
210 }
211  
212 =item C<< get_graphs >>
213  
214 Returns an iterator over the Attean::API::Term objects comprising
215 the set of graphs of the stored quads.
216  
217 =cut
218  
219 18 ▶sub get_graphs {
Subroutine get_graphs: called CC=1 SCAR=0.0
Pod documented
220 18 my $self = shift;
221 18 my @ctx = values %{ $self->graph_nodes() };
222 18 return Attean::ListIterator->new( values => \@ctx, item_type => 'Attean::API::Term' );
223 }
224  
225 =item C<< add_quad ( $quad ) >>
226  
227 Adds the specified C<$quad> to the underlying model.
228  
229 =cut
230  
231 140 ▶sub add_quad {
Subroutine add_quad: called CC=5 SCAR=16.1
Pod documented
232 140 my $self = shift;
233 140 my $st = shift;
234
235 140 my $count = $self->count_quads( $st->values );
236 140 ▶ if ($count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 0) 140 0 140
237 140 $self->_size($self->_size + 1);
238 140 my $id = scalar(@{ $self->statements });
239 140 $self->hash->add('+' . encode_utf8($st->as_string));
240 140 $self->mtime(time());
241 140 push( @{ $self->statements }, $st );
242 140 foreach my $pos (0 .. $#pos_names) {
243 560 my $name = $pos_names[ $pos ];
244 560 my $node = $st->$name();
245 560 my $string = $node->as_string;
246 560 my $set = $self->$name()->{ $string };
247 560 ▶ unless (blessed($set)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($set)) 355 205 560
248 355 $set = Set::Scalar->new();
249 355 $self->$name()->{ $string } = $set;
250 }
251 560 $set->insert( $id );
252 }
253
254 140 my $ctx = $st->graph;
255 140 my $str = $ctx->as_string;
256 140 ▶ unless (exists $self->graph_nodes->{ $str }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->graph_nodes->{$str}) 59 81 140
257 59 $self->graph_nodes->{ $str } = $ctx;
258 }
259 }
260 140 return;
261 }
262  
263 =item C<< remove_quad ( $statement ) >>
264  
265 Removes the specified C<$statement> from the underlying model.
266  
267 =cut
268  
269 17 ▶sub remove_quad {
Subroutine remove_quad: called CC=5 SCAR=16.1
Pod documented
270 17 my $self = shift;
271 17 my $st = shift;
272
273 17 my @nodes = $st->values;
274 17 my $count = $self->count_quads( @nodes[ 0..3 ] );
275 17 ▶ if ($count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count > 0) 16 1 17
276 16 $self->_size( $self->_size - 1 );
277 16 my $id = $self->_statement_id( $st->values );
278 16 $self->hash->add('-' . encode_utf8($st->as_string));
279 16 $self->mtime(time());
280 16 $self->statements->[ $id ] = undef;
281 16 foreach my $pos (0 .. 3) {
282 64 my $name = $pos_names[ $pos ];
283 64 my $node = $st->$name();
284 64 my $str = $node->as_string;
285 64 my $set = $self->$name()->{ $str };
286 64 $set->delete( $id );
287 64 ▶ if ($set->size == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set->size == 0) 37 27 64
288 37 ▶ if ($pos == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos == 3) 8 29 37
289 8 delete $self->graph_nodes->{ $str };
290 }
291 37 delete $self->$name()->{ $str };
292 }
293 }
294 }
295 17 return;
296 }
297  
298 =item C<< remove_quads ( $subject, $predicate, $object, $graph ) >>
299  
300 Removes the specified C<$statement> from the underlying model.
301  
302 =cut
303  
304 2 ▶sub remove_quads {
Subroutine remove_quads: called CC=2 SCAR=6.9
Pod documented
305 2 my $self = shift;
306 2 ▶ my @nodes = map { ref($_) eq 'ARRAY' ? $_ : [$_] } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 1 3 4
307 2 my @iters;
308 2 ▶ cartesian { $self->_remove_quads(@_) } @nodes;
Subroutine __ANON__: called CC=1 SCAR=0.0
309 }
310  
311 3 ▶sub _remove_quads {
Subroutine _remove_quads: called CC=2 SCAR=6.9
312 3 my $self = shift;
313 3 my $subj = shift;
314 3 my $pred = shift;
315 3 my $obj = shift;
316 3 my $graph = shift;
317 3 my $iter = $self->get_quads( $subj, $pred, $obj, $graph );
318 3 ▶ while (my $st = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $st = $iter->next) 3 3 6
319 3 $self->remove_quad( $st );
320 }
321 }
322  
323 =item C<< create_graph( $graph ) >>
324  
325 This is a no-op function for the memory quad-store.
326  
327 =cut
328  
329 4 ▶sub create_graph {
Subroutine create_graph: called CC=1 SCAR=0.0
Pod documented
330 # no-op on a quad-store
331 }
332  
333 =item C<< drop_graph( $graph ) >>
334  
335 Removes all quads with the given C<< $graph >>.
336  
337 =cut
338  
339 2 ▶sub drop_graph {
Subroutine drop_graph: called CC=1 SCAR=0.0
Pod documented
340 2 my $self = shift;
341 2 return $self->clear_graph(@_);
342 }
343  
344 =item C<< clear_graph( $graph ) >>
345  
346 Removes all quads with the given C<< $graph >>.
347  
348 =cut
349  
350 4 ▶sub clear_graph {
Subroutine clear_graph: called CC=3 SCAR=11.0
Pod documented
351 4 my $self = shift;
352 4 my $g = shift;
353 4 my $string = $g->as_string;
354 4 my $set = $self->graph()->{ $string };
355 4 ▶ return unless (blessed($set));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($set) 0 4 4
356
357 4 my @quads = @{ $self->statements}[ $set->elements ];
358 4 foreach my $q (@quads) {
359 6 $self->remove_quad($q);
360 }
361 }
362  
363 =item C<< count_quads ( $subject, $predicate, $object, $graph ) >>
364  
365 Returns a count of all the statements matching the specified subject,
366 predicate, object, and graph. Any of the arguments may be undef to match any
367 value.
368  
369 =cut
370  
371 220 ▶sub count_quads {
Subroutine count_quads: called CC=2 SCAR=6.9
Pod documented
372 220 my $self = shift;
373 220 ▶ my @nodes = map { ref($_) eq 'ARRAY' ? $_ : [$_] } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 27 769 796
374 220 my $count = 0;
375 220 ▶ cartesian { $count += $self->_count_quads(@_) } @nodes;
Subroutine __ANON__: called CC=1 SCAR=0.0
376 220 return $count;
377 }
378  
379 220 ▶sub _count_quads {
Subroutine _count_quads: called CC=13 SCAR=25.7
380 220 my $self = shift;
381 220 my @nodes = @_[0..3];
382 220 my $bound = 0;
383 220 my %bound;
384
385 220 foreach my $pos (0 .. 3) {
386 880 my $n = $nodes[ $pos ];
387 880 ▶ if (ref($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $n) 779 101 880
388 779 ▶ Carp::confess "Non-Attean node?" unless (ref($n) =~ /Attean/);
Branch: 1 branch
BranchTrueFalseTotal
unless ref($n) =~ /Attean/u 0 779 779
389 }
390 880 ▶ if (blessed($n) and not($n->does('Attean::API::Variable'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($n) and not $n->does("Attean::API::Variable")) 737 143 880
Condition100%3/3
builtin::blessed($n) and not $n->does("Attean::API::Variable")
!ll&&!rl&&r
10142737
MC/DC100%2/2
builtin::blessed($n) and not $n->does("Attean::API::Variable")
builtin::blessed($n) not $n->does("Attean::API::Variable")
Truth table100%3/3
A and not(B)
A= builtin::blessed($n)B= not $n->does("Attean::API::Variable")
ABresult
0X0
100
111
391 737 $bound++;
392 737 $bound{ $pos } = $n;
393 }
394 }
395
396 220 ▶ if ($bound == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bound == 0) { } 3 217 220
elsif ($bound == 1) { } 28 189 217
397 3 return $self->_size;
398 } elsif ($bound == 1) {
399 28 my ($pos) = keys %bound;
400 28 my $name = $pos_names[ $pos ];
401 28 my $set = $self->$name()->{ $bound{ $pos }->as_string };
402 28 ▶ unless (blessed($set)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($set)) 5 23 28
403 5 return 0;
404 }
405 23 return $set->size;
406 } else {
407 189 my @pos = keys %bound;
408 189 my @names = @pos_names[ @pos ];
409 189 my @sets;
410 189 foreach my $i (0 .. $#names) {
411 709 my $pos = $pos[ $i ];
412 709 my $setname = $names[ $i ];
413 709 my $data = $self->$setname();
414
415 709 my $node = $bound{ $pos };
416 709 my $str = $node->as_string;
417 709 my $set = $data->{ $str };
418 709 push( @sets, $set );
419 }
420 189 foreach my $s (@sets) {
421 337 ▶ unless (blessed($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($s)) 166 171 337
422 166 return 0;
423 }
424 }
425 23 my $i = shift(@sets);
426 23 ▶ while (@sets) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sets) 59 23 82
427 59 my $s = shift(@sets);
428 59 $i = $i->intersection($s);
429 }
430 23 return $i->size;
431 }
432 }
433  
434 =item C<< etag_value_for_quads >>
435  
436 If the store has the capability and knowledge to support caching, returns a
437 persistent token that will remain consistent as long as the store's data doesn't
438 change. This token is acceptable for use as an HTTP ETag.
439  
440 =cut
441  
442 3 ▶sub etag_value_for_quads {
Subroutine etag_value_for_quads: called CC=1 SCAR=0.0
Pod documented
443 3 my $self = shift;
444 3 return $self->hash->b64digest;
445 }
446  
447 =item C<< mtime_for_quads >>
448  
449 =cut
450  
451 3 ▶sub mtime_for_quads {
Subroutine mtime_for_quads: called CC=1 SCAR=0.0
Pod documented
452 3 my $self = shift;
453 3 return $self->mtime;
454 }
455  
456 16 ▶sub _statement_id {
Subroutine _statement_id: called CC=6 SCAR=18.0
457 16 my $self = shift;
458 16 my @nodes = @_;
459 16 my ($subj, $pred, $obj, $graph) = @nodes;
460
461 16 my @pos = (0 .. 3);
462 16 my @names = @pos_names[ @pos ];
463 16 my @sets;
464 16 foreach my $i (0 .. $#names) {
465 64 my $pos = $pos[ $i ];
466 64 my $setname = $names[ $i ];
467 64 my $data = $self->$setname();
468 64 my $node = $nodes[ $pos ];
469 64 my $str = $node->as_string;
470 64 my $set = $data->{ $str };
471 64 push( @sets, $set );
472 }
473
474 16 foreach my $s (@sets) {
475 64 ▶ unless (blessed($s)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($s)) 0 64 64
476 0 return -1;
477 }
478 }
479 16 my $i = shift(@sets);
480 16 ▶ while (@sets) {
Branch: 1 branch
BranchTrueFalseTotal
if (@sets) 48 16 64
481 48 my $s = shift(@sets);
482 48 $i = $i->intersection($s);
483 }
484 16 ▶ if ($i->size == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i->size == 1) { } 16 0 16
485 16 my ($id) = $i->elements;
486 16 return $id;
487 } else {
488 0 return -1;
489 }
490 }
491  
492  
493 =item C<< plans_for_algebra >>
494  
495 The store implements a cost-based query planner, but this method is
496 reimplemented to hand the overall control of the planning process to
497 an external planner by returning C<undef>.
498  
499 =cut
500  
501 128 ▶sub plans_for_algebra {
Subroutine plans_for_algebra: called CC=1 SCAR=0.0
Pod documented
502 128 my $self = shift;
503 128 my $algebra = shift;
504 128 return;
505 }
506  
507  
508 =item C<< cost_for_plan >>
509  
510 This store provides a cost estimate only for retrieving individual
511 quad patterns in this method. It will allow other planners to estimate
512 the cost for any other parts of the plan by returning C<undef> for
513 those parts.
514  
515 =cut
516  
517 88 ▶sub cost_for_plan {
Subroutine cost_for_plan: called CC=2 SCAR=6.9
Pod documented
518 88 my $self = shift;
519 88 my $plan = shift;
520 88 ▶ if ($plan->isa('Attean::Plan::Quad')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->isa("Attean::Plan::Quad")) 27 61 88
521 27 my @values = $plan->values;
522 27 my $count = $self->count_quads(@values);
523 27 return $count;
524 }
525 61 return;
526 }
527  
528 }
529  
530 11 1;
531  
532 __END__
« AtteanX/Parser/SPARQLJSON.pm ↑ Summary Attean/QuadModel.pm »