RDF/Trine/Store/Hexastore.pm

filter: Statementstmt 92.8% 479 / 516 Branchbran 81.7% 121 / 148 Conditioncond 77.5% 31 / 40 MC/DCmcdc 56.0% 14 / 25 Subroutinesub 91.2% 52 / 57 Podpod 100% 13 / 13 totaltotal 88.8% 710 / 799 CC 104 SCAR 25.0
CC
104
Cov
90%
get_statements
35.8
get_pattern
17.5
_new_with_config
11.7
CRAP 12.2
« RDF/Trine/Model/StatementFilter.pm ↑ Summary RDF/Trine/Model.pm »
1 =head1 NAME
2  
3 RDF::Trine::Store::Hexastore - RDF store implemented with the hexastore index
4  
5 =head1 VERSION
6  
7 This document describes RDF::Trine::Store::Hexastore version 1.019
8  
9 =head1 SYNOPSIS
10  
11 use RDF::Trine::Store::Hexastore;
12  
13 =head1 DESCRIPTION
14  
15 RDF::Trine::Store::Hexastore provides an in-memory triple-store based on
16 six-way indexing as popularized by Hexastore.
17  
18 =cut
19  
20 package RDF::Trine::Store::Hexastore;
21  
22 68 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 68 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 68 ▶use base qw(RDF::Trine::Store);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 68 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 68 ▶use RDF::Trine qw(iri);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 68 ▶use RDF::Trine::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 68 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 68 ▶use Scalar::Util qw(refaddr reftype blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 68 ▶use Storable qw(nstore retrieve);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 68 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
34 68 ▶use Time::HiRes qw ( time );
Subroutine BEGIN: called CC=1 SCAR=0.0
35 68 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 68 ▶use constant NODES => qw(subject predicate object);
Subroutine BEGIN: called CC=1 SCAR=0.0
38 68 ▶use constant NODEMAP => { subject => 0, predicate => 1, object => 2, context => 3 };
Subroutine BEGIN: called CC=1 SCAR=0.0
39 68 ▶use constant OTHERNODES => {
Subroutine BEGIN: called CC=1 SCAR=0.0
40 subject => [qw(predicate object)],
41 predicate => [qw(subject object)],
42 object => [qw(subject predicate)],
43 68 };
44  
45 ######################################################################
46  
47 68 our $VERSION;
48 68 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
49 68 $VERSION = "1.019";
50 68 my $class = __PACKAGE__;
51 68 $RDF::Trine::Store::STORE_CLASSES{ $class } = $VERSION;
52 }
53  
54 ######################################################################
55  
56 0 ▶sub _config_meta {
Subroutine _config_meta: not called CC=1 SCAR=6.9
57 return {
58 0 required_keys => [],
59 fields => {},
60 }
61 }
62  
63  
64 =head1 METHODS
65  
66 Beyond the methods documented below, this class inherits methods from the
67 L<RDF::Trine::Store> class.
68  
69 =over 4
70  
71 =item C<< new () >>
72  
73 Returns a new storage object.
74  
75 =item C<new_with_config ( $hashref )>
76  
77 Returns a new storage object configured with a hashref with certain
78 keys as arguments.
79  
80 The C<storetype> key must be C<Hexastore> for this backend.
81  
82 This module also supports initializing the store from a file or URL,
83 in which case, a C<sources> key may be used. This holds an arrayref of
84 hashrefs. To load a file, you may give the file name with a C<file>
85 key in the hashref, and to load a URL, use C<url>. See example
86 below. Furthermore, the following keys may be used:
87  
88 =over
89  
90 =item C<syntax>
91  
92 The syntax of the parsed file or URL.
93  
94 =item C<base_uri>
95  
96 The base URI to be used for a parsed file.
97  
98 =back
99  
100 The following example initializes a Hexastore store based on a local file and a remote URL:
101  
102 my $store = RDF::Trine::Store->new_with_config( {
103 storetype => 'Hexastore',
104 sources => [
105 {
106 file => 'test-23.ttl',
107 syntax => 'turtle',
108 },
109 {
110 url => 'http://www.kjetil.kjernsmo.net/foaf',
111 syntax => 'rdfxml',
112 }
113 ]});
114  
115  
116 =cut
117  
118 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
119 5 my $class = shift;
120 5 my $self = bless({}, $class);
121 5 $self->nuke; # nuke resets the store, thus doing the same thing as init should do
122 5 return $self;
123 }
124  
125 1 ▶sub _new_with_string {
Subroutine _new_with_string: called CC=1 SCAR=0.0
126 1 my ($self, $config) = @_;
127 1 my ($filename) = $config =~ m/file=(.+)$/; # TODO: It has a Storable part too, for later use.
128 1 return $self->load($filename);
129 }
130  
131 # TODO: Refactor, almost identical to Memory
132 1 ▶sub _new_with_config {
Subroutine _new_with_config: called CC=8 SCAR=24.6
133 1 my $class = shift;
134 1 my $config = shift;
135 1 ▶ my @sources = @{ $config->{sources} || [] };
Condition50%1/2
$config->{'sources'} || []
l!l
10
MC/DC0%0/1
$config->{'sources'} || []
$config->{'sources'}
Truth table50%1/2
A
A= $config->{'sources'}
Aresult
11
00
136 1 my $self = $class->new();
137 1 foreach my $source (@sources) {
138 2 my %args;
139 2 ▶ if (my $g = $source->{graph}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $g = $source->{"graph"}) 0 2 2
140 0 ▶ $args{context} = (blessed($g) ? $g : iri($g));
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($g) ? : 0 0 0
141 }
142 2 ▶ if ($source->{url}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($source->{'url'}) { } 0 2 2
elsif ($source->{'file'}) { } 2 0 2
143 0 my $parser = RDF::Trine::Parser->new($source->{syntax});
144 0 my $model = RDF::Trine::Model->new( $self );
145 0 $parser->parse_url_into_model( $source->{url}, $model, %args );
146 } elsif ($source->{file}) {
147 2 ▶ open(my $fh, "<:encoding(UTF-8)", $source->{file}) || throw RDF::Trine::Error -text => "Couldn't open file $source->{file}";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:encoding(UTF-8)", $source->{"file"} or "RDF::Trine::Error"->throw("-text", qq[Couldn't open file $source->{"file"}]) 2 0 2
148 2 my $parser = RDF::Trine::Parser->new($source->{syntax});
149 2 my $model = RDF::Trine::Model->new( $self );
150 2 $parser->parse_file_into_model( $source->{base_uri}, $source->{file}, $model, %args );
151 } else {
152 0 throw RDF::Trine::Error::MethodInvocationError -text => "$class needs a url or file argument";
153 }
154 }
155 1 return $self;
156 }
157  
158  
159  
160  
161 =item C<< store ( $filename ) >>
162  
163 Write the triples data to a file specified by C<< $filename >>.
164 This data may be read back in with the C<< load >> method.
165  
166 =cut
167  
168 1 ▶sub store {
Subroutine store: called CC=1 SCAR=0.0
Pod documented
169 1 my $self = shift;
170 1 my $fname = shift;
171 1 nstore( $self, $fname );
172 }
173  
174 =item C<< load ( $filename ) >>
175  
176 Returns a new Hexastore object with triples data from the specified file.
177  
178 =cut
179  
180 2 ▶sub load {
Subroutine load: called CC=1 SCAR=0.0
Pod documented
181 2 my $class = shift;
182 2 my $fname = shift;
183 2 return retrieve($fname);
184 }
185  
186 =item C<< temporary_store >>
187  
188 Returns a temporary (empty) triple store.
189  
190 =cut
191  
192 1 ▶sub temporary_store {
Subroutine temporary_store: called CC=1 SCAR=0.0
Pod documented
193 1 my $class = shift;
194 1 return $class->new();
195 }
196  
197 =item C<< get_statements ($subject, $predicate, $object [, $context] ) >>
198  
199 Returns a stream object of all statements matching the specified subject,
200 predicate and objects. Any of the arguments may be undef to match any value.
201  
202 =cut
203  
204 32 ▶sub get_statements {
Subroutine get_statements: called CC=34 SCAR=35.8
Pod documented
205 32 my $self = shift;
206 32 my @nodes = splice(@_, 0, 3);
207 32 my $context = shift;
208 32 my %args = @_;
209 32 ▶ my @orderby = (ref($args{orderby})) ? @{$args{orderby}} : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'orderby'} ? : 5 27 32
210
211 32 ▶ if (defined($context) and not($context->isa('RDF::Trine::Node::Nil'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context and not $context->isa("RDF::Trine::Node::Nil")) 0 32 32
Condition66%2/3
defined $context and not $context->isa("RDF::Trine::Node::Nil")
!ll&&!rl&&r
2840
MC/DC0%0/2
defined $context and not $context->isa("RDF::Trine::Node::Nil")
defined $context not $context->isa("RDF::Trine::Node::Nil")
Truth table66%2/3
A and not(B)
A= defined $contextB= not $context->isa("RDF::Trine::Node::Nil")
ABresult
0X0
100
111
212 0 return RDF::Trine::Iterator::Graph->new( [] );
213 }
214
215 32 my $defined = 0;
216 32 my %variable_map;
217 32 foreach my $i (0 .. 2) {
218 96 my $node = $nodes[ $i ];
219 96 my $pos = (NODES)[ $i ];
220 96 ▶ $defined++ if (defined($node) and not($node->isa('RDF::Trine::Node::Variable')));
Branch: 1 branch
BranchTrueFalseTotal
if defined $node and not $node->isa("RDF::Trine::Node::Variable") 38 58 96
Condition100%3/3
defined $node and not $node->isa("RDF::Trine::Node::Variable")
!ll&&!rl&&r
352338
MC/DC100%2/2
defined $node and not $node->isa("RDF::Trine::Node::Variable")
defined $node not $node->isa("RDF::Trine::Node::Variable")
Truth table100%3/3
A and not(B)
A= defined $nodeB= not $node->isa("RDF::Trine::Node::Variable")
ABresult
0X0
100
111
221 96 ▶ if (blessed($node) and $node->isa('RDF::Trine::Node::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa("RDF::Trine::Node::Variable")) 23 73 96
Condition100%3/3
builtin::blessed($node) and $node->isa("RDF::Trine::Node::Variable")
!ll&&!rl&&r
353823
MC/DC100%2/2
builtin::blessed($node) and $node->isa("RDF::Trine::Node::Variable")
builtin::blessed($node) $node->isa("RDF::Trine::Node::Variable")
Truth table100%3/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Trine::Node::Variable")
ABresult
0X0
100
111
222 23 $variable_map{ $node->name } = $pos;
223 }
224 }
225
226 32 my @ids = map { $self->_node2id( $_ ) } @nodes;
227 32 my @names = NODES;
228 32 my @keys = map { $names[$_], $ids[$_] } (0 .. $#names);
229 32 ▶ if ($defined == 3) {
Branch: 3 branches
BranchTrueFalseTotal
if ($defined == 3) { } 3 29 32
elsif ($defined == 2) { } 8 21 29
elsif ($defined == 1) { } 13 8 21
230 3 my $index = $self->_index_from_pair( $self->_index_root, @keys[ 0,1 ] );
231 3 my $list = $self->_index_from_pair( $index, @keys[ 2,3 ] );
232 3 ▶ if ($self->_page_contains_node( $list, $ids[2] )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_page_contains_node($list, $ids[2])) { } 1 2 3
233 1 return RDF::Trine::Iterator::Graph->new( [ RDF::Trine::Statement->new( @nodes ) ] );
234 } else {
235 2 return RDF::Trine::Iterator::Graph->new( [] );
236 }
237 } elsif ($defined == 2) {
238 8 my @dkeys;
239 my $ukey;
240 8 foreach my $i (0 .. 2) {
241 24 ▶ if (defined($nodes[ $i ]) and not($nodes[ $i ]->isa('RDF::Trine::Node::Variable'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nodes[$i] and not $nodes[$i]->isa('RDF::Trine::Node::Variable')) { } 16 8 24
Condition100%3/3
defined $nodes[$i] and not $nodes[$i]->isa("RDF::Trine::Node::Variable")
!ll&&!rl&&r
4416
MC/DC100%2/2
defined $nodes[$i] and not $nodes[$i]->isa("RDF::Trine::Node::Variable")
defined $nodes[$i] not $nodes[$i]->isa("RDF::Trine::Node::Variable")
Truth table100%3/3
A and not(B)
A= defined $nodes[$i]B= not $nodes[$i]->isa("RDF::Trine::Node::Variable")
ABresult
0X0
100
111
242 16 push( @dkeys, $names[$i] );
243 } else {
244 8 $ukey = $names[$i];
245 }
246 }
247 8 @keys = map { $_ => $self->_node2id( $nodes[ NODEMAP->{ $_ } ] ) } @dkeys;
248
249 8 my $index = $self->_index_from_pair( $self->_index_root, @keys[ 0,1 ] );
250 8 my $list = $self->_index_from_pair( $index, @keys[ 2,3 ] );
251
252 8 my @local_list = $self->_node_values( $list );
253 24 ▶ my $sub = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
254 24 ▶ return unless (scalar(@local_list));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @local_list 8 16 24
255 16 my $id = shift(@local_list);
256 16 my %data = map { $_ => $nodes[ NODEMAP->{ $_ } ] } @dkeys;
257 16 $data{ $ukey } = $self->_id2node( $id );
258 16 my $st = RDF::Trine::Statement->new( @data{qw(subject predicate object)} );
259 16 return $st;
260 8 };
261 8 return RDF::Trine::Iterator::Graph->new( $sub );
262 } elsif ($defined == 1) {
263 13 my $dkey;
264 my @ukeys;
265 13 my $uvar;
266 13 my $check_dup = 0;
267 13 foreach my $i (0 .. 2) {
268 39 ▶ if (defined($nodes[ $i ]) and not($nodes[ $i ]->isa('RDF::Trine::Node::Variable'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nodes[$i] and not $nodes[$i]->isa('RDF::Trine::Node::Variable')) { } 13 26 39
Condition100%3/3
defined $nodes[$i] and not $nodes[$i]->isa("RDF::Trine::Node::Variable")
!ll&&!rl&&r
161013
MC/DC100%2/2
defined $nodes[$i] and not $nodes[$i]->isa("RDF::Trine::Node::Variable")
defined $nodes[$i] not $nodes[$i]->isa("RDF::Trine::Node::Variable")
Truth table100%3/3
A and not(B)
A= defined $nodes[$i]B= not $nodes[$i]->isa("RDF::Trine::Node::Variable")
ABresult
0X0
100
111
269 13 $dkey = $names[$i];
270 } else {
271 26 ▶ if (blessed($nodes[ $i ]) and $nodes[ $i ]->isa('RDF::Trine::Node::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($nodes[$i]) and $nodes[$i]->isa("RDF::Trine::Node::Variable")) 10 16 26
Condition66%2/3
builtin::blessed($nodes[$i]) and $nodes[$i]->isa("RDF::Trine::Node::Variable")
!ll&&!rl&&r
16010
MC/DC50%1/2
builtin::blessed($nodes[$i]) and $nodes[$i]->isa("RDF::Trine::Node::Variable")
builtin::blessed($nodes[$i]) $nodes[$i]->isa("RDF::Trine::Node::Variable")
Truth table66%2/3
A and B
A= builtin::blessed($nodes[$i])B= $nodes[$i]->isa("RDF::Trine::Node::Variable")
ABresult
0X0
100
111
272 10 ▶ if (defined($uvar)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $uvar) { } 5 5 10
273 5 ▶ if ($uvar eq $nodes[ $i ]->name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uvar eq $nodes[$i]->name) 0 5 5
274 0 $check_dup = 1;
275 }
276 } else {
277 5 $uvar = $nodes[ $i ]->name;
278 }
279 }
280 26 push( @ukeys, $names[$i] );
281 }
282 }
283 13 @keys = ($dkey => $self->_node2id( $nodes[ NODEMAP->{ $dkey } ] ));
284
285 13 my $rev = 0;
286 13 ▶ if (@orderby) {
Branch: 1 branch
BranchTrueFalseTotal
if (@orderby) 3 10 13
287 3 ▶ $rev = 1 if ($orderby[1] eq 'DESC');
Branch: 1 branch
BranchTrueFalseTotal
if $orderby[1] eq "DESC" 1 2 3
288 3 my $sortkey = $variable_map{ $orderby[0] };
289 3 ▶ if ($sortkey ne $ukeys[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sortkey ne $ukeys[0]) 2 1 3
290 2 @ukeys = reverse(@ukeys);
291 }
292 }
293
294 13 my $index = $self->_index_from_pair( $self->_index_root, @keys );
295 13 my $ukeys1 = $self->_index_values_from_key( $index, $ukeys[0] );
296 13 my @ukeys1 = $self->_index_values( $ukeys1, $rev );
297  
298 13 my @local_list;
299 my $ukey1;
300 43 ▶ my $sub = sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
301 43 ▶ while (0 == scalar(@local_list)) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == scalar @local_list) 30 34 64
302 30 ▶ return unless (scalar(@ukeys1));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @ukeys1 9 21 30
303 21 $ukey1 = shift(@ukeys1);
304 # warn '>>>>>>>>> ' . Dumper( $ukeys[0], $ukey1, $data );
305 21 my $list = $self->_index_from_pair( $index, $ukeys[0], $ukey1 );
306 21 @local_list = $self->_node_values( $list );
307 21 ▶ if ($check_dup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check_dup) 0 21 21
308 0 @local_list = grep { $_ == $ukey1 } @local_list;
309 }
310 }
311 34 my $id = shift(@local_list);
312 34 my %data = ($dkey => $nodes[ NODEMAP->{ $dkey } ]);
313 34 @data{ @ukeys } = map { $self->_id2node( $_ ) } ($ukey1, $id);
314 34 my $st = RDF::Trine::Statement->new( @data{qw(subject predicate object)} );
315 34 return $st;
316 13 };
317 13 return RDF::Trine::Iterator::Graph->new( $sub );
318 } else {
319 8 my $dup_pos;
320 my $dup_var;
321 8 my %dup_counts;
322 8 my %dup_var_pos;
323 8 my $max = 0;
324 8 foreach my $i (0 .. 2) {
325 24 ▶ if (blessed($nodes[ $i ]) and $nodes[ $i ]->isa('RDF::Trine::Node::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($nodes[$i]) and $nodes[$i]->isa("RDF::Trine::Node::Variable")) 9 15 24
Condition66%2/3
builtin::blessed($nodes[$i]) and $nodes[$i]->isa("RDF::Trine::Node::Variable")
!ll&&!rl&&r
1509
MC/DC50%1/2
builtin::blessed($nodes[$i]) and $nodes[$i]->isa("RDF::Trine::Node::Variable")
builtin::blessed($nodes[$i]) $nodes[$i]->isa("RDF::Trine::Node::Variable")
Truth table66%2/3
A and B
A= builtin::blessed($nodes[$i])B= $nodes[$i]->isa("RDF::Trine::Node::Variable")
ABresult
0X0
100
111
326 9 my $name = $nodes[ $i ]->name;
327 9 push( @{ $dup_var_pos{ $name } }, $names[ $i ] );
328 9 ▶ if (++$dup_counts{ $name } > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$dup_counts{$name} > $max) 3 6 9
329 3 $max = $dup_counts{ $name };
330 3 $dup_pos = $names[ $i ];
331 3 $dup_var = $name;
332 }
333 }
334 }
335 # warn Dumper($dup_pos, $dup_var, $max, \%dup_var_pos);
336
337 8 my $rev = 0;
338 8 my (@order_keys, $final_key);
339 8 ▶ if (@orderby) {
Branch: 1 branch
BranchTrueFalseTotal
if (@orderby) { } 2 6 8
340 2 ▶ $rev = 1 if ($orderby[1] eq 'DESC');
Branch: 1 branch
BranchTrueFalseTotal
if $orderby[1] eq "DESC" 1 1 2
341 2 my $sortkey = $variable_map{ $orderby[0] };
342 2 my @nodes = ($sortkey, grep { $_ ne $sortkey } NODES);
343 2 @order_keys = @nodes[0,1];
344 2 $final_key = $nodes[2];
345 } else {
346 6 $final_key = 'object';
347 6 @order_keys = qw(subject predicate);
348 }
349 8 ▶ if ($max > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max > 1) 0 8 8
350 0 @order_keys = @{ $dup_var_pos{ $dup_var } };
351 0 my %order_keys = map { $_ => 1 } @order_keys;
352 0 ▶ if (3 == scalar(@order_keys)) {
Branch: 1 branch
BranchTrueFalseTotal
if (3 == scalar @order_keys) { } 0 0 0
353 0 $final_key = pop(@order_keys);
354 } else {
355 0 ▶ $final_key = first { not($order_keys{ $_ }) } @names;
Subroutine __ANON__: not called CC=1 SCAR=6.9
356 }
357 }
358
359 8 my $subj = $self->_index_values_from_key( $self->_index_root, $order_keys[0] );
360 8 my @skeys = $self->_index_values( $subj, $rev );
361 8 my ($sid, $pid);
362 8 my @pkeys;
363 8 my @local_list;
364 59 ▶ my $sub = sub {
Subroutine __ANON__: called CC=6 SCAR=18.3
365 59 ▶ while (0 == scalar(@local_list)) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == scalar @local_list) 41 51 92
366 # no more objects. go to next predicate.
367 41 ▶ while (0 == scalar(@pkeys)) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == scalar @pkeys) 28 33 61
368 # no more predicates. go to next subject.
369 28 ▶ return unless (scalar(@skeys));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @skeys 8 20 28
370 20 $sid = shift(@skeys);
371 # warn "*** using subject $sid\n";
372 20 @pkeys = sort { $a <=> $b } keys %{ $subj->{ $sid }{ $order_keys[1] } };
373 20 ▶ if ($max >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max >= 2) 0 20 20
374 0 @pkeys = grep { $_ == $sid } @pkeys;
375 }
376 }
377 33 $pid = shift(@pkeys);
378 # warn "*** using predicate $pid\n";
379 33 my $index = $self->_index_from_pair( $subj, $sid, $order_keys[1] );
380 33 my $list = $self->_node_list_from_id( $index, $pid );
381 33 @local_list = $self->_node_values( $list );
382 33 ▶ if ($max == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max == 3) 0 33 33
383 0 @local_list = grep { $_ == $pid } @local_list;
384 }
385 # warn "---> object list: [" . join(', ', @local_list) . "]\n";
386 }
387 51 my $id = shift(@local_list);
388 51 my %data = (
389 $order_keys[0] => $sid,
390 $order_keys[1] => $pid,
391 $final_key => $id,
392 );
393 51 my @nodes = map { $self->_id2node( $_ ) } (@data{qw(subject predicate object)});
394 51 my $st = RDF::Trine::Statement->new( @nodes );
395 51 return $st;
396 8 };
397 8 return RDF::Trine::Iterator::Graph->new( $sub );
398 }
399 }
400  
401 =item C<< get_pattern ( $bgp [, $context] ) >>
402  
403 Returns a stream object of all bindings matching the specified graph pattern.
404  
405 =cut
406  
407 4 ▶sub get_pattern {
Subroutine get_pattern: called CC=16 SCAR=28.6
Pod documented
408 4 my $self = shift;
409 4 my $bgp = shift;
410 4 ▶ if ($bgp->isa('RDF::Trine::Pattern')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bgp->isa("RDF::Trine::Pattern")) 4 0 4
411 4 $bgp = $bgp->sort_for_join_variables();
412 }
413 4 my @triples = $bgp->triples;
414 4 ▶ if (2 == scalar(@triples)) {
Branch: 1 branch
BranchTrueFalseTotal
if (2 == scalar @triples) { } 3 1 4
415 3 my ($t1, $t2) = @triples;
416 3 my @v1 = $t1->referenced_variables;
417 3 my %v1 = map { $_ => 1 } @v1;
418 3 my @v2 = $t2->referenced_variables;
419 3 my @shared = grep { exists($v1{$_}) } @v2;
420 3 ▶ if (@shared) {
Branch: 1 branch
BranchTrueFalseTotal
if (@shared) { } 1 2 3
421 # warn 'there is a shared variable -- we can use a merge-join';
422 # there is a shared variable -- we can use a merge-join
423 1 my $shrkey = $shared[0];
424 # warn "- $shrkey\n";
425 # warn $t2->as_string;
426 1 my $i1 = $self->SUPER::_get_pattern( RDF::Trine::Pattern->new( $t1 ), undef, orderby => [ $shrkey => 'ASC' ] );
427 1 my $i2 = $self->SUPER::_get_pattern( RDF::Trine::Pattern->new( $t2 ), undef, orderby => [ $shrkey => 'ASC' ] );
428
429 1 my $i1current = $i1->next;
430 1 my $i2current = $i2->next;
431 1 my @results;
432 1 ▶ while (defined($i1current) and defined($i2current)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $i1current and defined $i2current) 1 1 2
Condition66%2/3
defined $i1current and defined $i2current
!ll&&!rl&&r
101
MC/DC50%1/2
defined $i1current and defined $i2current
defined $i1current defined $i2current
Truth table66%2/3
A and B
A= defined $i1currentB= defined $i2current
ABresult
0X0
100
111
433 1 my $i1cur = $i1current->{ $shrkey };
434 1 my $i2cur = $i2current->{ $shrkey };
435 1 ▶ if ($i1current->{ $shrkey }->equal( $i2current->{ $shrkey } )) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i1current->{$shrkey}->equal($i2current->{$shrkey})) { } 1 0 1
elsif ($i1current->{$shrkey}->compare($i2current->{$shrkey}) == -1) { } 0 0 0
436 1 my @matching_i2_rows;
437 1 my $match_value = $i1current->{ $shrkey };
438 1 ▶ while ($match_value->equal( $i2current->{ $shrkey } )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match_value->equal($i2current->{$shrkey})) 4 1 5
439 4 push( @matching_i2_rows, $i2current );
440 4 ▶ unless ($i2current = $i2->next) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($i2current = $i2->next) 0 4 4
441 # warn "no more from i2";
442 0 last;
443 }
444 }
445
446 1 ▶ while ($match_value->equal( $i1current->{ $shrkey } )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match_value->equal($i1current->{$shrkey})) 1 0 1
447 1 foreach my $i2_row (@matching_i2_rows) {
448 4 my $new = $self->_join( $i1current, $i2_row );
449 4 push( @results, $new );
450 }
451 1 ▶ unless ($i1current = $i1->next) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($i1current = $i1->next) 1 0 1
452 # warn "no more from i1";
453 1 last;
454 }
455 }
456 } elsif ($i1current->{ $shrkey }->compare( $i2current->{ $shrkey } ) == -1) {
457 0 my $i1v = $i1current->{ $shrkey };
458 0 my $i2v = $i2current->{ $shrkey };
459 # warn "keys don't match: $i1v <=> $i2v\n";
460 0 $i1current = $i1->next;
461 } else { # ($i1current->{ $shrkey } > $i2current->{ $shrkey })
462 0 my $i1v = $i1current->{ $shrkey };
463 0 my $i2v = $i2current->{ $shrkey };
464 # warn "keys don't match: $i1v <=> $i2v\n";
465 0 $i2current = $i2->next;
466 }
467 }
468 1 return RDF::Trine::Iterator::Bindings->new( \@results, [ $bgp->referenced_variables ] );
469 } else {
470 2 my $l = Log::Log4perl->get_logger("rdf.trine.store.hexastore");
471 2 $l->info('No shared variable -- cartesian product');
472 # no shared variable -- cartesian product
473 2 my $i1 = $self->SUPER::_get_pattern( RDF::Trine::Pattern->new( $t1 ) );
474 2 my $i2 = $self->SUPER::_get_pattern( RDF::Trine::Pattern->new( $t2 ) );
475 2 my @i1;
476 2 ▶ while (my $row = $i1->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $i1->next) 3 2 5
477 3 push(@i1, $row);
478 }
479
480 2 my @results;
481 2 ▶ while (my $row2 = $i2->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row2 = $i2->next) 6 2 8
482 6 foreach my $row1 (@i1) {
483 9 push(@results, { %$row1, %$row2 });
484 }
485 }
486 2 return RDF::Trine::Iterator::Bindings->new( \@results, [ $bgp->referenced_variables ] );
487 }
488 } else {
489 1 return $self->SUPER::_get_pattern( $bgp );
490 }
491 }
492  
493 =item C<< supports ( [ $feature ] ) >>
494  
495 If C<< $feature >> is specified, returns true if the feature is supported by the
496 store, false otherwise. If C<< $feature >> is not specified, returns a list of
497 supported features.
498  
499 =cut
500  
501 0 ▶sub supports {
Subroutine supports: not called CC=1 SCAR=6.9
Pod documented
502 0 return;
503 }
504  
505 4 ▶sub _join {
Subroutine _join: called CC=5 SCAR=16.4
506 4 my $self = shift;
507 4 my $rowa = shift;
508 4 my $rowb = shift;
509
510 4 my %keysa;
511 4 my @keysa = keys %$rowa;
512 4 @keysa{ @keysa } = (1) x scalar(@keysa);
513 4 my @shared = grep { exists $keysa{ $_ } } (keys %$rowb);
514 4 foreach my $key (@shared) {
515 4 my $val_a = $rowa->{ $key };
516 4 my $val_b = $rowb->{ $key };
517 4 ▶ next unless (defined($val_a) and defined($val_b));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val_a and defined $val_b 0 4 4
Condition33%1/3
defined $val_a and defined $val_b
!ll&&!rl&&r
004
MC/DC0%0/2
defined $val_a and defined $val_b
defined $val_a defined $val_b
Truth table33%1/3
A and B
A= defined $val_aB= defined $val_b
ABresult
0X0
100
111
518 4 my $equal = $val_a->equal( $val_b );
519 4 ▶ unless ($equal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($equal) 0 4 4
520 0 return;
521 }
522 }
523
524 4 my $row = { (map { $_ => $rowa->{$_} } grep { defined($rowa->{$_}) } keys %$rowa), (map { $_ => $rowb->{$_} } grep { defined($rowb->{$_}) } keys %$rowb) };
525 4 return $row;
526 }
527  
528 =item C<< get_contexts >>
529  
530 =cut
531  
532 1 ▶sub get_contexts {
Subroutine get_contexts: called CC=1 SCAR=0.0
Pod documented
533 1 my $l = Log::Log4perl->get_logger("rdf.trine.store.hexastore");
534 1 $l->warn("Contexts not supported for the Hexastore store");
535 1 return RDF::Trine::Iterator->new([]);
536 }
537  
538 =item C<< add_statement ( $statement [, $context] ) >>
539  
540 Adds the specified C<$statement> to the underlying model.
541  
542 =cut
543  
544 55 ▶sub add_statement {
Subroutine add_statement: called CC=5 SCAR=16.1
Pod documented
545 55 my $self = shift;
546 55 my $st = shift;
547 55 my $added = 0;
548  
549 # believe it or not, these calls add up.
550 55 my %stmt = map { $_ => $st->$_ } NODES;
551 55 my %ids = map { $_ => $self->_node2id($stmt{$_}) } NODES;
552  
553 55 foreach my $first (NODES) {
554 165 my $firstnode = $stmt{$first};
555 165 my $id1 = $ids{$first};
556 165 my @others = @{ OTHERNODES->{ $first } };
557 165 my @orders = ([@others], [reverse @others]);
558 165 foreach my $order (@orders) {
559 330 my ($second, $third) = @$order;
560 330 my ($id2, $id3) = @ids{$second, $third};
561 330 my $list = $self->_get_terminal_list( $first => $id1, $second => $id2 );
562 330 ▶ if ($self->_add_node_to_page( $list, $id3 )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_add_node_to_page($list, $id3)) 159 171 330
563 159 $added++;
564 }
565 }
566 }
567 55 ▶ if ($added) {
Branch: 1 branch
BranchTrueFalseTotal
if ($added) 53 2 55
568 53 $self->{ size }++;
569 53 $self->{etag} = time;
570 }
571 }
572  
573 =item C<< remove_statement ( $statement [, $context]) >>
574  
575 Removes the specified C<$statement> from the underlying model.
576  
577 =cut
578  
579 13 ▶sub remove_statement {
Subroutine remove_statement: called CC=5 SCAR=16.1
Pod documented
580 13 my $self = shift;
581 13 my $st = shift;
582 13 my @ids = map { $self->_node2id( $st->$_() ) } NODES;
583 # warn "*** removing statement @ids\n";
584  
585 13 my $removed = 0;
586 13 foreach my $first (NODES) {
587 39 my $firstnode = $st->$first();
588 39 my $id1 = $self->_node2id( $firstnode );
589 39 my @others = @{ OTHERNODES->{ $first } };
590 39 my @orders = ([@others], [reverse @others]);
591 39 foreach my $order (@orders) {
592 78 my ($second, $third) = @$order;
593 78 my ($id2, $id3) = map { $self->_node2id( $st->$_() ) } ($second, $third);
594 78 my $list = $self->_get_terminal_list( $first => $id1, $second => $id2 );
595 78 ▶ if ($self->_remove_node_from_page( $list, $id3 )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_remove_node_from_page($list, $id3)) 39 39 78
596 39 $removed++;
597 }
598 # warn "removing $first-$second-$third $id1-$id2-$id3 from list [" . join(', ', @$list) . "]\n";
599 # warn "\t- remaining: [" . join(', ', @$list) . "]\n";
600 }
601 }
602  
603 13 ▶ if ($removed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($removed) 13 0 13
604 13 $self->{ size }--;
605 13 $self->{etag} = time;
606 }
607 }
608  
609 =item C<< remove_statements ( $subject, $predicate, $object [, $context]) >>
610  
611 Removes the specified C<$statement> from the underlying model.
612  
613 =item C<< etag >>
614  
615 Returns an Etag suitable for use in an HTTP Header.
616  
617 =cut
618  
619 0 ▶sub etag {
Subroutine etag: not called CC=1 SCAR=6.9
Pod documented
620 0 return $_[0]->{etag};
621 }
622  
623  
624 =item C<< nuke >>
625  
626 Permanently removes all the data in the store.
627  
628 =cut
629  
630 6 ▶sub nuke {
Subroutine nuke: called CC=1 SCAR=0.0
Pod documented
631 6 my $self = shift;
632 6 $self->{data} = $self->_new_index_page;
633 6 $self->{node2id} = {};
634 6 $self->{id2node} = {};
635 6 $self->{next_id} = 1;
636 6 $self->{size} = 0;
637 6 $self->{etag} = time;
638 6 return $self;
639 }
640  
641  
642  
643 =item C<< count_statements ($subject, $predicate, $object) >>
644  
645 Returns a count of all the statements matching the specified subject,
646 predicate and objects. Any of the arguments may be undef to match any value.
647  
648 =cut
649  
650 55 ▶sub count_statements {
Subroutine count_statements: called CC=10 SCAR=23.0
Pod documented
651 55 my $self = shift;
652 55 my @nodes = @_;
653 55 my @ids = map { $self->_node2id( $_ ) } @nodes;
654 55 my @names = NODES;
655 55 my @keys = map { $names[$_], $ids[$_] } (0 .. $#names);
656 55 my @dkeys;
657 my @ukeys;
658
659 55 ▶ if (scalar(@nodes) > 3 and defined($nodes[3]) and not($nodes[3]->isa('RDF::Trine::Node::Nil'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @nodes > 3 and defined $nodes[3] and not $nodes[3]->isa("RDF::Trine::Node::Nil")) 1 54 55
Condition83%5/6
scalar @nodes > 3 and defined $nodes[3] and not $nodes[3]->isa("RDF::Trine::Node::Nil")
!ll&&!rl&&r
5401
scalar @nodes > 3 and defined $nodes[3]
!ll&&!rl&&r
17371
MC/DC66%2/3
scalar @nodes > 3 and defined $nodes[3] and not $nodes[3]->isa("RDF::Trine::Node::Nil")
scalar @nodes > 3 defined $nodes[3] not $nodes[3]->isa("RDF::Trine::Node::Nil")
Truth table75%3/4
A and B and not(C)
A= scalar @nodes > 3B= defined $nodes[3]C= not $nodes[3]->isa("RDF::Trine::Node::Nil")
ABCresult
0XX0
10X0
1100
1111
660 1 return 0;
661 }
662
663 54 foreach my $i (0 .. 2) {
664 162 ▶ if (defined($nodes[ $i ])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $nodes[$i]) { } 38 124 162
665 38 push( @dkeys, $names[$i] );
666 } else {
667 124 push( @ukeys, $names[$i] );
668 }
669 }
670 54 @keys = map { $_ => $self->_node2id( $nodes[ NODEMAP->{ $_ } ] ) } @dkeys;
671 54 ▶ if (0 == scalar(@keys)) {
Branch: 3 branches
BranchTrueFalseTotal
if (0 == scalar @keys) { } 29 25 54
elsif (2 == scalar @keys) { } 15 10 25
elsif (4 == scalar @keys) { } 7 3 10
672 29 return $self->{ size };
673 } elsif (2 == scalar(@keys)) {
674 15 my $index = $self->_index_from_pair( $self->_index_root, @keys );
675 15 return $self->_count_statements( $index, @ukeys );
676 } elsif (4 == scalar(@keys)) {
677 7 my $index = $self->_index_from_pair( $self->_index_root, @keys[ 0,1 ] );
678 7 my $list = $self->_index_from_pair( $index, @keys[ 2,3 ] );
679 7 return $self->_node_count( $list );
680 } else {
681 3 my $index = $self->_index_from_pair( $self->_index_root, @keys[ 0,1 ] );
682 3 my $list = $self->_index_from_pair( $index, @keys[ 2,3 ] );
683 3 ▶ return ($self->_page_contains_node( $list, $keys[5] ))
Branch: 1 branch
BranchTrueFalseTotal
$self->_page_contains_node($list, $keys[5]) ? : 2 1 3
684 ? 1
685 : 0;
686 }
687 }
688  
689 35 ▶sub _count_statements {
Subroutine _count_statements: called CC=3 SCAR=11.0
690 35 my $self = shift;
691 35 my $data = shift;
692 35 my @ukeys = @_;
693 35 ▶ if (1 >= scalar(@ukeys)) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 >= scalar @ukeys) { } 20 15 35
694 20 return $self->_node_count( $data );
695 } else {
696 15 my $count = 0;
697 15 my $ukey = shift(@ukeys);
698 15 my $data = $data->{ $ukey };
699 15 foreach my $k (keys %$data) {
700 20 $count += $self->_count_statements( $data->{ $k }, @ukeys );
701 }
702 15 return $count;
703 }
704 }
705  
706 735 ▶sub _node2id {
Subroutine _node2id: called CC=4 SCAR=13.9
707 735 my $self = shift;
708 735 my $node = shift;
709 735 ▶ return unless (blessed($node));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($node) 168 567 735
710 567 ▶ return if ($node->isa('RDF::Trine::Node::Variable'));
Branch: 1 branch
BranchTrueFalseTotal
if $node->isa("RDF::Trine::Node::Variable") 23 544 567
711  
712 # this gets called so much it actually significantly impacts run
713 # time. call it once per invocation of _node2id instead of twice.
714 544 my $str = $node->as_string;
715 544 my $id = $self->{ node2id }{ $str };
716  
717 544 ▶ if (defined $id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id) { } 499 45 544
718 499 return $id;
719 } else {
720 45 $id = ($self->{ node2id }{ $str } = $self->{ next_id }++);
721 45 $self->{ id2node }{ $id } = $node;
722 45 return $id
723 }
724 }
725  
726 237 ▶sub _id2node {
Subroutine _id2node: called CC=2 SCAR=7.4
727 237 my $self = shift;
728 237 my $id = shift;
729 237 ▶ if (exists( $self->{ id2node }{ $id } )) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'id2node'}{$id}) { } 237 0 237
730 237 return $self->{ id2node }{ $id };
731 } else {
732 0 return;
733 }
734 }
735  
736 0 ▶sub _seen_nodes {
Subroutine _seen_nodes: not called CC=1 SCAR=6.9
737 0 my $self = shift;
738 0 return values %{ $self->{ id2node } };
739 }
740  
741 ################################################################################
742 ### The methods below are the only ones that directly access and manipulate the
743 ### index structure. The terminal node lists, however, are manipulated by other
744 ### methods (add_statement, remove_statement, etc.).
745  
746 686 ▶sub _index_root {
Subroutine _index_root: called CC=1 SCAR=0.0
747 686 my $self = shift;
748 686 return $self->{'data'};
749 }
750  
751 408 ▶sub _get_terminal_list {
Subroutine _get_terminal_list: called CC=5 SCAR=16.1
752 408 my $self = shift;
753 408 my $first = shift;
754 408 my $id1 = shift;
755 408 my $second = shift;
756 408 my $id2 = shift;
757 408 my $index = $self->_index_from_pair( $self->_index_root, $first, $id1 );
758 408 my $page = $self->_index_from_pair( $index, $second, $id2 );
759 408 ▶ if (ref($page)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $page) { } 322 86 408
760 322 return $page;
761 } else {
762 86 my ($k1, $k2) = sort { $a->[0] cmp $b->[0] } ([$first, $id1], [$second, $id2]);
763 86 my $index = $self->_index_from_pair( $self->_index_root, $k1->[0], $k1->[1] );
764 86 ▶ unless ($index) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($index) 37 49 86
765 37 $index = $self->_add_index_page( $self->_index_root, $k1->[0], $k1->[1] );
766 }
767
768 86 my $list = $self->_index_from_pair( $index, $k2->[0], $k2->[1] );
769 86 ▶ unless ($list) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($list) 86 0 86
770 86 $list = $self->_add_list_page( $index, $k2->[0], $k2->[1] );
771 }
772
773 ###
774
775 86 my $index2 = $self->_index_from_pair( $self->_index_root, $k2->[0], $k2->[1] );
776 86 ▶ unless ($index2) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($index2) 12 74 86
777 12 $index2 = $self->_add_index_page( $self->_index_root, $k2->[0], $k2->[1] );
778 }
779 86 $self->_add_list_page( $index2, $k1->[0], $k1->[1], $list );
780 86 return $list;
781 }
782 }
783  
784 #########################################
785 #########################################
786 #########################################
787 172 ▶sub _add_list_page {
Subroutine _add_list_page: called CC=2 SCAR=7.0
788 172 my $self = shift;
789 172 my $index = shift;
790 172 my $key = shift;
791 172 my $value = shift;
792 172 ▶ my $list = shift || $self->_new_list_page;
Condition66%2/3
shift() || $self->_new_list_page
l!l&&r!l&&!r
86860
MC/DC0%0/2
shift() || $self->_new_list_page
shift() $self->_new_list_page
Truth table66%2/3
A || B
A= shift()B= $self->_new_list_page
ABresult
1X1
011
000
793 172 $index->{ $key }{ $value } = $list;
794 }
795  
796 49 ▶sub _add_index_page {
Subroutine _add_index_page: called CC=1 SCAR=0.0
797 49 my $self = shift;
798 49 my $index = shift;
799 49 my $key = shift;
800 49 my $value = shift;
801 49 $index->{ $key }{ $value } = $self->_new_index_page;
802 }
803  
804 1198 ▶sub _index_from_pair {
Subroutine _index_from_pair: called CC=1 SCAR=0.0
805 1198 my $self = shift;
806 1198 my $index = shift;
807 1198 my $key = shift;
808 1198 my $val = shift;
809 1198 return $index->{ $key }{ $val };
810 }
811  
812 33 ▶sub _node_list_from_id {
Subroutine _node_list_from_id: called CC=1 SCAR=0.0
813 33 my $self = shift;
814 33 my $index = shift;
815 33 my $id = shift;
816 33 return $index->{ $id };
817 }
818  
819 21 ▶sub _index_values_from_key {
Subroutine _index_values_from_key: called CC=1 SCAR=0.0
820 21 my $self = shift;
821 21 my $index = shift;
822 21 my $key = shift;
823 21 return $index->{ $key };
824 }
825  
826 21 ▶sub _index_values {
Subroutine _index_values: called CC=2 SCAR=6.9
827 21 my $self = shift;
828 21 my $index = shift;
829 21 my $rev = shift;
830 21 ▶ if ($rev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rev) { } 2 19 21
831 2 my @values = sort { $b <=> $a } keys %$index;
832 2 return @values;
833 } else {
834 19 my @values = sort { $a <=> $b } keys %$index;
835 19 return @values;
836 }
837 }
838 #########################################
839 #########################################
840 #########################################
841  
842 27 ▶sub _node_count {
Subroutine _node_count: called CC=2 SCAR=6.9
843 27 my $self = shift;
844 27 my $list = shift;
845 27 ▶ return scalar(@{ $list || [] });
Condition100%2/2
$list || []
l!l
261
MC/DC100%1/1
$list || []
$list
Truth table100%2/2
A
A= $list
Aresult
11
00
846 }
847  
848 62 ▶sub _node_values {
Subroutine _node_values: called CC=2 SCAR=7.4
849 62 my $self = shift;
850 62 my $list = shift;
851 62 ▶ if (ref($list)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $list) { } 62 0 62
852 62 return @$list;
853 } else {
854 0 return;
855 }
856 }
857  
858 414 ▶sub _page_contains_node {
Subroutine _page_contains_node: called CC=3 SCAR=11.0
859 414 my $self = shift;
860 414 my $list = shift;
861 414 my $id = shift;
862 414 foreach (@$list) {
863 433 ▶ return 1 if ($_ == $id);
Branch: 1 branch
BranchTrueFalseTotal
if $_ == $id 213 220 433
864 }
865 201 return 0;
866 }
867  
868 330 ▶sub _add_node_to_page {
Subroutine _add_node_to_page: called CC=2 SCAR=6.9
869 330 my $self = shift;
870 330 my $list = shift;
871 330 my $id = shift;
872 330 ▶ if ($self->_page_contains_node( $list, $id )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_page_contains_node($list, $id)) { } 171 159 330
873 171 return 0;
874 } else {
875 159 @$list = sort { $a <=> $b } (@$list, $id);
876 159 return 1;
877 }
878 }
879  
880 78 ▶sub _remove_node_from_page {
Subroutine _remove_node_from_page: called CC=2 SCAR=6.9
881 78 my $self = shift;
882 78 my $list = shift;
883 78 my $id = shift;
884 78 ▶ if ($self->_page_contains_node( $list, $id )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_page_contains_node($list, $id)) { } 39 39 78
885 39 @$list = grep { $_ != $id } @$list;
886 39 return 1;
887 } else {
888 39 return 0;
889 }
890 }
891  
892 55 ▶sub _new_index_page {
Subroutine _new_index_page: called CC=1 SCAR=0.0
893 55 return { __type => 'index' };
894 }
895  
896 86 ▶sub _new_list_page {
Subroutine _new_list_page: called CC=1 SCAR=0.0
897 86 return [];
898 }
899  
900 ################################################################################
901  
902 68 1;
903  
904 __END__
« RDF/Trine/Model/StatementFilter.pm ↑ Summary RDF/Trine/Model.pm »