AtteanX/Parser/SPARQL.pm

filter: Statementstmt 65.0% 1846 / 2837 Branchbran 52.3% 619 / 1182 Conditioncond 35.1% 108 / 307 MC/DCmcdc 15.3% 25 / 163 Subroutinesub 87.8% 203 / 231 Podpod 91.6% 11 / 12 totaltotal 59.4% 2812 / 4732 CC 734 SCAR 38.5
CC
734
Cov
59%
_InlineDataClause
506.0
_SubSelect
372.1
_ReifiedTripleSubject
165.0
CRAP 47.2
« AtteanX/Parser/Trig.pm ↑ Summary AtteanX/Serializer/SPARQL.pm »
1 12 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 AtteanX::Parser::SPARQL - SPARQL 1.1 Parser.
7  
8 =head1 VERSION
9  
10 This document describes AtteanX::Parser::SPARQL version 0.040
11  
12 =head1 SYNOPSIS
13  
14 use AtteanX::Parser::SPARQL;
15 my $algbrea = AtteanX::Parser::SPARQL->parse($sparql);
16 # or:
17 my $parser = AtteanX::Parser::SPARQL->new();
18 my ($algebra) = $parser->parse_list_from_bytes($sparql);
19
20 # or to allow parsing of SPARQL 1.1 Updates:
21
22 my $algbrea = AtteanX::Parser::SPARQL->parse_update($sparql);
23 # or:
24 my $parser = AtteanX::Parser::SPARQL->new(update => 1);
25 my ($algebra) = $parser->parse_list_from_bytes($sparql);
26
27 =head1 DESCRIPTION
28  
29 This module implements a recursive-descent parser for SPARQL 1.1 using the
30 L<AtteanX::Parser::SPARQLLex> tokenizer. Successful parsing results in an
31 object whose type is one of: L<Attean::Algebra::Query>,
32 L<Attean::Algebra::Update>, or L<Attean::Algebra::Sequence>.
33  
34 =head1 ROLES
35  
36 This class consumes L<Attean::API::Parser>, L<Attean::API::AtOnceParser>, and
37 L<Attean::API::AbbreviatingParser>.
38  
39 =head1 ATTRIBUTES
40  
41 =over 4
42  
43 =item C<< canonical_media_type >>
44  
45 =item C<< media_types >>
46  
47 =item C<< file_extensions >>
48  
49 =item C<< handled_type >>
50  
51 =item C<< lexer >>
52  
53 =item C<< args >>
54  
55 =item C<< build >>
56  
57 =item C<< update >>
58  
59 =item C<< namespaces >>
60  
61 =item C<< baseURI >>
62  
63 =item C<< filters >>
64  
65 =item C<< blank_nodes >>
66  
67 =item C<< has_blank_nodes_map >>
68  
69 =back
70  
71 =head1 METHODS
72  
73 =over 4
74  
75 =cut
76  
77 package AtteanX::Parser::SPARQL 0.040;
78  
79 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 12 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
82 12 ▶use Carp qw(cluck confess croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 12 ▶use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 12 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 12 ▶use URI::NamespaceMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 12 ▶use List::Util qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
88 12 ▶use AtteanX::Parser::SPARQLLex;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 12 ▶use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 12 ▶use Types::Standard qw(ConsumerOf InstanceOf HashRef ArrayRef Bool Str Int);
Subroutine BEGIN: called CC=1 SCAR=0.0
91 12 ▶use Scalar::Util qw(blessed looks_like_number reftype refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
92  
93 ######################################################################
94  
95 12 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 12 has 'version' => (is => 'rw', isa => Str, default => '1.2');
98 12 has 'lexer' => (is => 'rw', isa => InstanceOf['AtteanX::Parser::SPARQLLex::Iterator']);
99 12 has 'args' => (is => 'ro', isa => HashRef);
100 12 has 'build' => (is => 'rw', isa => HashRef);
101 12 has 'update' => (is => 'rw', isa => Bool);
102 12 has 'baseURI' => (is => 'rw');
103 12 has '_stack' => (is => 'rw', isa => ArrayRef);
104 12 has 'filters' => (is => 'rw', isa => ArrayRef);
105 12 has 'counter' => (is => 'rw', isa => Int, default => 0);
106 12 has '_pattern_container_stack' => (is => 'rw', isa => ArrayRef);
107 54 ▶has 'blank_nodes' => (is => 'ro', isa => HashRef[ConsumerOf['Attean::API::Blank']], predicate => 'has_blank_nodes_map', default => sub { +{} });
Subroutine __ANON__: called CC=1 SCAR=0.0
108  
109 8 ▶sub file_extensions { return [qw(rq ru)] }
Subroutine file_extensions: called CC=1 SCAR=0.0
Pod documented
110  
111 1 ▶sub canonical_media_type { return "application/sparql-query" }
Subroutine canonical_media_type: called CC=1 SCAR=0.0
Pod documented
112  
113 3 ▶sub media_types {
Subroutine media_types: called CC=1 SCAR=0.0
Pod documented
114 3 return [qw(application/sparql-query application/sparql-update)];
115 }
116  
117 5 ▶sub handled_type {
Subroutine handled_type: called CC=1 SCAR=0.0
Pod documented
118 5 state $ITEM_TYPE = Type::Tiny::Role->new(role => 'Attean::API::Algebra');
119 5 return $ITEM_TYPE;
120 }
121  
122 12 with 'Attean::API::AtOnceParser', 'Attean::API::Parser', 'Attean::API::AbbreviatingParser';
123 12 with 'Attean::API::CDTBlankNodeMappingParser';
124 12 with 'MooX::Log::Any';
125  
126 54 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=4 SCAR=13.9
Pod undocumented
127 54 my $class = shift;
128 54 my %args = @_;
129 54 ▶ my $ns = delete $args{namespaces} // URI::NamespaceMap->new();
Condition66%2/3
delete $args{"namespaces"} // "URI::NamespaceMap"->new
l!l&&r!l&&!r
3510
MC/DC0%0/2
delete $args{"namespaces"} // "URI::NamespaceMap"->new
delete $args{"namespaces"} "URI::NamespaceMap"->new
Truth table66%2/3
A // B
A= delete $args{"namespaces"}B= "URI::NamespaceMap"->new
ABresult
1X1
011
000
130 54 my $version = delete $args{version};
131 54 my %passthru = (namespaces => $ns);
132 54 ▶ if (defined($version)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version) 1 53 54
133 1 $passthru{ version } = $version;
134 }
135 54 my %a = (args => \%args, , %passthru);
136 54 ▶ if (my $handler = delete $args{handler}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = delete $args{"handler"}) 1 53 54
137 1 $a{handler} = $handler;
138 }
139 54 return \%a;
140 }
141  
142 ################################################################################
143  
144 53 ▶sub _configure_lexer {
Subroutine _configure_lexer: called CC=1 SCAR=0.0
145 53 my $self = shift;
146 53 my $l = shift;
147 53 ▶ $l->add_regex_rule( qr/RANK/, KEYWORD, sub { return uc(shift) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
148 53 return $l;
149 }
150  
151 =item C<< parse ( $sparql ) >>
152  
153 Parse the C<< $sparql >> query string and return the resulting
154 L<Attean::API::Algebra> object.
155  
156 =cut
157  
158 29 ▶sub parse {
Subroutine parse: called CC=2 SCAR=6.9
Pod documented
159 29 my $self = shift;
160 29 ▶ my $parser = ref($self) ? $self : $self->new();
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 10 19 29
161 29 my ($algebra) = $parser->parse_list_from_bytes(@_);
162 26 return $algebra;
163 }
164  
165 =item C<< parse_update ( $sparql ) >>
166  
167 Parse the C<< $sparql >> update string and return the resulting
168 L<Attean::API::Algebra> object.
169  
170 =cut
171  
172 14 ▶sub parse_update {
Subroutine parse_update: called CC=2 SCAR=7.0
Pod documented
173 14 my $self = shift;
174 14 ▶ my $parser = ref($self) ? $self : $self->new();
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 14 14
175 14 $parser->update(1);
176 14 my ($algebra) = $parser->parse_list_from_bytes(@_);
177 13 return $algebra;
178 }
179  
180 =item C<< parse_list_from_io( $fh ) >>
181  
182 =cut
183  
184 2 ▶sub parse_list_from_io {
Subroutine parse_list_from_io: called CC=3 SCAR=11.1
Pod documented
185 2 my $self = shift;
186 2 my $p = AtteanX::Parser::SPARQLLex->new(version => $self->version);
187 2 my $l = $self->_configure_lexer( $p->parse_iter_from_io(@_) );
188 2 $self->lexer($l);
189 2 $self->baseURI($self->{args}{base});
190 2 my $q = $self->_parse();
191 2 ▶ return unless (ref($q));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $q 0 2 2
192 2 my $a = $q->{triples}[0];
193 2 ▶ return unless (ref($a));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $a 0 2 2
194 2 return $a;
195 }
196  
197 =item C<< parse_list_from_bytes( $bytes ) >>
198  
199 =cut
200  
201 46 ▶sub parse_list_from_bytes {
Subroutine parse_list_from_bytes: called CC=3 SCAR=11.1
Pod documented
202 46 my $self = shift;
203 46 my $p = AtteanX::Parser::SPARQLLex->new(version => $self->version);
204 46 my $l = $self->_configure_lexer( $p->parse_iter_from_bytes(@_) );
205 46 $self->lexer($l);
206 46 $self->baseURI($self->{args}{base});
207 46 my $q = $self->_parse();
208 42 ▶ return unless (ref($q));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $q 0 42 42
209 42 my $a = $q->{triples}[0];
210 42 ▶ return unless (ref($a));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $a 0 42 42
211 42 return $a;
212 }
213  
214 =item C<< parse_nodes ( $string ) >>
215  
216 Returns a list of L<Attean::API::Term> or L<Attean::API::Variable> objects,
217 parsed in SPARQL syntax from the supplied C<< $string >>. Parsing is ended
218 either upon seeing a DOT, or reaching the end of the string.
219  
220 =cut
221  
222 5 ▶sub parse_nodes {
Subroutine parse_nodes: called CC=6 SCAR=18.3
Pod documented
223 5 my $self = shift;
224 5 my $p = AtteanX::Parser::SPARQLLex->new(version => $self->version);
225 5 my $bytes = shift;
226 5 my %args = @_;
227 5 ▶ my $commas = $args{'commas'} || 0;
Condition50%1/2
$args{'commas'} || 0
l!l
05
MC/DC0%0/1
$args{'commas'} || 0
$args{'commas'}
Truth table50%1/2
A
A= $args{'commas'}
Aresult
11
00
228 5 my $l = $self->_configure_lexer( $p->parse_iter_from_bytes($bytes) );
229 5 $self->lexer($l);
230 5 $self->baseURI($self->{args}{base});
231 5 $self->build({base => $self->baseURI});
232
233 5 my @nodes;
234 5 ▶ while ($self->_peek_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_peek_token) 15 5 20
235 15 ▶ if ($self->_Verb_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_Verb_test) { } 13 2 15
236 13 $self->_Verb;
237 } else {
238 2 $self->_GraphNode;
239 }
240
241 15 ▶ if ($commas) {
Branch: 1 branch
BranchTrueFalseTotal
if ($commas) 0 15 15
242 0 $self->_optional_token(COMMA);
243 }
244
245 15 push(@nodes, splice(@{ $self->{_stack} }));
246 15 ▶ if ($self->_test_token(DOT)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(9)) 0 15 15
247 0 $self->log->notice('DOT seen in string, stopping here');
248 0 last;
249 }
250 }
251
252 5 return @nodes;
253 }
254  
255 48 ▶sub _parse {
Subroutine _parse: called CC=4 SCAR=13.9
256 48 my $self = shift;
257
258 48 ▶ unless ($self->update) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->update) 34 14 48
259 34 my $t = $self->lexer->peek;
260 34 ▶ unless (defined($t)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 0 34 34
261 0 confess "No query string found to parse";
262 }
263 }
264  
265 48 $self->_stack([]);
266 48 $self->filters([]);
267 48 $self->_pattern_container_stack([]);
268 48 my $triples = $self->_push_pattern_container();
269 48 my $build = { sources => [], triples => $triples };
270 48 $self->build($build);
271 48 ▶ if ($self->baseURI) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->baseURI) 1 47 48
272 1 $build->{base} = $self->baseURI;
273 }
274  
275 48 $self->_RW_Query();
276 44 delete $build->{star};
277 44 my $data = $build;
278 44 return $data;
279 }
280  
281 ################################################################################
282  
283  
284 # [1] Query ::= Prologue ( SelectQuery | ConstructQuery | DescribeQuery | AskQuery | LoadUpdate )
285 48 ▶sub _RW_Query {
Subroutine _RW_Query: called CC=42 SCAR=48.9
286 48 my $self = shift;
287 48 $self->_Prologue;
288  
289 48 my $read_query = 0;
290 48 my $update = 0;
291 48 while (1) {
292 50 ▶ if ($self->_optional_token(KEYWORD, 'SELECT')) {
Branch: 13 branches
BranchTrueFalseTotal
if ($self->_optional_token(47, 'SELECT')) { } 29 21 50
elsif ($self->_optional_token(47, 'CONSTRUCT')) { } 3 18 21
elsif ($self->_optional_token(47, 'DESCRIBE')) { } 1 17 18
elsif ($self->_optional_token(47, 'ASK')) { } 4 13 17
elsif ($self->_test_token(47, 'CREATE')) { } 0 13 13
elsif ($self->_test_token(47, 'DROP')) { } 0 13 13
elsif ($self->_test_token(47, 'LOAD')) { } 0 13 13
elsif ($self->_test_token(47, 'CLEAR')) { } 0 13 13
elsif ($self->_test_token(47, qr/^(WITH|INSERT|DELETE)/u)) { } 9 4 13
elsif ($self->_test_token(47, 'COPY')) { } 0 4 4
elsif ($self->_test_token(47, 'MOVE')) { } 0 4 4
elsif ($self->_test_token(47, 'ADD')) { } 3 1 4
elsif ($self->_test_token(25)) { } 0 1 1
293 29 $self->_SelectQuery();
294 27 $read_query++;
295 } elsif ($self->_optional_token(KEYWORD, 'CONSTRUCT')) {
296 3 $self->_ConstructQuery();
297 3 $read_query++;
298 } elsif ($self->_optional_token(KEYWORD, 'DESCRIBE')) {
299 1 $self->_DescribeQuery();
300 1 $read_query++;
301 } elsif ($self->_optional_token(KEYWORD, 'ASK')) {
302 4 $self->_AskQuery();
303 4 $read_query++;
304 } elsif ($self->_test_token(KEYWORD, 'CREATE')) {
305 0 ▶ unless ($self->update) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->update) 0 0 0
306 0 croak "CREATE GRAPH update forbidden in read-only queries";
307 }
308 0 $update++;
309 0 $self->_CreateGraph();
310 } elsif ($self->_test_token(KEYWORD, 'DROP')) {
311 0 ▶ unless ($self->update) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->update) 0 0 0
312 0 croak "DROP GRAPH update forbidden in read-only queries";
313 }
314 0 $update++;
315 0 $self->_DropGraph();
316 } elsif ($self->_test_token(KEYWORD, 'LOAD')) {
317 0 ▶ unless ($self->update) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->update) 0 0 0
318 0 croak "LOAD update forbidden in read-only queries"
319 }
320 0 $update++;
321 0 $self->_LoadUpdate();
322 } elsif ($self->_test_token(KEYWORD, 'CLEAR')) {
323 0 ▶ unless ($self->update) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->update) 0 0 0
324 0 croak "CLEAR GRAPH update forbidden in read-only queries";
325 }
326 0 $update++;
327 0 $self->_ClearGraphUpdate();
328 } elsif ($self->_test_token(KEYWORD, qr/^(WITH|INSERT|DELETE)/)) {
329 9 ▶ unless ($self->update) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->update) 0 9 9
330 0 croak "INSERT/DELETE update forbidden in read-only queries";
331 }
332 9 $update++;
333 9 my ($graph);
334 9 ▶ if ($self->_optional_token(KEYWORD, 'WITH')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "WITH")) 0 9 9
335 0 $self->{build}{custom_update_dataset} = 1;
336 0 $self->_IRIref;
337 0 ($graph) = splice( @{ $self->{_stack} } );
338 }
339 9 ▶ if ($self->_optional_token(KEYWORD, 'INSERT')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_optional_token(47, 'INSERT')) { } 3 6 9
elsif ($self->_optional_token(47, 'DELETE')) { } 6 0 6
340 3 ▶ if ($self->_optional_token(KEYWORD, 'DATA')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, 'DATA')) { } 1 2 3
341 1 ▶ unless ($self->update) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->update) 0 1 1
342 0 croak "INSERT DATA update forbidden in read-only queries";
343 }
344 1 $self->_InsertDataUpdate();
345 } else {
346 2 $self->_InsertUpdate($graph);
347 }
348 } elsif ($self->_optional_token(KEYWORD, 'DELETE')) {
349 6 ▶ if ($self->_optional_token(KEYWORD, 'DATA')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, 'DATA')) { } 1 5 6
350 1 ▶ unless ($self->update) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->update) 0 1 1
351 0 croak "DELETE DATA update forbidden in read-only queries";
352 }
353 1 $self->_DeleteDataUpdate();
354 } else {
355 5 $self->_DeleteUpdate($graph);
356 }
357 }
358 } elsif ($self->_test_token(KEYWORD, 'COPY')) {
359 0 $update++;
360 0 $self->_AddCopyMoveUpdate('COPY');
361 } elsif ($self->_test_token(KEYWORD, 'MOVE')) {
362 0 $update++;
363 0 $self->_AddCopyMoveUpdate('MOVE');
364 } elsif ($self->_test_token(KEYWORD, 'ADD')) {
365 3 $update++;
366 3 $self->_AddCopyMoveUpdate('ADD');
367 } elsif ($self->_test_token(SEMICOLON)) {
368 0 $self->_expected_token(SEMICOLON);
369 0 ▶ next if ($self->_Query_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_Query_test 0 0 0
370 0 last;
371 } else {
372 1 ▶ if ($self->update and not $self->_peek_token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->update and not $self->_peek_token) 0 1 1
Condition33%1/3
$self->update and not $self->_peek_token
!ll&&!rl&&r
100
MC/DC0%0/2
$self->update and not $self->_peek_token
$self->update not $self->_peek_token
Truth table33%1/3
A and not(B)
A= $self->updateB= not $self->_peek_token
ABresult
0X0
100
111
373 0 last;
374 }
375
376 1 my $t = $self->_peek_token;
377 1 return $self->_token_error($t, 'Expected query type');
378 }
379  
380 46 ▶ last if ($read_query);
Branch: 1 branch
BranchTrueFalseTotal
if $read_query 35 11 46
381 11 ▶ if ($self->_optional_token(SEMICOLON)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(25)) 2 9 11
382 2 ▶ if ($self->_Query_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_Query_test) 2 0 2
383 2 next;
384 }
385 }
386 9 last;
387 }
388 44 my $count = scalar(@{ $self->{build}{triples} });
389
390 44 my $t = $self->_peek_token;
391 44 ▶ if ($t) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t) 0 44 44
392 0 my $type = AtteanX::SPARQL::Constants::decrypt_constant($t->type);
393 0 croak "Syntax error: Remaining input after query: $type " . Dumper($t->args);
394 }
395  
396 44 ▶ if ($count == 0 or $count > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 0 or $count > 1) 2 42 44
Condition66%2/3
$count == 0 or $count > 1
l!l&&r!l&&!r
0242
MC/DC50%1/2
$count == 0 or $count > 1
$count == 0 $count > 1
Truth table66%2/3
A or B
A= $count == 0B= $count > 1
ABresult
1X1
011
000
397 2 my @patterns = splice(@{ $self->{build}{triples} });
398 2 my %seen;
399 2 foreach my $p (@patterns) {
400 4 my @blanks = $p->blank_nodes;
401 4 foreach my $b (@blanks) {
402 0 ▶ if ($seen{$b->value}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen{$b->value}++) 0 0 0
403 0 croak "Cannot re-use a blank node label in multiple update operations in a single request";
404 }
405 }
406 }
407 2 my $pattern = Attean::Algebra::Sequence->new( children => \@patterns );
408 2 $self->_check_duplicate_blanks($pattern);
409 2 $self->{build}{triples} = [ $pattern ];
410 }
411
412 44 my %dataset;
413 44 foreach my $s (@{ $self->{build}{sources} }) {
414 8 my ($iri, $group) = @$s;
415 8 ▶ if ($group eq 'NAMED') {
Branch: 1 branch
BranchTrueFalseTotal
if ($group eq 'NAMED') { } 4 4 8
416 4 push(@{ $dataset{named} }, $iri );
417 } else {
418 4 push(@{ $dataset{default} }, $iri );
419 }
420 }
421  
422 44 my $algebra = $self->{build}{triples}[0];
423  
424 44 my %args;
425 44 ▶ if (defined(my $version = $self->{build}{version})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $version = $self->{"build"}{"version"})) 0 44 44
426 0 $args{ version } = $version;
427 }
428 44 ▶ if ($update) {
Branch: 1 branch
BranchTrueFalseTotal
if ($update) { } 9 35 44
429 9 $self->{build}{triples}[0] = Attean::Algebra::Update->new( children => [$algebra], %args );
430 } else {
431 35 $self->{build}{triples}[0] = Attean::Algebra::Query->new( children => [$algebra], dataset => \%dataset, %args );
432 }
433 }
434  
435 2 ▶sub _Query_test {
Subroutine _Query_test: called CC=1 SCAR=0.0
436 2 my $self = shift;
437 2 return ($self->_test_token(KEYWORD, qr/^(SELECT|CONSTRUCT|DESCRIBE|ASK|LOAD|CLEAR|DROP|ADD|MOVE|COPY|CREATE|INSERT|DELETE|WITH)/i));
438 }
439  
440 63 ▶sub _Prologue_test {
Subroutine _Prologue_test: called CC=4 SCAR=14.1
441 63 my $self = shift;
442 63 ▶ return 1 if ($self->_test_token(KEYWORD, 'BASE'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "BASE") 0 63 63
443 63 ▶ return 1 if ($self->_test_token(KEYWORD, 'PREFIX'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "PREFIX") 15 48 63
444 48 ▶ return 1 if ($self->_test_token(KEYWORD, 'VERSION'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "VERSION") 0 48 48
445 48 return 0;
446 }
447  
448 # [2] Prologue ::= ( BaseDecl | PrefixDecl | VersionDecl )*
449 # [3] BaseDecl ::= 'BASE' IRI_REF
450 # [4] PrefixDecl ::= 'PREFIX' PNAME_NS IRI_REF
451 # VersionDecl ::= 'VERSION' VersionSpecifier
452 48 ▶sub _Prologue {
Subroutine _Prologue: called CC=10 SCAR=30.8
453 48 my $self = shift;
454  
455 48 my $base;
456 my @base;
457 48 my %namespaces;
458 48 my $version;
459 48 ▶ while ($self->_Prologue_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_Prologue_test) 15 48 63
460 15 ▶ if ($self->_optional_token(KEYWORD, 'BASE')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_optional_token(47, 'BASE')) { } 0 15 15
elsif ($self->_optional_token(47, 'PREFIX')) { } 15 0 15
461 0 my $iriref = $self->_expected_token(IRI);
462 0 my $iri = $iriref->value;
463 0 $base = $self->new_iri( value => $iri );
464 0 @base = $base;
465 0 $self->{base} = $base;
466 } elsif ($self->_optional_token(KEYWORD, 'PREFIX')) {
467 15 my $prefix = $self->_expected_token(PREFIXNAME);
468 15 my @args = @{ $prefix->args };
469 15 ▶ if (scalar(@args) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args > 1) 0 15 15
470 0 croak "Syntax error: PREFIX namespace used a full PNAME_LN, not a PNAME_NS";
471 }
472 15 my $ns = substr($prefix->value, 0, length($prefix->value) - 1);
473 15 my $iriref = $self->_expected_token(IRI);
474 15 my $iri = $iriref->value;
475 15 ▶ if (@base) {
Branch: 1 branch
BranchTrueFalseTotal
if (@base) 0 15 15
476 0 my $r = $self->new_iri( value => $iri, base => shift(@base) );
477 0 $iri = $r->value;
478 }
479 15 $namespaces{ $ns } = $iri;
480 15 $self->namespaces->add_mapping($ns, $iri);
481 } else {
482 # VERSION
483 0 $self->_expected_token(KEYWORD, 'VERSION');
484 0 my $t = $self->_peek_token;
485 0 ▶ if (my $s1 = $self->_optional_token(STRING1D)) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $s1 = $self->_optional_token(26)) { } 0 0 0
elsif (my $s2 = $self->_optional_token(27)) { } 0 0 0
486 0 $version = $s1->value;
487 } elsif (my $s2 = $self->_optional_token(STRING1S)) {
488 0 $version = $s2->value;
489 } else {
490 0 my $got = AtteanX::SPARQL::Constants::decrypt_constant($t->type);
491 0 my $value = $t->value;
492 0 $self->_token_error($t, "Expecting VERSION specifier but found $got '$value'")
493 }
494 }
495 }
496  
497 48 $self->{build}{namespaces} = \%namespaces;
498 48 ▶ $self->{build}{base} = $base if (defined($base));
Branch: 1 branch
BranchTrueFalseTotal
if defined $base 0 48 48
499 48 ▶ $self->{build}{version} = $version if (defined($version));
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 0 48 48
500  
501 # push(@data, (base => $base)) if (defined($base));
502 # return @data;
503 }
504  
505 1 ▶sub _InsertDataUpdate {
Subroutine _InsertDataUpdate: called CC=1 SCAR=0.0
506 1 my $self = shift;
507 1 $self->_expected_token(LBRACE);
508 1 local($self->{__data_pattern}) = 1;
509 1 my @triples = $self->_ModifyTemplate();
510 1 $self->_expected_token(RBRACE);
511  
512 1 my $insert = Attean::Algebra::Modify->new(insert => \@triples, specifies_dataset => $self->{build}{custom_update_dataset});
513 1 $self->_add_patterns( $insert );
514 1 $self->{build}{method} = 'UPDATE';
515 }
516  
517 1 ▶sub _DeleteDataUpdate {
Subroutine _DeleteDataUpdate: called CC=1 SCAR=0.0
518 1 my $self = shift;
519 1 $self->_expected_token(LBRACE);
520 1 local($self->{__data_pattern}) = 1;
521 1 local($self->{__data_pattern_delete}) = 1;
522 1 local($self->{__no_bnodes}) = "DELETE DATA block";
523 1 my @triples = $self->_ModifyTemplate();
524 1 $self->_expected_token(RBRACE);
525
526 1 my $delete = Attean::Algebra::Modify->new(delete => \@triples, specifies_dataset => $self->{build}{custom_update_dataset});
527 1 $self->_add_patterns( $delete );
528 1 $self->{build}{method} = 'UPDATE';
529 }
530  
531 2 ▶sub _InsertUpdate {
Subroutine _InsertUpdate: called CC=6 SCAR=25.1
532 2 my $self = shift;
533 2 my $graph = shift;
534 2 $self->_expected_token(LBRACE);
535 2 my @triples = $self->_ModifyTemplate();
536 2 $self->_expected_token(RBRACE);
537
538 2 ▶ if ($graph) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph) 0 2 2
539 0 @triples = map { $_->as_quad_pattern($graph) } @triples;
540 }
541  
542 2 my %dataset;
543 2 ▶ while ($self->_optional_token(KEYWORD, 'USING')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "USING")) 0 2 2
544 0 $self->{build}{custom_update_dataset} = 1;
545 0 my $named = 0;
546 0 ▶ if ($self->_optional_token(KEYWORD, 'NAMED')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "NAMED")) 0 0 0
547 0 $named = 1;
548 }
549 0 $self->_IRIref;
550 0 my ($iri) = splice( @{ $self->{_stack} } );
551 0 ▶ if ($named) {
Branch: 1 branch
BranchTrueFalseTotal
if ($named) { } 0 0 0
552 0 $dataset{named}{$iri->value} = $iri;
553 } else {
554 0 push(@{ $dataset{default} }, $iri );
555 }
556 }
557  
558 2 $self->_expected_token(KEYWORD, 'WHERE');
559 1 ▶ if ($graph) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph) { } 0 1 1
560 0 $self->_GroupGraphPattern;
561 0 my $ggp = $self->_remove_pattern;
562 0 $ggp = Attean::Algebra::Graph->new( children => [$ggp], graph => $graph );
563 0 $self->_add_patterns( $ggp );
564 } else {
565 1 $self->_GroupGraphPattern;
566 }
567  
568 1 my $ggp = $self->_remove_pattern;
569  
570 1 my @triples_with_fresh_bnodes = $self->_statements_with_fresh_bnodes(@triples);
571 1 my $insert = Attean::Algebra::Modify->new( children => [$ggp], insert => \@triples_with_fresh_bnodes, dataset => \%dataset, specifies_dataset => $self->{build}{custom_update_dataset} );
572 1 $self->_add_patterns( $insert );
573 1 $self->{build}{method} = 'UPDATE';
574 }
575  
576 1 ▶sub _statements_with_fresh_bnodes {
Subroutine _statements_with_fresh_bnodes: called CC=6 SCAR=28.1
577 1 my $self = shift;
578 1 my @triples = @_;
579
580 1 my %fresh_blank_map;
581 my @triples_with_fresh_bnodes;
582 1 foreach my $t (@triples) {
583 1 my @pos = ref($t)->variables;
584 1 ▶ if ($t->has_blanks) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->has_blanks) { } 0 1 1
585 0 my @terms;
586 0 foreach my $term ($t->values) {
587 0 ▶ if ($term->does('Attean::API::Blank')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does('Attean::API::Blank')) { } 0 0 0
588 0 ▶ if (my $b = $fresh_blank_map{$term->value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $b = $fresh_blank_map{$term->value}) { } 0 0 0
589 0 push(@terms, $b);
590 } else {
591 0 my $id = $self->counter;
592 0 $self->counter($id+1);
593 0 my $name = ".b-$id";
594 0 my $b = Attean::Blank->new($name);
595 0 push(@terms, $b);
596 0 $fresh_blank_map{$term->value} = $b;
597 }
598 } else {
599 0 push(@terms, $term);
600 }
601 }
602 0 push(@triples_with_fresh_bnodes, ref($t)->new(mesh \@pos, \@terms));
603 } else {
604 1 push(@triples_with_fresh_bnodes, $t);
605 }
606 }
607 1 return @triples_with_fresh_bnodes;
608 }
609  
610 5 ▶sub _DeleteUpdate {
Subroutine _DeleteUpdate: called CC=17 SCAR=40.3
611 5 my $self = shift;
612 5 my $graph = shift;
613
614 5 my %dataset;
615 5 ▶ if ($self->_optional_token(KEYWORD, 'WHERE')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, 'WHERE')) { } 0 5 5
616 0 ▶ if ($graph) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph) 0 0 0
617 0 croak "Syntax error: WITH clause cannot be used with DELETE WHERE operations";
618 }
619 0 $self->_expected_token(LBRACE);
620 0 my @st = $self->_ModifyTemplate();
621 0 $self->_expected_token(RBRACE);
622 0 my @patterns;
623 my @triples;
624 0 my @quads;
625 0 my @blanks = grep { $_->does('Attean::API::Blank') } map { $_->values } @st;
626 0 ▶ if (scalar(@blanks) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @blanks > 0) 0 0 0
627 0 croak "Cannot use blank nodes in a DELETE pattern";
628 }
629 0 foreach my $s (@st) {
630 0 ▶ if ($s->does('Attean::API::QuadPattern')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->does('Attean::API::QuadPattern')) { } 0 0 0
631 0 push(@quads, $s);
632 0 my $tp = $s->as_triple_pattern;
633 0 my $bgp = Attean::Algebra::BGP->new( triples => [$tp] );
634 0 push(@patterns, Attean::Algebra::Graph->new( graph => $s->graph, children => [$bgp] ));
635 } else {
636 0 push(@triples, $s);
637 }
638 }
639 0 push(@patterns, Attean::Algebra::BGP->new( triples => \@triples ));
640 0 my $ggp = Attean::Algebra::Join->new( children => \@patterns );
641 0 my $update = Attean::Algebra::Modify->new( children => [$ggp], delete => [@st], specifies_dataset => $self->{build}{custom_update_dataset});
642 0 $self->_add_patterns( $update );
643 0 $self->{build}{method} = 'UPDATE';
644 0 return;
645 } else {
646 5 my @delete_triples;
647 {
648 5 local($self->{__no_bnodes}) = "DELETE block";
649 5 $self->_expected_token(LBRACE);
650 5 @delete_triples = $self->_ModifyTemplate( $graph );
651 5 $self->_expected_token(RBRACE);
652 }
653
654 5 my @insert_triples;
655 5 ▶ if ($self->_optional_token(KEYWORD, 'INSERT')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "INSERT")) 0 5 5
656 0 $self->_expected_token(LBRACE);
657 0 @insert_triples = $self->_ModifyTemplate( $graph );
658 0 @insert_triples = $self->_statements_with_fresh_bnodes(@insert_triples);
659 0 $self->_expected_token(RBRACE);
660 }
661
662 5 ▶ if ($graph) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph) 0 5 5
663 0 ▶ @insert_triples = map { $_->does('Attean::API::QuadPattern') ? $_ : $_->as_quad_pattern($graph) } @insert_triples;
Branch: 1 branch
BranchTrueFalseTotal
$_->does('Attean::API::QuadPattern') ? : 0 0 0
664 0 ▶ @delete_triples = map { $_->does('Attean::API::QuadPattern') ? $_ : $_->as_quad_pattern($graph) } @delete_triples;
Branch: 1 branch
BranchTrueFalseTotal
$_->does('Attean::API::QuadPattern') ? : 0 0 0
665 }
666  
667 5 ▶ while ($self->_optional_token(KEYWORD, 'USING')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "USING")) 9 5 14
668 9 $self->{build}{custom_update_dataset} = 1;
669 9 my $named = 0;
670 9 ▶ if ($self->_optional_token(KEYWORD, 'NAMED')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "NAMED")) 3 6 9
671 3 $named = 1;
672 }
673 9 $self->_IRIref;
674 9 my ($iri) = splice( @{ $self->{_stack} } );
675 9 ▶ if ($named) {
Branch: 1 branch
BranchTrueFalseTotal
if ($named) { } 3 6 9
676 3 $dataset{named}{$iri->value} = $iri;
677 } else {
678 6 push(@{ $dataset{default} }, $iri );
679 }
680 }
681
682 5 $self->_expected_token(KEYWORD, 'WHERE');
683
684 5 ▶ if ($graph) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph) { } 0 5 5
685 0 $self->_GroupGraphPattern;
686 0 delete $self->{__no_bnodes};
687 0 my $ggp = $self->_remove_pattern;
688 0 $ggp = Attean::Algebra::Graph->new( children => [$ggp], graph => $graph );
689 0 $self->_add_patterns( $ggp );
690 } else {
691 5 $self->_GroupGraphPattern;
692 5 delete $self->{__no_bnodes};
693 }
694  
695 5 my $ggp = $self->_remove_pattern;
696  
697 5 my %args = (children => [$ggp], dataset => \%dataset);
698 5 ▶ if (scalar(@insert_triples)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @insert_triples) 0 5 5
699 0 $args{insert} = \@insert_triples;
700 }
701 5 ▶ if (scalar(@delete_triples)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @delete_triples) 5 0 5
702 5 $args{delete} = \@delete_triples;
703 5 my @blanks = grep { $_->does('Attean::API::Blank') } map { $_->values } @delete_triples;
704 5 ▶ if (scalar(@blanks) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @blanks > 0) 0 5 5
705 0 croak "Cannot use blank nodes in a DELETE pattern";
706 }
707 }
708 5 my $update = Attean::Algebra::Modify->new( %args, specifies_dataset => $self->{build}{custom_update_dataset} );
709 5 $self->_add_patterns( $update );
710 5 $self->{build}{method} = 'UPDATE';
711 }
712 }
713  
714 18 ▶sub _ModifyTemplate_test {
Subroutine _ModifyTemplate_test: called CC=3 SCAR=11.0
715 18 my $self = shift;
716 18 ▶ return 1 if ($self->_TriplesBlock_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_TriplesBlock_test 9 9 18
717 9 ▶ return 1 if ($self->_test_token(KEYWORD, 'GRAPH'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "GRAPH") 0 9 9
718 9 return 0;
719 }
720  
721 9 ▶sub _ModifyTemplate {
Subroutine _ModifyTemplate: called CC=2 SCAR=6.9
722 9 my $self = shift;
723 9 my $graph = shift;
724
725 9 my @triples;
726 9 ▶ while ($self->_ModifyTemplate_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ModifyTemplate_test) 9 9 18
727 9 push(@triples, $self->__ModifyTemplate( $graph ));
728 }
729
730 9 return @triples;
731 }
732  
733 9 ▶sub __ModifyTemplate {
Subroutine __ModifyTemplate: called CC=3 SCAR=14.7
734 9 my $self = shift;
735 9 my $graph = shift;
736 9 local($self->{_modify_template}) = 1;
737 9 ▶ if ($self->_TriplesBlock_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_TriplesBlock_test) { } 9 0 9
738 9 $self->_push_pattern_container;
739 9 $self->_TriplesBlock;
740 9 (my $cont, undef) = $self->_pop_pattern_container; # ignore hints in a modify template
741 9 my ($bgp) = @{ $cont };
742 9 my @triples = @{ $bgp->triples };
743 9 ▶ if ($graph) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph) 0 9 9
744 0 @triples = map { $_->as_quad_pattern($graph) } @triples;
745 }
746
747 9 return @triples;
748 } else {
749 0 $self->_GraphGraphPattern;
750
751 {
752 0 my (@d) = splice(@{ $self->{_stack} });
753 0 $self->__handle_GraphPatternNotTriples( @d );
754 }
755
756 0 my $data = $self->_remove_pattern;
757 0 my $graph = $data->graph;
758 0 my @bgps = $data->subpatterns_of_type('Attean::Algebra::BGP');
759 0 my @triples = map { $_->as_quad_pattern($graph) } map { @{ $_->triples } } @bgps;
760 0 return @triples;
761 }
762 }
763  
764 0 ▶sub _LoadUpdate {
Subroutine _LoadUpdate: not called CC=3 SCAR=24.8
765 0 my $self = shift;
766 0 $self->_expected_token(KEYWORD, 'LOAD');
767 0 ▶ my $silent = $self->_optional_token(KEYWORD, 'SILENT') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_optional_token(47, 'SILENT') ? : 0 0 0
768 0 $self->_IRIref;
769 0 my ($iri) = splice( @{ $self->{_stack} } );
770 0 ▶ if ($self->_optional_token(KEYWORD, 'INTO')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, 'INTO')) { } 0 0 0
771 0 $self->_expected_token(KEYWORD, 'GRAPH');
772 0 $self->_IRIref;
773 0 my ($graph) = splice( @{ $self->{_stack} } );
774 0 my $pat = Attean::Algebra::Load->new( silent => $silent, url => $iri, graph => $graph );
775 0 $self->_add_patterns( $pat );
776 } else {
777 0 my $pat = Attean::Algebra::Load->new( silent => $silent, url => $iri );
778 0 $self->_add_patterns( $pat );
779 }
780 0 $self->{build}{method} = 'LOAD';
781 }
782  
783 0 ▶sub _CreateGraph {
Subroutine _CreateGraph: not called CC=2 SCAR=17.9
784 0 my $self = shift;
785 0 $self->_expected_token(KEYWORD, 'CREATE');
786 0 ▶ my $silent = $self->_optional_token(KEYWORD, 'SILENT') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_optional_token(47, 'SILENT') ? : 0 0 0
787 0 $self->_expected_token(KEYWORD, 'GRAPH');
788 0 $self->_IRIref;
789 0 my ($graph) = splice( @{ $self->{_stack} } );
790 0 my $pat = Attean::Algebra::Create->new( silent => $silent, graph => $graph );
791 0 $self->_add_patterns( $pat );
792 0 $self->{build}{method} = 'CREATE';
793 }
794  
795 0 ▶sub _ClearGraphUpdate {
Subroutine _ClearGraphUpdate: not called CC=6 SCAR=37.4
796 0 my $self = shift;
797 0 $self->_expected_token(KEYWORD, 'CLEAR');
798 0 ▶ my $silent = $self->_optional_token(KEYWORD, 'SILENT') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_optional_token(47, 'SILENT') ? : 0 0 0
799 0 ▶ if ($self->_optional_token(KEYWORD, 'GRAPH')) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->_optional_token(47, 'GRAPH')) { } 0 0 0
elsif ($self->_optional_token(47, 'DEFAULT')) { } 0 0 0
elsif ($self->_optional_token(47, 'NAMED')) { } 0 0 0
elsif ($self->_optional_token(47, 'ALL')) { } 0 0 0
800 0 $self->_IRIref;
801 0 my ($graph) = splice( @{ $self->{_stack} } );
802 0 my $pat = Attean::Algebra::Clear->new(silent => $silent, target => 'GRAPH', graph => $graph);
803 0 $self->_add_patterns( $pat );
804 } elsif ($self->_optional_token(KEYWORD, 'DEFAULT')) {
805 0 my $pat = Attean::Algebra::Clear->new(silent => $silent, target => 'DEFAULT');
806 0 $self->_add_patterns( $pat );
807 } elsif ($self->_optional_token(KEYWORD, 'NAMED')) {
808 0 my $pat = Attean::Algebra::Clear->new(silent => $silent, target => 'NAMED');
809 0 $self->_add_patterns( $pat );
810 } elsif ($self->_optional_token(KEYWORD, 'ALL')) {
811 0 my $pat = Attean::Algebra::Clear->new(silent => $silent, target => 'ALL');
812 0 $self->_add_patterns( $pat );
813 }
814 0 $self->{build}{method} = 'CLEAR';
815 }
816  
817 0 ▶sub _DropGraph {
Subroutine _DropGraph: not called CC=6 SCAR=37.4
818 0 my $self = shift;
819 0 $self->_expected_token(KEYWORD, 'DROP');
820 0 ▶ my $silent = $self->_optional_token(KEYWORD, 'SILENT') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_optional_token(47, 'SILENT') ? : 0 0 0
821 0 ▶ if ($self->_optional_token(KEYWORD, 'GRAPH')) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->_optional_token(47, 'GRAPH')) { } 0 0 0
elsif ($self->_optional_token(47, 'DEFAULT')) { } 0 0 0
elsif ($self->_optional_token(47, 'NAMED')) { } 0 0 0
elsif ($self->_optional_token(47, 'ALL')) { } 0 0 0
822 0 $self->_IRIref;
823 0 my ($graph) = splice( @{ $self->{_stack} } );
824 0 my $pat = Attean::Algebra::Clear->new(drop => 1, silent => $silent, target => 'GRAPH', graph => $graph);
825 0 $self->_add_patterns( $pat );
826 } elsif ($self->_optional_token(KEYWORD, 'DEFAULT')) {
827 0 my $pat = Attean::Algebra::Clear->new(drop => 1, silent => $silent, target => 'DEFAULT');
828 0 $self->_add_patterns( $pat );
829 } elsif ($self->_optional_token(KEYWORD, 'NAMED')) {
830 0 my $pat = Attean::Algebra::Clear->new(drop => 1, silent => $silent, target => 'NAMED');
831 0 $self->_add_patterns( $pat );
832 } elsif ($self->_optional_token(KEYWORD, 'ALL')) {
833 0 my $pat = Attean::Algebra::Clear->new(drop => 1, silent => $silent, target => 'ALL');
834 0 $self->_add_patterns( $pat );
835 }
836 0 $self->{build}{method} = 'CLEAR';
837 }
838  
839 6 ▶sub __graph {
Subroutine __graph: called CC=2 SCAR=6.9
840 6 my $self = shift;
841 6 ▶ if ($self->_optional_token(KEYWORD, 'DEFAULT')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, 'DEFAULT')) { } 3 3 6
842 3 return;
843 } else {
844 3 $self->_optional_token(KEYWORD, 'GRAPH');
845 3 $self->_IRIref;
846 3 my ($g) = splice( @{ $self->{_stack} } );
847 3 return $g;
848 }
849 }
850  
851 3 ▶sub _AddCopyMoveUpdate {
Subroutine _AddCopyMoveUpdate: called CC=6 SCAR=19.9
852 3 my $self = shift;
853 3 my $op = shift;
854 3 $self->_expected_token(KEYWORD, $op);
855 3 ▶ my $silent = $self->_optional_token(KEYWORD, 'SILENT') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_optional_token(47, 'SILENT') ? : 0 3 3
856
857 3 my %args = (silent => $silent);
858 3 ▶ if ($op eq 'COPY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq 'COPY') { } 0 3 3
elsif ($op eq 'MOVE') { } 0 3 3
859 0 $args{drop_destination} =1;
860 } elsif ($op eq 'MOVE') {
861 0 $args{drop_destination} = 1;
862 0 $args{drop_source} = 1;
863 }
864 3 ▶ if (my $from = $self->__graph()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $from = $self->__graph) 3 0 3
865 3 $args{source} = $from;
866 }
867 3 $self->_expected_token(KEYWORD, 'TO');
868 3 ▶ if (my $to = $self->__graph()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $to = $self->__graph) 0 3 3
869 0 $args{destination} = $to;
870 }
871 3 my $pattern = Attean::Algebra::Add->new( %args );
872 3 $self->_add_patterns( $pattern );
873 3 $self->{build}{method} = 'UPDATE';
874 }
875  
876 # [5] SelectQuery ::= 'SELECT' ( 'DISTINCT' | 'REDUCED' )? ( Var+ | '*' ) DatasetClause* WhereClause SolutionModifier
877 29 ▶sub _SelectQuery {
Subroutine _SelectQuery: called CC=3 SCAR=11.0
878 29 my $self = shift;
879 29 ▶ if ($self->_optional_token(KEYWORD, qr/^(DISTINCT)/)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_optional_token(47, qr/^(DISTINCT)/u)) { } 0 29 29
elsif ($self->_optional_token(47, qr/^(REDUCED)/u)) { } 1 28 29
880 0 $self->{build}{options}{distinct} = 1;
881 } elsif ($self->_optional_token(KEYWORD, qr/^(REDUCED)/)) {
882 1 $self->{build}{options}{distinct} = 2;
883 }
884
885 29 my ($star, $exprs, $vars) = $self->__SelectVars;
886 29 my @exprs = @$exprs;
887
888 29 $self->_DatasetClause();
889
890 29 $self->_WhereClause;
891 28 $self->_SolutionModifier($vars);
892 28 $self->_ValuesClause();
893  
894 28 my %projected = map { $_ => 1 } $self->__solution_modifiers( $star, @exprs );
895 27 delete $self->{build}{options};
896 27 $self->{build}{method} = 'SELECT';
897 }
898  
899 30 ▶sub __SelectVars {
Subroutine __SelectVars: called CC=9 SCAR=22.1
900 30 my $self = shift;
901 30 my $star = 0;
902 30 my @vars;
903 30 my $count = 0;
904 30 my @exprs;
905 30 ▶ while ($self->_test_token(STAR) or $self->__SelectVar_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(58) or $self->__SelectVar_test) 33 4 37
Condition100%3/3
$self->_test_token(58) or $self->__SelectVar_test
l!l&&r!l&&!r
2674
MC/DC100%2/2
$self->_test_token(58) or $self->__SelectVar_test
$self->_test_token(58) $self->__SelectVar_test
Truth table100%3/3
A or B
A= $self->_test_token(58)B= $self->__SelectVar_test
ABresult
1X1
011
000
906 33 ▶ if ($self->_test_token(STAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(58)) { } 26 7 33
907 26 $self->{build}{star}++;
908 26 $self->_expected_token(STAR);
909 26 $star = 1;
910 26 $count++;
911 26 last;
912 } else {
913 7 my @s = $self->__SelectVar;
914 7 ▶ if (scalar(@s) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @s > 1) { } 1 6 7
915 1 my ($var, $expr) = @s;
916 1 push(@exprs, $var->value, $expr);
917 } else {
918 6 my $var = $s[0];
919 6 push(@exprs, $var->value, $var);
920 }
921 7 push(@vars, shift(@s));
922 7 $count++;
923 }
924 }
925
926 30 my %seen;
927 30 foreach my $v (@vars) {
928 7 ▶ if ($v->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->does("Attean::API::Variable")) 7 0 7
929 7 my $name = $v->value;
930 7 ▶ if ($seen{ $name }++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen{$name}++) 0 7 7
931 0 croak "Syntax error: Repeated variable ($name) used in projection list";
932 }
933 }
934 }
935
936 30 $self->{build}{variables} = \@vars;
937 30 ▶ if ($count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 0) 0 30 30
938 0 croak "Syntax error: No select variable or expression specified";
939 }
940 30 return $star, \@exprs, \@vars;
941 }
942  
943 3 ▶sub _BrackettedAliasExpression {
Subroutine _BrackettedAliasExpression: called CC=4 SCAR=16.5
944 3 my $self = shift;
945 3 ▶ my $allow_multiple_vars = shift || 0;
Condition50%1/2
shift() || 0
l!l
03
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
946 3 $self->_expected_token(LPAREN);
947 3 $self->_Expression;
948 3 my ($expr) = splice(@{ $self->{_stack} });
949 3 $self->_expected_token(KEYWORD, 'AS');
950 3 $self->_Var;
951 3 my ($var) = splice(@{ $self->{_stack} });
952
953 3 ▶ if ($allow_multiple_vars) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_multiple_vars) { } 0 3 3
954 0 my @vars = ($var);
955 0 ▶ while ($self->_optional_token(COMMA)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(6)) 0 0 0
956 0 $self->_Var;
957 0 push( @vars, splice(@{ $self->{_stack} }));
958 }
959 0 $self->_expected_token(RPAREN);
960 0 return (\@vars, $expr);
961 } else {
962 3 $self->_expected_token(RPAREN);
963 3 return ($var, $expr);
964 }
965 }
966  
967 11 ▶sub __SelectVar_test {
Subroutine __SelectVar_test: called CC=2 SCAR=6.9
968 11 my $self = shift;
969 11 local($self->{__aggregate_call_ok}) = 1;
970 # return 1 if $self->_BuiltInCall_test;
971 11 ▶ return 1 if $self->_test_token(LPAREN);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(18) 1 10 11
972 10 return $self->_test_token(VAR);
973 }
974  
975 7 ▶sub __SelectVar {
Subroutine __SelectVar: called CC=2 SCAR=6.9
976 7 my $self = shift;
977 7 local($self->{__aggregate_call_ok}) = 1;
978 7 ▶ if ($self->_test_token(LPAREN)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(18)) { } 1 6 7
979 1 my ($var, $expr) = $self->_BrackettedAliasExpression;
980 1 return ($var, $expr);
981 } else {
982 6 $self->_Var;
983 6 my ($var) = splice(@{ $self->{_stack} });
984 6 return $var;
985 }
986 }
987  
988 # [6] ConstructQuery ::= 'CONSTRUCT' ConstructTemplate DatasetClause* WhereClause SolutionModifier
989 3 ▶sub _ConstructQuery {
Subroutine _ConstructQuery: called CC=5 SCAR=16.8
990 3 my $self = shift;
991 3 my $shortcut = 1;
992 3 ▶ if ($self->_test_token(LBRACE)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(16)) 3 0 3
993 3 $shortcut = 0;
994 3 $self->_ConstructTemplate;
995 }
996 3 $self->_DatasetClause();
997 3 ▶ if ($shortcut) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shortcut) { } 0 3 3
998 0 $self->_TriplesWhereClause;
999 } else {
1000 3 $self->_WhereClause;
1001 }
1002
1003 3 $self->_SolutionModifier();
1004 3 $self->_ValuesClause();
1005
1006 3 $self->__solution_modifiers();
1007  
1008 3 my $pattern = $self->{build}{triples}[0];
1009 3 my $triples = delete $self->{build}{construct_triples};
1010 3 ▶ if (blessed($triples) and $triples->isa('Attean::Algebra::BGP')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($triples) and $triples->isa("Attean::Algebra::BGP")) 0 3 3
Condition33%1/3
builtin::blessed($triples) and $triples->isa("Attean::Algebra::BGP")
!ll&&!rl&&r
300
MC/DC0%0/2
builtin::blessed($triples) and $triples->isa("Attean::Algebra::BGP")
builtin::blessed($triples) $triples->isa("Attean::Algebra::BGP")
Truth table33%1/3
A and B
A= builtin::blessed($triples)B= $triples->isa("Attean::Algebra::BGP")
ABresult
0X0
100
111
1011 0 $triples = $triples->triples;
1012 }
1013 # my @triples;
1014 # warn $triples;
1015 # foreach my $t (@{ $triples // [] }) {
1016 # if ($t->isa('Attean::Algebra::BGP')) {
1017 # push(@triples, @{ $t->triples });
1018 # } else {
1019 # push(@triples, $t);
1020 # }
1021 # }
1022 3 my $construct = Attean::Algebra::Construct->new( children => [$pattern], triples => $triples );
1023 3 $self->{build}{triples}[0] = $construct;
1024 3 $self->{build}{method} = 'CONSTRUCT';
1025 }
1026  
1027 # [7] DescribeQuery ::= 'DESCRIBE' ( VarOrIRIref+ | '*' ) DatasetClause* WhereClause? SolutionModifier
1028 1 ▶sub _DescribeQuery {
Subroutine _DescribeQuery: called CC=5 SCAR=18.0
1029 1 my $self = shift;
1030
1031 1 my $star = 0;
1032 1 ▶ if ($self->_optional_token(STAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(58)) { } 0 1 1
1033 0 $star = 1;
1034 0 $self->{build}{variables} = ['*'];
1035 } else {
1036 1 $self->_VarOrIRIref;
1037 1 ▶ while ($self->_VarOrIRIref_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_VarOrIRIref_test) 0 1 1
1038 0 $self->_VarOrIRIref;
1039 }
1040 1 $self->{build}{variables} = [ splice(@{ $self->{_stack} }) ];
1041 }
1042
1043 1 $self->_DatasetClause();
1044
1045 1 ▶ if ($self->_WhereClause_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_WhereClause_test) { } 1 0 1
1046 1 $self->_WhereClause;
1047 } else {
1048 0 my $pattern = Attean::Algebra::BGP->new();
1049 0 $self->_add_patterns( $pattern );
1050 }
1051
1052 1 $self->_SolutionModifier();
1053 1 $self->{build}{method} = 'DESCRIBE';
1054  
1055 1 my $pattern = $self->{build}{triples}[0];
1056 0 ▶ my $terms = $star ? [map { Attean::Variable->new($_) } $pattern->in_scope_variables] : $self->{build}{variables};
Branch: 1 branch
BranchTrueFalseTotal
$star ? : 0 1 1
1057 1 $self->{build}{triples}[0] = Attean::Algebra::Describe->new( terms => $terms, children => [$pattern] );
1058 }
1059  
1060 # [8] AskQuery ::= 'ASK' DatasetClause* WhereClause
1061 4 ▶sub _AskQuery {
Subroutine _AskQuery: called CC=1 SCAR=0.0
1062 4 my $self = shift;
1063
1064 4 $self->_DatasetClause();
1065
1066 4 $self->_WhereClause;
1067 4 $self->_ValuesClause();
1068  
1069 4 $self->__solution_modifiers();
1070
1071 4 $self->{build}{variables} = [];
1072 4 $self->{build}{method} = 'ASK';
1073
1074
1075 4 my $pattern = $self->{build}{triples}[0];
1076 4 $self->{build}{triples}[0] = Attean::Algebra::Ask->new( children => [$pattern] );
1077 }
1078  
1079 # sub _DatasetClause_test {
1080 # my $self = shift;
1081 # return $self->_test_token(KEYWORD, 'FROM');
1082 # }
1083  
1084 # [9] DatasetClause ::= 'FROM' ( DefaultGraphClause | NamedGraphClause )
1085 37 ▶sub _DatasetClause {
Subroutine _DatasetClause: called CC=3 SCAR=11.0
1086 37 my $self = shift;
1087
1088 # my @dataset;
1089 37 $self->{build}{sources} = [];
1090 37 ▶ while ($self->_optional_token(KEYWORD, 'FROM')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "FROM")) 8 37 45
1091 8 ▶ if ($self->_test_token(KEYWORD, 'NAMED')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(47, 'NAMED')) { } 4 4 8
1092 4 $self->_NamedGraphClause;
1093 } else {
1094 4 $self->_DefaultGraphClause;
1095 }
1096 }
1097 }
1098  
1099 # [10] DefaultGraphClause ::= SourceSelector
1100 4 ▶sub _DefaultGraphClause {
Subroutine _DefaultGraphClause: called CC=1 SCAR=0.0
1101 4 my $self = shift;
1102 4 $self->_SourceSelector;
1103 4 my ($source) = splice(@{ $self->{_stack} });
1104 4 push( @{ $self->{build}{sources} }, [$source, 'DEFAULT'] );
1105 }
1106  
1107 # [11] NamedGraphClause ::= 'NAMED' SourceSelector
1108 4 ▶sub _NamedGraphClause {
Subroutine _NamedGraphClause: called CC=1 SCAR=0.0
1109 4 my $self = shift;
1110 4 $self->_expected_token(KEYWORD, 'NAMED');
1111 4 $self->_SourceSelector;
1112 4 my ($source) = splice(@{ $self->{_stack} });
1113 4 push( @{ $self->{build}{sources} }, [$source, 'NAMED'] );
1114 }
1115  
1116 # [12] SourceSelector ::= IRIref
1117 8 ▶sub _SourceSelector {
Subroutine _SourceSelector: called CC=1 SCAR=0.0
1118 8 my $self = shift;
1119 8 $self->_IRIref;
1120 }
1121  
1122 # [13] WhereClause ::= 'WHERE'? GroupGraphPattern
1123 1 ▶sub _WhereClause_test {
Subroutine _WhereClause_test: called CC=3 SCAR=16.5
1124 1 my $self = shift;
1125 1 ▶ return 1 if ($self->_test_token(KEYWORD, 'WHERE'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "WHERE") 1 0 1
1126 0 ▶ return 1 if ($self->_test_token(LBRACE));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(16) 0 0 0
1127 0 return 0;
1128 }
1129 38 ▶sub _WhereClause {
Subroutine _WhereClause: called CC=1 SCAR=0.0
1130 38 my $self = shift;
1131 38 $self->_optional_token(KEYWORD, 'WHERE');
1132 38 $self->_GroupGraphPattern;
1133
1134 37 my $ggp = $self->_peek_pattern;
1135 37 $self->_check_duplicate_blanks($ggp);
1136 }
1137  
1138 # TODO: This is commented out because of SPARQL errata regarding blank node labels shared between
1139 # an adjacent BGP and a property path.
1140 39 ▶sub _check_duplicate_blanks {
Subroutine _check_duplicate_blanks: called CC=1 SCAR=0.0
1141 39 my $self = shift;
1142 39 my $ggp = shift;
1143 # warn 'TODO: $ggp->_check_duplicate_blanks'; # XXXXXXXX
1144 # my @children = @{ $ggp->children };
1145 # my %seen;
1146 # foreach my $c (@{ $ggp->children }) {
1147 # my @blanks = $c->blank_nodes;
1148 # foreach my $b (@blanks) {
1149 # my $id = $b->value;
1150 # if ($seen{ $id }++) {
1151 # warn $ggp->as_string;
1152 # croak "Same blank node identifier ($id) used in more than one BasicGraphPattern.";
1153 # }
1154 # }
1155 # }
1156 39 return 1;
1157 }
1158  
1159 0 ▶sub _TriplesWhereClause {
Subroutine _TriplesWhereClause: not called CC=2 SCAR=17.9
1160 0 my $self = shift;
1161 0 $self->_push_pattern_container;
1162
1163 0 $self->_expected_token(KEYWORD, 'WHERE');
1164 0 $self->_expected_token(LBRACE);
1165 0 ▶ if ($self->_TriplesBlock_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_TriplesBlock_test) 0 0 0
1166 0 $self->_TriplesBlock;
1167 }
1168 0 $self->_expected_token(RBRACE);
1169
1170 0 my ($cont, $hints) = $self->_pop_pattern_container;
1171 0 $self->{build}{construct_triples} = $cont->[0];
1172
1173 0 my $pattern = $self->_new_join(@$cont);
1174 0 $pattern->hints($hints);
1175 0 $self->_add_patterns( $pattern );
1176 }
1177  
1178 # sub _Binding_test {
1179 # my $self = shift;
1180 # return $self->_test_token(LPAREN);
1181 # }
1182  
1183 2 ▶sub _Binding {
Subroutine _Binding: called CC=4 SCAR=14.6
1184 2 my $self = shift;
1185 2 my $count = shift;
1186
1187 2 my @terms;
1188 2 ▶ if ($count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 0) { } 0 2 2
1189 0 $self->_expected_token(NIL);
1190 } else {
1191 2 $self->_expected_token(LPAREN);
1192 2 foreach my $i (1..$count) {
1193 2 ▶ unless ($self->_BindingValue_test) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_BindingValue_test) 0 2 2
1194 0 my $found = $i-1;
1195 0 croak "Syntax error: Expected $count BindingValues but only found $found";
1196 }
1197 2 $self->_BindingValue;
1198 2 push( @terms, splice(@{ $self->{_stack} }));
1199 }
1200 2 $self->_expected_token(RPAREN);
1201 }
1202 2 return \@terms;
1203 }
1204  
1205 6 ▶sub _BindingValue_test {
Subroutine _BindingValue_test: called CC=8 SCAR=21.6
1206 6 my $self = shift;
1207 6 ▶ return 1 if ($self->_IRIref_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 2 4 6
1208 4 ▶ return 1 if ($self->_test_token(KEYWORD, 'UNDEF'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "UNDEF") 0 4 4
1209 4 ▶ return 1 if ($self->_test_literal_token);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_literal_token 3 1 4
1210 1 ▶ return 1 if ($self->_IRIref_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 0 1 1
1211 1 ▶ return 1 if ($self->_test_token(BNODE));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(4) 0 1 1
1212 1 ▶ return 1 if ($self->_test_token(NIL));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(51) 0 1 1
1213 1 ▶ return 1 if ($self->_test_token(LTLTP));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(36) 0 1 1
1214 1 return 0;
1215 }
1216  
1217 5 ▶sub _BindingValue {
Subroutine _BindingValue: called CC=4 SCAR=23.4
1218 5 my $self = shift;
1219 5 ▶ if ($self->_optional_token(KEYWORD, 'UNDEF')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_optional_token(47, 'UNDEF')) { } 0 5 5
elsif ($self->_test_token(36)) { } 0 5 5
1220 0 push(@{ $self->{_stack} }, undef);
1221 } elsif ($self->_test_token(LTLTP)) {
1222 0 my @loc = $self->lexer->current_location;
1223 0 my $tp = $self->_TripleTermData();
1224 0 my $t = eval { $tp->as_triple };
1225 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1226 0 $self->lexer->throw_near_error("Invalid triple term", @loc);
1227 }
1228 0 push(@{ $self->{_stack} }, $t);
1229 } else {
1230 5 $self->_GraphTerm;
1231 }
1232 }
1233  
1234 # [20] GroupCondition ::= ( BuiltInCall | FunctionCall | '(' Expression ( 'AS' Var )? ')' | Var )
1235 2 ▶sub __GroupByVar_test {
Subroutine __GroupByVar_test: called CC=5 SCAR=17.2
1236 2 my $self = shift;
1237 2 ▶ return 1 if ($self->_BuiltInCall_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_BuiltInCall_test 0 2 2
1238 2 ▶ return 1 if ($self->_IRIref_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 0 2 2
1239 2 ▶ return 1 if ($self->_test_token(LPAREN));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(18) 0 2 2
1240 2 ▶ return 1 if ($self->_test_token(VAR));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(59) 0 2 2
1241 2 return 0;
1242 }
1243  
1244 2 ▶sub __GroupByVar {
Subroutine __GroupByVar: called CC=5 SCAR=25.2
1245 2 my $self = shift;
1246 2 ▶ if ($self->_optional_token(LPAREN)) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_optional_token(18)) { } 0 2 2
elsif ($self->_IRIref_test) { } 0 2 2
elsif ($self->_BuiltInCall_test) { } 0 2 2
1247 0 $self->_Expression;
1248 0 my ($expr) = splice(@{ $self->{_stack} });
1249 0 ▶ if ($self->_optional_token(KEYWORD, 'AS')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, 'AS')) { } 0 0 0
1250 0 $self->_Var;
1251 0 my ($var) = splice(@{ $self->{_stack} });
1252 0 push(@{ $self->{build}{__group_vars} }, [$var, $expr]);
1253 0 my $vexpr = Attean::ValueExpression->new( value => $var );
1254 0 $self->_add_stack( $vexpr );
1255 } else {
1256 0 $self->_add_stack( $expr );
1257 }
1258 0 $self->_expected_token(RPAREN);
1259
1260 } elsif ($self->_IRIref_test) {
1261 0 $self->_FunctionCall;
1262 } elsif ($self->_BuiltInCall_test) {
1263 0 $self->_BuiltInCall;
1264 } else {
1265 2 $self->_Var;
1266 2 my $var = pop(@{ $self->{_stack} });
1267 2 my $expr = Attean::ValueExpression->new(value => $var);
1268 2 $self->_add_stack($expr);
1269 }
1270 }
1271  
1272 # [14] SolutionModifier ::= OrderClause? LimitOffsetClauses?
1273 33 ▶sub _SolutionModifier {
Subroutine _SolutionModifier: called CC=7 SCAR=19.5
1274 33 my $self = shift;
1275 33 ▶ my $vars = shift // [];
Condition100%2/2
shift() // []
l!l
294
MC/DC100%1/1
shift() // []
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1276
1277 33 ▶ if ($self->_test_token(KEYWORD, 'GROUP')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(47, "GROUP")) 2 31 33
1278 2 $self->_GroupClause($vars);
1279 }
1280
1281 33 ▶ if ($self->_test_token(KEYWORD, 'RANK')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(47, "RANK")) 1 32 33
1282 1 $self->_RankClause;
1283 }
1284
1285 33 ▶ if ($self->_test_token(KEYWORD, 'HAVING')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(47, "HAVING")) 1 32 33
1286 1 $self->_HavingClause;
1287 }
1288
1289 33 ▶ if ($self->_OrderClause_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_OrderClause_test) 1 32 33
1290 1 $self->_OrderClause;
1291 }
1292
1293 33 ▶ if ($self->_LimitOffsetClauses_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_LimitOffsetClauses_test) 2 31 33
1294 2 $self->_LimitOffsetClauses;
1295 }
1296 }
1297  
1298 2 ▶sub _GroupClause {
Subroutine _GroupClause: called CC=6 SCAR=18.8
1299 2 my $self = shift;
1300 2 my $vars = shift;
1301 2 $self->_expected_token(KEYWORD, 'GROUP');
1302 2 $self->_expected_token(KEYWORD, 'BY');
1303
1304 2 ▶ if ($self->{build}{star}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"build"}{"star"}) 0 2 2
1305 0 croak "Syntax error: SELECT * cannot be used with aggregate grouping";
1306 }
1307
1308 2 ▶ $self->{build}{__aggregate} ||= {};
Condition100%2/2
$self->{"build"}{"__aggregate"} ||= {}
l!l
11
MC/DC100%1/1
$self->{"build"}{"__aggregate"} ||= {}
$self->{"build"}{"__aggregate"}
Truth table100%2/2
A
A= $self->{"build"}{"__aggregate"}
Aresult
11
00
1309 2 my @vars;
1310 2 $self->__GroupByVar;
1311 2 my ($v) = splice(@{ $self->{_stack} });
1312 2 push( @vars, $v );
1313 2 ▶ while ($self->__GroupByVar_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__GroupByVar_test) 0 2 2
1314 0 $self->__GroupByVar;
1315 0 my ($v) = splice(@{ $self->{_stack} });
1316 0 push( @vars, $v );
1317 }
1318  
1319 2 my %seen;
1320 2 foreach my $v (@vars) {
1321 2 my $var = $v->value;
1322 2 ▶ if ($var->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var->does("Attean::API::Variable")) 2 0 2
1323 2 my $name = $var->value;
1324 2 $seen{ $name }++;
1325 }
1326 }
1327
1328 # warn 'TODO: verify that projection only includes aggregates and grouping variables'; # XXXXX
1329 # foreach my $v (@$vars) {
1330 # if ($v->does('Attean::API::Variable')) {
1331 # my $name = $v->value;
1332 # unless ($seen{ $name }) {
1333 # croak "Syntax error: Variable used in projection but not present in aggregate grouping ($name)";
1334 # # throw ::Error::ParseError -text => "Syntax error: Variable used in projection but not present in aggregate grouping ($name)";
1335 # }
1336 # }
1337 # }
1338
1339 2 $self->{build}{__group_by} = \@vars;
1340 }
1341  
1342 1 ▶sub _RankClause {
Subroutine _RankClause: called CC=4 SCAR=14.1
1343 1 my $self = shift;
1344 1 $self->_expected_token(KEYWORD, 'RANK');
1345 1 $self->_expected_token(LPAREN);
1346 1 $self->_OrderCondition;
1347 1 my @order;
1348 1 push(@order, splice(@{ $self->{_stack} }));
1349 1 ▶ while ($self->_OrderCondition_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_OrderCondition_test) 0 1 1
1350 0 $self->_OrderCondition;
1351 0 push(@order, splice(@{ $self->{_stack} }));
1352 }
1353 1 $self->_expected_token(RPAREN);
1354 1 $self->_expected_token(KEYWORD, 'AS');
1355 1 $self->_Var;
1356 1 my ($var) = splice(@{ $self->{_stack} });
1357
1358 1 my @exprs;
1359 my %ascending;
1360 1 foreach my $o (@order) {
1361 1 my ($dir, $expr) = @$o;
1362 1 push(@exprs, $expr);
1363 1 ▶ $ascending{ $expr->value->value } = ($dir eq 'ASC') ? 1 : 0; # TODO: support ranking by complex expressions, not just variables
Branch: 1 branch
BranchTrueFalseTotal
$dir eq 'ASC' ? : 1 0 1
1364 }
1365 1 my $r = Attean::AggregateExpression->new(
1366 distinct => 0,
1367 operator => 'RANK',
1368 children => \@exprs,
1369 scalar_vars => {
1370 ascending => \%ascending,
1371 },
1372 variable => $var,
1373 );
1374
1375 1 $self->{build}{__aggregate}{ $var->value } = [ $var, $r ];
1376 }
1377  
1378 1 ▶sub _HavingClause {
Subroutine _HavingClause: called CC=4 SCAR=14.2
1379 1 my $self = shift;
1380 1 $self->_expected_token(KEYWORD, 'HAVING');
1381 1 ▶ $self->{build}{__aggregate} ||= {};
Condition50%1/2
$self->{"build"}{"__aggregate"} ||= {}
l!l
10
MC/DC0%0/1
$self->{"build"}{"__aggregate"} ||= {}
$self->{"build"}{"__aggregate"}
Truth table50%1/2
A
A= $self->{"build"}{"__aggregate"}
Aresult
11
00
1382 1 local($self->{__aggregate_call_ok}) = 1;
1383 1 my $expr;
1384 1 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->_Constraint_test and do { do { $self->_Constraint; my($_expr) = splice(@{$$self{"_stack"};}); if ($expr) { $expr = "Attean::BinaryExpression"->new("operator", "&&", "children", [$expr, $_expr]); } else { $expr = $_expr; } } } 0 1 1
1385 1 $self->_Constraint;
1386 1 my ($_expr) = splice(@{ $self->{_stack} });
1387 1 ▶ if ($expr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expr) { } 0 1 1
1388 0 $expr = Attean::BinaryExpression->new( operator => '&&', children => [$expr, $_expr] );
1389 } else {
1390 1 $expr = $_expr;
1391 }
1392 } while ($self->_Constraint_test);
1393 1 $self->{build}{__having} = $expr;
1394 }
1395  
1396 # [15] LimitOffsetClauses ::= ( LimitClause OffsetClause? | OffsetClause LimitClause? )
1397 33 ▶sub _LimitOffsetClauses_test {
Subroutine _LimitOffsetClauses_test: called CC=3 SCAR=11.0
1398 33 my $self = shift;
1399 33 ▶ return 1 if ($self->_test_token(KEYWORD, 'LIMIT'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "LIMIT") 1 32 33
1400 32 ▶ return 1 if ($self->_test_token(KEYWORD, 'OFFSET'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "OFFSET") 1 31 32
1401 31 return 0;
1402 }
1403  
1404 2 ▶sub _LimitOffsetClauses {
Subroutine _LimitOffsetClauses: called CC=4 SCAR=14.2
1405 2 my $self = shift;
1406 2 ▶ if ($self->_LimitClause_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_LimitClause_test) { } 1 1 2
1407 1 $self->_LimitClause;
1408 1 ▶ if ($self->_OffsetClause_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_OffsetClause_test) 1 0 1
1409 1 $self->_OffsetClause;
1410 }
1411 } else {
1412 1 $self->_OffsetClause;
1413 1 ▶ if ($self->_LimitClause_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_LimitClause_test) 0 1 1
1414 0 $self->_LimitClause;
1415 }
1416 }
1417 }
1418  
1419 # [16] OrderClause ::= 'ORDER' 'BY' OrderCondition+
1420 34 ▶sub _OrderClause_test {
Subroutine _OrderClause_test: called CC=2 SCAR=6.9
1421 34 my $self = shift;
1422 34 ▶ return 1 if ($self->_test_token(KEYWORD, 'ORDER'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "ORDER") 1 33 34
1423 33 return 0;
1424 }
1425  
1426 1 ▶sub _OrderClause {
Subroutine _OrderClause: called CC=3 SCAR=11.6
1427 1 my $self = shift;
1428 1 $self->_expected_token(KEYWORD, 'ORDER');
1429 1 $self->_expected_token(KEYWORD, 'BY');
1430 1 my @order;
1431 1 ▶ $self->{build}{__aggregate} ||= {};
Condition50%1/2
$self->{"build"}{"__aggregate"} ||= {}
l!l
01
MC/DC0%0/1
$self->{"build"}{"__aggregate"} ||= {}
$self->{"build"}{"__aggregate"}
Truth table50%1/2
A
A= $self->{"build"}{"__aggregate"}
Aresult
11
00
1432 1 local($self->{__aggregate_call_ok}) = 1;
1433 1 $self->_OrderCondition;
1434 1 push(@order, splice(@{ $self->{_stack} }));
1435 1 ▶ while ($self->_OrderCondition_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_OrderCondition_test) 0 1 1
1436 0 $self->_OrderCondition;
1437 0 push(@order, splice(@{ $self->{_stack} }));
1438 }
1439 1 $self->{build}{options}{orderby} = \@order;
1440 }
1441  
1442 # [17] OrderCondition ::= ( ( 'ASC' | 'DESC' ) BrackettedExpression ) | ( Constraint | Var )
1443 2 ▶sub _OrderCondition_test {
Subroutine _OrderCondition_test: called CC=5 SCAR=17.2
1444 2 my $self = shift;
1445 2 ▶ return 1 if ($self->_test_token(KEYWORD, 'ASC'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "ASC") 0 2 2
1446 2 ▶ return 1 if ($self->_test_token(KEYWORD, 'DESC'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "DESC") 0 2 2
1447 2 ▶ return 1 if ($self->_test_token(VAR));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(59) 0 2 2
1448 2 ▶ return 1 if $self->_Constraint_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_Constraint_test 0 2 2
1449 2 return 0;
1450 }
1451  
1452 2 ▶sub _OrderCondition {
Subroutine _OrderCondition: called CC=3 SCAR=11.0
1453 2 my $self = shift;
1454 2 my $dir = 'ASC';
1455 2 ▶ if (my $t = $self->_optional_token(KEYWORD, qr/^(ASC|DESC)/)) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $t = $self->_optional_token(47, qr/^(ASC|DESC)/u)) { } 1 1 2
elsif ($self->_test_token(59)) { } 1 0 1
1456 1 $dir = $t->value;
1457 1 $self->_BrackettedExpression;
1458 } elsif ($self->_test_token(VAR)) {
1459 1 $self->_Var;
1460 1 my $var = pop(@{ $self->{_stack} });
1461 1 my $expr = Attean::ValueExpression->new(value => $var);
1462 1 $self->_add_stack($expr);
1463 } else {
1464 0 $self->_Constraint;
1465 }
1466 2 my ($expr) = splice(@{ $self->{_stack} });
1467 2 $self->_add_stack( [ $dir, $expr ] );
1468 }
1469  
1470 # [18] LimitClause ::= 'LIMIT' INTEGER
1471 3 ▶sub _LimitClause_test {
Subroutine _LimitClause_test: called CC=1 SCAR=0.0
1472 3 my $self = shift;
1473 3 return ($self->_test_token(KEYWORD, 'LIMIT'));
1474 }
1475  
1476 1 ▶sub _LimitClause {
Subroutine _LimitClause: called CC=1 SCAR=0.0
1477 1 my $self = shift;
1478 1 $self->_expected_token(KEYWORD, 'LIMIT');
1479 1 my $t = $self->_expected_token(INTEGER);
1480 1 $self->{build}{options}{limit} = $t->value;
1481 }
1482  
1483 # [19] OffsetClause ::= 'OFFSET' INTEGER
1484 1 ▶sub _OffsetClause_test {
Subroutine _OffsetClause_test: called CC=1 SCAR=0.0
1485 1 my $self = shift;
1486 1 return ($self->_test_token(KEYWORD, 'OFFSET'));
1487 }
1488  
1489 2 ▶sub _OffsetClause {
Subroutine _OffsetClause: called CC=1 SCAR=0.0
1490 2 my $self = shift;
1491 2 $self->_expected_token(KEYWORD, 'OFFSET');
1492 2 my $t = $self->_expected_token(INTEGER);
1493 2 $self->{build}{options}{offset} = $t->value;
1494 }
1495  
1496 # [20] GroupGraphPattern ::= '{' TriplesBlock? ( ( GraphPatternNotTriples | Filter ) '.'? TriplesBlock? )* '}'
1497 55 ▶sub _GroupGraphPattern {
Subroutine _GroupGraphPattern: called CC=2 SCAR=6.9
1498 55 my $self = shift;
1499
1500 55 $self->_expected_token(LBRACE);
1501
1502 55 ▶ if ($self->_SubSelect_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_SubSelect_test) { } 1 54 55
1503 1 $self->_SubSelect;
1504 } else {
1505 54 $self->_GroupGraphPatternSub;
1506 }
1507  
1508 54 $self->_expected_token(RBRACE);
1509 }
1510  
1511 54 ▶sub _GroupGraphPatternSub {
Subroutine _GroupGraphPatternSub: called CC=15 SCAR=31.0
1512 54 my $self = shift;
1513 54 $self->_push_pattern_container;
1514
1515 54 my $got_pattern = 0;
1516 54 my $need_dot = 0;
1517 54 ▶ if ($self->_TriplesBlock_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_TriplesBlock_test) 42 12 54
1518 42 $need_dot = 1;
1519 42 $got_pattern++;
1520 42 $self->_TriplesBlock;
1521 }
1522
1523 53 ▶ while (not $self->_test_token(RBRACE)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_token(22)) 17 53 70
1524 17 my $cur = $self->_peek_token;
1525 17 ▶ if ($self->_GraphPatternNotTriples_test) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_GraphPatternNotTriples_test) { } 13 4 17
elsif ($self->_test_token(47, 'FILTER')) { } 4 0 4
1526 13 $need_dot = 0;
1527 13 $got_pattern++;
1528 13 $self->_GraphPatternNotTriples;
1529 13 my (@data) = splice(@{ $self->{_stack} });
1530 13 $self->__handle_GraphPatternNotTriples( @data );
1531 } elsif ($self->_test_token(KEYWORD, 'FILTER')) {
1532 4 $got_pattern++;
1533 4 $need_dot = 0;
1534 4 $self->_Filter;
1535 }
1536
1537 17 ▶ if ($need_dot or $self->_test_token(DOT)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_dot or $self->_test_token(9)) 0 17 17
Condition33%1/3
$need_dot or $self->_test_token(9)
l!l&&r!l&&!r
0017
MC/DC0%0/2
$need_dot or $self->_test_token(9)
$need_dot $self->_test_token(9)
Truth table33%1/3
A or B
A= $need_dotB= $self->_test_token(9)
ABresult
1X1
011
000
1538 0 $self->_expected_token(DOT);
1539 0 ▶ if ($got_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got_pattern) { } 0 0 0
1540 0 $need_dot = 0;
1541 0 $got_pattern = 0;
1542 } else {
1543 0 croak "Syntax error: Extra dot found without preceding pattern";
1544 }
1545 }
1546
1547 17 ▶ if ($self->_TriplesBlock_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_TriplesBlock_test) 1 16 17
1548 1 my $peek = $self->_peek_pattern;
1549 1 ▶ if (blessed($peek) and $peek->isa('Attean::Algebra::BGP')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($peek) and $peek->isa('Attean::Algebra::BGP')) { } 0 1 1
Condition33%1/3
builtin::blessed($peek) and $peek->isa("Attean::Algebra::BGP")
!ll&&!rl&&r
100
MC/DC0%0/2
builtin::blessed($peek) and $peek->isa("Attean::Algebra::BGP")
builtin::blessed($peek) $peek->isa("Attean::Algebra::BGP")
Truth table33%1/3
A and B
A= builtin::blessed($peek)B= $peek->isa("Attean::Algebra::BGP")
ABresult
0X0
100
111
1550 0 $self->_TriplesBlock;
1551 0 my $rhs = $self->_remove_pattern;
1552 0 my $lhs = $self->_remove_pattern;
1553 0 ▶ if ($rhs->isa('Attean::Algebra::BGP')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhs->isa('Attean::Algebra::BGP')) { } 0 0 0
1554 0 my $merged = $self->__new_bgp( map { @{ $_->triples } } ($lhs, $rhs) );
1555 0 $self->_add_patterns( $merged );
1556 } else {
1557 0 my $merged = $self->_new_join($lhs, $rhs);
1558 0 $self->_add_patterns( $merged );
1559 }
1560 } else {
1561 1 $self->_TriplesBlock;
1562 }
1563 }
1564  
1565 17 my $t = $self->_peek_token;
1566 12 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1567 17 ▶ last if (refaddr($t) == refaddr($cur));
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($t) == builtin::refaddr($cur) 0 17 17
1568 }
1569 53 my ($cont, $hints) = $self->_pop_pattern_container;
1570  
1571 53 my @filters = splice(@{ $self->{filters} });
1572 53 my @patterns;
1573 53 my $pattern = $self->_new_join(@$cont);
1574 53 $pattern->hints($hints);
1575 53 ▶ if (@filters) {
Branch: 1 branch
BranchTrueFalseTotal
if (@filters) 4 49 53
1576 4 ▶ while (my $f = shift @filters) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = shift @filters) 4 4 8
1577 4 $pattern = Attean::Algebra::Filter->new( children => [$pattern], expression => $f );
1578 }
1579 }
1580 53 $self->_add_patterns( $pattern );
1581 }
1582  
1583 13 ▶sub __handle_GraphPatternNotTriples {
Subroutine __handle_GraphPatternNotTriples: called CC=15 SCAR=35.6
1584 13 my $self = shift;
1585 13 my $data = shift;
1586 13 ▶ return unless ($data);
Branch: 1 branch
BranchTrueFalseTotal
unless $data 1 12 13
1587 12 my ($class, @args) = @$data;
1588 12 ▶ if ($class =~ /^Attean::Algebra::(LeftJoin|Minus)$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($class =~ /^Attean::Algebra::(LeftJoin|Minus)$/u) { } 2 10 12
elsif ($class eq 'Attean::Algebra::Table') { } 0 10 10
elsif ($class =~ /^Attean::Algebra::Unfold$/u) { } 0 10 10
elsif ($class =~ /^Attean::Algebra::Extend$/u) { } 2 8 10
elsif ($class eq 'Attean::Algebra::Service') { } 2 6 8
elsif ($class =~ /Attean::Algebra::(Union|Graph|Join)$/u) { } 6 0 6
1589 2 my ($cont, $hints) = $self->_pop_pattern_container;
1590 2 my $ggp = $self->_new_join(@$cont);
1591 2 $ggp->hints($hints);
1592 2 $self->_push_pattern_container;
1593 # my $ggp = $self->_remove_pattern();
1594 2 ▶ unless ($ggp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ggp) 0 2 2
1595 0 $ggp = Attean::Algebra::BGP->new();
1596 }
1597
1598 2 my $opt = $class->new( children => [$ggp, @args] );
1599 2 $self->_add_patterns( $opt );
1600 } elsif ($class eq 'Attean::Algebra::Table') {
1601 0 my ($table) = @args;
1602 0 $self->_add_patterns( $table );
1603 } elsif ($class =~ /^Attean::Algebra::Unfold$/) {
1604 0 my ($cont, $hints) = $self->_pop_pattern_container;
1605 0 my $ggp = $self->_new_join(@$cont);
1606 0 $ggp->hints($hints);
1607 0 $self->_push_pattern_container;
1608 # my $ggp = $self->_remove_pattern();
1609 0 ▶ unless ($ggp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ggp) 0 0 0
1610 0 $ggp = Attean::Algebra::BGP->new();
1611 }
1612 0 my @vars = @{ $args[0] };
1613 0 my $expr = $args[1];
1614 0 foreach my $var (@vars) {
1615 0 my %in_scope = map { $_ => 1 } $ggp->in_scope_variables;
1616 0 ▶ if (exists $in_scope{ $var->value }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $in_scope{$var->value}) 0 0 0
1617 0 croak "Syntax error: BIND used with variable already in scope";
1618 }
1619 }
1620 0 my $bind = $class->new( children => [$ggp], variables => \@vars, expression => $expr );
1621 0 $self->_add_patterns( $bind );
1622 } elsif ($class =~ /^Attean::Algebra::Extend$/) {
1623 2 my ($cont, $hints) = $self->_pop_pattern_container;
1624 2 my $ggp = $self->_new_join(@$cont);
1625 2 $ggp->hints($hints);
1626 2 $self->_push_pattern_container;
1627 # my $ggp = $self->_remove_pattern();
1628 2 ▶ unless ($ggp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ggp) 0 2 2
1629 0 $ggp = Attean::Algebra::BGP->new();
1630 }
1631 2 my ($var, $expr) = @args;
1632 2 my %in_scope = map { $_ => 1 } $ggp->in_scope_variables;
1633 2 ▶ if (exists $in_scope{ $var->value }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $in_scope{$var->value}) 0 2 2
1634 0 croak "Syntax error: BIND used with variable already in scope";
1635 }
1636 2 my $bind = $class->new( children => [$ggp], variable => $var, expression => $expr );
1637 2 $self->_add_patterns( $bind );
1638 } elsif ($class eq 'Attean::Algebra::Service') {
1639 2 my ($endpoint, $pattern, $silent) = @args;
1640 2 ▶ if ($endpoint->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($endpoint->does('Attean::API::Variable')) { } 0 2 2
1641 # SERVICE ?var
1642 0 croak "SERVICE ?var not implemented";
1643 } else {
1644 # SERVICE <endpoint>
1645 # no-op
1646 2 my $service = Attean::Algebra::Service->new( children => [$pattern], endpoint => $endpoint, silent => $silent );
1647 2 $self->_add_patterns( $service );
1648 }
1649 } elsif ($class =~ /Attean::Algebra::(Union|Graph|Join)$/) {
1650 # no-op
1651 } else {
1652 0 croak 'Unrecognized GraphPattern: ' . $class;
1653 }
1654 }
1655  
1656 55 ▶sub _SubSelect_test {
Subroutine _SubSelect_test: called CC=1 SCAR=0.0
1657 55 my $self = shift;
1658 55 return $self->_test_token(KEYWORD, 'SELECT');
1659 }
1660  
1661 1 ▶sub _SubSelect {
Subroutine _SubSelect: called CC=26 SCAR=59.2
1662 1 my $self = shift;
1663 1 my $pattern;
1664 {
1665 1 local($self->{namespaces}) = $self->{namespaces};
1666 1 local($self->{_stack}) = [];
1667 1 local($self->{filters}) = [];
1668 1 local($self->{_pattern_container_stack}) = [];
1669  
1670 1 my $triples = $self->_push_pattern_container();
1671 1 local($self->{build}) = { triples => $triples};
1672 1 ▶ if ($self->{baseURI}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"baseURI"}) 0 1 1
1673 0 $self->{build}{base} = $self->{baseURI};
1674 }
1675
1676 1 $self->_expected_token(KEYWORD, 'SELECT');
1677 1 ▶ if (my $t = $self->_optional_token(KEYWORD, qr/^(DISTINCT|REDUCED)/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = $self->_optional_token(47, qr/^(DISTINCT|REDUCED)/u)) 0 1 1
1678 0 my $mod = $t->value;
1679 0 $self->{build}{options}{lc($mod)} = 1;
1680 }
1681
1682 1 my ($star, $exprs, $vars) = $self->__SelectVars;
1683 1 my @exprs = @$exprs;
1684
1685 1 $self->_WhereClause;
1686 1 $self->_SolutionModifier($vars);
1687
1688 1 ▶ if ($self->{build}{options}{orderby}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"build"}{"options"}{"orderby"}) 0 1 1
1689 0 my $order = delete $self->{build}{options}{orderby};
1690 0 my $pattern = pop(@{ $self->{build}{triples} });
1691
1692 0 my @order = @$order;
1693 0 my @cmps;
1694 0 foreach my $o (@order) {
1695 0 my ($dir, $expr) = @$o;
1696 0 my $asc = ($dir eq 'ASC');
1697 0 push(@cmps, Attean::Algebra::Comparator->new(ascending => $asc, expression => $expr));
1698 }
1699 0 my $sort = Attean::Algebra::OrderBy->new( children => [$pattern], comparators => \@cmps );
1700 0 push(@{ $self->{build}{triples} }, $sort);
1701 }
1702
1703 1 ▶ if ($self->_optional_token(KEYWORD, 'VALUES')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "VALUES")) 0 1 1
1704 0 my @vars;
1705 0 my $parens = 0;
1706 0 my $nil = 0;
1707 0 ▶ if ($self->_optional_token(NIL)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_optional_token(51)) { } 0 0 0
elsif ($self->_optional_token(18)) { } 0 0 0
1708 0 $parens = 1;
1709 0 $nil = 1;
1710 } elsif ($self->_optional_token(LPAREN)) {
1711 0 $parens = 1;
1712 }
1713 0 ▶ unless ($nil) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nil) 0 0 0
1714 0 ▶ while ($self->_test_token(VAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(59)) 0 0 0
1715 0 $self->_Var;
1716 0 push( @vars, splice(@{ $self->{_stack} }));
1717 }
1718 0 ▶ if ($parens) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parens) 0 0 0
1719 0 $self->_expected_token(RPAREN);
1720 }
1721 }
1722 0 my $count = scalar(@vars);
1723 0 ▶ if (not($parens) and $count == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $parens and $count == 0) { } 0 0 0
elsif (not $parens and $count > 1) { } 0 0 0
Condition0%0/3
not $parens and $count == 0
!ll&&!rl&&r
000
MC/DC0%0/2
not $parens and $count == 0
not $parens $count == 0
Truth table0%0/3
not(A) and B
A= not $parensB= $count == 0
ABresult
0X0
100
111
1724 0 croak "Syntax error: Expected VAR in inline data declaration";
1725 ▶ } elsif (not($parens) and $count > 1) {
Condition0%0/3
not $parens and $count > 1
!ll&&!rl&&r
000
MC/DC0%0/2
not $parens and $count > 1
not $parens $count > 1
Truth table0%0/3
not(A) and B
A= not $parensB= $count > 1
ABresult
0X0
100
111
1726 0 croak "Syntax error: Inline data declaration can only have one variable when parens are omitted";
1727 }
1728
1729 0 ▶ my $short = (not($parens) and $count == 1);
Condition0%0/3
!$parens && $count == 1
!ll&&!rl&&r
000
MC/DC0%0/2
!$parens && $count == 1
!$parens $count == 1
Truth table0%0/3
not(A) && B
A= !$parensB= $count == 1
ABresult
0X0
100
111
1730 0 $self->_expected_token(LBRACE);
1731  
1732 0 ▶ if ($self->_optional_token(NIL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(51)) { } 0 0 0
1733 # no-op
1734 } else {
1735 0 ▶ if (not($short) or ($short and $self->_test_token(LPAREN))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $short or $short and $self->_test_token(18)) { } 0 0 0
Condition0%0/6
not $short or $short and $self->_test_token(18)
l!l&&r!l&&!r
000
$short and $self->_test_token(18)
!ll&&!rl&&r
000
MC/DC0%0/3
not $short or $short and $self->_test_token(18)
not $short $short $self->_test_token(18)
Truth table0%0/4
not(A) or B and C
A= not $shortB= $shortC= $self->_test_token(18)
ABCresult
1XX1
0111
00X0
0100
1736 0 ▶ while ($self->_test_token(LPAREN) or $self->_test_token(NIL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(18) or $self->_test_token(51)) 0 0 0
Condition0%0/3
$self->_test_token(18) or $self->_test_token(51)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_test_token(18) or $self->_test_token(51)
$self->_test_token(18) $self->_test_token(51)
Truth table0%0/3
A or B
A= $self->_test_token(18)B= $self->_test_token(51)
ABresult
1X1
011
000
1737 0 my $terms = $self->_Binding($count);
1738 0 push( @{ $self->{build}{bindings}{terms} }, $terms );
1739 }
1740 } else {
1741 0 ▶ while ($self->_BindingValue_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_BindingValue_test) 0 0 0
1742 0 $self->_BindingValue;
1743 0 my ($term) = splice(@{ $self->{_stack} });
1744 0 push( @{ $self->{build}{bindings}{terms} }, [$term] );
1745 }
1746 }
1747 }
1748
1749 0 $self->_expected_token(RBRACE);
1750 0 $self->{build}{bindings}{vars} = \@vars;
1751
1752 0 my $bindings = delete $self->{build}{bindings};
1753 0 my @rows = @{ $bindings->{terms} };
1754 0 my @vbs;
1755 0 foreach my $r (@rows) {
1756 0 my %d;
1757 0 foreach my $i (0 .. $#{ $r }) {
1758 0 ▶ if (blessed($r->[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($r->[$i])) 0 0 0
1759 0 $d{ $vars[$i]->value } = $r->[$i];
1760 }
1761 }
1762 0 my $r = Attean::Result->new(bindings => \%d);
1763 0 push(@vbs, $r);
1764 }
1765 0 my $table = Attean::Algebra::Table->new( variables => \@vars, rows => \@vbs );
1766 0 my $pattern = pop(@{ $self->{build}{triples} });
1767 0 push(@{ $self->{build}{triples} }, $self->_new_join($pattern, $table));
1768 }
1769
1770 1 $self->__solution_modifiers( $star, @exprs );
1771
1772 1 delete $self->{build}{options};
1773 1 my $data = delete $self->{build};
1774 1 $pattern = $data->{triples}[0];
1775 1 $pattern = Attean::Algebra::Query->new( children => [$pattern], subquery => 1 );
1776 }
1777
1778 1 $self->_add_patterns( $pattern );
1779 }
1780  
1781 # [21] TriplesBlock ::= TriplesSameSubject ( '.' TriplesBlock? )?
1782 110 ▶sub _TriplesBlock_test {
Subroutine _TriplesBlock_test: called CC=11 SCAR=24.7
1783 110 my $self = shift;
1784 # VarOrTerm | TriplesNode -> (Var | GraphTerm) | (Collection | BlankNodePropertyList) -> Var | IRIref | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL | Collection | BlankNodePropertyList
1785 # but since a triple can't start with a literal, this is reduced to:
1786 # Var | IRIref | BlankNode | NIL
1787 110 ▶ return 1 if ($self->_test_token(VAR));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(59) 51 59 110
1788 59 ▶ return 1 if ($self->_test_token(NIL));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(51) 0 59 59
1789 59 ▶ return 1 if ($self->_test_token(ANON));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(2) 0 59 59
1790 59 ▶ return 1 if ($self->_test_token(BNODE));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(4) 0 59 59
1791 59 ▶ return 1 if ($self->_test_token(LPAREN));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(18) 1 58 59
1792 58 ▶ return 1 if ($self->_test_token(LBRACKET));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(17) 0 58 58
1793 58 ▶ return 1 if ($self->_test_token(LTLT));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(35) 2 56 58
1794 56 ▶ return 1 if ($self->_test_token(LTLTP)); # Not in official grammar yet
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(36) 0 56 56
1795 56 ▶ return 1 if ($self->_IRIref_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 10 46 56
1796 46 ▶ return 1 if ($self->_test_literal_token);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_literal_token 0 46 46
1797 46 return 0;
1798 }
1799  
1800 86 ▶sub _test_literal_token {
Subroutine _test_literal_token: called CC=9 SCAR=22.6
1801 86 my $self = shift;
1802 86 ▶ return 1 if ($self->_test_token(STRING1D));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(26) 10 76 86
1803 76 ▶ return 1 if ($self->_test_token(STRING3D));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(28) 0 76 76
1804 76 ▶ return 1 if ($self->_test_token(STRING1S));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(27) 1 75 76
1805 75 ▶ return 1 if ($self->_test_token(STRING3S));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(29) 1 74 75
1806 74 ▶ return 1 if ($self->_test_token(DECIMAL));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(8) 0 74 74
1807 74 ▶ return 1 if ($self->_test_token(DOUBLE));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(10) 0 74 74
1808 74 ▶ return 1 if ($self->_test_token(INTEGER));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(13) 0 74 74
1809 74 ▶ return 1 if ($self->_test_token(BOOLEAN));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(5) 0 74 74
1810 74 return 0;
1811 }
1812  
1813  
1814 52 ▶sub _TriplesBlock {
Subroutine _TriplesBlock: called CC=1 SCAR=0.0
1815 52 my $self = shift;
1816 52 $self->_push_pattern_container;
1817 52 $self->__TriplesBlock;
1818 51 my ($triples, $hints) = $self->_pop_pattern_container;
1819 51 my $bgp = $self->__new_bgp( @$triples );
1820 51 $bgp->hints($hints);
1821 51 $self->_add_patterns( $bgp );
1822 }
1823  
1824 ## this one (with two underscores) doesn't pop patterns off the stack and make a BGP.
1825 ## instead, things are left on the stack so we can recurse without doing the wrong thing.
1826 ## the one with one underscore (_TriplesBlock) will pop everything off and make the BGP.
1827 52 ▶sub __TriplesBlock {
Subroutine __TriplesBlock: called CC=4 SCAR=14.8
1828 52 my $self = shift;
1829 52 my $got_dot = 0;
1830 52 TRIPLESBLOCKLOOP:
1831 $self->_TriplesSameSubjectPath;
1832 51 ▶ while ($self->_test_token(DOT)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(9)) 9 51 60
1833 9 ▶ if ($got_dot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got_dot) 0 9 9
1834 0 croak "Syntax error: found extra DOT after TriplesBlock";
1835 }
1836 9 $self->_expected_token(DOT);
1837 9 $got_dot++;
1838 9 ▶ if ($self->_TriplesBlock_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_TriplesBlock_test) 0 9 9
1839 0 $got_dot = 0;
1840 0 goto TRIPLESBLOCKLOOP;
1841 }
1842 }
1843 }
1844  
1845 # [22] GraphPatternNotTriples ::= OptionalGraphPattern | GroupOrUnionGraphPattern | GraphGraphPattern
1846 17 ▶sub _GraphPatternNotTriples_test {
Subroutine _GraphPatternNotTriples_test: called CC=4 SCAR=14.0
1847 17 my $self = shift;
1848 17 ▶ return 1 if ($self->_test_token(LBRACE));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(16) 3 14 17
1849 14 my $t = $self->_peek_token;
1850 14 ▶ return unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 14 14
1851 14 ▶ return 0 unless ($t->type == KEYWORD);
Branch: 1 branch
BranchTrueFalseTotal
unless $t->type == 47 0 14 14
1852 14 return ($t->value =~ qr/^(VALUES|BIND|UNFOLD|SERVICE|MINUS|OPTIONAL|GRAPH|HINT)$/i);
1853 }
1854  
1855 13 ▶sub _GraphPatternNotTriples {
Subroutine _GraphPatternNotTriples: called CC=9 SCAR=22.3
1856 13 my $self = shift;
1857 13 ▶ if ($self->_test_token(KEYWORD, 'VALUES')) {
Branch: 8 branches
BranchTrueFalseTotal
if ($self->_test_token(47, 'VALUES')) { } 0 13 13
elsif ($self->_test_token(47, 'SERVICE')) { } 2 11 13
elsif ($self->_test_token(47, 'MINUS')) { } 1 10 11
elsif ($self->_test_token(47, 'BIND')) { } 2 8 10
elsif ($self->_test_token(47, 'UNFOLD')) { } 0 8 8
elsif ($self->_test_token(47, 'HINT')) { } 1 7 8
elsif ($self->_test_token(47, 'OPTIONAL')) { } 1 6 7
elsif ($self->_test_token(16)) { } 3 3 6
1858 0 $self->_InlineDataClause;
1859 } elsif ($self->_test_token(KEYWORD, 'SERVICE')) {
1860 2 $self->_ServiceGraphPattern;
1861 } elsif ($self->_test_token(KEYWORD, 'MINUS')) {
1862 1 $self->_MinusGraphPattern;
1863 } elsif ($self->_test_token(KEYWORD, 'BIND')) {
1864 2 $self->_Bind;
1865 } elsif ($self->_test_token(KEYWORD, 'UNFOLD')) {
1866 0 $self->_Unfold;
1867 } elsif ($self->_test_token(KEYWORD, 'HINT')) {
1868 1 $self->_Hint;
1869 } elsif ($self->_test_token(KEYWORD, 'OPTIONAL')) {
1870 1 $self->_OptionalGraphPattern;
1871 } elsif ($self->_test_token(LBRACE)) {
1872 3 $self->_GroupOrUnionGraphPattern;
1873 } else {
1874 3 $self->_GraphGraphPattern;
1875 }
1876 }
1877  
1878 0 ▶sub _InlineDataClause {
Subroutine _InlineDataClause: not called CC=22 SCAR=62.3
1879 0 my $self = shift;
1880 0 $self->_expected_token(KEYWORD, 'VALUES');
1881 0 my @vars;
1882
1883 0 my $parens = 0;
1884 0 my $nil = 0;
1885 0 ▶ if ($self->_optional_token(NIL)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_optional_token(51)) { } 0 0 0
elsif ($self->_optional_token(18)) { } 0 0 0
1886 0 $nil = 1;
1887 0 $parens = 1;
1888 } elsif ($self->_optional_token(LPAREN)) {
1889 0 $parens = 1;
1890 }
1891
1892 0 ▶ unless ($nil) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nil) 0 0 0
1893 0 ▶ while ($self->_test_token(VAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(59)) 0 0 0
1894 0 $self->_Var;
1895 0 push( @vars, splice(@{ $self->{_stack} }));
1896 }
1897 0 ▶ if ($parens) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parens) 0 0 0
1898 0 $self->_expected_token(RPAREN);
1899 }
1900 }
1901
1902 0 my $count = scalar(@vars);
1903 0 ▶ if (not($parens) and $count == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $parens and $count == 0) { } 0 0 0
elsif (not $parens and $count > 1) { } 0 0 0
Condition0%0/3
not $parens and $count == 0
!ll&&!rl&&r
000
MC/DC0%0/2
not $parens and $count == 0
not $parens $count == 0
Truth table0%0/3
not(A) and B
A= not $parensB= $count == 0
ABresult
0X0
100
111
1904 0 croak "Syntax error: Expected VAR in inline data declaration";
1905 ▶ } elsif (not($parens) and $count > 1) {
Condition0%0/3
not $parens and $count > 1
!ll&&!rl&&r
000
MC/DC0%0/2
not $parens and $count > 1
not $parens $count > 1
Truth table0%0/3
not(A) and B
A= not $parensB= $count > 1
ABresult
0X0
100
111
1906 0 croak "Syntax error: Inline data declaration can only have one variable when parens are omitted";
1907 }
1908
1909 0 ▶ my $short = (not($parens) and $count == 1);
Condition0%0/3
!$parens && $count == 1
!ll&&!rl&&r
000
MC/DC0%0/2
!$parens && $count == 1
!$parens $count == 1
Truth table0%0/3
not(A) && B
A= !$parensB= $count == 1
ABresult
0X0
100
111
1910 0 $self->_expected_token(LBRACE);
1911 0 my @rows;
1912 0 ▶ if (not($short) or ($short and $self->_test_token(LPAREN))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $short or $short and $self->_test_token(18)) { } 0 0 0
Condition0%0/6
not $short or $short and $self->_test_token(18)
l!l&&r!l&&!r
000
$short and $self->_test_token(18)
!ll&&!rl&&r
000
MC/DC0%0/3
not $short or $short and $self->_test_token(18)
not $short $short $self->_test_token(18)
Truth table0%0/4
not(A) or B and C
A= not $shortB= $shortC= $self->_test_token(18)
ABCresult
1XX1
0111
00X0
0100
1913 # { (term) (term) }
1914 0 ▶ while ($self->_test_token(LPAREN) or $self->_test_token(NIL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(18) or $self->_test_token(51)) 0 0 0
Condition0%0/3
$self->_test_token(18) or $self->_test_token(51)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_test_token(18) or $self->_test_token(51)
$self->_test_token(18) $self->_test_token(51)
Truth table0%0/3
A or B
A= $self->_test_token(18)B= $self->_test_token(51)
ABresult
1X1
011
000
1915 0 my $terms = $self->_Binding($count);
1916 0 push( @rows, $terms );
1917 }
1918 } else {
1919 # { term term }
1920 0 ▶ while ($self->_BindingValue_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_BindingValue_test) 0 0 0
1921 0 $self->_BindingValue;
1922 0 my ($term) = splice(@{ $self->{_stack} });
1923 0 push( @rows, [$term] );
1924 }
1925 }
1926
1927 0 $self->_expected_token(RBRACE);
1928
1929 0 my @vbs;
1930 0 foreach my $row (@rows) {
1931 0 my %d;
1932 # Turn triple patterns into ground triples.
1933 0 ▶ @d{ map { $_->value } @vars } = map { (blessed($_) and $_->does('Attean::API::TriplePattern')) ? $_->as_triple : $_ } @$row;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) && $_->does('Attean::API::TriplePattern') ? : 0 0 0
Condition0%0/3
builtin::blessed($_) and $_->does("Attean::API::TriplePattern")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($_) and $_->does("Attean::API::TriplePattern")
builtin::blessed($_) $_->does("Attean::API::TriplePattern")
Truth table0%0/3
A and B
A= builtin::blessed($_)B= $_->does("Attean::API::TriplePattern")
ABresult
0X0
100
111
1934 0 foreach my $k (keys %d) {
1935 0 ▶ unless (blessed($d{$k})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($d{$k})) 0 0 0
1936 0 delete $d{$k};
1937 }
1938 }
1939 0 my $result = Attean::Result->new(bindings => \%d);
1940 0 push(@vbs, $result);
1941 }
1942 0 my $table = Attean::Algebra::Table->new( variables => \@vars, rows => \@vbs );
1943 0 $self->_add_stack( ['Attean::Algebra::Table', $table] );
1944
1945 }
1946  
1947 2 ▶sub _Bind {
Subroutine _Bind: called CC=1 SCAR=0.0
1948 2 my $self = shift;
1949 2 $self->_expected_token(KEYWORD, 'BIND');
1950 2 my ($var, $expr) = $self->_BrackettedAliasExpression;
1951 2 $self->_add_stack( ['Attean::Algebra::Extend', $var, $expr] );
1952 }
1953  
1954 0 ▶sub _Unfold {
Subroutine _Unfold: not called CC=1 SCAR=6.9
1955 0 my $self = shift;
1956 0 $self->_expected_token(KEYWORD, 'UNFOLD');
1957 0 local($self->{__require_ground_triple_terms}) = 1;
1958 0 my ($var, $expr) = $self->_BrackettedAliasExpression(1);
1959 0 $self->_add_stack( ['Attean::Algebra::Unfold', $var, $expr] );
1960 }
1961  
1962 1 ▶sub _Hint {
Subroutine _Hint: called CC=1 SCAR=0.0
1963 1 my $self = shift;
1964 1 $self->_expected_token(KEYWORD, 'HINT');
1965 1 my $terms = $self->_HintTerms();
1966 1 $self->_add_hint($terms);
1967 }
1968  
1969 1 ▶sub _HintTerms {
Subroutine _HintTerms: called CC=2 SCAR=6.9
1970 1 my $self = shift;
1971
1972 1 $self->_expected_token(LPAREN);
1973
1974 1 my @terms;
1975 1 ▶ while ($self->_BindingValue_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_BindingValue_test) 3 1 4
1976 3 $self->_BindingValue;
1977 3 push(@terms, splice(@{ $self->{_stack} }));
1978 }
1979 1 $self->_expected_token(RPAREN);
1980 1 return \@terms;
1981 }
1982  
1983 2 ▶sub _ServiceGraphPattern {
Subroutine _ServiceGraphPattern: called CC=4 SCAR=14.2
1984 2 my $self = shift;
1985 2 $self->_expected_token(KEYWORD, 'SERVICE');
1986 2 ▶ my $silent = $self->_optional_token(KEYWORD, 'SILENT') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->_optional_token(47, 'SILENT') ? : 0 2 2
1987 2 $self->__close_bgp_with_filters;
1988 2 ▶ if ($self->_test_token(VAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(59)) { } 0 2 2
1989 0 $self->_Var;
1990 } else {
1991 2 $self->_IRIref;
1992 }
1993 2 my ($endpoint) = splice( @{ $self->{_stack} } );
1994 2 $self->_GroupGraphPattern;
1995 2 my $ggp = $self->_remove_pattern;
1996
1997 2 ▶ my $opt = ['Attean::Algebra::Service', $endpoint, $ggp, ($silent ? 1 : 0)];
Branch: 1 branch
BranchTrueFalseTotal
$silent ? : 0 2 2
1998 2 $self->_add_stack( $opt );
1999 }
2000  
2001 # [23] OptionalGraphPattern ::= 'OPTIONAL' GroupGraphPattern
2002 # sub _OptionalGraphPattern_test {
2003 # my $self = shift;
2004 # return $self->_test_token(KEYWORD, 'OPTIONAL');
2005 # }
2006  
2007 4 ▶sub __close_bgp_with_filters {
Subroutine __close_bgp_with_filters: called CC=4 SCAR=23.4
2008 4 my $self = shift;
2009 4 my @filters = splice(@{ $self->{filters} });
2010 4 ▶ if (@filters) {
Branch: 1 branch
BranchTrueFalseTotal
if (@filters) 0 4 4
2011 0 my ($cont, $hints) = $self->_pop_pattern_container;
2012 0 my $ggp = $self->_new_join(@$cont);
2013 0 $ggp->hints($hints);
2014 0 $self->_push_pattern_container;
2015 # my $ggp = $self->_remove_pattern();
2016 0 ▶ unless ($ggp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ggp) 0 0 0
2017 0 $ggp = Attean::Algebra::BGP->new();
2018 }
2019 0 ▶ while (my $f = shift @filters) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = shift @filters) 0 0 0
2020 0 $ggp = Attean::Algebra::Filter->new( children => [$ggp], expression => $f );
2021 }
2022 0 $self->_add_patterns($ggp);
2023 }
2024 }
2025  
2026 1 ▶sub _OptionalGraphPattern {
Subroutine _OptionalGraphPattern: called CC=1 SCAR=0.0
2027 1 my $self = shift;
2028 1 $self->_expected_token(KEYWORD, 'OPTIONAL');
2029 1 $self->__close_bgp_with_filters;
2030
2031 1 $self->_GroupGraphPattern;
2032 1 my $ggp = $self->_remove_pattern;
2033 1 my $opt = ['Attean::Algebra::LeftJoin', $ggp];
2034 1 $self->_add_stack( $opt );
2035 }
2036  
2037 1 ▶sub _MinusGraphPattern {
Subroutine _MinusGraphPattern: called CC=1 SCAR=0.0
2038 1 my $self = shift;
2039 1 $self->_expected_token(KEYWORD, 'MINUS');
2040 1 $self->__close_bgp_with_filters;
2041
2042 1 $self->_GroupGraphPattern;
2043 1 my $ggp = $self->_remove_pattern;
2044 1 my $opt = ['Attean::Algebra::Minus', $ggp];
2045 1 $self->_add_stack( $opt );
2046 }
2047  
2048 # [24] GraphGraphPattern ::= 'GRAPH' VarOrIRIref GroupGraphPattern
2049 3 ▶sub _GraphGraphPattern {
Subroutine _GraphGraphPattern: called CC=5 SCAR=17.1
2050 3 my $self = shift;
2051 3 ▶ if ($self->{__data_pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__data_pattern"}) 0 3 3
2052 0 ▶ if ($self->{__graph_nesting_level}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__graph_nesting_level"}++) 0 0 0
2053 0 croak "Syntax error: Nested named GRAPH blocks not allowed in data template.";
2054 }
2055 }
2056
2057 3 $self->_expected_token(KEYWORD, 'GRAPH');
2058 3 $self->_VarOrIRIref;
2059 3 my ($graph) = splice(@{ $self->{_stack} });
2060 3 ▶ if ($graph->does('Attean::API::IRI')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($graph->does('Attean::API::IRI')) { } 2 1 3
2061 2 $self->_GroupGraphPattern;
2062 } else {
2063 1 $self->_GroupGraphPattern;
2064 }
2065  
2066 3 ▶ if ($self->{__data_pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__data_pattern"}) 0 3 3
2067 0 $self->{__graph_nesting_level}--;
2068 }
2069
2070 3 my $ggp = $self->_remove_pattern;
2071 3 my $pattern = Attean::Algebra::Graph->new( children => [$ggp], graph => $graph );
2072 3 $self->_add_patterns( $pattern );
2073 3 $self->_add_stack( [ 'Attean::Algebra::Graph' ] );
2074 }
2075  
2076 # [25] GroupOrUnionGraphPattern ::= GroupGraphPattern ( 'UNION' GroupGraphPattern )*
2077 # sub _GroupOrUnionGraphPattern_test {
2078 # my $self = shift;
2079 # return $self->_test_token(LBRACE);
2080 # }
2081  
2082 3 ▶sub _GroupOrUnionGraphPattern {
Subroutine _GroupOrUnionGraphPattern: called CC=3 SCAR=11.0
2083 3 my $self = shift;
2084 3 $self->_GroupGraphPattern;
2085 3 my $ggp = $self->_remove_pattern;
2086 3 ▶ if ($self->_test_token(KEYWORD, 'UNION')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(47, 'UNION')) { } 1 2 3
2087 1 ▶ while ($self->_optional_token(KEYWORD, 'UNION')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "UNION")) 1 1 2
2088 1 $self->_GroupGraphPattern;
2089 1 my $rhs = $self->_remove_pattern;
2090 1 $ggp = Attean::Algebra::Union->new( children => [$ggp, $rhs] );
2091 }
2092 1 $self->_add_patterns( $ggp );
2093 1 $self->_add_stack( [ 'Attean::Algebra::Union' ] );
2094 } else {
2095 2 $self->_add_patterns( $ggp );
2096 2 $self->_add_stack( [ 'Attean::Algebra::Join' ] );
2097 }
2098 }
2099  
2100 # [26] Filter ::= 'FILTER' Constraint
2101 4 ▶sub _Filter {
Subroutine _Filter: called CC=1 SCAR=0.0
2102 4 my $self = shift;
2103 4 $self->_expected_token(KEYWORD, 'FILTER');
2104 4 $self->_Constraint;
2105 4 my ($expr) = splice(@{ $self->{_stack} });
2106 4 $self->_add_filter( $expr );
2107 }
2108  
2109 # [27] Constraint ::= BrackettedExpression | BuiltInCall | FunctionCall
2110 3 ▶sub _Constraint_test {
Subroutine _Constraint_test: called CC=4 SCAR=14.6
2111 3 my $self = shift;
2112 3 ▶ return 1 if ($self->_test_token(LPAREN));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(18) 0 3 3
2113 3 ▶ return 1 if $self->_BuiltInCall_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_BuiltInCall_test 0 3 3
2114 3 ▶ return 1 if $self->_IRIref_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 0 3 3
2115 3 return 0;
2116 }
2117  
2118 5 ▶sub _Constraint {
Subroutine _Constraint: called CC=3 SCAR=11.3
2119 5 my $self = shift;
2120 5 ▶ if ($self->_test_token(LPAREN)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_test_token(18)) { } 4 1 5
elsif ($self->_BuiltInCall_test) { } 0 1 1
2121 4 $self->_BrackettedExpression();
2122 } elsif ($self->_BuiltInCall_test) {
2123 0 $self->_BuiltInCall();
2124 } else {
2125 1 $self->_FunctionCall();
2126 }
2127 }
2128  
2129 # [28] FunctionCall ::= IRIref ArgList
2130 # sub _FunctionCall_test {
2131 # my $self = shift;
2132 # return $self->_IRIref_test;
2133 # }
2134  
2135 1 ▶sub _FunctionCall {
Subroutine _FunctionCall: called CC=3 SCAR=11.4
2136 1 my $self = shift;
2137 1 $self->_IRIref;
2138 1 my ($iri) = splice(@{ $self->{_stack} });
2139 1 ▶ if (my $func = Attean->get_global_aggregate($iri)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $func = "Attean"->get_global_aggregate($iri)) 0 1 1
2140
2141 }
2142
2143 1 my @args = $self->_ArgList;
2144  
2145 1 ▶ if ($iri->value =~ m<^http://www[.]w3[.]org/2001/XMLSchema#(?:integer|decimal|float|double|boolean|string|dateTime)$>) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iri->value =~ m[^http://www[.]w3[.]org/2001/XMLSchema#(?:integer|decimal|float|double|boolean|string|dateTime)$]u) { } 0 1 1
2146 0 my $expr = Attean::CastExpression->new( children => \@args, datatype => $iri );
2147 0 $self->_add_stack( $expr );
2148 } else {
2149 1 my $func = Attean::ValueExpression->new( value => $iri );
2150 1 my $expr = $self->new_function_expression( 'INVOKE', $func, @args );
2151 1 $self->_add_stack( $expr );
2152 }
2153 }
2154  
2155 # [28] ValuesClause ::= ( 'VALUES' DataBlock )?
2156 35 ▶sub _ValuesClause {
Subroutine _ValuesClause: called CC=21 SCAR=36.9
2157 35 my $self = shift;
2158 35 ▶ if ($self->_optional_token(KEYWORD, 'VALUES')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "VALUES")) 1 34 35
2159 1 my @vars;
2160 # $self->_Var;
2161 # push( @vars, splice(@{ $self->{_stack} }));
2162 1 my $parens = 0;
2163 1 my $nil = 0;
2164 1 ▶ if ($self->_optional_token(NIL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(51)) { } 0 1 1
2165 0 $parens = 1;
2166 0 $nil = 1;
2167 } else {
2168 1 ▶ if ($self->_optional_token(LPAREN)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(18)) 1 0 1
2169 1 $parens = 1;
2170 }
2171 1 ▶ while ($self->_test_token(VAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(59)) 1 1 2
2172 1 $self->_Var;
2173 1 push( @vars, splice(@{ $self->{_stack} }));
2174 }
2175 1 ▶ if ($parens) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parens) 1 0 1
2176 1 $self->_expected_token(RPAREN);
2177 }
2178 }
2179
2180 1 my $count = scalar(@vars);
2181 1 ▶ if (not($parens) and $count == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $parens and $count == 0) { } 0 1 1
elsif (not $parens and $count > 1) { } 0 2 2
Condition33%1/3
not $parens and $count == 0
!ll&&!rl&&r
100
MC/DC0%0/2
not $parens and $count == 0
not $parens $count == 0
Truth table33%1/3
not(A) and B
A= not $parensB= $count == 0
ABresult
0X0
100
111
2182 0 croak "Syntax error: Expected VAR in inline data declaration";
2183 ▶ } elsif (not($parens) and $count > 1) {
Condition33%1/3
not $parens and $count > 1
!ll&&!rl&&r
100
MC/DC0%0/2
not $parens and $count > 1
not $parens $count > 1
Truth table33%1/3
not(A) and B
A= not $parensB= $count > 1
ABresult
0X0
100
111
2184 0 croak "Syntax error: Inline data declaration can only have one variable when parens are omitted";
2185 }
2186
2187 1 ▶ my $short = (not($parens) and $count == 1);
Condition33%1/3
!$parens && $count == 1
!ll&&!rl&&r
100
MC/DC0%0/2
!$parens && $count == 1
!$parens $count == 1
Truth table33%1/3
not(A) && B
A= !$parensB= $count == 1
ABresult
0X0
100
111
2188 1 $self->_expected_token(LBRACE);
2189 1 ▶ if (not($short) or ($short and $self->_test_token(LPAREN))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $short or $short and $self->_test_token(18)) { } 1 0 1
Condition16%1/6
not $short or $short and $self->_test_token(18)
l!l&&r!l&&!r
100
$short and $self->_test_token(18)
!ll&&!rl&&r
000
MC/DC0%0/3
not $short or $short and $self->_test_token(18)
not $short $short $self->_test_token(18)
Truth table25%1/4
not(A) or B and C
A= not $shortB= $shortC= $self->_test_token(18)
ABCresult
1XX1
0111
00X0
0100
2190 1 ▶ while ($self->_test_token(LPAREN) or $self->_test_token(NIL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(18) or $self->_test_token(51)) 2 1 3
Condition66%2/3
$self->_test_token(18) or $self->_test_token(51)
l!l&&r!l&&!r
201
MC/DC50%1/2
$self->_test_token(18) or $self->_test_token(51)
$self->_test_token(18) $self->_test_token(51)
Truth table66%2/3
A or B
A= $self->_test_token(18)B= $self->_test_token(51)
ABresult
1X1
011
000
2191 2 my $terms = $self->_Binding($count);
2192 2 push( @{ $self->{build}{bindings}{terms} }, $terms );
2193 }
2194 } else {
2195 0 ▶ while ($self->_BindingValue_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_BindingValue_test) 0 0 0
2196 0 $self->_BindingValue;
2197 0 my ($term) = splice(@{ $self->{_stack} });
2198 0 push( @{ $self->{build}{bindings}{terms} }, [$term] );
2199 }
2200 }
2201
2202 1 $self->_expected_token(RBRACE);
2203  
2204 1 my $bindings = delete $self->{build}{bindings};
2205 1 ▶ my @rows = @{ $bindings->{terms} || [] };
Condition50%1/2
$bindings->{'terms'} || []
l!l
10
MC/DC0%0/1
$bindings->{'terms'} || []
$bindings->{'terms'}
Truth table50%1/2
A
A= $bindings->{'terms'}
Aresult
11
00
2206 1 my @vbs;
2207 1 foreach my $r (@rows) {
2208 2 my %d;
2209 2 foreach my $i (0 .. $#{ $r }) {
2210 2 ▶ if (blessed($r->[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($r->[$i])) 2 0 2
2211 2 $d{ $vars[$i]->value } = $r->[$i];
2212 }
2213 }
2214 2 my $r = Attean::Result->new(bindings => \%d);
2215 2 push(@vbs, $r);
2216 }
2217 1 my $table = Attean::Algebra::Table->new( variables => \@vars, rows => \@vbs );
2218 1 $self->{build}{trailing_values} = $table; # joined into the pattern in __solution_modifiers
2219 1 $self->{build}{trailing_values_vars} = \@vars;
2220 }
2221 }
2222  
2223  
2224 # [29] ArgList ::= ( NIL | '(' Expression ( ',' Expression )* ')' )
2225 1 ▶sub _ArgList_test {
Subroutine _ArgList_test: called CC=2 SCAR=7.1
2226 1 my $self = shift;
2227 1 ▶ return 1 if $self->_test_token(NIL);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(51) 0 1 1
2228 1 return $self->_test_token(LPAREN);
2229 }
2230  
2231 2 ▶sub _ArgList {
Subroutine _ArgList: called CC=4 SCAR=15.2
2232 2 my $self = shift;
2233 2 ▶ if ($self->_optional_token(NIL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(51)) { } 0 2 2
2234 0 return;
2235 } else {
2236 2 $self->_expected_token(LPAREN);
2237 2 my @args;
2238 2 ▶ unless ($self->_test_token(RPAREN)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_token(24)) 2 0 2
2239 2 $self->_Expression;
2240 2 push( @args, splice(@{ $self->{_stack} }) );
2241 2 ▶ while ($self->_optional_token(COMMA)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(6)) 0 2 2
2242 0 $self->_Expression;
2243 0 push( @args, splice(@{ $self->{_stack} }) );
2244 }
2245 }
2246 2 $self->_expected_token(RPAREN);
2247 2 return @args;
2248 }
2249 }
2250  
2251 # [30] ConstructTemplate ::= '{' ConstructTriples? '}'
2252 3 ▶sub _ConstructTemplate {
Subroutine _ConstructTemplate: called CC=2 SCAR=7.0
2253 3 my $self = shift;
2254 3 $self->_push_pattern_container;
2255 3 $self->_expected_token(LBRACE);
2256
2257 3 ▶ if ($self->_ConstructTriples_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ConstructTriples_test) 3 0 3
2258 3 $self->_ConstructTriples;
2259 }
2260  
2261 3 $self->_expected_token(RBRACE);
2262 3 (my $cont, undef) = $self->_pop_pattern_container; # ignore hints in a construct template
2263 3 $self->{build}{construct_triples} = $cont;
2264 }
2265  
2266 # [31] ConstructTriples ::= TriplesSameSubject ( '.' ConstructTriples? )?
2267 3 ▶sub _ConstructTriples_test {
Subroutine _ConstructTriples_test: called CC=1 SCAR=0.0
2268 3 my $self = shift;
2269 3 return $self->_TriplesBlock_test;
2270 }
2271  
2272 3 ▶sub _ConstructTriples {
Subroutine _ConstructTriples: called CC=3 SCAR=15.1
2273 3 my $self = shift;
2274 3 $self->_TriplesSameSubject;
2275 3 ▶ while ($self->_optional_token(DOT)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(9)) 0 3 3
2276 0 ▶ if ($self->_ConstructTriples_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ConstructTriples_test) 0 0 0
2277 0 $self->_TriplesSameSubject;
2278 }
2279 }
2280 }
2281  
2282 # [32] TriplesSameSubject ::= VarOrTerm PropertyListNotEmpty | TriplesNode PropertyList
2283 3 ▶sub _TriplesSameSubject {
Subroutine _TriplesSameSubject: called CC=5 SCAR=16.4
2284 3 my $self = shift;
2285 3 my @triples;
2286 3 ▶ if ($self->_TriplesNode_test) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_TriplesNode_test) { } 1 2 3
elsif ($self->_test_token(35)) { } 0 2 2
2287 1 $self->_TriplesNode;
2288 1 my ($s) = splice(@{ $self->{_stack} });
2289 1 $self->_PropertyList($s);
2290 1 my @list = splice(@{ $self->{_stack} });
2291 1 foreach my $data (@list) {
2292 0 push(@triples, $self->__new_statement( $s, @$data ));
2293 }
2294 } elsif ($self->_test_token(LTLT)) {
2295 0 $self->_ReifiedTripleBlock();
2296 0 push(@triples, splice(@{ $self->{_stack} }));
2297 } else {
2298 2 $self->_VarOrTerm;
2299 2 my ($s) = splice(@{ $self->{_stack} });
2300  
2301 2 $self->_PropertyListNotEmpty($s);
2302 2 my (@list) = splice(@{ $self->{_stack} });
2303 2 foreach my $data (@list) {
2304 2 push(@triples, $self->__new_statement( $s, @$data ));
2305 }
2306 }
2307
2308 3 $self->_add_patterns( @triples );
2309 # return @triples;
2310 }
2311  
2312 # TriplesSameSubjectPath ::= VarOrTerm PropertyListNotEmptyPath | TriplesNode PropertyListPath
2313 52 ▶sub _TriplesSameSubjectPath {
Subroutine _TriplesSameSubjectPath: called CC=6 SCAR=21.6
2314 52 my $self = shift;
2315 52 my @triples;
2316 52 ▶ if ($self->_TriplesNode_test) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_TriplesNode_test) { } 0 52 52
elsif ($self->_test_token(35)) { } 2 50 52
2317 0 ▶ if ($self->_test_token(LTLTP)) { # Not in official grammar yet
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(36)) { } 0 0 0
2318 0 $self->_TripleTerm();
2319 } else {
2320 0 $self->_TriplesNode;
2321 }
2322 0 my ($s) = splice(@{ $self->{_stack} });
2323 0 $self->_PropertyListPath($s);
2324 0 my @list = splice(@{ $self->{_stack} });
2325 0 foreach my $data (@list) {
2326 0 push(@triples, $self->__new_statement( $s, @$data ));
2327 }
2328 } elsif ($self->_test_token(LTLT)) {
2329 2 $self->_ReifiedTripleBlockPath();
2330 2 push(@triples, splice(@{ $self->{_stack} }));
2331 } else {
2332 50 $self->_VarOrTerm;
2333 50 my ($s) = splice(@{ $self->{_stack} });
2334 50 $self->_PropertyListNotEmptyPath($s);
2335 49 my (@list) = splice(@{ $self->{_stack} });
2336 49 foreach my $data (@list) {
2337 57 push(@triples, $self->__new_statement( $s, @$data ));
2338 }
2339 }
2340 51 $self->_add_patterns( @triples );
2341 # return @triples;
2342 }
2343  
2344 # [33] PropertyListNotEmpty ::= Verb ObjectList ( ';' ( Verb ObjectList )? )*
2345 2 ▶sub _PropertyListNotEmpty {
Subroutine _PropertyListNotEmpty: called CC=3 SCAR=13.9
2346 2 my $self = shift;
2347 2 my $s = shift;
2348 2 $self->_Verb;
2349 2 my ($p) = splice(@{ $self->{_stack} });
2350 2 $self->_ObjectList($s, $p);
2351 2 my @l = splice(@{ $self->{_stack} });
2352 2 my @props = map { [$p, $_] } @l;
2353 2 ▶ while ($self->_optional_token(SEMICOLON)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(25)) 0 2 2
2354 0 ▶ if ($self->_Verb_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_Verb_test) 0 0 0
2355 0 $self->_Verb;
2356 0 my ($p) = splice(@{ $self->{_stack} });
2357 0 $self->_ObjectList($s, $p);
2358 0 my @l = splice(@{ $self->{_stack} });
2359 0 push(@props, map { [$p, $_] } @l);
2360 }
2361 }
2362 2 $self->_add_stack( @props );
2363 }
2364  
2365 # [34] PropertyList ::= PropertyListNotEmpty?
2366 1 ▶sub _PropertyList {
Subroutine _PropertyList: called CC=2 SCAR=7.6
2367 1 my $self = shift;
2368 1 my $s = shift;
2369 1 ▶ if ($self->_Verb_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_Verb_test) 0 1 1
2370 0 $self->_PropertyListNotEmpty($s);
2371 }
2372 }
2373  
2374 # [33] PropertyListNotEmptyPath ::= (VerbPath | VerbSimple) ObjectList ( ';' ( (VerbPath | VerbSimple) ObjectList )? )*
2375 54 ▶sub _PropertyListNotEmptyPath {
Subroutine _PropertyListNotEmptyPath: called CC=6 SCAR=18.1
2376 54 my $self = shift;
2377 54 my $s = shift;
2378 54 ▶ if ($self->_VerbPath_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_VerbPath_test) { } 25 29 54
2379 25 $self->_VerbPath;
2380 } else {
2381 29 $self->_VerbSimple;
2382 }
2383 54 my ($p) = splice(@{ $self->{_stack} });
2384 54 $self->_ObjectList($s, $p);
2385 53 my @l = splice(@{ $self->{_stack} });
2386 53 my @props = map { [$p, $_] } @l;
2387 53 ▶ while ($self->_optional_token(SEMICOLON)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(25)) 9 53 62
2388 9 ▶ if ($self->_VerbPath_test or $self->_test_token(VAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_VerbPath_test or $self->_test_token(59)) 9 0 9
Condition33%1/3
$self->_VerbPath_test or $self->_test_token(59)
l!l&&r!l&&!r
900
MC/DC0%0/2
$self->_VerbPath_test or $self->_test_token(59)
$self->_VerbPath_test $self->_test_token(59)
Truth table33%1/3
A or B
A= $self->_VerbPath_testB= $self->_test_token(59)
ABresult
1X1
011
000
2389 9 ▶ if ($self->_VerbPath_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_VerbPath_test) { } 9 0 9
2390 9 $self->_VerbPath;
2391 } else {
2392 0 $self->_VerbSimple;
2393 }
2394 9 my ($p) = splice(@{ $self->{_stack} });
2395 9 $self->_ObjectList($s, $p);
2396 9 my @l = splice(@{ $self->{_stack} });
2397 9 push(@props, map { [$p, $_] } @l);
2398 }
2399 }
2400 53 $self->_add_stack( @props );
2401 }
2402  
2403 # [34] PropertyListPath ::= PropertyListNotEmptyPath?
2404 2 ▶sub _PropertyListPath {
Subroutine _PropertyListPath: called CC=2 SCAR=7.0
2405 2 my $self = shift;
2406 2 my $s = shift;
2407 2 ▶ if ($self->_Verb_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_Verb_test) 2 0 2
2408 2 $self->_PropertyListNotEmptyPath($s);
2409 }
2410 }
2411  
2412 # [35] ObjectList ::= Object ( ',' Object )*
2413 65 ▶sub _ObjectList {
Subroutine _ObjectList: called CC=2 SCAR=7.4
2414 65 my $self = shift;
2415 65 my $s = shift;
2416 65 my $p = shift;
2417
2418 65 my @list;
2419 65 $self->_Object($s, $p);
2420 64 push(@list, splice(@{ $self->{_stack} }));
2421
2422 64 ▶ while ($self->_optional_token(COMMA)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(6)) 0 64 64
2423 0 $self->_Object($s, $p);
2424 0 push(@list, splice(@{ $self->{_stack} }));
2425 }
2426 64 $self->_add_stack( @list );
2427 }
2428  
2429 # [36] Object ::= GraphNode
2430 65 ▶sub _Object {
Subroutine _Object: called CC=1 SCAR=0.0
2431 65 my $self = shift;
2432 65 my $s = shift;
2433 65 my $p = shift;
2434 65 $self->_GraphNode;
2435 64 my ($o) = ${ $self->{_stack} }[-1];
2436 64 $self->_AnnotationPath($s, $p, $o); # this should be _Annotation, but the calling code doesn't distinguish between Object and ObjectPath from the SPARQL grammar
2437 }
2438  
2439 # [37] Verb ::= VarOrIRIref | 'a'
2440 18 ▶sub _Verb_test {
Subroutine _Verb_test: called CC=4 SCAR=13.9
2441 18 my $self = shift;
2442 18 ▶ return 1 if ($self->_test_token(A));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(1) 2 16 18
2443 16 ▶ return 1 if ($self->_test_token(VAR));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(59) 1 15 16
2444 15 ▶ return 1 if ($self->_IRIref_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 12 3 15
2445 3 return 0;
2446 }
2447  
2448 19 ▶sub _Verb {
Subroutine _Verb: called CC=2 SCAR=6.9
2449 19 my $self = shift;
2450 19 ▶ if ($self->_optional_token(A)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(1)) { } 6 13 19
2451 6 my $type = Attean::IRI->new(value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', lazy => 1);
2452 6 $self->_add_stack( $type );
2453 } else {
2454 13 $self->_VarOrIRIref;
2455 }
2456 }
2457  
2458 # VerbSimple ::= Var
2459 # sub _VerbSimple_test {
2460 # my $self = shift;
2461 # return ($self->_test_token(VAR));
2462 # }
2463  
2464 29 ▶sub _VerbSimple {
Subroutine _VerbSimple: called CC=1 SCAR=0.0
2465 29 my $self = shift;
2466 29 $self->_Var;
2467 }
2468  
2469 # VerbPath ::= Path
2470 72 ▶sub _VerbPath_test {
Subroutine _VerbPath_test: called CC=7 SCAR=20.0
2471 72 my $self = shift;
2472 72 ▶ return 1 if ($self->_IRIref_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 36 36 72
2473 36 ▶ return 1 if ($self->_test_token(HAT));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(46) 0 36 36
2474 36 ▶ return 1 if ($self->_test_token(OR));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(53) 0 36 36
2475 36 ▶ return 1 if ($self->_test_token(BANG));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(43) 0 36 36
2476 36 ▶ return 1 if ($self->_test_token(LPAREN));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(18) 0 36 36
2477 36 ▶ return 1 if ($self->_test_token(A));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(1) 7 29 36
2478 29 return 0;
2479 }
2480  
2481 34 ▶sub _VerbPath {
Subroutine _VerbPath: called CC=1 SCAR=0.0
2482 34 my $self = shift;
2483 34 $self->_Path
2484 }
2485  
2486 # [74] Path ::= PathAlternative
2487 34 ▶sub _Path {
Subroutine _Path: called CC=1 SCAR=0.0
2488 34 my $self = shift;
2489 34 $self->_PathAlternative;
2490 }
2491  
2492 ################################################################################
2493  
2494 # [75] PathAlternative ::= PathSequence ( '|' PathSequence )*
2495 34 ▶sub _PathAlternative {
Subroutine _PathAlternative: called CC=2 SCAR=11.1
2496 34 my $self = shift;
2497 34 $self->_PathSequence;
2498 34 ▶ while ($self->_optional_token(OR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(53)) 0 34 34
2499 0 my ($lhs) = splice(@{ $self->{_stack} });
2500 # $self->_PathOneInPropertyClass;
2501 0 $self->_PathSequence;
2502 0 my ($rhs) = splice(@{ $self->{_stack} });
2503 0 $self->_add_stack( ['PATH', '|', $lhs, $rhs] );
2504 }
2505 }
2506  
2507 # [76] PathSequence ::= PathEltOrInverse ( '/' PathEltOrInverse | '^' PathElt )*
2508 34 ▶sub _PathSequence {
Subroutine _PathSequence: called CC=4 SCAR=14.3
2509 34 my $self = shift;
2510 34 $self->_PathEltOrInverse;
2511 34 ▶ while ($self->_test_token(SLASH) or $self->_test_token(HAT)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(57) or $self->_test_token(46)) 1 34 35
Condition66%2/3
$self->_test_token(57) or $self->_test_token(46)
l!l&&r!l&&!r
1034
MC/DC50%1/2
$self->_test_token(57) or $self->_test_token(46)
$self->_test_token(57) $self->_test_token(46)
Truth table66%2/3
A or B
A= $self->_test_token(57)B= $self->_test_token(46)
ABresult
1X1
011
000
2512 1 my $op;
2513 1 my ($lhs) = splice(@{ $self->{_stack} });
2514 1 ▶ if ($self->_optional_token(SLASH)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(57)) { } 1 0 1
2515 1 $op = '/';
2516 1 $self->_PathEltOrInverse;
2517 } else {
2518 0 $op = '^';
2519 0 $self->_expected_token(HAT);
2520 0 $self->_PathElt;
2521 }
2522 1 my ($rhs) = splice(@{ $self->{_stack} });
2523 1 $self->_add_stack( ['PATH', $op, $lhs, $rhs] );
2524 }
2525 }
2526  
2527 # [77] PathElt ::= PathPrimary PathMod?
2528 35 ▶sub _PathElt {
Subroutine _PathElt: called CC=3 SCAR=11.1
2529 35 my $self = shift;
2530 35 $self->_PathPrimary;
2531 # $self->__consume_ws_opt;
2532 35 ▶ if ($self->_PathMod_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_PathMod_test) 1 34 35
2533 1 my @path = splice(@{ $self->{_stack} });
2534 1 $self->_PathMod;
2535 1 my ($mod) = splice(@{ $self->{_stack} });
2536 1 ▶ if (defined($mod)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mod) { } 1 0 1
2537 1 $self->_add_stack( ['PATH', $mod, @path] );
2538 } else {
2539 # this might happen if we descend into _PathMod by mistaking a + as
2540 # a path modifier, but _PathMod figures out it's actually part of a
2541 # signed numeric object that follows the path
2542 0 $self->_add_stack( @path );
2543 }
2544 }
2545 }
2546  
2547 # [78] PathEltOrInverse ::= PathElt | '^' PathElt
2548 35 ▶sub _PathEltOrInverse {
Subroutine _PathEltOrInverse: called CC=2 SCAR=9.9
2549 35 my $self = shift;
2550 35 ▶ if ($self->_optional_token(HAT)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(46)) { } 0 35 35
2551 0 $self->_PathElt;
2552 0 my @props = splice(@{ $self->{_stack} });
2553 0 $self->_add_stack( [ 'PATH', '^', @props ] );
2554 } else {
2555 35 $self->_PathElt;
2556 }
2557 }
2558  
2559 # [79] PathMod ::= ( '*' | '?' | '+' | '{' ( Integer ( ',' ( '}' | Integer '}' ) | '}' ) ) )
2560 35 ▶sub _PathMod_test {
Subroutine _PathMod_test: called CC=5 SCAR=16.6
2561 35 my $self = shift;
2562 35 ▶ return 1 if ($self->_test_token(STAR));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(58) 1 34 35
2563 34 ▶ return 1 if ($self->_test_token(QUESTION));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(56) 0 34 34
2564 34 ▶ return 1 if ($self->_test_token(PLUS));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(55) 0 34 34
2565 34 ▶ return 1 if ($self->_test_token(LBRACE));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(16) 0 34 34
2566 34 return 0;
2567 }
2568  
2569 1 ▶sub _PathMod {
Subroutine _PathMod: called CC=6 SCAR=22.9
2570 1 my $self = shift;
2571 1 ▶ if ($self->_test_token(STAR) or $self->_test_token(QUESTION) or $self->_test_token(PLUS)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(58) or $self->_test_token(56) or $self->_test_token(55)) 1 0 1
Condition33%2/6
$self->_test_token(58) or $self->_test_token(56) or $self->_test_token(55)
l!l&&r!l&&!r
100
$self->_test_token(58) or $self->_test_token(56)
l!l&&r!l&&!r
100
MC/DC0%0/3
$self->_test_token(58) or $self->_test_token(56) or $self->_test_token(55)
$self->_test_token(58) $self->_test_token(56) $self->_test_token(55)
Truth table25%1/4
A or B or C
A= $self->_test_token(58)B= $self->_test_token(56)C= $self->_test_token(55)
ABCresult
1XX1
01X1
0011
0000
2572 1 my $t = $self->_next_token;
2573 1 my $op;
2574 1 ▶ if ($t->type == STAR) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->type == 58) { } 1 0 1
elsif ($t->type == 56) { } 0 0 0
2575 1 $op = '*';
2576 } elsif ($t->type == QUESTION) {
2577 0 $op = '?';
2578 } else {
2579 0 $op = '+';
2580 }
2581 1 $self->_add_stack($op);
2582 ### path repetition range syntax :path{n,m}; removed from 1.1 Query 2LC
2583 # } else {
2584 # $self->_eat(qr/{/);
2585 # $self->__consume_ws_opt;
2586 # my $value = 0;
2587 # if ($self->_test(qr/}/)) {
2588 # throw ::Error::ParseError -text => "Syntax error: Empty Path Modifier";
2589 # }
2590 # if ($self->_test($r_INTEGER)) {
2591 # $value = $self->_eat( $r_INTEGER );
2592 # $self->__consume_ws_opt;
2593 # }
2594 # if ($self->_test(qr/,/)) {
2595 # $self->_eat(qr/,/);
2596 # $self->__consume_ws_opt;
2597 # if ($self->_test(qr/}/)) {
2598 # $self->_eat(qr/}/);
2599 # $self->_add_stack( "$value-" );
2600 # } else {
2601 # my $end = $self->_eat( $r_INTEGER );
2602 # $self->__consume_ws_opt;
2603 # $self->_eat(qr/}/);
2604 # $self->_add_stack( "$value-$end" );
2605 # }
2606 # } else {
2607 # $self->_eat(qr/}/);
2608 # $self->_add_stack( "$value" );
2609 # }
2610 }
2611 }
2612  
2613 # [80] PathPrimary ::= ( IRIref | 'a' | '!' PathNegatedPropertyClass | '(' Path ')' )
2614 35 ▶sub _PathPrimary {
Subroutine _PathPrimary: called CC=4 SCAR=19.1
2615 35 my $self = shift;
2616 35 ▶ if ($self->_IRIref_test) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_IRIref_test) { } 29 6 35
elsif ($self->_optional_token(1)) { } 6 0 6
elsif ($self->_optional_token(43)) { } 0 0 0
2617 29 $self->_IRIref;
2618 } elsif ($self->_optional_token(A)) {
2619 6 my $type = Attean::IRI->new(value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', lazy => 1);
2620 6 $self->_add_stack( $type );
2621 } elsif ($self->_optional_token(BANG)) {
2622 0 $self->_PathNegatedPropertyClass;
2623 0 my (@path) = splice(@{ $self->{_stack} });
2624 0 $self->_add_stack( ['PATH', '!', @path] );
2625 } else {
2626 0 $self->_expected_token(LPAREN);
2627 0 $self->_Path;
2628 0 $self->_expected_token(RPAREN);
2629 }
2630 }
2631  
2632 # [81] PathNegatedPropertyClass ::= ( PathOneInPropertyClass | '(' ( PathOneInPropertyClass ( '|' PathOneInPropertyClass )* )? ')' )
2633 0 ▶sub _PathNegatedPropertyClass {
Subroutine _PathNegatedPropertyClass: not called CC=4 SCAR=30.0
2634 0 my $self = shift;
2635 0 ▶ if ($self->_optional_token(LPAREN)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(18)) { } 0 0 0
2636
2637 0 my @nodes;
2638 0 ▶ if ($self->_PathOneInPropertyClass_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_PathOneInPropertyClass_test) 0 0 0
2639 0 $self->_PathOneInPropertyClass;
2640 0 push(@nodes, splice(@{ $self->{_stack} }));
2641 0 ▶ while ($self->_optional_token(OR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(53)) 0 0 0
2642 0 $self->_PathOneInPropertyClass;
2643 0 push(@nodes, splice(@{ $self->{_stack} }));
2644 # $self->_add_stack( ['PATH', '|', $lhs, $rhs] );
2645 }
2646 }
2647 0 $self->_expected_token(RPAREN);
2648 0 $self->_add_stack( @nodes );
2649 } else {
2650 0 $self->_PathOneInPropertyClass;
2651 }
2652 }
2653  
2654 # [82] PathOneInPropertyClass ::= IRIref | 'a'
2655 0 ▶sub _PathOneInPropertyClass_test {
Subroutine _PathOneInPropertyClass_test: not called CC=4 SCAR=30.0
2656 0 my $self = shift;
2657 0 ▶ return 1 if $self->_IRIref_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 0 0 0
2658 0 ▶ return 1 if ($self->_test_token(A));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(1) 0 0 0
2659 0 ▶ return 1 if ($self->_test_token(HAT));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(46) 0 0 0
2660 0 return 0;
2661 }
2662  
2663 0 ▶sub _PathOneInPropertyClass {
Subroutine _PathOneInPropertyClass: not called CC=5 SCAR=34.0
2664 0 my $self = shift;
2665 0 my $rev = 0;
2666 0 ▶ if ($self->_optional_token(HAT)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(46)) 0 0 0
2667 0 $rev = 1;
2668 }
2669 0 ▶ if ($self->_optional_token(A)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(1)) { } 0 0 0
2670 0 my $type = Attean::IRI->new(value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', lazy => 1);
2671 0 ▶ if ($rev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rev) { } 0 0 0
2672 0 $self->_add_stack( [ 'PATH', '^', $type ] );
2673 } else {
2674 0 $self->_add_stack( $type );
2675 }
2676 } else {
2677 0 $self->_IRIref;
2678 0 ▶ if ($rev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rev) 0 0 0
2679 0 my ($path) = splice(@{ $self->{_stack} });
2680 0 $self->_add_stack( [ 'PATH', '^', $path ] );
2681 }
2682 }
2683 }
2684  
2685 ################################################################################
2686  
2687 # [38] TriplesNode ::= Collection | BlankNodePropertyList
2688 124 ▶sub _TriplesNode_test {
Subroutine _TriplesNode_test: called CC=3 SCAR=11.0
2689 124 my $self = shift;
2690 124 ▶ return 1 if $self->_test_token(LPAREN);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(18) 1 122 123
2691 122 ▶ return 1 if $self->_test_token(LBRACKET);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(17) 0 122 122
2692 122 return 0;
2693 }
2694  
2695 1 ▶sub _TriplesNode {
Subroutine _TriplesNode: called CC=2 SCAR=7.6
2696 1 my $self = shift;
2697 1 ▶ if ($self->_test_token(LPAREN)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(18)) { } 1 0 1
2698 1 $self->_Collection;
2699 } else {
2700 0 $self->_BlankNodePropertyList;
2701 }
2702 }
2703  
2704 # [39] BlankNodePropertyList ::= '[' PropertyListNotEmpty ']'
2705 0 ▶sub _BlankNodePropertyList {
Subroutine _BlankNodePropertyList: not called CC=3 SCAR=24.8
2706 0 my $self = shift;
2707 0 ▶ if (my $where = $self->{__no_bnodes}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $where = $self->{"__no_bnodes"}) 0 0 0
2708 0 croak "Syntax error: Blank nodes not allowed in $where";
2709 }
2710 0 $self->_expected_token(LBRACKET);
2711 0 my $subj = Attean::Blank->new();
2712 0 ▶ if ($self->_optional_token(RBRACKET)) { # not parsed as ANON for some reason
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(23)) 0 0 0
2713 0 $self->_add_stack( $subj );
2714 0 return;
2715 }
2716 # $self->_PropertyListNotEmpty($subj);
2717 0 $self->_PropertyListNotEmptyPath($subj);
2718 0 $self->_expected_token(RBRACKET);
2719
2720 0 my @props = splice(@{ $self->{_stack} });
2721 0 my @triples = map { $self->__new_statement( $subj, @$_ ) } @props;
2722 0 $self->_add_patterns( @triples );
2723 0 $self->_add_stack( $subj );
2724 }
2725  
2726 # [40] Collection ::= '(' GraphNode+ ')'
2727 1 ▶sub _Collection {
Subroutine _Collection: called CC=3 SCAR=11.0
2728 1 my $self = shift;
2729 1 $self->_expected_token(LPAREN);
2730 1 $self->_GraphNode;
2731 1 my @nodes;
2732 1 push(@nodes, splice(@{ $self->{_stack} }));
2733
2734 1 ▶ while ($self->_GraphNode_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_GraphNode_test) 1 1 2
2735 1 $self->_GraphNode;
2736 1 push(@nodes, splice(@{ $self->{_stack} }));
2737 }
2738
2739 1 $self->_expected_token(RPAREN);
2740
2741 1 my $subj = Attean::Blank->new();
2742 1 my $cur = $subj;
2743 1 my $last;
2744  
2745 1 my $first = Attean::IRI->new(value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first', lazy => 1);
2746 1 my $rest = Attean::IRI->new(value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest', lazy => 1);
2747 1 my $nil = Attean::IRI->new(value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil', lazy => 1);
2748  
2749
2750 1 my @triples;
2751 1 foreach my $node (@nodes) {
2752 2 push(@triples, $self->__new_statement( $cur, $first, $node ) );
2753 2 my $new = Attean::Blank->new();
2754 2 push(@triples, $self->__new_statement( $cur, $rest, $new ) );
2755 2 $last = $cur;
2756 2 $cur = $new;
2757 }
2758 1 pop(@triples);
2759 1 push(@triples, $self->__new_statement( $last, $rest, $nil ));
2760 1 $self->_add_patterns( @triples );
2761
2762 1 $self->_add_stack( $subj );
2763 }
2764  
2765 # [41] GraphNode ::= VarOrTerm | TriplesNode
2766 2 ▶sub _GraphNode_test {
Subroutine _GraphNode_test: called CC=18 SCAR=35.7
2767 2 my $self = shift;
2768 # VarOrTerm | TriplesNode -> (Var | GraphTerm) | (Collection | BlankNodePropertyList) -> Var | IRIref | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL | Collection | BlankNodePropertyList
2769 # but since a triple can't start with a literal, this is reduced to:
2770 # Var | IRIref | BlankNode | NIL
2771 2 ▶ return 1 if ($self->_test_token(VAR));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(59) 1 1 2
2772 1 ▶ return 1 if ($self->_IRIref_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 0 1 1
2773 1 ▶ return 1 if ($self->_test_token(BNODE));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(4) 0 1 1
2774 1 ▶ return 1 if ($self->_test_token(LBRACKET));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(17) 0 1 1
2775 1 ▶ return 1 if ($self->_test_token(LPAREN));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(18) 0 1 1
2776 1 ▶ return 1 if ($self->_test_token(ANON));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(2) 0 1 1
2777 1 ▶ return 1 if ($self->_test_token(NIL));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(51) 0 1 1
2778 1 ▶ return 1 if ($self->_test_token(BNODE));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(4) 0 1 1
2779 1 ▶ return 1 if ($self->_test_token(BOOLEAN));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(5) 0 1 1
2780 1 ▶ return 1 if ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(MINUS) or $self->_test_token(PLUS));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55) 0 1 1
Condition33%4/12
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
l!l&&r!l&&!r
001
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50)
l!l&&r!l&&!r
001
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10)
l!l&&r!l&&!r
001
$self->_test_token(13) or $self->_test_token(8)
l!l&&r!l&&!r
001
MC/DC0%0/5
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
$self->_test_token(13) $self->_test_token(8) $self->_test_token(10) $self->_test_token(50) $self->_test_token(55)
Truth table16%1/6
A or B or C or D or E
A= $self->_test_token(13)B= $self->_test_token(8)C= $self->_test_token(10)D= $self->_test_token(50)E= $self->_test_token(55)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
2781 1 ▶ return 1 if ($self->_test_literal_token);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_literal_token 0 1 1
2782 1 ▶ return 1 if ($self->_test_token(LTLT));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(35) 0 1 1
2783 1 ▶ return 1 if ($self->_test_token(LTLTP));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(36) 0 1 1
2784 1 return 0;
2785 }
2786  
2787 69 ▶sub _GraphNode {
Subroutine _GraphNode: called CC=3 SCAR=11.3
2788 69 my $self = shift;
2789 69 ▶ if ($self->_TriplesNode_test) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_TriplesNode_test) { } 0 68 68
elsif ($self->_test_token(35)) { } 1 67 68
2790 0 $self->_TriplesNode;
2791 } elsif ($self->_test_token(LTLT)) {
2792 1 $self->_ReifiedTriple();
2793 } else {
2794 67 $self->_VarOrTerm;
2795 }
2796 }
2797  
2798 # [42] VarOrTerm ::= Var | GraphTerm
2799 # sub _VarOrTerm_test {
2800 # my $self = shift;
2801 # return 1 if ($self->_peek_token(VAR));
2802 # return 1 if ($self->_IRIref_test);
2803 # return 1 if ($self->_peek_token(BOOLEAN));
2804 # return 1 if ($self->_test_literal_token);
2805 # return 1 if ($self->_peek_token(BNODE));
2806 # return 1 if ($self->_peek_token(NIL));
2807 # return 0;
2808 # }
2809  
2810 # sub _VarOrTermOrQuotedTP {
2811 # my $self = shift;
2812 # if ($self->_test_token(VAR)) {
2813 # $self->_Var();
2814 # } elsif ($self->_test_token(LTLT)) {
2815 # $self->_QuotedTP();
2816 # } else {
2817 # $self->_GraphTerm;
2818 # }
2819 # }
2820  
2821 119 ▶sub _VarOrTerm {
Subroutine _VarOrTerm: called CC=3 SCAR=11.8
2822 119 my $self = shift;
2823 119 ▶ if ($self->_test_token(VAR)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_test_token(59)) { } 82 37 119
elsif ($self->_test_token(36)) { } 0 37 37
2824 82 $self->_Var;
2825 } elsif ($self->_test_token(LTLTP)) {
2826 0 my $t = $self->_TripleTerm();
2827 0 $self->_add_stack( $t );
2828 } else {
2829 37 $self->_GraphTerm;
2830 }
2831 }
2832  
2833 # [43] VarOrIRIref ::= Var | IRIref
2834 1 ▶sub _VarOrIRIref_test {
Subroutine _VarOrIRIref_test: called CC=3 SCAR=11.4
2835 1 my $self = shift;
2836 1 ▶ return 1 if ($self->_IRIref_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 0 1 1
2837 1 ▶ return 1 if ($self->_test_token(VAR));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(59) 0 1 1
2838 1 return 0;
2839 }
2840  
2841 17 ▶sub _VarOrIRIref {
Subroutine _VarOrIRIref: called CC=2 SCAR=6.9
2842 17 my $self = shift;
2843 17 ▶ if ($self->_test_token(VAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(59)) { } 5 12 17
2844 5 $self->_Var;
2845 } else {
2846 12 $self->_IRIref;
2847 }
2848 }
2849  
2850 # [44] Var ::= VAR1 | VAR2
2851 143 ▶sub _Var {
Subroutine _Var: called CC=2 SCAR=7.4
2852 143 my $self = shift;
2853 143 ▶ if ($self->{__data_pattern}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__data_pattern"}) 0 143 143
2854 0 croak "Syntax error: Variable found where Term expected";
2855 }
2856  
2857 143 my $var = $self->_expected_token(VAR);
2858 143 $self->_add_stack( Attean::Variable->new( $var->value ) );
2859 }
2860  
2861 # [45] GraphTerm ::= IRIref | RDFLiteral | NumericLiteral | BooleanLiteral | BlankNode | NIL
2862 43 ▶sub _GraphTerm {
Subroutine _GraphTerm: called CC=13 SCAR=31.8
2863 43 my $self = shift;
2864 43 ▶ if ($self->_test_token(BOOLEAN)) {
Branch: 7 branches
BranchTrueFalseTotal
if ($self->_test_token(5)) { } 0 43 43
elsif ($self->_test_token(51)) { } 1 42 43
elsif ($self->_test_token(2) or $self->_test_token(4)) { } 0 42 42
elsif ($self->_optional_token(17)) { } 0 42 42
elsif ($self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)) { } 11 31 42
elsif ($self->_test_literal_token) { } 9 22 31
elsif ($self->_test_token(36)) { } 0 22 22
2865 0 my $b = $self->_BooleanLiteral;
2866 0 $self->_add_stack( $b );
2867 } elsif ($self->_test_token(NIL)) {
2868 1 my $n = $self->_NIL;
2869 1 $self->_add_stack( $n );
2870 ▶ } elsif ($self->_test_token(ANON) or $self->_test_token(BNODE)) {
Condition33%1/3
$self->_test_token(2) or $self->_test_token(4)
l!l&&r!l&&!r
0042
MC/DC0%0/2
$self->_test_token(2) or $self->_test_token(4)
$self->_test_token(2) $self->_test_token(4)
Truth table33%1/3
A or B
A= $self->_test_token(2)B= $self->_test_token(4)
ABresult
1X1
011
000
2871 0 my $b = $self->_BlankNode;
2872 0 $self->_add_stack( $b );
2873 } elsif ($self->_optional_token(LBRACKET)) { # not parsed as ANON for some reason
2874 0 $self->_expected_token(RBRACKET);
2875 0 my $b = $self->_BlankNode;
2876 0 $self->_add_stack( $b );
2877 ▶ } elsif ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(MINUS) or $self->_test_token(PLUS)) {
Condition66%8/12
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
l!l&&r!l&&!r
11031
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50)
l!l&&r!l&&!r
11031
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10)
l!l&&r!l&&!r
11031
$self->_test_token(13) or $self->_test_token(8)
l!l&&r!l&&!r
11031
MC/DC20%1/5
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
$self->_test_token(13) $self->_test_token(8) $self->_test_token(10) $self->_test_token(50) $self->_test_token(55)
Truth table33%2/6
A or B or C or D or E
A= $self->_test_token(13)B= $self->_test_token(8)C= $self->_test_token(10)D= $self->_test_token(50)E= $self->_test_token(55)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
2878 11 my $l = $self->_NumericLiteral;
2879 11 $self->_add_stack( $l );
2880 } elsif ($self->_test_literal_token) {
2881 9 my $l = $self->_RDFLiteral;
2882 9 $self->_add_stack( $l );
2883 } elsif ($self->_test_token(LTLTP)) {
2884 0 my $t = $self->_TripleTerm();
2885 0 $self->_add_stack( $t );
2886 } else {
2887 22 $self->_IRIref;
2888 }
2889 }
2890  
2891 # [46] Expression ::= ConditionalOrExpression
2892 11 ▶sub _Expression {
Subroutine _Expression: called CC=1 SCAR=0.0
2893 11 my $self = shift;
2894 11 $self->_ConditionalOrExpression;
2895 }
2896  
2897 # [47] ConditionalOrExpression ::= ConditionalAndExpression ( '||' ConditionalAndExpression )*
2898 11 ▶sub _ConditionalOrExpression {
Subroutine _ConditionalOrExpression: called CC=5 SCAR=21.8
2899 11 my $self = shift;
2900 11 my @list;
2901
2902 11 $self->_ConditionalAndExpression;
2903 11 push(@list, splice(@{ $self->{_stack} }));
2904
2905 11 ▶ while ($self->_test_token(OROR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(54)) 0 11 11
2906 0 $self->_expected_token(OROR);
2907 0 $self->_ConditionalAndExpression;
2908 0 push(@list, splice(@{ $self->{_stack} }));
2909 }
2910
2911 11 ▶ if (scalar(@list) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @list > 1) { } 0 11 11
2912 0 my $algebra = Attean::BinaryExpression->new( operator => '||', children => [splice(@list, 0, 2)] );
2913 0 ▶ while (scalar(@list)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @list) 0 0 0
2914 0 $algebra = Attean::BinaryExpression->new( operator => '||', children => [$algebra, shift(@list)] );
2915 }
2916 0 $self->_add_stack($algebra);
2917 } else {
2918 11 $self->_add_stack( @list );
2919 }
2920 11 ▶ if (scalar(@{ $self->{_stack} }) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{"_stack"};} == 0) 0 11 11
2921 0 my $t = $self->_peek_token;
2922 0 $self->_token_error($t, "Missing conditional expression");
2923 }
2924 }
2925  
2926 # [48] ConditionalAndExpression ::= ValueLogical ( '&&' ValueLogical )*
2927 11 ▶sub _ConditionalAndExpression {
Subroutine _ConditionalAndExpression: called CC=4 SCAR=13.9
2928 11 my $self = shift;
2929 11 $self->_ValueLogical;
2930 11 my @list = splice(@{ $self->{_stack} });
2931
2932 11 ▶ while ($self->_test_token(ANDAND)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(42)) 1 11 12
2933 1 $self->_expected_token(ANDAND);
2934 1 $self->_ValueLogical;
2935 1 push(@list, splice(@{ $self->{_stack} }));
2936 }
2937
2938 11 ▶ if (scalar(@list) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @list > 1) { } 1 10 11
2939 1 my $algebra = Attean::BinaryExpression->new( operator => '&&', children => [splice(@list, 0, 2)] );
2940 1 ▶ while (scalar(@list)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @list) 0 1 1
2941 0 $algebra = Attean::BinaryExpression->new( operator => '&&', children => [$algebra, shift(@list)] );
2942 }
2943 1 $self->_add_stack($algebra);
2944 } else {
2945 10 $self->_add_stack( @list );
2946 }
2947 }
2948  
2949 # [49] ValueLogical ::= RelationalExpression
2950 12 ▶sub _ValueLogical {
Subroutine _ValueLogical: called CC=1 SCAR=0.0
2951 12 my $self = shift;
2952 12 $self->_RelationalExpression;
2953 }
2954  
2955 # [50] RelationalExpression ::= NumericExpression ( '=' NumericExpression | '!=' NumericExpression | '<' NumericExpression | '>' NumericExpression | '<=' NumericExpression | '>=' NumericExpression )?
2956 12 ▶sub _RelationalExpression {
Subroutine _RelationalExpression: called CC=9 SCAR=28.1
2957 12 my $self = shift;
2958 12 $self->_NumericExpression;
2959
2960 12 my $t = $self->_peek_token;
2961 12 my $type = $t->type;
2962 12 ▶ if ($type == EQUALS or $type == NOTEQUALS or $type == LE or $type == GE or $type == LT or $type == GT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 11 or $type == 52 or $type == 48 or $type == 44 or $type == 49 or $type == 45) { } 3 9 12
elsif ($self->_test_token(47, qr/^(NOT|IN)/u)) { } 0 9 9
Condition53%8/15
$type == 11 or $type == 52 or $type == 48 or $type == 44 or $type == 49 or $type == 45
l!l&&r!l&&!r
219
$type == 11 or $type == 52 or $type == 48 or $type == 44 or $type == 49
l!l&&r!l&&!r
0210
$type == 11 or $type == 52 or $type == 48 or $type == 44
l!l&&r!l&&!r
0012
$type == 11 or $type == 52 or $type == 48
l!l&&r!l&&!r
0012
$type == 11 or $type == 52
l!l&&r!l&&!r
0012
MC/DC33%2/6
$type == 11 or $type == 52 or $type == 48 or $type == 44 or $type == 49 or $type == 45
$type == 11 $type == 52 $type == 48 $type == 44 $type == 49 $type == 45
Truth table42%3/7
A or B or C or D or E or F
A= $type == 11B= $type == 52C= $type == 48D= $type == 44E= $type == 49F= $type == 45
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
2963 3 $self->_next_token;
2964 3 my @list = splice(@{ $self->{_stack} });
2965 3 my $op = $t->value;
2966 3 $self->_NumericExpression;
2967 3 push(@list, splice(@{ $self->{_stack} }));
2968 3 $self->_add_stack( $self->new_binary_expression( $op, @list ) );
2969 } elsif ($self->_test_token(KEYWORD, qr/^(NOT|IN)/)) {
2970 0 my @list = splice(@{ $self->{_stack} });
2971 0 my $not = $self->_optional_token(KEYWORD, 'NOT');
2972 0 $self->_expected_token(KEYWORD, 'IN');
2973 0 ▶ my $op = $not ? 'NOTIN' : 'IN';
Branch: 1 branch
BranchTrueFalseTotal
$not ? : 0 0 0
2974 0 $self->_ExpressionList();
2975 0 push(@list, splice(@{ $self->{_stack} }));
2976 0 my $p = $self->new_function_expression( $op, @list );
2977 0 $self->_add_stack($p);
2978 }
2979 }
2980  
2981 0 ▶sub _ExpressionList {
Subroutine _ExpressionList: not called CC=4 SCAR=30.0
2982 0 my $self = shift;
2983 0 ▶ if ($self->_optional_token(NIL)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(51)) { } 0 0 0
2984 0 return;
2985 } else {
2986 0 $self->_expected_token(LPAREN);
2987 0 my @args;
2988 0 ▶ unless ($self->_test_token(RPAREN)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_token(24)) 0 0 0
2989 0 $self->_Expression;
2990 0 push( @args, splice(@{ $self->{_stack} }) );
2991 0 ▶ while ($self->_optional_token(COMMA)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(6)) 0 0 0
2992 0 $self->_Expression;
2993 0 push( @args, splice(@{ $self->{_stack} }) );
2994 }
2995 }
2996 0 $self->_expected_token(RPAREN);
2997 0 $self->_add_stack( @args );
2998 }
2999 }
3000  
3001 # [51] NumericExpression ::= AdditiveExpression
3002 15 ▶sub _NumericExpression {
Subroutine _NumericExpression: called CC=1 SCAR=0.0
3003 15 my $self = shift;
3004 15 $self->_AdditiveExpression;
3005 }
3006  
3007 # [52] AdditiveExpression ::= MultiplicativeExpression ( '+' MultiplicativeExpression | '-' MultiplicativeExpression | NumericLiteralPositive | NumericLiteralNegative )*
3008 15 ▶sub _AdditiveExpression {
Subroutine _AdditiveExpression: called CC=4 SCAR=13.9
3009 15 my $self = shift;
3010 15 $self->_MultiplicativeExpression;
3011 15 my ($expr) = splice(@{ $self->{_stack} });
3012
3013 15 ▶ while ($self->_test_token(MINUS) or $self->_test_token(PLUS)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(50) or $self->_test_token(55)) 1 15 16
Condition66%2/3
$self->_test_token(50) or $self->_test_token(55)
l!l&&r!l&&!r
0115
MC/DC50%1/2
$self->_test_token(50) or $self->_test_token(55)
$self->_test_token(50) $self->_test_token(55)
Truth table66%2/3
A or B
A= $self->_test_token(50)B= $self->_test_token(55)
ABresult
1X1
011
000
3014 1 my $t = $self->_next_token;
3015 1 ▶ my $op = ($t->type == MINUS) ? '-' : '+';
Branch: 1 branch
BranchTrueFalseTotal
$t->type == 50 ? : 0 1 1
3016 1 $self->_MultiplicativeExpression;
3017 1 my ($rhs) = splice(@{ $self->{_stack} });
3018 1 $expr = $self->new_binary_expression( $op, $expr, $rhs );
3019 }
3020 15 $self->_add_stack( $expr );
3021 }
3022  
3023 # [53] MultiplicativeExpression ::= UnaryExpression ( '*' UnaryExpression | '/' UnaryExpression )*
3024 16 ▶sub _MultiplicativeExpression {
Subroutine _MultiplicativeExpression: called CC=4 SCAR=19.6
3025 16 my $self = shift;
3026 16 $self->_UnaryExpression;
3027 16 my ($expr) = splice(@{ $self->{_stack} });
3028
3029 16 ▶ while ($self->_test_token(STAR) or $self->_test_token(SLASH)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(58) or $self->_test_token(57)) 0 16 16
Condition33%1/3
$self->_test_token(58) or $self->_test_token(57)
l!l&&r!l&&!r
0016
MC/DC0%0/2
$self->_test_token(58) or $self->_test_token(57)
$self->_test_token(58) $self->_test_token(57)
Truth table33%1/3
A or B
A= $self->_test_token(58)B= $self->_test_token(57)
ABresult
1X1
011
000
3030 0 my $t = $self->_next_token;
3031 0 ▶ my $op = ($t->type == STAR) ? '*' : '/';
Branch: 1 branch
BranchTrueFalseTotal
$t->type == 58 ? : 0 0 0
3032 0 $self->_UnaryExpression;
3033 0 my ($rhs) = splice(@{ $self->{_stack} });
3034 0 $expr = $self->new_binary_expression( $op, $expr, $rhs );
3035 }
3036 16 $self->_add_stack( $expr );
3037 }
3038  
3039 # [54] UnaryExpression ::= '!' UnaryExpression | '+' PrimaryExpression | '-' PrimaryExpression | PrimaryExpression
3040 17 ▶sub _UnaryExpression {
Subroutine _UnaryExpression: called CC=10 SCAR=26.2
3041 17 my $self = shift;
3042 17 ▶ if ($self->_optional_token(BANG)) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_optional_token(43)) { } 1 16 17
elsif ($self->_optional_token(55)) { } 1 15 16
elsif ($self->_optional_token(50)) { } 1 14 15
3043 1 $self->_UnaryExpression;
3044 1 my ($expr) = splice(@{ $self->{_stack} });
3045 1 my $not = Attean::UnaryExpression->new( operator => '!', children => [$expr] );
3046 1 $self->_add_stack( $not );
3047 } elsif ($self->_optional_token(PLUS)) {
3048 1 $self->_PrimaryExpression;
3049 1 my ($expr) = splice(@{ $self->{_stack} });
3050
3051 ### if it's just a literal, force the positive down into the literal
3052 1 ▶ if (blessed($expr) and $expr->isa('Attean::ValueExpression') and $expr->value->does('Attean::API::NumericLiteral')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($expr) and $expr->isa('Attean::ValueExpression') and $expr->value->does('Attean::API::NumericLiteral')) { } 1 0 1
Condition33%2/6
builtin::blessed($expr) and $expr->isa("Attean::ValueExpression") and $expr->value->does("Attean::API::NumericLiteral")
!ll&&!rl&&r
001
builtin::blessed($expr) and $expr->isa("Attean::ValueExpression")
!ll&&!rl&&r
001
MC/DC0%0/3
builtin::blessed($expr) and $expr->isa("Attean::ValueExpression") and $expr->value->does("Attean::API::NumericLiteral")
builtin::blessed($expr) $expr->isa("Attean::ValueExpression") $expr->value->does("Attean::API::NumericLiteral")
Truth table25%1/4
A and B and C
A= builtin::blessed($expr)B= $expr->isa("Attean::ValueExpression")C= $expr->value->does("Attean::API::NumericLiteral")
ABCresult
0XX0
10X0
1100
1111
3053 1 my $value = '+' . $expr->value->value;
3054 1 my $l = $self->new_literal( value => $value, datatype => $expr->value->datatype );
3055 1 my $lexpr = Attean::ValueExpression->new( value => $l );
3056 1 $self->_add_stack( $lexpr );
3057 } else {
3058 0 my $int = 'http://www.w3.org/2001/XMLSchema#integer';
3059 0 my $l = $self->new_literal( value => '0', datatype => $int );
3060 0 my $neg = $self->new_binary_expression( '+', Attean::ValueExpression->new( value => $l ), $expr );
3061 0 $self->_add_stack( $neg );
3062 }
3063 } elsif ($self->_optional_token(MINUS)) {
3064 1 $self->_PrimaryExpression;
3065 1 my ($expr) = splice(@{ $self->{_stack} });
3066
3067 ### if it's just a literal, force the negative down into the literal instead of make an unnecessary multiplication.
3068 1 ▶ if (blessed($expr) and $expr->isa('Attean::ValueExpression') and $expr->value->does('Attean::API::NumericLiteral')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($expr) and $expr->isa('Attean::ValueExpression') and $expr->value->does('Attean::API::NumericLiteral')) { } 1 0 1
Condition33%2/6
builtin::blessed($expr) and $expr->isa("Attean::ValueExpression") and $expr->value->does("Attean::API::NumericLiteral")
!ll&&!rl&&r
001
builtin::blessed($expr) and $expr->isa("Attean::ValueExpression")
!ll&&!rl&&r
001
MC/DC0%0/3
builtin::blessed($expr) and $expr->isa("Attean::ValueExpression") and $expr->value->does("Attean::API::NumericLiteral")
builtin::blessed($expr) $expr->isa("Attean::ValueExpression") $expr->value->does("Attean::API::NumericLiteral")
Truth table25%1/4
A and B and C
A= builtin::blessed($expr)B= $expr->isa("Attean::ValueExpression")C= $expr->value->does("Attean::API::NumericLiteral")
ABCresult
0XX0
10X0
1100
1111
3069 1 my $value = -1 * $expr->value->value;
3070 1 my $l = $self->new_literal( value => $value, datatype => $expr->value->datatype );
3071 1 my $lexpr = Attean::ValueExpression->new( value => $l );
3072 1 $self->_add_stack( $lexpr );
3073 } else {
3074 0 my $int = 'http://www.w3.org/2001/XMLSchema#integer';
3075 0 my $l = $self->new_literal( value => '-1', datatype => $int );
3076 0 my $neg = $self->new_binary_expression( '*', Attean::ValueExpression->new( value => $l ), $expr );
3077 0 $self->_add_stack( $neg );
3078 }
3079 } else {
3080 14 $self->_PrimaryExpression;
3081 }
3082 }
3083  
3084 # [55] PrimaryExpression ::= BrackettedExpression | BuiltInCall | IRIrefOrFunction | RDFLiteral | NumericLiteral | BooleanLiteral | Var
3085 16 ▶sub _PrimaryExpression {
Subroutine _PrimaryExpression: called CC=13 SCAR=27.3
3086 16 my $self = shift;
3087 16 my $t = $self->_peek_token;
3088 16 ▶ if ($self->_test_token(LPAREN)) {
Branch: 7 branches
BranchTrueFalseTotal
if ($self->_test_token(18)) { } 0 16 16
elsif ($self->_BuiltInCall_test) { } 2 14 16
elsif ($self->_IRIref_test) { } 1 13 14
elsif ($self->_test_token(59)) { } 8 5 13
elsif ($self->_test_token(5)) { } 0 5 5
elsif ($self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(55) or $self->_test_token(50)) { } 4 1 5
elsif ($self->_test_token(36)) { } 1 0 1
3089 0 $self->_BrackettedExpression;
3090 } elsif ($self->_BuiltInCall_test) {
3091 2 $self->_BuiltInCall;
3092 } elsif ($self->_IRIref_test) {
3093 1 $self->_IRIrefOrFunction;
3094 1 my $v = pop(@{ $self->{_stack} });
3095 1 ▶ if ($v->does('Attean::API::IRI')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->does("Attean::API::IRI")) 0 1 1
3096 0 $v = Attean::ValueExpression->new(value => $v);
3097 }
3098 1 $self->_add_stack($v);
3099 } elsif ($self->_test_token(VAR)) {
3100 8 $self->_Var;
3101 8 my $var = pop(@{ $self->{_stack} });
3102 8 my $expr = Attean::ValueExpression->new(value => $var);
3103 8 $self->_add_stack($expr);
3104 } elsif ($self->_test_token(BOOLEAN)) {
3105 0 my $b = $self->_BooleanLiteral;
3106 0 my $expr = Attean::ValueExpression->new(value => $b);
3107 0 $self->_add_stack($expr);
3108 ▶ } elsif ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(PLUS) or $self->_test_token(MINUS)) {
Condition83%10/12
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(55) or $self->_test_token(50)
l!l&&r!l&&!r
401
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(55)
l!l&&r!l&&!r
401
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10)
l!l&&r!l&&!r
311
$self->_test_token(13) or $self->_test_token(8)
l!l&&r!l&&!r
212
MC/DC60%3/5
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(55) or $self->_test_token(50)
$self->_test_token(13) $self->_test_token(8) $self->_test_token(10) $self->_test_token(55) $self->_test_token(50)
Truth table66%4/6
A or B or C or D or E
A= $self->_test_token(13)B= $self->_test_token(8)C= $self->_test_token(10)D= $self->_test_token(55)E= $self->_test_token(50)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
3109 4 my $l = $self->_NumericLiteral;
3110 4 my $expr = Attean::ValueExpression->new(value => $l);
3111 4 $self->_add_stack($expr);
3112 } elsif ($self->_test_token(LTLTP)) {
3113 1 $self->_ExprTripleTerm();
3114 1 my $tp = pop(@{ $self->{_stack} });
3115 1 my $expr = Attean::ValueExpression->new(value => $tp);
3116 1 $self->_add_stack($expr);
3117 } else {
3118 0 my $value = $self->_RDFLiteral;
3119 0 my $expr = Attean::ValueExpression->new(value => $value);
3120 0 $self->_add_stack($expr);
3121 }
3122 }
3123  
3124  
3125 # sub _ExprVarOrTerm {
3126 # my $self = shift;
3127 # if ($self->_test_token(VAR)) {
3128 # $self->_Var();
3129 # } elsif ($self->_test_token(LTLT)) {
3130 # $self->_ExprQuotedTP();
3131 # } else {
3132 # # TODO: this should prevent use of bnodes
3133 # $self->_GraphTerm;
3134 # my $term = ${ $self->{_stack} }[-1];
3135 # if ($term->does('Attean::API::Blank')) {
3136 # croak "Expecting (non-blank) RDF term but found blank";
3137 # }
3138 # }
3139 # }
3140  
3141 # [56] BrackettedExpression ::= '(' Expression ')'
3142 # sub _BrackettedExpression_test {
3143 # my $self = shift;
3144 # return $self->_test_token(LPAREN);
3145 # }
3146  
3147 5 ▶sub _BrackettedExpression {
Subroutine _BrackettedExpression: called CC=1 SCAR=0.0
3148 5 my $self = shift;
3149 5 $self->_expected_token(LPAREN);
3150 5 $self->_Expression;
3151 5 $self->_expected_token(RPAREN);
3152 }
3153  
3154 1 ▶sub _Aggregate {
Subroutine _Aggregate: called CC=12 SCAR=32.5
3155 1 my $self = shift;
3156
3157 1 ▶ unless ($self->{__aggregate_call_ok}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__aggregate_call_ok"}) 0 1 1
3158 0 my $t = $self->_peek_token;
3159 0 $self->_token_error($t, "Aggregate function not valid in this location")
3160 # local($self->{__aggregate_call_ok}) = 1;
3161 }
3162  
3163 1 my $op;
3164 my $custom_agg_iri;
3165 1 ▶ if (scalar(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) { } 0 1 1
3166 0 $custom_agg_iri = shift->value;
3167 0 $op = 'CUSTOM';
3168 } else {
3169 1 my $t = $self->_expected_token(KEYWORD);
3170 1 $op = $t->value;
3171 }
3172 1 $self->_expected_token(LPAREN);
3173
3174 1 my $distinct = 0;
3175 1 ▶ if ($self->_optional_token(KEYWORD, 'DISTINCT')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "DISTINCT")) 0 1 1
3176 0 $distinct = 1;
3177 }
3178
3179 1 my $star = 0;
3180 1 my (@expr, %scalar_args, %options);
3181 1 ▶ if ($self->_optional_token(STAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(58)) { } 0 1 1
3182 0 $star = 1;
3183 } else {
3184 {
3185 1 local($self->{__aggregate_call_ok}) = 0; # aggregates cannot be nested in the expression
3186 1 $self->_Expression;
3187 }
3188
3189 1 push(@expr, splice(@{ $self->{_stack} }));
3190 1 ▶ if ($op =~ /^(GROUP_CONCAT|FOLD)$/) { # aggs that can take multiple arguments
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /^(GROUP_CONCAT|FOLD)$/u) 0 1 1
3191 0 ▶ while ($self->_optional_token(COMMA)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(6)) 0 0 0
3192 0 $self->_Expression;
3193 0 push(@expr, splice(@{ $self->{_stack} }));
3194 }
3195 }
3196
3197 1 ▶ if ($self->_OrderClause_test()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_OrderClause_test) 0 1 1
3198 0 local($self->{build}{__aggregate});
3199 0 local($self->{__aggregate_call_ok});
3200 0 local($self->{build}{options}{orderby});
3201 0 $self->_OrderClause();
3202 0 $options{ order } = $self->{build}{options}{orderby};
3203 }
3204 1 ▶ if ($self->_optional_token(SEMICOLON)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(25)) 0 1 1
3205 0 ▶ if ($self->_optional_token(KEYWORD, 'SEPARATOR')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(47, "SEPARATOR")) 0 0 0
3206 0 $self->_expected_token(EQUALS);
3207 0 my $sep = $self->_String;
3208 0 $scalar_args{ seperator } = $sep;
3209 }
3210 }
3211 }
3212 1 $self->_expected_token(RPAREN);
3213  
3214 1 ▶ my $arg = join(',', map { blessed($_) ? $_->as_string : $_ } @expr);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) ? : 1 0 1
3215 1 ▶ if ($distinct) {
Branch: 1 branch
BranchTrueFalseTotal
if ($distinct) 0 1 1
3216 0 $arg = 'DISTINCT ' . $arg;
3217 }
3218 1 my $name = sprintf('%s(%s)', $op, $arg);
3219
3220 1 my $var = Attean::Variable->new( value => ".$name");
3221 1 my $agg = Attean::AggregateExpression->new(
3222 distinct => $distinct,
3223 operator => $op,
3224 children => [@expr],
3225 scalar_vars => \%scalar_args,
3226 variable => $var,
3227 custom_iri => $custom_agg_iri,
3228 %options
3229 );
3230 1 $self->{build}{__aggregate}{ $name } = [ $var, $agg ];
3231 1 my $expr = Attean::ValueExpression->new(value => $var);
3232 1 $self->_add_stack($expr);
3233 }
3234  
3235 # [57] BuiltInCall ::= 'STR' '(' Expression ')' | 'LANG' '(' Expression ')' | 'LANGMATCHES' '(' Expression ',' Expression ')' | 'DATATYPE' '(' Expression ')' | 'BOUND' '(' Var ')' | 'sameTerm' '(' Expression ',' Expression ')' | 'isIRI' '(' Expression ')' | 'isURI' '(' Expression ')' | 'isBLANK' '(' Expression ')' | 'isLITERAL' '(' Expression ')' | RegexExpression
3236 24 ▶sub _BuiltInCall_test {
Subroutine _BuiltInCall_test: called CC=9 SCAR=22.5
3237 24 my $self = shift;
3238 24 my $t = $self->_peek_token;
3239 24 ▶ return unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 2 22 24
3240 22 ▶ if ($self->{__aggregate_call_ok}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__aggregate_call_ok"}) 3 19 22
3241 3 ▶ return 1 if ($self->_test_token(KEYWORD, qr/^(MIN|MAX|COUNT|AVG|SUM|SAMPLE|GROUP_CONCAT|FOLD)$/io));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, qr/^(MIN|MAX|COUNT|AVG|SUM|SAMPLE|GROUP_CONCAT|FOLD)$/iou) 1 2 3
3242 }
3243 21 ▶ return 1 if ($self->_test_token(KEYWORD, 'NOT'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "NOT") 0 21 21
3244 21 ▶ return 1 if ($self->_test_token(KEYWORD, 'EXISTS'));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, "EXISTS") 0 21 21
3245 21 ▶ return 1 if ($self->_test_token(KEYWORD, qr/^(ABS|CEIL|FLOOR|ROUND|CONCAT|SUBSTR|STRLEN|UCASE|LCASE|ENCODE_FOR_URI|CONTAINS|STRSTARTS|STRENDS|RAND|MD5|SHA1|SHA224|SHA256|SHA384|SHA512|HOURS|MINUTES|SECONDS|DAY|MONTH|YEAR|TIMEZONE|TZ|NOW)$/i));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, qr/^(ABS|CEIL|FLOOR|ROUND|CONCAT|SUBSTR|STRLEN|UCASE|LCASE|ENCODE_FOR_URI|CONTAINS|STRSTARTS|STRENDS|RAND|MD5|SHA1|SHA224|SHA256|SHA384|SHA512|HOURS|MINUTES|SECONDS|DAY|MONTH|YEAR|TIMEZONE|TZ|NOW)$/iu) 0 21 21
3246 21 ▶ return 1 if ($self->_test_token(KEYWORD, qr/^(TRIPLE|ISTRIPLE|SUBJECT|PREDICATE|OBJECT)$/i));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, qr/^(TRIPLE|ISTRIPLE|SUBJECT|PREDICATE|OBJECT)$/iu) 0 21 21
3247 21 ▶ return 1 if ($self->_test_token(KEYWORD, qr/^(HASLANG|HASLANGDIR|LANGDIR)$/i));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(47, qr/^(HASLANG|HASLANGDIR|LANGDIR)$/iu) 0 21 21
3248 21 return ($self->_test_token(KEYWORD, qr/^(COALESCE|UUID|STRUUID|STR|STRDT|STRLANG|STRLANGDIR|STRBEFORE|STRAFTER|REPLACE|BNODE|IRI|URI|LANG|LANGMATCHES|DATATYPE|BOUND|sameTerm|isIRI|isURI|isBLANK|isLITERAL|REGEX|IF|isNumeric)$/i));
3249 }
3250  
3251 2 ▶sub _BuiltInCall {
Subroutine _BuiltInCall: called CC=13 SCAR=44.6
3252 2 my $self = shift;
3253 2 my $t = $self->_peek_token;
3254 2 ▶ if ($self->{__aggregate_call_ok} and $self->_test_token(KEYWORD, qr/^(MIN|MAX|COUNT|AVG|SUM|SAMPLE|GROUP_CONCAT|FOLD)\b/io)) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->{'__aggregate_call_ok'} and $self->_test_token(47, qr/^(MIN|MAX|COUNT|AVG|SUM|SAMPLE|GROUP_CONCAT|FOLD)\b/iou)) { } 1 1 2
elsif ($self->_test_token(47, qr/^(NOT|EXISTS)/u)) { } 0 1 1
elsif ($self->_test_token(47, qr/^(COALESCE|BNODE|CONCAT|SUBSTR|RAND|NOW)/iu)) { } 0 1 1
elsif ($self->_test_token(47, 'REGEX')) { } 0 1 1
Condition66%2/3
$self->{"__aggregate_call_ok"} and $self->_test_token(47, qr/^(MIN|MAX|COUNT|AVG|SUM|SAMPLE|GROUP_CONCAT|FOLD)\b/iou)
!ll&&!rl&&r
101
MC/DC50%1/2
$self->{"__aggregate_call_ok"} and $self->_test_token(47, qr/^(MIN|MAX|COUNT|AVG|SUM|SAMPLE|GROUP_CONCAT|FOLD)\b/iou)
$self->{"__aggregate_call_ok"} $self->_test_token(47, qr/^(MIN|MAX|COUNT|AVG|SUM|SAMPLE|GROUP_CONCAT|FOLD)\b/iou)
Truth table66%2/3
A and B
A= $self->{"__aggregate_call_ok"}B= $self->_test_token(47, qr/^(MIN|MAX|COUNT|AVG|SUM|SAMPLE|GROUP_CONCAT|FOLD)\b/iou)
ABresult
0X0
100
111
3255 1 $self->_Aggregate;
3256 } elsif ($self->_test_token(KEYWORD, qr/^(NOT|EXISTS)/)) {
3257 0 my $not = $self->_optional_token(KEYWORD, 'NOT');
3258 0 $self->_expected_token(KEYWORD, 'EXISTS');
3259 0 local($self->{filters}) = [];
3260 0 $self->_GroupGraphPattern;
3261 0 my $cont = $self->_remove_pattern;
3262 0 my $p = Attean::ExistsExpression->new( pattern => $cont );
3263 0 ▶ if ($not) {
Branch: 1 branch
BranchTrueFalseTotal
if ($not) 0 0 0
3264 0 $p = Attean::UnaryExpression->new( operator => '!', children => [$p] );
3265 }
3266 0 $self->_add_stack($p);
3267 } elsif ($self->_test_token(KEYWORD, qr/^(COALESCE|BNODE|CONCAT|SUBSTR|RAND|NOW)/i)) {
3268 # n-arg functions that take expressions
3269 0 my $t = $self->_next_token;
3270 0 my $op = $t->value;
3271 0 my @args = $self->_ArgList;
3272 0 my $func = $self->new_function_expression( $op, @args );
3273 0 $self->_add_stack( $func );
3274 } elsif ($self->_test_token(KEYWORD, 'REGEX')) {
3275 0 $self->_RegexExpression;
3276 } else {
3277 1 my $t = $self->_next_token;
3278 1 my $op = $t->value;
3279 1 ▶ if ($op =~ /^(STR)?UUID$/i) {
Branch: 5 branches
BranchTrueFalseTotal
if ($op =~ /^(STR)?UUID$/iu) { } 0 1 1
elsif ($op =~ /^(STR|URI|IRI|LANG|LANGDIR|HASLANG|HASLANGDIR|DATATYPE|isIRI|isURI|isBLANK|isLITERAL|isNumeric|ABS|CEIL|FLOOR|ROUND|STRLEN|UCASE|LCASE|ENCODE_FOR_URI|MD5|SHA1|SHA224|SHA256|SHA384|SHA512|HOURS|MINUTES|SECONDS|DAY|MONTH|YEAR|TIMEZONE|TZ|ISTRIPLE|SUBJECT|PREDICATE|OBJECT)$/iu) { } 0 1 1
elsif ($op =~ /^(STRDT|STRLANG|LANGMATCHES|sameTerm|CONTAINS|STRSTARTS|STRENDS|STRBEFORE|STRAFTER)$/iu) { } 0 1 1
elsif ($op =~ /^(IF|TRIPLE|STRLANGDIR)$/iu) { } 0 1 1
elsif ($op =~ /^(REPLACE)$/iu) { } 0 1 1
3280 # no-arg functions
3281 0 $self->_expected_token(NIL);
3282 0 $self->_add_stack( $self->new_function_expression($op) );
3283 } elsif ($op =~ /^(STR|URI|IRI|LANG|LANGDIR|HASLANG|HASLANGDIR|DATATYPE|isIRI|isURI|isBLANK|isLITERAL|isNumeric|ABS|CEIL|FLOOR|ROUND|STRLEN|UCASE|LCASE|ENCODE_FOR_URI|MD5|SHA1|SHA224|SHA256|SHA384|SHA512|HOURS|MINUTES|SECONDS|DAY|MONTH|YEAR|TIMEZONE|TZ|ISTRIPLE|SUBJECT|PREDICATE|OBJECT)$/i) {
3284 ### one-arg functions that take an expression
3285 0 $self->_expected_token(LPAREN);
3286 0 $self->_Expression;
3287 0 my ($expr) = splice(@{ $self->{_stack} });
3288 0 $self->_add_stack( $self->new_function_expression($op, $expr) );
3289 0 $self->_expected_token(RPAREN);
3290 } elsif ($op =~ /^(STRDT|STRLANG|LANGMATCHES|sameTerm|CONTAINS|STRSTARTS|STRENDS|STRBEFORE|STRAFTER)$/i) {
3291 ### two-arg functions that take expressions
3292 0 $self->_expected_token(LPAREN);
3293 0 $self->_Expression;
3294 0 my ($arg1) = splice(@{ $self->{_stack} });
3295 0 $self->_expected_token(COMMA);
3296 0 $self->_Expression;
3297 0 my ($arg2) = splice(@{ $self->{_stack} });
3298 0 $self->_add_stack( $self->new_function_expression($op, $arg1, $arg2) );
3299 0 $self->_expected_token(RPAREN);
3300 } elsif ($op =~ /^(IF|TRIPLE|STRLANGDIR)$/i) {
3301 ### three-arg functions that take expressions
3302 0 $self->_expected_token(LPAREN);
3303 0 $self->_Expression;
3304 0 my ($arg1) = splice(@{ $self->{_stack} });
3305 0 $self->_expected_token(COMMA);
3306 0 $self->_Expression;
3307 0 my ($arg2) = splice(@{ $self->{_stack} });
3308 0 $self->_expected_token(COMMA);
3309 0 $self->_Expression;
3310 0 my ($arg3) = splice(@{ $self->{_stack} });
3311 0 $self->_add_stack( $self->new_function_expression($op, $arg1, $arg2, $arg3) );
3312 0 $self->_expected_token(RPAREN);
3313 } elsif ($op =~ /^(REPLACE)$/i) {
3314 ### three- or four-arg functions that take expressions
3315 0 $self->_expected_token(LPAREN);
3316 0 $self->_Expression;
3317 0 my ($arg1) = splice(@{ $self->{_stack} });
3318 0 $self->_expected_token(COMMA);
3319 0 $self->_Expression;
3320 0 my ($arg2) = splice(@{ $self->{_stack} });
3321 0 $self->_expected_token(COMMA);
3322 0 $self->_Expression;
3323 0 my ($arg3) = splice(@{ $self->{_stack} });
3324 0 my @args = ($arg1, $arg2, $arg3);
3325 0 ▶ if ($self->_test_token(COMMA)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(6)) 0 0 0
3326 0 $self->_expected_token(COMMA);
3327 0 $self->_Expression;
3328 0 my ($arg4) = splice(@{ $self->{_stack} });
3329 0 push(@args, $arg4);
3330 }
3331 0 $self->_add_stack( $self->new_function_expression($op, @args) );
3332 0 $self->_expected_token(RPAREN);
3333 } else {
3334 ### BOUND(Var)
3335 1 $self->_expected_token(LPAREN);
3336 1 $self->_Var;
3337 1 my $var = pop(@{ $self->{_stack} });
3338 1 my $expr = Attean::ValueExpression->new(value => $var);
3339 1 $self->_add_stack( $self->new_function_expression($op, $expr) );
3340 1 $self->_expected_token(RPAREN);
3341 }
3342 }
3343 }
3344  
3345 # [58] RegexExpression ::= 'REGEX' '(' Expression ',' Expression ( ',' Expression )? ')'
3346 # sub _RegexExpression_test {
3347 # my $self = shift;
3348 # return $self->_test_token(KEYWORD, 'REGEX');
3349 # }
3350  
3351 0 ▶sub _RegexExpression {
Subroutine _RegexExpression: not called CC=2 SCAR=17.9
3352 0 my $self = shift;
3353 0 $self->_expected_token(KEYWORD, 'REGEX');
3354 0 $self->_expected_token(LPAREN);
3355 0 $self->_Expression;
3356 0 my $string = splice(@{ $self->{_stack} });
3357
3358 0 $self->_expected_token(COMMA);
3359 0 $self->_Expression;
3360 0 my $pattern = splice(@{ $self->{_stack} });
3361
3362 0 my @args = ($string, $pattern);
3363 0 ▶ if ($self->_optional_token(COMMA)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_optional_token(6)) 0 0 0
3364 0 $self->_Expression;
3365 0 push(@args, splice(@{ $self->{_stack} }));
3366 }
3367
3368 0 $self->_expected_token(RPAREN);
3369 0 $self->_add_stack( $self->new_function_expression( 'REGEX', @args ) );
3370 }
3371  
3372 # [59] IRIrefOrFunction ::= IRIref ArgList?
3373 # sub _IRIrefOrFunction_test {
3374 # my $self = shift;
3375 # $self->_IRIref_test;
3376 # }
3377  
3378 1 ▶sub _IRIrefOrFunction {
Subroutine _IRIrefOrFunction: called CC=4 SCAR=14.9
3379 1 my $self = shift;
3380 1 $self->_IRIref;
3381 1 ▶ if ($self->_ArgList_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ArgList_test) 1 0 1
3382 1 my ($iri) = splice(@{ $self->{_stack} });
3383 1 ▶ if (my $func = Attean->get_global_aggregate($iri->value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $func = "Attean"->get_global_aggregate($iri->value)) 0 1 1
3384 # special-case: treat this as an aggregate invocation instead of a scalar function call, since there is a custom aggregate registered
3385 0 return $self->_Aggregate($iri);
3386 }
3387 1 my @args = $self->_ArgList;
3388 1 ▶ if ($iri->value =~ m<^http://www[.]w3[.]org/2001/XMLSchema#(?:integer|decimal|float|double|boolean|string|dateTime)$>) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iri->value =~ m[^http://www[.]w3[.]org/2001/XMLSchema#(?:integer|decimal|float|double|boolean|string|dateTime)$]u) { } 0 1 1
3389 0 my $expr = Attean::CastExpression->new( children => \@args, datatype => $iri );
3390 0 $self->_add_stack( $expr );
3391 } else {
3392 1 my $func = Attean::ValueExpression->new( value => $iri );
3393 1 my $expr = $self->new_function_expression( 'INVOKE', $func, @args );
3394 1 $self->_add_stack( $expr );
3395 }
3396 }
3397 }
3398  
3399 # [60] RDFLiteral ::= String ( LANGTAG | ( '^^' IRIref ) )?
3400 9 ▶sub _RDFLiteral {
Subroutine _RDFLiteral: called CC=3 SCAR=12.0
3401 9 my $self = shift;
3402 9 my $value = $self->_String;
3403
3404 9 my $obj;
3405 9 ▶ if ($self->_test_token(LANG)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_test_token(15)) { } 2 7 9
elsif ($self->_test_token(12)) { } 0 7 7
3406 2 my $t = $self->_expected_token(LANG);
3407 2 my $lang = $t->value;
3408 2 $obj = $self->new_literal( value => $value, language => $lang );
3409 } elsif ($self->_test_token(HATHAT)) {
3410 0 $self->_expected_token(HATHAT);
3411 0 $self->_IRIref;
3412 0 my ($iri) = splice(@{ $self->{_stack} });
3413 0 $obj = $self->new_literal( value => $value, datatype => $iri );
3414 } else {
3415 7 $obj = $self->new_literal( value => $value );
3416 }
3417
3418 9 return $obj;
3419 }
3420  
3421 # [61] NumericLiteral ::= NumericLiteralUnsigned | NumericLiteralPositive | NumericLiteralNegative
3422 # [62] NumericLiteralUnsigned ::= INTEGER | DECIMAL | DOUBLE
3423 # [63] NumericLiteralPositive ::= INTEGER_POSITIVE | DECIMAL_POSITIVE | DOUBLE_POSITIVE
3424 # [64] NumericLiteralNegative ::= INTEGER_NEGATIVE | DECIMAL_NEGATIVE | DOUBLE_NEGATIVE
3425 15 ▶sub _NumericLiteral {
Subroutine _NumericLiteral: called CC=6 SCAR=18.5
3426 15 my $self = shift;
3427 15 my $sign = 0;
3428 15 ▶ if ($self->_optional_token(PLUS)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_optional_token(55)) { } 0 15 15
elsif ($self->_optional_token(50)) { } 0 15 15
3429 0 $sign = '+';
3430 } elsif ($self->_optional_token(MINUS)) {
3431 0 $sign = '-';
3432 }
3433
3434 15 my $value;
3435 my $type;
3436 15 ▶ if (my $db = $self->_optional_token(DOUBLE)) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $db = $self->_optional_token(10)) { } 1 14 15
elsif (my $dc = $self->_optional_token(8)) { } 1 13 14
3437 1 $value = $db->value;
3438 1 $type = Attean::IRI->new(value => 'http://www.w3.org/2001/XMLSchema#double', lazy => 1);
3439 } elsif (my $dc = $self->_optional_token(DECIMAL)) {
3440 1 $value = $dc->value;
3441 1 $type = Attean::IRI->new(value => 'http://www.w3.org/2001/XMLSchema#decimal', lazy => 1);
3442 } else {
3443 13 my $i = $self->_expected_token(INTEGER);
3444 13 $value = $i->value;
3445 13 $type = Attean::IRI->new(value => 'http://www.w3.org/2001/XMLSchema#integer', lazy => 1);
3446 }
3447
3448 15 ▶ if ($sign) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sign) 0 15 15
3449 0 $value = $sign . $value;
3450 }
3451
3452 15 my $obj = $self->new_literal( value => $value, datatype => $type );
3453 # if ($self->{args}{canonicalize} and blessed($obj) and $obj->isa('RDF::Trine::Node::Literal')) {
3454 # $obj = $obj->canonicalize;
3455 # }
3456  
3457 15 return $obj;
3458 }
3459  
3460 # [65] BooleanLiteral ::= 'true' | 'false'
3461 0 ▶sub _BooleanLiteral {
Subroutine _BooleanLiteral: not called CC=1 SCAR=6.9
3462 0 my $self = shift;
3463 0 my $t = $self->_expected_token(BOOLEAN);
3464 0 my $bool = $t->value;
3465  
3466 0 my $obj = $self->new_literal( value => $bool, datatype => 'http://www.w3.org/2001/XMLSchema#boolean' );
3467 # if ($self->{args}{canonicalize} and blessed($obj) and $obj->isa('RDF::Trine::Node::Literal')) {
3468 # $obj = $obj->canonicalize;
3469 # }
3470 0 return $obj;
3471 }
3472  
3473 # [66] String ::= STRING_LITERAL1 | STRING_LITERAL2 | STRING_LITERAL_LONG1 | STRING_LITERAL_LONG2
3474 9 ▶sub _String {
Subroutine _String: called CC=5 SCAR=18.0
3475 9 my $self = shift;
3476 9 my $value;
3477 my $string;
3478 9 my $t = $self->_peek_token;
3479 9 ▶ if ($string = $self->_optional_token(STRING1D)) {
Branch: 4 branches
BranchTrueFalseTotal
if ($string = $self->_optional_token(26)) { } 7 2 9
elsif ($string = $self->_optional_token(27)) { } 1 1 2
elsif ($string = $self->_optional_token(29)) { } 1 0 1
elsif ($string = $self->_optional_token(28)) { } 0 0 0
3480 7 $value = $string->value;
3481 } elsif ($string = $self->_optional_token(STRING1S)) {
3482 1 $value = $string->value;
3483 } elsif ($string = $self->_optional_token(STRING3S)) {
3484 1 $value = $string->value;
3485 } elsif ($string = $self->_optional_token(STRING3D)) {
3486 0 $value = $string->value;
3487 } else {
3488 0 my $got = AtteanX::SPARQL::Constants::decrypt_constant($t->type);
3489 0 my $value = $t->value;
3490 # Carp::cluck "Expecting string literal but found $got '$value'";
3491 0 $self->_token_error($t, "Expecting string literal but found $got '$value'")
3492 # croak "Expecting string literal but found $got '$value'";
3493 }
3494  
3495 9 return $value;
3496 }
3497  
3498 # [67] IRIref ::= IRI_REF | PrefixedName
3499 209 ▶sub _IRIref_test {
Subroutine _IRIref_test: called CC=3 SCAR=11.0
3500 209 my $self = shift;
3501 209 ▶ return 1 if ($self->_test_token(IRI));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(14) 50 159 209
3502 159 ▶ return 1 if ($self->_test_token(PREFIXNAME));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(21) 41 118 159
3503 118 return 0;
3504 }
3505  
3506  
3507 91 ▶sub _IRIref {
Subroutine _IRIref: called CC=3 SCAR=11.0
3508 91 my $self = shift;
3509 91 ▶ if (my $t = $self->_optional_token(IRI)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = $self->_optional_token(14)) { } 63 28 91
3510 63 my $iri = $t->value;
3511 63 my $base = $self->__base;
3512 63 ▶ my $node = $self->new_iri( value => $iri, $base ? (base => $base) : () );
Branch: 1 branch
BranchTrueFalseTotal
$base ? : 4 59 63
3513 63 $self->_add_stack( $node );
3514 } else {
3515 28 my $p = $self->_PrefixedName;
3516 28 $self->_add_stack( $p );
3517 }
3518 }
3519  
3520 # [68] PrefixedName ::= PNAME_LN | PNAME_NS
3521 28 ▶sub _PrefixedName {
Subroutine _PrefixedName: called CC=3 SCAR=11.2
3522 28 my $self = shift;
3523 28 my $t = $self->_expected_token(PREFIXNAME);
3524 28 my ($ns, $local) = @{ $t->args };
3525 28 chop($ns);
3526 # $local =~ s{\\([-~.!&'()*+,;=:/?#@%_\$])}{$1}g;
3527
3528 28 ▶ unless ($self->namespaces->namespace_uri($ns)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->namespaces->namespace_uri($ns)) 0 28 28
3529 0 croak "Syntax error: Use of undefined namespace '$ns'";
3530 }
3531
3532 28 my $iri = $self->namespaces->namespace_uri($ns)->iri($local);
3533 28 my $base = $self->__base;
3534 28 ▶ my $p = $self->new_iri( value => $iri->value, $base ? (base => $base) : () );
Branch: 1 branch
BranchTrueFalseTotal
$base ? : 0 28 28
3535 28 return $p;
3536 }
3537  
3538 # sub _qtSubjectOrObject {
3539 # my $self = shift;
3540 # # Var | BlankNode | iri | RDFLiteral | NumericLiteral | BooleanLiteral | QuotedTP
3541 # if ($self->_test_token(LTLT)) {
3542 # $self->_QuotedTP();
3543 # } else {
3544 # $self->_VarOrTerm;
3545 # }
3546 # }
3547 #
3548 # sub _QuotedTP {
3549 # my $self = shift;
3550 # #'<<' qtSubjectOrObject Verb qtSubjectOrObject '>>'
3551 # $self->_expected_token(LTLT);
3552 # $self->_qtSubjectOrObject();
3553 # $self->_Verb();
3554 # $self->_qtSubjectOrObject();
3555 # my ($s, $p, $o) = splice(@{ $self->{_stack} }, -3);
3556 #
3557 # my $reif = Attean::Blank->new();
3558 # if ($self->_test_token(TILDE)) {
3559 # $self->_expected_token(TILDE);
3560 # $self->_GraphNode();
3561 # $reif = pop(@{ $self->{_stack} });
3562 # }
3563 # $self->_expected_token(GTGT);
3564 #
3565 # if ($self->{__data_pattern}) {
3566 # foreach my $term ($s, $o) {
3567 # if ($term->does('Attean::API::Blank')) {
3568 # croak "Expecting (non-blank) RDF term in quoted triple, but found blank";
3569 # }
3570 # }
3571 # }
3572 #
3573 # my ($t) = $self->__new_statement( $s, $p, $o );
3574 # my $reifies = Attean::IRI->new(value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies', lazy => 1);
3575 # $self->_add_patterns( $self->__new_statement( $reif, $reifies, $t ) );
3576 # $self->_add_stack( $reif );
3577 # }
3578 #
3579 # sub _QuotedTriple {
3580 # my $self = shift;
3581 # #'<<' DataValueTerm Verb DataValueTerm '>>'
3582 # local($self->{__data_pattern}) = 1;
3583 # $self->_QuotedTP();
3584 # }
3585  
3586 # [69] BlankNode ::= BLANK_NODE_LABEL | ANON
3587 0 ▶sub _BlankNode {
Subroutine _BlankNode: not called CC=3 SCAR=24.8
3588 0 my $self = shift;
3589 0 ▶ if (my $where = $self->{__no_bnodes}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $where = $self->{"__no_bnodes"}) 0 0 0
3590 0 croak "Syntax error: Blank nodes not allowed in $where";
3591 }
3592 0 ▶ if (my $b = $self->_optional_token(BNODE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $b = $self->_optional_token(4)) { } 0 0 0
3593 0 my $label = $b->value;
3594 0 my $b = Attean::Blank->new($label);
3595 0 $self->blank_nodes->{$label} = $b;
3596 0 return $b;
3597 } else {
3598 0 $self->_expected_token(ANON);
3599 0 return Attean::Blank->new();
3600 }
3601 }
3602  
3603 1 ▶sub _NIL {
Subroutine _NIL: called CC=1 SCAR=0.0
3604 1 my $self = shift;
3605 1 $self->_expected_token(NIL);
3606 1 return Attean::IRI->new(value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil', lazy => 1);
3607 }
3608  
3609 ##########
3610  
3611 1 ▶sub _Reifier {
Subroutine _Reifier: called CC=2 SCAR=7.4
3612 1 my $self = shift;
3613 1 $self->_expected_token(TILDE);
3614 1 ▶ if ($self->_VarOrReifierId_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_VarOrReifierId_test) { } 1 0 1
3615 1 return $self->_VarOrReifierId();
3616 } else {
3617 0 return Attean::Blank->new();
3618 }
3619 }
3620  
3621 0 ▶sub _ReifierData {
Subroutine _ReifierData: not called CC=2 SCAR=17.9
3622 0 my $self = shift;
3623 0 $self->_expected_token(TILDE);
3624 0 ▶ if ($self->_ReifierId_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ReifierId_test) { } 0 0 0
3625 0 return $self->_ReifierId();
3626 } else {
3627 0 return Attean::Blank->new();
3628 }
3629 }
3630  
3631 1 ▶sub _VarOrReifierId_test {
Subroutine _VarOrReifierId_test: called CC=5 SCAR=24.5
3632 1 my $self = shift;
3633 1 ▶ return 1 if ($self->_test_token(VAR));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(59) 0 1 1
3634 1 ▶ return 1 if ($self->_IRIref_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 1 0 1
3635 0 ▶ return 1 if ($self->_test_token(BNODE));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(4) 0 0 0
3636 0 ▶ return 1 if ($self->_test_token(ANON));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(2) 0 0 0
3637 0 return 0;
3638 }
3639  
3640 0 ▶sub _ReifierId_test {
Subroutine _ReifierId_test: not called CC=4 SCAR=30.0
3641 0 my $self = shift;
3642 0 ▶ return 1 if ($self->_IRIref_test);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_IRIref_test 0 0 0
3643 0 ▶ return 1 if ($self->_test_token(BNODE));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(4) 0 0 0
3644 0 ▶ return 1 if ($self->_test_token(ANON));
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test_token(2) 0 0 0
3645 0 return 0;
3646 }
3647  
3648 1 ▶sub _VarOrReifierId {
Subroutine _VarOrReifierId: called CC=2 SCAR=7.6
3649 1 my $self = shift;
3650 1 ▶ if (my $b = $self->_test_token(VAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $b = $self->_test_token(59)) { } 0 1 1
3651 0 $self->_Var();
3652 } else {
3653 1 $self->_GraphTerm();
3654 }
3655 }
3656  
3657 0 ▶sub _ReifierId {
Subroutine _ReifierId: not called CC=1 SCAR=6.9
3658 0 my $self = shift;
3659 0 $self->_GraphTerm();
3660 }
3661  
3662 64 ▶sub _AnnotationPath {
Subroutine _AnnotationPath: called CC=9 SCAR=24.4
3663 64 my $self = shift;
3664 64 my $s = shift;
3665 64 my $p = shift;
3666 64 my $o = shift;
3667  
3668 64 my $reif;
3669 64 ▶ while ($self->_test_token(TILDE) or $self->_AnnotationBlockPath_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(39) or $self->_AnnotationBlockPath_test) 2 64 66
Condition66%2/3
$self->_test_token(39) or $self->_AnnotationBlockPath_test
l!l&&r!l&&!r
0264
MC/DC50%1/2
$self->_test_token(39) or $self->_AnnotationBlockPath_test
$self->_test_token(39) $self->_AnnotationBlockPath_test
Truth table66%2/3
A or B
A= $self->_test_token(39)B= $self->_AnnotationBlockPath_test
ABresult
1X1
011
000
3670 2 ▶ unless (defined($reif)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $reif) 2 0 2
3671 2 $reif = Attean::Blank->new();
3672 }
3673 2 my $assert_reification = undef;
3674 2 ▶ if ($self->_test_token(TILDE)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(39)) { } 0 2 2
3675 0 $self->_Reifier();
3676 0 $reif = pop(@{ $self->{_stack} });
3677 0 $assert_reification = $reif;
3678 } else {
3679 2 $self->_AnnotationBlockPath($reif);
3680 2 $assert_reification = $reif;
3681 2 $reif = undef;
3682 }
3683 2 ▶ if ($assert_reification) {
Branch: 1 branch
BranchTrueFalseTotal
if ($assert_reification) 2 0 2
3684 2 my $reif = $assert_reification;
3685 2 ▶ if (blessed($reif) and $reif->does('Attean::API::Blank') and $self->{__data_pattern_delete}) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($reif) and $reif->does("Attean::API::Blank") and $self->{"__data_pattern_delete"}) 0 2 2
Condition33%2/6
builtin::blessed($reif) and $reif->does("Attean::API::Blank") and $self->{"__data_pattern_delete"}
!ll&&!rl&&r
020
builtin::blessed($reif) and $reif->does("Attean::API::Blank")
!ll&&!rl&&r
002
MC/DC0%0/3
builtin::blessed($reif) and $reif->does("Attean::API::Blank") and $self->{"__data_pattern_delete"}
builtin::blessed($reif) $reif->does("Attean::API::Blank") $self->{"__data_pattern_delete"}
Truth table25%1/4
A and B and C
A= builtin::blessed($reif)B= $reif->does("Attean::API::Blank")C= $self->{"__data_pattern_delete"}
ABCresult
0XX0
10X0
1100
1111
3686 0 croak "Syntax error: Annotation syntax with non-IRI reifier not allowed in DELETE DATA template.";
3687 }
3688 2 my $reifies = Attean::IRI->new(value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies', lazy => 1);
3689 2 my ($tt) = $self->__new_statement($s, $p, $o);
3690 2 my ($reification) = $self->__new_statement( $reif, $reifies, $tt);
3691 2 $self->_add_patterns( $reification );
3692 2 undef $assert_reification;
3693 }
3694 }
3695 }
3696  
3697 0 ▶sub _Annotation {
Subroutine _Annotation: not called CC=5 SCAR=34.0
3698 0 my $self = shift;
3699 0 my $reif;
3700 0 ▶ while ($self->_test_token(TILDE) or $self->_AnnotationBlockPath_test) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(39) or $self->_AnnotationBlockPath_test) 0 0 0
Condition0%0/3
$self->_test_token(39) or $self->_AnnotationBlockPath_test
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_test_token(39) or $self->_AnnotationBlockPath_test
$self->_test_token(39) $self->_AnnotationBlockPath_test
Truth table0%0/3
A or B
A= $self->_test_token(39)B= $self->_AnnotationBlockPath_test
ABresult
1X1
011
000
3701 0 ▶ unless (defined($reif)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $reif) 0 0 0
3702 0 $reif = Attean::Blank->new();
3703 }
3704 0 ▶ if ($self->_test_token(TILDE)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(39)) { } 0 0 0
3705 0 $self->_Reifier();
3706 0 $reif = pop(@{ $self->{_stack} });
3707 } else {
3708 0 $self->_AnnotationBlock($reif);
3709 0 $reif = undef;
3710 }
3711 }
3712 }
3713  
3714 66 ▶sub _AnnotationBlockPath_test {
Subroutine _AnnotationBlockPath_test: called CC=1 SCAR=0.0
3715 66 my $self = shift;
3716 66 return ($self->_test_token(LANNOT));
3717 }
3718  
3719 0 ▶sub _AnnotationBlock_test {
Subroutine _AnnotationBlock_test: not called CC=1 SCAR=6.9
3720 0 my $self = shift;
3721 0 return ($self->_test_token(LANNOT));
3722 }
3723  
3724 2 ▶sub _AnnotationBlockPath {
Subroutine _AnnotationBlockPath: called CC=1 SCAR=0.0
3725 2 my $self = shift;
3726 2 my $reif = shift;
3727 2 my @state = splice(@{ $self->{_stack} });
3728  
3729 2 $self->_expected_token(LANNOT);
3730 2 $self->_PropertyListNotEmptyPath($reif);
3731 2 $self->_expected_token(RANNOT);
3732  
3733 2 my @props = splice(@{ $self->{_stack} });
3734 2 my @triples = map { $self->__new_statement( $reif, @$_ ) } @props;
3735 2 $self->_add_patterns( @triples );
3736
3737 2 push(@{ $self->{_stack} }, @state);
3738 }
3739  
3740 0 ▶sub _AnnotationBlock {
Subroutine _AnnotationBlock: not called CC=1 SCAR=6.9
3741 0 my $self = shift;
3742 0 my $reif = shift;
3743 0 my @state = splice(@{ $self->{_stack} });
3744  
3745 0 $self->_expected_token(LANNOT);
3746 0 $self->_PropertyListNotEmpty($reif);
3747 0 $self->_expected_token(RANNOT);
3748  
3749 0 my @props = splice(@{ $self->{_stack} });
3750 0 my @triples = map { $self->__new_statement( $reif, @$_ ) } @props;
3751 0 $self->_add_patterns( @triples );
3752
3753 0 push(@{ $self->{_stack} }, @state);
3754 }
3755  
3756 2 ▶sub _ReifiedTripleBlockPath {
Subroutine _ReifiedTripleBlockPath: called CC=2 SCAR=6.9
3757 2 my $self = shift;
3758 2 $self->_ReifiedTriple();
3759 # XXX
3760 2 my ($s) = splice(@{ $self->{_stack} });
3761 2 $self->_PropertyListPath($s);
3762 2 my @list = splice(@{ $self->{_stack} });
3763 2 my @triples;
3764 2 foreach my $data (@list) {
3765 2 push(@triples, $self->__new_statement( $s, @$data ));
3766 }
3767 2 push( @{ $self->{_stack} }, @triples );
3768 }
3769  
3770 0 ▶sub _ReifiedTripleBlock {
Subroutine _ReifiedTripleBlock: not called CC=2 SCAR=17.9
3771 0 my $self = shift;
3772 0 $self->_ReifiedTriple();
3773 # XXX
3774 0 my ($s) = splice(@{ $self->{_stack} });
3775 0 $self->_PropertyList($s);
3776 0 my @list = splice(@{ $self->{_stack} });
3777 0 my @triples;
3778 0 foreach my $data (@list) {
3779 0 push(@triples, $self->__new_statement( $s, @$data ));
3780 }
3781 0 push( @{ $self->{_stack} }, @triples );
3782 }
3783  
3784 3 ▶sub _ReifiedTriple {
Subroutine _ReifiedTriple: called CC=3 SCAR=11.0
3785 3 my $self = shift;
3786 3 $self->_expected_token(LTLT);
3787 3 $self->_ReifiedTripleSubject();
3788 3 $self->_Verb();
3789 3 $self->_ReifiedTripleObject();
3790 3 ▶ if (scalar(@{ $self->{_stack} }) < 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{"_stack"};} < 3) 0 3 3
3791 12 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
3792 0 Carp::cluck Dumper($self->{_stack});
3793 }
3794 3 my ($s, $p, $o) = splice(@{ $self->{_stack} }, -3);
3795 # XXX handle default reifier
3796 3 my $reif = Attean::Blank->new();
3797 3 ▶ if ($self->_test_token(TILDE)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(39)) 1 2 3
3798 1 $self->_Reifier();
3799 1 $reif = pop(@{ $self->{_stack} });
3800 }
3801 # add rdf:reifies triple pattern
3802
3803 3 my $reifies = Attean::IRI->new(value => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies', lazy => 1);
3804 3 my ($tt) = $self->__new_statement($s, $p, $o);
3805 3 my ($reification) = $self->__new_statement( $reif, $reifies, $tt);
3806 3 $self->_add_patterns( $reification );
3807
3808 3 push( @{ $self->{_stack} }, $reif );
3809 3 $self->_expected_token(GTGT);
3810 }
3811  
3812 3 ▶sub _ReifiedTripleSubject {
Subroutine _ReifiedTripleSubject: called CC=14 SCAR=51.1
3813 3 my $self = shift;
3814 3 ▶ if ($self->_test_token(VAR)) {
Branch: 8 branches
BranchTrueFalseTotal
if ($self->_test_token(59)) { } 3 0 3
elsif ($self->_test_token(5)) { } 0 0 0
elsif ($self->_test_token(51)) { } 0 0 0
elsif ($self->_test_token(2) or $self->_test_token(4)) { } 0 0 0
elsif ($self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)) { } 0 0 0
elsif ($self->_test_literal_token) { } 0 0 0
elsif ($self->_test_token(35)) { } 0 0 0
elsif ($self->_test_token(36)) { } 0 0 0
3815 3 $self->_Var();
3816 } elsif ($self->_test_token(BOOLEAN)) {
3817 0 my $b = $self->_BooleanLiteral;
3818 0 $self->_add_stack( $b );
3819 } elsif ($self->_test_token(NIL)) {
3820 0 my $n = $self->_NIL;
3821 0 $self->_add_stack( $n );
3822 ▶ } elsif ($self->_test_token(ANON) or $self->_test_token(BNODE)) {
Condition0%0/3
$self->_test_token(2) or $self->_test_token(4)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_test_token(2) or $self->_test_token(4)
$self->_test_token(2) $self->_test_token(4)
Truth table0%0/3
A or B
A= $self->_test_token(2)B= $self->_test_token(4)
ABresult
1X1
011
000
3823 0 my $b = $self->_BlankNode;
3824 0 $self->_add_stack( $b );
3825 ▶ } elsif ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(MINUS) or $self->_test_token(PLUS)) {
Condition0%0/12
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
l!l&&r!l&&!r
000
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50)
l!l&&r!l&&!r
000
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10)
l!l&&r!l&&!r
000
$self->_test_token(13) or $self->_test_token(8)
l!l&&r!l&&!r
000
MC/DC0%0/5
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
$self->_test_token(13) $self->_test_token(8) $self->_test_token(10) $self->_test_token(50) $self->_test_token(55)
Truth table0%0/6
A or B or C or D or E
A= $self->_test_token(13)B= $self->_test_token(8)C= $self->_test_token(10)D= $self->_test_token(50)E= $self->_test_token(55)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
3826 0 my $l = $self->_NumericLiteral;
3827 0 $self->_add_stack( $l );
3828 } elsif ($self->_test_literal_token) {
3829 0 my $l = $self->_RDFLiteral;
3830 0 $self->_add_stack( $l );
3831 } elsif ($self->_test_token(LTLT)) {
3832 0 $self->_ReifiedTriple();
3833 } elsif ($self->_test_token(LTLTP)) { # Not in official grammar yet
3834 0 my $t = $self->_TripleTerm();
3835 0 $self->_add_stack( $t );
3836 } else {
3837 0 $self->_IRIref;
3838 }
3839 }
3840  
3841 3 ▶sub _ReifiedTripleObject {
Subroutine _ReifiedTripleObject: called CC=13 SCAR=41.2
3842 3 my $self = shift;
3843 3 ▶ if ($self->_test_token(VAR)) {
Branch: 7 branches
BranchTrueFalseTotal
if ($self->_test_token(59)) { } 0 3 3
elsif ($self->_test_token(5)) { } 0 3 3
elsif ($self->_test_token(2) or $self->_test_token(4)) { } 0 3 3
elsif ($self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)) { } 0 3 3
elsif ($self->_test_literal_token) { } 0 3 3
elsif ($self->_test_token(35)) { } 0 3 3
elsif ($self->_test_token(36)) { } 0 3 3
3844 0 $self->_Var();
3845 } elsif ($self->_test_token(BOOLEAN)) {
3846 0 my $b = $self->_BooleanLiteral;
3847 0 $self->_add_stack( $b );
3848 ▶ } elsif ($self->_test_token(ANON) or $self->_test_token(BNODE)) {
Condition33%1/3
$self->_test_token(2) or $self->_test_token(4)
l!l&&r!l&&!r
003
MC/DC0%0/2
$self->_test_token(2) or $self->_test_token(4)
$self->_test_token(2) $self->_test_token(4)
Truth table33%1/3
A or B
A= $self->_test_token(2)B= $self->_test_token(4)
ABresult
1X1
011
000
3849 0 my $b = $self->_BlankNode;
3850 0 $self->_add_stack( $b );
3851 ▶ } elsif ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(MINUS) or $self->_test_token(PLUS)) {
Condition33%4/12
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
l!l&&r!l&&!r
003
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50)
l!l&&r!l&&!r
003
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10)
l!l&&r!l&&!r
003
$self->_test_token(13) or $self->_test_token(8)
l!l&&r!l&&!r
003
MC/DC0%0/5
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
$self->_test_token(13) $self->_test_token(8) $self->_test_token(10) $self->_test_token(50) $self->_test_token(55)
Truth table16%1/6
A or B or C or D or E
A= $self->_test_token(13)B= $self->_test_token(8)C= $self->_test_token(10)D= $self->_test_token(50)E= $self->_test_token(55)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
3852 0 my $l = $self->_NumericLiteral;
3853 0 $self->_add_stack( $l );
3854 } elsif ($self->_test_literal_token) {
3855 0 my $l = $self->_RDFLiteral;
3856 0 $self->_add_stack( $l );
3857 } elsif ($self->_test_token(LTLT)) {
3858 0 $self->_ReifiedTriple();
3859 } elsif ($self->_test_token(LTLTP)) { # Not in official grammar yet
3860 0 my $t = $self->_TripleTerm();
3861 0 $self->_add_stack( $t );
3862 } else {
3863 3 $self->_IRIref;
3864 }
3865 }
3866  
3867 0 ▶sub _TripleTerm {
Subroutine _TripleTerm: not called CC=1 SCAR=6.9
3868 0 my $self = shift;
3869 0 $self->_expected_token(LTLTP);
3870 0 $self->_TripleTermSubject;
3871 0 $self->_Verb;
3872 0 $self->_TripleTermObject;
3873 0 $self->_expected_token(PGTGT);
3874 0 my ($s, $p, $o) = splice(@{ $self->{_stack} }, -3);
3875 0 my ($t) = $self->__new_statement( $s, $p, $o );
3876 0 return $t;
3877 }
3878  
3879 0 ▶sub _TripleTermData {
Subroutine _TripleTermData: not called CC=1 SCAR=6.9
3880 0 my $self = shift;
3881 0 $self->_expected_token(LTLTP);
3882 0 $self->_TripleTermDataSubject;
3883 0 $self->_Verb;
3884 0 $self->_TripleTermDataObject;
3885 0 $self->_expected_token(PGTGT);
3886 0 my ($s, $p, $o) = splice(@{ $self->{_stack} }, -3);
3887 0 my ($t) = $self->__new_statement( $s, $p, $o );
3888 0 return $t;
3889 }
3890  
3891 0 ▶sub _TripleTermSubject {
Subroutine _TripleTermSubject: not called CC=6 SCAR=37.4
3892 0 my $self = shift;
3893 0 ▶ if ($self->_test_token(VAR)) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->_test_token(59)) { } 0 0 0
elsif ($self->_test_token(36)) { } 0 0 0
elsif ($self->_test_token(51)) { } 0 0 0
elsif ($self->_test_token(2) or $self->_test_token(4)) { } 0 0 0
3894 0 $self->_Var();
3895 } elsif ($self->_test_token(LTLTP)) {
3896 0 my $t = $self->_TripleTerm();
3897 0 $self->_add_stack( $t );
3898 # } elsif ($self->_test_token(BOOLEAN)) {
3899 # my $b = $self->_BooleanLiteral;
3900 # $self->_add_stack( $b );
3901 } elsif ($self->_test_token(NIL)) {
3902 0 my $n = $self->_NIL;
3903 0 $self->_add_stack( $n );
3904 ▶ } elsif ($self->_test_token(ANON) or $self->_test_token(BNODE)) {
Condition0%0/3
$self->_test_token(2) or $self->_test_token(4)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_test_token(2) or $self->_test_token(4)
$self->_test_token(2) $self->_test_token(4)
Truth table0%0/3
A or B
A= $self->_test_token(2)B= $self->_test_token(4)
ABresult
1X1
011
000
3905 0 my $b = $self->_BlankNode;
3906 0 $self->_add_stack( $b );
3907 # } elsif ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(MINUS) or $self->_test_token(PLUS)) {
3908 # my $l = $self->_NumericLiteral;
3909 # $self->_add_stack( $l );
3910 # } elsif ($self->_test_literal_token) {
3911 # my $l = $self->_RDFLiteral;
3912 # $self->_add_stack( $l );
3913 } else {
3914 0 $self->_IRIref;
3915 }
3916 }
3917  
3918 0 ▶sub _TripleTermObject {
Subroutine _TripleTermObject: not called CC=12 SCAR=50.5
3919 0 my $self = shift;
3920 0 ▶ if ($self->_test_token(VAR)) {
Branch: 6 branches
BranchTrueFalseTotal
if ($self->_test_token(59)) { } 0 0 0
elsif ($self->_test_token(5)) { } 0 0 0
elsif ($self->_test_token(2) or $self->_test_token(4)) { } 0 0 0
elsif ($self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)) { } 0 0 0
elsif ($self->_test_literal_token) { } 0 0 0
elsif ($self->_test_token(36)) { } 0 0 0
3921 0 $self->_Var();
3922 } elsif ($self->_test_token(BOOLEAN)) {
3923 0 my $b = $self->_BooleanLiteral;
3924 0 $self->_add_stack( $b );
3925 ▶ } elsif ($self->_test_token(ANON) or $self->_test_token(BNODE)) {
Condition0%0/3
$self->_test_token(2) or $self->_test_token(4)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_test_token(2) or $self->_test_token(4)
$self->_test_token(2) $self->_test_token(4)
Truth table0%0/3
A or B
A= $self->_test_token(2)B= $self->_test_token(4)
ABresult
1X1
011
000
3926 0 my $b = $self->_BlankNode;
3927 0 $self->_add_stack( $b );
3928 ▶ } elsif ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(MINUS) or $self->_test_token(PLUS)) {
Condition0%0/12
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
l!l&&r!l&&!r
000
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50)
l!l&&r!l&&!r
000
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10)
l!l&&r!l&&!r
000
$self->_test_token(13) or $self->_test_token(8)
l!l&&r!l&&!r
000
MC/DC0%0/5
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
$self->_test_token(13) $self->_test_token(8) $self->_test_token(10) $self->_test_token(50) $self->_test_token(55)
Truth table0%0/6
A or B or C or D or E
A= $self->_test_token(13)B= $self->_test_token(8)C= $self->_test_token(10)D= $self->_test_token(50)E= $self->_test_token(55)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
3929 0 my $l = $self->_NumericLiteral;
3930 0 $self->_add_stack( $l );
3931 } elsif ($self->_test_literal_token) {
3932 0 my $l = $self->_RDFLiteral;
3933 0 $self->_add_stack( $l );
3934 } elsif ($self->_test_token(LTLTP)) {
3935 0 my $tt = $self->_TripleTerm();
3936 0 $self->_add_stack( $tt );
3937 } else {
3938 0 $self->_IRIref;
3939 }
3940 }
3941  
3942 0 ▶sub _TripleTermDataSubject {
Subroutine _TripleTermDataSubject: not called CC=1 SCAR=6.9
3943 0 my $self = shift;
3944 # if ($self->_test_token(BOOLEAN)) {
3945 # my $b = $self->_BooleanLiteral;
3946 # $self->_add_stack( $b );
3947 # } elsif ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(MINUS) or $self->_test_token(PLUS)) {
3948 # my $l = $self->_NumericLiteral;
3949 # $self->_add_stack( $l );
3950 # } elsif ($self->_test_literal_token) {
3951 # my $l = $self->_RDFLiteral;
3952 # $self->_add_stack( $l );
3953 # } else {
3954 0 $self->_IRIref;
3955 # }
3956 }
3957  
3958 0 ▶sub _TripleTermDataObject {
Subroutine _TripleTermDataObject: not called CC=9 SCAR=45.0
3959 0 my $self = shift;
3960 0 ▶ if ($self->_test_token(BOOLEAN)) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->_test_token(5)) { } 0 0 0
elsif ($self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)) { } 0 0 0
elsif ($self->_test_literal_token) { } 0 0 0
elsif ($self->_test_token(36)) { } 0 0 0
3961 0 my $b = $self->_BooleanLiteral;
3962 0 $self->_add_stack( $b );
3963 ▶ } elsif ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(MINUS) or $self->_test_token(PLUS)) {
Condition0%0/12
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
l!l&&r!l&&!r
000
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50)
l!l&&r!l&&!r
000
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10)
l!l&&r!l&&!r
000
$self->_test_token(13) or $self->_test_token(8)
l!l&&r!l&&!r
000
MC/DC0%0/5
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
$self->_test_token(13) $self->_test_token(8) $self->_test_token(10) $self->_test_token(50) $self->_test_token(55)
Truth table0%0/6
A or B or C or D or E
A= $self->_test_token(13)B= $self->_test_token(8)C= $self->_test_token(10)D= $self->_test_token(50)E= $self->_test_token(55)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
3964 0 my $l = $self->_NumericLiteral;
3965 0 $self->_add_stack( $l );
3966 } elsif ($self->_test_literal_token) {
3967 0 my $l = $self->_RDFLiteral;
3968 0 $self->_add_stack( $l );
3969 } elsif ($self->_test_token(LTLTP)) {
3970 0 push(@{ $self->{_stack} }, $self->_TripleTermData());
3971 } else {
3972 0 $self->_IRIref;
3973 }
3974 }
3975  
3976 1 ▶sub _ExprTripleTerm {
Subroutine _ExprTripleTerm: called CC=1 SCAR=0.0
3977 1 my $self = shift;
3978 1 $self->_expected_token(LTLTP);
3979 1 $self->_ExprTripleTermSubject();
3980 1 $self->_Verb();
3981 1 $self->_ExprTripleTermObject();
3982 1 $self->_expected_token(PGTGT);
3983
3984 1 my ($s, $p, $o) = splice(@{ $self->{_stack} }, -3);
3985
3986 1 $self->_add_stack( $self->__new_statement( $s, $p, $o ) );
3987 }
3988  
3989 1 ▶sub _ExprTripleTermSubject {
Subroutine _ExprTripleTermSubject: called CC=2 SCAR=7.6
3990 1 my $self = shift;
3991 1 ▶ if ($self->_test_token(VAR)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(59)) { } 1 0 1
3992 1 $self->_Var();
3993 # } elsif ($self->_test_token(BOOLEAN)) {
3994 # my $b = $self->_BooleanLiteral;
3995 # $self->_add_stack( $b );
3996 # } elsif ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(MINUS) or $self->_test_token(PLUS)) {
3997 # my $l = $self->_NumericLiteral;
3998 # $self->_add_stack( $l );
3999 # } elsif ($self->_test_literal_token) {
4000 # my $l = $self->_RDFLiteral;
4001 # $self->_add_stack( $l );
4002 } else {
4003 0 $self->_IRIref;
4004 }
4005 }
4006  
4007 1 ▶sub _ExprTripleTermObject {
Subroutine _ExprTripleTermObject: called CC=10 SCAR=36.1
4008 1 my $self = shift;
4009 1 ▶ if ($self->_test_token(VAR)) {
Branch: 5 branches
BranchTrueFalseTotal
if ($self->_test_token(59)) { } 0 1 1
elsif ($self->_test_token(5)) { } 0 1 1
elsif ($self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)) { } 0 1 1
elsif ($self->_test_literal_token) { } 0 1 1
elsif ($self->_test_token(36)) { } 0 1 1
4010 0 $self->_Var();
4011 } elsif ($self->_test_token(BOOLEAN)) {
4012 0 my $b = $self->_BooleanLiteral;
4013 0 $self->_add_stack( $b );
4014 ▶ } elsif ($self->_test_token(INTEGER) or $self->_test_token(DECIMAL) or $self->_test_token(DOUBLE) or $self->_test_token(MINUS) or $self->_test_token(PLUS)) {
Condition33%4/12
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
l!l&&r!l&&!r
001
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50)
l!l&&r!l&&!r
001
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10)
l!l&&r!l&&!r
001
$self->_test_token(13) or $self->_test_token(8)
l!l&&r!l&&!r
001
MC/DC0%0/5
$self->_test_token(13) or $self->_test_token(8) or $self->_test_token(10) or $self->_test_token(50) or $self->_test_token(55)
$self->_test_token(13) $self->_test_token(8) $self->_test_token(10) $self->_test_token(50) $self->_test_token(55)
Truth table16%1/6
A or B or C or D or E
A= $self->_test_token(13)B= $self->_test_token(8)C= $self->_test_token(10)D= $self->_test_token(50)E= $self->_test_token(55)
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
4015 0 my $l = $self->_NumericLiteral;
4016 0 $self->_add_stack( $l );
4017 } elsif ($self->_test_literal_token) {
4018 0 my $l = $self->_RDFLiteral;
4019 0 $self->_add_stack( $l );
4020 } elsif ($self->_test_token(LTLTP)) {
4021 0 push(@{ $self->{_stack} }, $self->_TripleTermData());
4022 } else {
4023 1 $self->_IRIref;
4024 }
4025 }
4026  
4027 ##########
4028  
4029 36 ▶sub __solution_modifiers {
Subroutine __solution_modifiers: called CC=39 SCAR=38.0
4030 36 my $self = shift;
4031 36 my $star = shift;
4032 36 my @exprs = @_;
4033
4034 36 ▶ if (my $computed_group_vars = delete( $self->{build}{__group_vars} )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $computed_group_vars = delete $self->{"build"}{"__group_vars"}) 0 36 36
4035 0 my $pattern = $self->{build}{triples}[0];
4036 0 foreach my $data (@$computed_group_vars) {
4037 0 my ($var, $expr) = @$data;
4038 0 $pattern = Attean::Algebra::Extend->new( children => [$pattern], variable => $var, expression => $expr );
4039 }
4040 0 $self->{build}{triples}[0] = $pattern;
4041 }
4042
4043 36 my $has_aggregation = 0;
4044 36 my $having_expr;
4045 36 my $aggdata = delete( $self->{build}{__aggregate} );
4046 36 ▶ my $groupby = delete( $self->{build}{__group_by} ) || [];
Condition100%2/2
delete $self->{'build'}{'__group_by'} || []
l!l
234
MC/DC100%1/1
delete $self->{'build'}{'__group_by'} || []
delete $self->{'build'}{'__group_by'}
Truth table100%2/2
A
A= delete $self->{'build'}{'__group_by'}
Aresult
11
00
4047 36 ▶ my @aggkeys = keys %{ $aggdata || {} };
Condition100%2/2
$aggdata || {}
l!l
333
MC/DC100%1/1
$aggdata || {}
$aggdata
Truth table100%2/2
A
A= $aggdata
Aresult
11
00
4048 36 ▶ if (scalar(@aggkeys) or scalar(@$groupby)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @aggkeys or scalar @$groupby) 2 34 36
Condition100%2/2
scalar @aggkeys or scalar @$groupby
l!l
234
MC/DC100%1/1
scalar @aggkeys or scalar @$groupby
scalar @aggkeys
Truth table100%2/2
A
A= scalar @aggkeys
Aresult
11
00
4049 2 $has_aggregation++;
4050 2 my @aggs;
4051 2 foreach my $k (@aggkeys) {
4052 2 my ($var, $expr) = @{ $aggdata->{$k} };
4053 2 push(@aggs, $expr);
4054 }
4055
4056 2 my $pattern = $self->{build}{triples};
4057 2 my $ggp = shift(@$pattern);
4058 2 ▶ if (my $having = delete( $self->{build}{__having} )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $having = delete $self->{"build"}{"__having"}) 1 1 2
4059 1 $having_expr = $having;
4060 }
4061 2 my $agg = Attean::Algebra::Group->new( children => [$ggp], groupby => $groupby, aggregates => \@aggs );
4062 2 push(@{ $self->{build}{triples} }, $agg);
4063 }
4064
4065 36 my %group_vars;
4066 my %agg_vars;
4067 36 ▶ if ($has_aggregation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_aggregation) 2 34 36
4068 2 foreach my $agg_var (map { $_->[0] } values %$aggdata) {
4069 2 $agg_vars{ $agg_var->value }++;
4070 }
4071 2 foreach my $g (@$groupby) {
4072 2 ▶ if ($g->isa('Attean::ValueExpression') and $g->value->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($g->isa('Attean::ValueExpression') and $g->value->does('Attean::API::Variable')) { } 2 0 2
Condition33%1/3
$g->isa("Attean::ValueExpression") and $g->value->does("Attean::API::Variable")
!ll&&!rl&&r
002
MC/DC0%0/2
$g->isa("Attean::ValueExpression") and $g->value->does("Attean::API::Variable")
$g->isa("Attean::ValueExpression") $g->value->does("Attean::API::Variable")
Truth table33%1/3
A and B
A= $g->isa("Attean::ValueExpression")B= $g->value->does("Attean::API::Variable")
ABresult
0X0
100
111
4073 2 $group_vars{ $g->value->value }++;
4074 } else {
4075 0 $self->log->trace("Remaining GROUP BY clauses:\n" . Dumper($g));
4076 0 croak 'Unrecognized GROUP BY clauses, see trace log for details.';
4077 }
4078 }
4079 }
4080
4081 36 ▶ if (my $table = $self->{build}{trailing_values}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $table = $self->{"build"}{"trailing_values"}) 1 35 36
4082 1 my $pattern = pop(@{ $self->{build}{triples} });
4083 1 push(@{ $self->{build}{triples} }, $self->_new_join($pattern, $table));
4084 }
4085
4086 36 ▶ my %trailing_values_vars = map { $_->value => 1 } @{ $self->{build}{trailing_values_vars} || [] };
Condition100%2/2
$self->{'build'}{'trailing_values_vars'} || []
l!l
135
MC/DC100%1/1
$self->{'build'}{'trailing_values_vars'} || []
$self->{'build'}{'trailing_values_vars'}
Truth table100%2/2
A
A= $self->{'build'}{'trailing_values_vars'}
Aresult
11
00
4087
4088 36 my @project;
4089 my @vars;
4090 36 my @extend;
4091 36 ▶ if ($star) {
Branch: 1 branch
BranchTrueFalseTotal
if ($star) { } 25 11 36
4092 25 my $pattern = ${ $self->{build}{triples} }[-1];
4093 25 push(@project, $pattern->in_scope_variables);
4094 25 ▶ if ($has_aggregation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_aggregation) 0 25 25
4095 0 croak "Cannot SELECT * in an aggregate query";
4096 }
4097 } else {
4098 11 my %already_projected;
4099 11 ▶ for (my $i = 0; $i < $#exprs; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#exprs) 5 10 15
4100 5 my $k = $exprs[$i];
4101 5 my $v = $exprs[$i+1];
4102 5 ▶ if ($has_aggregation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_aggregation) 3 2 5
4103 3 ▶ my @vars = $v->does('Attean::API::Variable') ? $v : $v->unaggregated_variables;
Branch: 1 branch
BranchTrueFalseTotal
$v->does('Attean::API::Variable') ? : 2 1 3
4104 3 foreach my $var (@vars) {
4105 3 my $name = $var->value;
4106 3 ▶ unless (exists $agg_vars{$name} or exists $group_vars{$name} or exists $trailing_values_vars{$name} or exists $already_projected{ $name }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $agg_vars{$name} or exists $group_vars{$name} or exists $trailing_values_vars{$name} or exists $already_projected{$name}) 1 2 3
Condition77%7/9
exists $agg_vars{$name} or exists $group_vars{$name} or exists $trailing_values_vars{$name} or exists $already_projected{$name}
l!l&&r!l&&!r
201
exists $agg_vars{$name} or exists $group_vars{$name} or exists $trailing_values_vars{$name}
l!l&&r!l&&!r
201
exists $agg_vars{$name} or exists $group_vars{$name}
l!l&&r!l&&!r
111
MC/DC50%2/4
exists $agg_vars{$name} or exists $group_vars{$name} or exists $trailing_values_vars{$name} or exists $already_projected{$name}
exists $agg_vars{$name} exists $group_vars{$name} exists $trailing_values_vars{$name} exists $already_projected{$name}
Truth table60%3/5
A or B or C or D
A= exists $agg_vars{$name}B= exists $group_vars{$name}C= exists $trailing_values_vars{$name}D= exists $already_projected{$name}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
4107 1 Carp::confess "Cannot project variable ?$name that is not aggregated or used in grouping";
4108 0 croak "Cannot project variable ?$name that is not aggregated or used in grouping";
4109 }
4110 2 $already_projected{ $k }++;
4111 }
4112 }
4113
4114 4 push(@project, $k);
4115 4 ▶ if ($v->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->does('Attean::API::Variable')) { } 3 1 4
4116 3 push(@vars, $v);
4117 } else {
4118 1 push(@extend, $k, $v);
4119 }
4120 }
4121 }
4122  
4123 {
4124 35 my $pattern = pop(@{ $self->{build}{triples} });
4125 35 my %in_scope = map { $_ => 1 } $pattern->in_scope_variables;
4126 35 ▶ while (my($name, $expr) = splice(@extend, 0, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@extend, 0, 2)) 1 35 36
4127 1 ▶ if (exists $in_scope{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $in_scope{$name}) 0 1 1
4128 0 croak "Syntax error: Already-bound variable ($name) used in project expression";
4129 }
4130 1 my $var = Attean::Variable->new( value => $name );
4131 1 $pattern = Attean::Algebra::Extend->new(children => [$pattern], variable => $var, expression => $expr);
4132 }
4133 35 push(@{ $self->{build}{triples} }, $pattern);
4134 }
4135
4136 35 ▶ if ($having_expr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($having_expr) 0 35 35
4137 0 my $pattern = pop(@{ $self->{build}{triples} });
4138 0 my $filter = Attean::Algebra::Filter->new( children => [$pattern], expression => $having_expr );
4139 0 push(@{ $self->{build}{triples} }, $filter);
4140 }
4141
4142 35 ▶ if ($self->{build}{options}{orderby}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"build"}{"options"}{"orderby"}) 1 34 35
4143 1 my $order = delete $self->{build}{options}{orderby};
4144 1 my $pattern = pop(@{ $self->{build}{triples} });
4145 1 my @order = @$order;
4146 1 my @cmps;
4147 1 foreach my $o (@order) {
4148 1 my ($dir, $expr) = @$o;
4149 1 my $asc = ($dir eq 'ASC');
4150 1 push(@cmps, Attean::Algebra::Comparator->new(ascending => $asc, expression => $expr));
4151 }
4152 1 my $sort = Attean::Algebra::OrderBy->new( children => [$pattern], comparators => \@cmps );
4153 1 push(@{ $self->{build}{triples} }, $sort);
4154 }
4155  
4156 {
4157 35 my $pattern = pop(@{ $self->{build}{triples} });
4158 35 my $vars = [map { Attean::Variable->new(value => $_) } @project];
4159 35 ▶ if (scalar(@$vars)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$vars) 27 8 35
4160 27 $pattern = Attean::Algebra::Project->new( children => [$pattern], variables => $vars);
4161 }
4162 35 push(@{ $self->{build}{triples} }, $pattern);
4163 }
4164
4165 35 ▶ if (my $level = $self->{build}{options}{distinct}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $level = $self->{"build"}{"options"}{"distinct"}) 1 34 35
4166 1 delete $self->{build}{options}{distinct};
4167 1 my $pattern = pop(@{ $self->{build}{triples} });
4168 1 ▶ my $sort = ($level == 1)
Branch: 1 branch
BranchTrueFalseTotal
$level == 1 ? : 0 1 1
4169 ? Attean::Algebra::Distinct->new( children => [$pattern] )
4170 : Attean::Algebra::Reduced->new( children => [$pattern] );
4171 1 push(@{ $self->{build}{triples} }, $sort);
4172 }
4173
4174 35 ▶ if (exists $self->{build}{options}{offset} and exists $self->{build}{options}{limit}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $self->{'build'}{'options'}{'offset'} and exists $self->{'build'}{'options'}{'limit'}) { } 1 34 35
elsif (exists $self->{'build'}{'options'}{'offset'}) { } 1 33 34
elsif (exists $self->{'build'}{'options'}{'limit'}) { } 0 33 33
Condition100%3/3
exists $self->{"build"}{"options"}{"offset"} and exists $self->{"build"}{"options"}{"limit"}
!ll&&!rl&&r
3311
MC/DC100%2/2
exists $self->{"build"}{"options"}{"offset"} and exists $self->{"build"}{"options"}{"limit"}
exists $self->{"build"}{"options"}{"offset"} exists $self->{"build"}{"options"}{"limit"}
Truth table100%3/3
A and B
A= exists $self->{"build"}{"options"}{"offset"}B= exists $self->{"build"}{"options"}{"limit"}
ABresult
0X0
100
111
4175 1 my $limit = delete $self->{build}{options}{limit};
4176 1 my $offset = delete $self->{build}{options}{offset};
4177 1 my $pattern = pop(@{ $self->{build}{triples} });
4178 1 my $sliced = Attean::Algebra::Slice->new( children => [$pattern], limit => $limit, offset => $offset );
4179 1 push(@{ $self->{build}{triples} }, $sliced);
4180 } elsif (exists $self->{build}{options}{offset}) {
4181 1 my $offset = delete $self->{build}{options}{offset};
4182 1 my $pattern = pop(@{ $self->{build}{triples} });
4183 1 my $sliced = Attean::Algebra::Slice->new( children => [$pattern], offset => $offset );
4184 1 push(@{ $self->{build}{triples} }, $sliced);
4185 } elsif (exists $self->{build}{options}{limit}) {
4186 0 my $limit = delete $self->{build}{options}{limit};
4187 0 my $pattern = pop(@{ $self->{build}{triples} });
4188 0 my $sliced = Attean::Algebra::Slice->new( children => [$pattern], limit => $limit );
4189 0 push(@{ $self->{build}{triples} }, $sliced);
4190 }
4191
4192 35 return @project;
4193 }
4194  
4195 ################################################################################
4196  
4197 =item C<< error >>
4198  
4199 Returns the error encountered during the last parse.
4200  
4201 =cut
4202  
4203 190 ▶sub _add_patterns {
Subroutine _add_patterns: called CC=1 SCAR=0.0
4204 190 my $self = shift;
4205 190 my @triples = @_;
4206 190 my $container = $self->{ _pattern_container_stack }[0];
4207 190 push( @{ $container }, @triples );
4208 }
4209  
4210 17 ▶sub _remove_pattern {
Subroutine _remove_pattern: called CC=1 SCAR=0.0
4211 17 my $self = shift;
4212 17 my $container = $self->{ _pattern_container_stack }[0];
4213 17 my $pattern = pop( @{ $container } );
4214 17 return $pattern;
4215 }
4216  
4217 38 ▶sub _peek_pattern {
Subroutine _peek_pattern: called CC=1 SCAR=0.0
4218 38 my $self = shift;
4219 38 my $container = $self->{ _pattern_container_stack }[0];
4220 38 my $pattern = $container->[-1];
4221 38 return $pattern;
4222 }
4223  
4224 1 ▶sub _add_hint {
Subroutine _add_hint: called CC=1 SCAR=0.0
4225 1 my $self = shift;
4226 1 my $hints = shift;
4227 1 push( @{ $self->{ _pattern_container_hints_stack }[0] }, $hints );
4228 }
4229  
4230 171 ▶sub _push_pattern_container {
Subroutine _push_pattern_container: called CC=1 SCAR=0.0
4231 171 my $self = shift;
4232 171 my $cont = [];
4233 171 unshift( @{ $self->{ _pattern_container_stack } }, $cont );
4234 171 unshift( @{ $self->{ _pattern_container_hints_stack } }, [] );
4235 171 return $cont;
4236 }
4237  
4238 120 ▶sub _pop_pattern_container {
Subroutine _pop_pattern_container: called CC=1 SCAR=0.0
4239 120 my $self = shift;
4240 120 my $hints = shift( @{ $self->{ _pattern_container_hints_stack } } );
4241 120 my $cont = shift( @{ $self->{ _pattern_container_stack } } );
4242 120 return ($cont, $hints);
4243 }
4244  
4245 485 ▶sub _add_stack {
Subroutine _add_stack: called CC=1 SCAR=0.0
4246 485 my $self = shift;
4247 485 my @items = @_;
4248 485 push( @{ $self->{_stack} }, @items );
4249 }
4250  
4251 4 ▶sub _add_filter {
Subroutine _add_filter: called CC=1 SCAR=0.0
4252 4 my $self = shift;
4253 4 my @filters = shift;
4254 4 push( @{ $self->{filters} }, @filters );
4255 }
4256  
4257 94 ▶sub __base {
Subroutine __base: called CC=3 SCAR=11.2
4258 94 my $self = shift;
4259 94 my $build = $self->{build};
4260 94 ▶ if (blessed($build->{base})) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($build->{'base'})) { } 4 90 94
elsif (defined $build->{'base'}) { } 0 90 90
4261 4 return $build->{base};
4262 } elsif (defined($build->{base})) {
4263 0 return $self->new_iri($build->{base});
4264 } else {
4265 90 return;
4266 }
4267 }
4268  
4269 80 ▶sub __new_statement {
Subroutine __new_statement: called CC=7 SCAR=27.1
4270 80 my $self = shift;
4271 80 my $s = shift;
4272 80 my $p = shift;
4273 80 my $o = shift;
4274 80 my $annot;
4275 80 ▶ if ($o->isa('AtteanX::Parser::SPARQL::ObjectWrapper')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->isa("AtteanX::Parser::SPARQL::ObjectWrapper")) 0 80 80
4276 0 ▶ if (reftype($p) eq 'ARRAY' and $p->[0] eq 'PATH') {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($p) eq "ARRAY" and $p->[0] eq "PATH") 0 0 0
Condition0%0/3
builtin::reftype($p) eq "ARRAY" and $p->[0] eq "PATH"
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::reftype($p) eq "ARRAY" and $p->[0] eq "PATH"
builtin::reftype($p) eq "ARRAY" $p->[0] eq "PATH"
Truth table0%0/3
A and B
A= builtin::reftype($p) eq "ARRAY"B= $p->[0] eq "PATH"
ABresult
0X0
100
111
4277 # this is actually a property path, for which annotations (stored in the ObjectWrapper) are forbidden
4278 0 croak "Syntax error: Cannot use SPARQL-star annotation syntax on a property path";
4279 }
4280 0 $annot = $o->annotations;
4281 0 $o = $o->value;
4282 }
4283 80 my $t = Attean::TriplePattern->new($s, $p, $o);
4284 80 ▶ if ($self->{__require_ground_triple_terms}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__require_ground_triple_terms"}) 0 80 80
4285 0 $t = $t->ground();
4286 }
4287 80 my @st = ($t);
4288 80 ▶ if ($annot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($annot) 0 80 80
4289 0 $s = $t;
4290 0 foreach my $pair (@$annot) {
4291 0 my ($p, $o) = @$pair;
4292 0 push(@st, $self->__new_statement($s, $p, $o));
4293 }
4294 }
4295
4296 80 return @st;
4297 }
4298  
4299 1 ▶sub __new_path {
Subroutine __new_path: called CC=1 SCAR=0.0
4300 1 my $self = shift;
4301 1 my $start = shift;
4302 1 my $pdata = shift;
4303 1 my $end = shift;
4304 1 (undef, my $op, my @nodes) = @$pdata;
4305 1 my $path = $self->__new_path_pred($op, @nodes);
4306 1 return Attean::Algebra::Path->new( subject => $start, path => $path, object => $end );
4307 }
4308  
4309 2 ▶sub __new_path_pred {
Subroutine __new_path_pred: called CC=16 SCAR=41.7
4310 2 my $self = shift;
4311 2 my $op = shift;
4312 2 my @nodes = @_;
4313  
4314 2 ▶ if ($op eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq "!") 0 2 2
4315 0 my @preds;
4316 my @reversed;
4317 0 foreach my $p (@nodes) {
4318 0 ▶ if (blessed($p)) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($p)) { } 0 0 0
elsif (builtin::reftype($p) eq 'ARRAY' and $p->[1] eq '^' and builtin::blessed($p->[2])) { } 0 0 0
4319 0 push(@preds, $p);
4320 ▶ } elsif (reftype($p) eq 'ARRAY' and $p->[1] eq '^' and blessed($p->[2])) {
Condition0%0/6
builtin::reftype($p) eq "ARRAY" and $p->[1] eq "^" and builtin::blessed($p->[2])
!ll&&!rl&&r
000
builtin::reftype($p) eq "ARRAY" and $p->[1] eq "^"
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::reftype($p) eq "ARRAY" and $p->[1] eq "^" and builtin::blessed($p->[2])
builtin::reftype($p) eq "ARRAY" $p->[1] eq "^" builtin::blessed($p->[2])
Truth table0%0/4
A and B and C
A= builtin::reftype($p) eq "ARRAY"B= $p->[1] eq "^"C= builtin::blessed($p->[2])
ABCresult
0XX0
10X0
1100
1111
4321 0 push(@reversed, $p->[2]);
4322 } else {
4323 0 die "Unexpected NPS element: " . Dumper($p);
4324 }
4325 }
4326 0 return Attean::Algebra::NegatedPropertySet->new( predicates => \@preds, reversed => \@reversed );
4327 }
4328
4329 2 foreach my $i (0 .. $#nodes) {
4330 3 ▶ if (ref($nodes[$i]) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $nodes[$i] eq 'ARRAY') { } 1 2 3
elsif ($nodes[$i]->does('Attean::API::IRI')) { } 2 0 2
4331 1 (undef, my @data) = @{ $nodes[$i] };
4332 1 $nodes[$i] = $self->__new_path_pred(@data);
4333 } elsif ($nodes[$i]->does('Attean::API::IRI')) {
4334 2 $nodes[$i] = Attean::Algebra::PredicatePath->new( predicate => $nodes[$i] );
4335 }
4336 }
4337
4338 2 ▶ if ($op eq '*') {
Branch: 6 branches
BranchTrueFalseTotal
if ($op eq '*') { } 1 1 2
elsif ($op eq '+') { } 0 1 1
elsif ($op eq '?') { } 0 1 1
elsif ($op eq '^') { } 0 1 1
elsif ($op eq '/') { } 1 0 1
elsif ($op eq '|') { } 0 0 0
4339 1 return Attean::Algebra::ZeroOrMorePath->new( children => [@nodes] );
4340 } elsif ($op eq '+') {
4341 0 return Attean::Algebra::OneOrMorePath->new( children => [@nodes] );
4342 } elsif ($op eq '?') {
4343 0 return Attean::Algebra::ZeroOrOnePath->new( children => [@nodes] );
4344 } elsif ($op eq '^') {
4345 0 return Attean::Algebra::InversePath->new( children => [@nodes] );
4346 } elsif ($op eq '/') {
4347 1 return Attean::Algebra::SequencePath->new( children => [@nodes] );
4348 } elsif ($op eq '|') {
4349 0 return Attean::Algebra::AlternativePath->new( children => [@nodes] );
4350 } else {
4351 0 $self->log->debug("Path $op:\n". Dumper(\@nodes));
4352 0 confess "Error in path $op. See debug log for details."
4353 }
4354 }
4355  
4356 51 ▶sub __new_bgp {
Subroutine __new_bgp: called CC=10 SCAR=24.9
4357 # fix up BGPs that might actually have property paths in them. split those
4358 # out as their own path algebra objects, and join them with the bgp with a
4359 # ggp if necessary
4360 51 my $self = shift;
4361 51 my @patterns = @_;
4362 51 ▶ my @paths = grep { reftype($_->predicate) eq 'ARRAY' and $_->predicate->[0] eq 'PATH' } @patterns;
Condition66%2/3
builtin::reftype($_->predicate) eq 'ARRAY' && $_->predicate->[0] eq 'PATH'
!ll&&!rl&&r
6601
MC/DC50%1/2
builtin::reftype($_->predicate) eq 'ARRAY' && $_->predicate->[0] eq 'PATH'
builtin::reftype($_->predicate) eq 'ARRAY' $_->predicate->[0] eq 'PATH'
Truth table66%2/3
A && B
A= builtin::reftype($_->predicate) eq 'ARRAY'B= $_->predicate->[0] eq 'PATH'
ABresult
0X0
100
111
4363 51 my @triples = grep { blessed($_->predicate) } @patterns;
4364 51 ▶ if ($self->log->is_trace && (scalar(@patterns) > scalar(@paths) + scalar(@triples))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->log->is_trace and scalar @patterns > scalar(@paths) + scalar(@triples)) 0 51 51
Condition33%1/3
$self->log->is_trace and scalar @patterns > scalar(@paths) + scalar(@triples)
!ll&&!rl&&r
5100
MC/DC0%0/2
$self->log->is_trace and scalar @patterns > scalar(@paths) + scalar(@triples)
$self->log->is_trace scalar @patterns > scalar(@paths) + scalar(@triples)
Truth table33%1/3
A and B
A= $self->log->is_traceB= scalar @patterns > scalar(@paths) + scalar(@triples)
ABresult
0X0
100
111
4365 0 $self->log->warn('More than just triples and paths passed to __new_bgp');
4366 0 $self->log->trace("Arguments to __new_bgp:\n" .Dumper(\@patterns));
4367 }
4368
4369 51 foreach my $t (@triples) {
4370 66 ▶ Carp::cluck Dumper($t) unless (blessed($t) and $t->can('does'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($t) and $t->can("does") 0 66 66
Condition33%1/3
builtin::blessed($t) and $t->can("does")
!ll&&!rl&&r
0066
MC/DC0%0/2
builtin::blessed($t) and $t->can("does")
builtin::blessed($t) $t->can("does")
Truth table33%1/3
A and B
A= builtin::blessed($t)B= $t->can("does")
ABresult
0X0
100
111
4371 }
4372
4373 51 my $bgp = Attean::Algebra::BGP->new( triples => \@triples );
4374 51 ▶ if (@paths) {
Branch: 1 branch
BranchTrueFalseTotal
if (@paths) { } 1 50 51
4375 1 my @p;
4376 1 foreach my $p (@paths) {
4377 1 my $start = $p->subject;
4378 1 my $end = $p->object;
4379 1 my $pdata = $p->predicate;
4380 1 push(@p, $self->__new_path( $start, $pdata, $end ));
4381 }
4382 1 ▶ if (scalar(@triples)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @triples) { } 0 1 1
4383 0 return $self->_new_join($bgp, @p);
4384 } else {
4385 1 return $self->_new_join(@p);
4386 }
4387 } else {
4388 50 return $bgp;
4389 }
4390 }
4391  
4392 =item C<new_binary_expression ( $operator, @operands )>
4393  
4394 Returns a new binary expression structure.
4395  
4396 =cut
4397  
4398 4 ▶sub new_binary_expression {
Subroutine new_binary_expression: called CC=1 SCAR=0.0
Pod documented
4399 4 my $self = shift;
4400 4 my $op = shift;
4401 4 my @operands = @_[0,1];
4402 4 return Attean::BinaryExpression->new( operator => $op, children => \@operands );
4403 }
4404  
4405 =item C<new_function_expression ( $function, @operands )>
4406  
4407 Returns a new function expression structure.
4408  
4409 =cut
4410  
4411 3 ▶sub new_function_expression {
Subroutine new_function_expression: called CC=2 SCAR=7.0
Pod documented
4412 3 my $self = shift;
4413 3 my $function = shift;
4414 3 my @operands = @_;
4415 3 my $base = $self->__base;
4416 3 ▶ return Attean::FunctionExpression->new( operator => $function, children => \@operands, $base ? (base => $base) : () );
Branch: 1 branch
BranchTrueFalseTotal
$base ? : 0 3 3
4417 }
4418  
4419 59 ▶sub _new_join {
Subroutine _new_join: called CC=3 SCAR=11.0
4420 59 my $self = shift;
4421 59 my @parts = @_;
4422 59 ▶ if (0 == scalar(@parts)) {
Branch: 2 branches
BranchTrueFalseTotal
if (0 == scalar @parts) { } 3 56 59
elsif (1 == scalar @parts) { } 55 1 56
4423 3 return Attean::Algebra::BGP->new();
4424 } elsif (1 == scalar(@parts)) {
4425 55 return shift(@parts);
4426 } else {
4427 1 return Attean::Algebra::Join->new( children => \@parts );
4428 }
4429 }
4430  
4431 5814 ▶sub _peek_token {
Subroutine _peek_token: called CC=4 SCAR=15.5
4432 5814 my $self = shift;
4433 5814 my $l = $self->lexer;
4434 5814 my $t = $l->peek;
4435 5813 ▶ return unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 279 5534 5813
4436 5534 ▶ while ($t == COMMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t == 7) 0 5534 5534
4437 0 $t = $l->peek;
4438 0 ▶ return unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 0 0
4439 }
4440 5534 return $t;
4441 }
4442  
4443 5637 ▶sub _test_token {
Subroutine _test_token: called CC=7 SCAR=19.5
4444 5637 my $self = shift;
4445 5637 my $type = shift;
4446 5637 my $t = $self->_peek_token;
4447 5636 ▶ return unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 227 5409 5636
4448 5409 ▶ return if ($t->type != $type);
Branch: 1 branch
BranchTrueFalseTotal
if $t->type != $type 3751 1658 5409
4449 1658 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 677 981 1658
4450 677 my $value = shift;
4451 677 ▶ if (ref($value) eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'Regexp') { } 32 645 677
4452 32 ▶ return unless ($t->value =~ $value);
Branch: 1 branch
BranchTrueFalseTotal
unless $t->value =~ /$value/u 16 16 32
4453 } else {
4454 645 ▶ return unless ($t->value eq $value);
Branch: 1 branch
BranchTrueFalseTotal
unless $t->value eq $value 429 216 645
4455 }
4456 }
4457 1213 return 1;
4458 }
4459  
4460 906 ▶sub _optional_token {
Subroutine _optional_token: called CC=2 SCAR=6.9
4461 906 my $self = shift;
4462 906 ▶ if ($self->_test_token(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token(@_)) 229 677 906
4463 229 return $self->_next_token;
4464 }
4465 677 return;
4466 }
4467  
4468 721 ▶sub _next_token {
Subroutine _next_token: called CC=3 SCAR=13.5
4469 721 my $self = shift;
4470 721 my $l = $self->lexer;
4471 721 my $t = $l->next;
4472 721 ▶ while ($t->type == COMMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 7) 0 721 721
4473 0 $t = $l->peek;
4474 0 ▶ return unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 0 0
4475 }
4476 721 return $t;
4477 }
4478  
4479 487 ▶sub _expected_token {
Subroutine _expected_token: called CC=5 SCAR=17.1
4480 487 my $self = shift;
4481 487 my $type = shift;
4482 487 ▶ if ($self->_test_token($type, @_)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test_token($type, @_)) { } 486 1 487
4483 486 return $self->_next_token;
4484 } else {
4485 1 my $t = $self->_peek_token;
4486 1 my $expecting = AtteanX::SPARQL::Constants::decrypt_constant($type);
4487 1 ▶ my $got = blessed($t) ? AtteanX::SPARQL::Constants::decrypt_constant($t->type) : '(undef)';
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($t) ? : 0 1 1
4488 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 0 1
4489 1 my $value = shift;
4490 1 ▶ if ($t) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t) { } 0 1 1
4491 0 my $value2 = $t->value;
4492 0 confess "Expecting $expecting '$value' but got $got '$value2' before " . $self->lexer->buffer;
4493 } else {
4494 1 confess "Expecting $expecting '$value' but found EOF";
4495 }
4496 } else {
4497 0 confess "Expecting $expecting but found $got before " . $self->lexer->buffer;
4498 }
4499 }
4500 }
4501  
4502 1 ▶sub _token_error {
Subroutine _token_error: called CC=5 SCAR=20.0
4503 1 my $self = shift;
4504 1 my $t = shift;
4505 1 my $note = shift;
4506 1 ▶ my $got = blessed($t) ? AtteanX::SPARQL::Constants::decrypt_constant($t->type) : '(undef)';
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($t) ? : 1 0 1
4507 1 my $message = "$note but got $got";
4508 1 ▶ if ($t and $t->start_line > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t and $t->start_line > 0) { } 1 0 1
Condition33%1/3
$t and $t->start_line > 0
!ll&&!rl&&r
001
MC/DC0%0/2
$t and $t->start_line > 0
$t $t->start_line > 0
Truth table33%1/3
A and B
A= $tB= $t->start_line > 0
ABresult
0X0
100
111
4509 1 my $l = $t->start_line;
4510 1 my $c = $t->start_column;
4511 1 $message .= " at $l:$c";
4512 } else {
4513 0 my $n = $self->lexer->buffer;
4514 0 $n =~ s/\s+/ /g;
4515 0 $n =~ s/\s*$//;
4516 0 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
4517 0 $message .= " near '$n'";
4518 }
4519 }
4520 1 croak $message;
4521 }
4522  
4523 package AtteanX::Parser::SPARQL::ObjectWrapper 0.040;
4524  
4525 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4526 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4527 12 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
4528 12 ▶use Types::Standard qw(InstanceOf HashRef ArrayRef Bool Str Int);
Subroutine BEGIN: called CC=1 SCAR=0.0
4529  
4530 12 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4531 12 has 'value' => (is => 'rw');
4532 12 has 'annotations' => (is => 'rw', isa => ArrayRef);
4533  
4534  
4535 12 1;
4536  
4537 __END__
« AtteanX/Parser/Trig.pm ↑ Summary AtteanX/Serializer/SPARQL.pm »