AtteanX/Parser/Turtle.pm

filter: Statementstmt 62.3% 308 / 494 Branchbran 44.1% 91 / 206 Conditioncond 37.2% 57 / 153 MC/DCmcdc 5.5% 4 / 72 Subroutinesub 85.4% 41 / 48 Podpod 100% 6 / 6 totaltotal 51.7% 507 / 979 CC 155 SCAR 43.8
CC
155
Cov
53%
_ttObject
506.0
_statement
60.0
_object
55.8
CRAP 79.9
« Attean/API/Term.pm ↑ Summary AtteanX/Parser/Trig.pm »
1 50 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 # AtteanX::Parser::Turtle
5 # -----------------------------------------------------------------------------
6  
7 =head1 NAME
8  
9 AtteanX::Parser::Turtle - Turtle RDF Parser
10  
11 =head1 VERSION
12  
13 This document describes AtteanX::Parser::Turtle version 0.040
14  
15 =head1 SYNOPSIS
16  
17 use Attean;
18 my $parser = AtteanX::Parser::Turtle->new( handler => sub {...}, base => $base_iri );
19
20 # Parse data from a file-handle and handle triples in the 'handler' callback
21 $parser->parse_cb_from_io( $fh );
22
23 # Parse the given byte-string, and return an iterator of triples
24 my $iter = $parser->parse_iter_from_bytes('<s> <p> 1, 2, 3 .');
25 while (my $triple = $iter->next) {
26 print $triple->as_string;
27 }
28  
29 =head1 DESCRIPTION
30  
31 This module implements a parser for the Turtle RDF format.
32  
33 =head1 ROLES
34  
35 This class consumes L<Attean::API::Parser>, L<Attean::API::PushParser>,
36 <Attean::API::AbbreviatingParser>, and <Attean::API::TripleParser>.
37  
38 =head1 ATTRIBUTES
39  
40 =over 4
41  
42 =item C<< canonical_media_type >>
43  
44 =item C<< media_types >>
45  
46 =item C<< file_extensions >>
47  
48 =item C<< canonicalize >>
49  
50 A boolean indicating whether term values should be canonicalized during parsing.
51  
52 =item C<< blank_nodes >>
53  
54 =item C<< has_blank_nodes_map >>
55  
56 =back
57  
58 =head1 METHODS
59  
60 =over 4
61  
62 =cut
63  
64 50 package AtteanX::Parser::Turtle 0.040 {
65 50 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 50 ▶ use Types::Standard qw(Bool HashRef ArrayRef HashRef Str Maybe InstanceOf ConsumerOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
67 50 ▶ use Types::Namespace qw( NamespaceMap );
Subroutine BEGIN: called CC=1 SCAR=0.0
68 50 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 50 ▶ use Carp qw(carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
70 50 ▶ use Encode qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
71 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
72 50 ▶ use AtteanX::Parser::Turtle::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 50 ▶ use AtteanX::Parser::Turtle::Lexer;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 50 ▶ use AtteanX::Parser::Turtle::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 50 ▶ use Attean::API::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 50 ▶ use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 1 ▶ sub canonical_media_type { return "text/turtle" }
Subroutine canonical_media_type: called CC=1 SCAR=0.0
Pod documented
79  
80 3 ▶ sub media_types {
Subroutine media_types: called CC=1 SCAR=0.0
Pod documented
81 3 return [qw(application/x-turtle application/turtle text/turtle)];
82 }
83  
84 2 ▶ sub file_extensions { return [qw(ttl)] }
Subroutine file_extensions: called CC=1 SCAR=0.0
Pod documented
85  
86 50 has 'version' => (is => 'rw', isa => Str, default => '');
87 50 has 'canonicalize' => (is => 'rw', isa => Bool, default => 0);
88 34 ▶ has '_map' => (is => 'ro', isa => HashRef[Str], default => sub { +{} });
Subroutine __ANON__: called CC=1 SCAR=0.0
89  
90 =item C<< has_namespaces >>
91  
92 Returns true if the parser has a namespace map, false otherwise.
93  
94 =cut
95  
96 50 has 'namespaces' => (is => 'rw', isa => Maybe[NamespaceMap], predicate => 'has_namespaces');
97 34 ▶ 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
98 has '_stack' => (
99 is => 'ro',
100 isa => ArrayRef,
101 34 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
102 50 init_arg => undef,
103 );
104
105 50 with 'Attean::API::TripleParser';
106 50 with 'Attean::API::AbbreviatingParser';
107 50 with 'Attean::API::PushParser';
108 50 with 'Attean::API::CDTBlankNodeMappingParser';
109
110 50 my $RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
111 50 my $XSD = 'http://www.w3.org/2001/XMLSchema#';
112  
113 =item C<< parse_cb_from_io( $fh ) >>
114  
115 Calls the C<< $parser->handler >> function once for each
116 L<Attean::API::Binding> object that result from parsing
117 the data read from the L<IO::Handle> object C<< $fh >>.
118  
119 =cut
120  
121 sub parse_cb_from_io {
122 0 my $self = shift;
123 2 my $fh = shift;
124  
125 2 ▶ unless (ref($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fh) 0 2 2
126 my $filename = $fh;
127 undef $fh;
128 ▶ open( $fh, '<', $filename ) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $filename or die $! 0 0 0
129 }
130
131 my $l = AtteanX::Parser::Turtle::Lexer->new($fh);
132 $self->_parse($l);
133 }
134  
135 =item C<< parse_cb_from_bytes( $data ) >>
136  
137 Calls the C<< $parser->handler >> function once for each
138 L<Attean::API::Binding> object that result from parsing
139 the data read from the UTF-8 encoded byte string C<< $data >>.
140  
141 =cut
142  
143 30 ▶ sub parse_cb_from_bytes {
Subroutine parse_cb_from_bytes: called CC=1 SCAR=0.0
Pod documented
144 30 my $self = shift;
145 30 my $data = shift;
146  
147 30 open(my $fh, '<:encoding(UTF-8)', \$data);
148 28 my $l = AtteanX::Parser::Turtle::Lexer->new($fh);
149 28 $self->_parse($l);
150 }
151  
152 =item C<< parse_term_from_bytes ( $bytes ) >>
153  
154 =item C<< parse_node ( $bytes ) >>
155  
156 Returns the Attean::API::Term object corresponding to the node whose N-Triples
157 serialization is found at the beginning of C<< $bytes >>.
158  
159 =cut
160  
161 12 ▶ sub parse_term_from_bytes {
Subroutine parse_term_from_bytes: called CC=2 SCAR=7.6
Pod documented
162 12 my $self = shift;
163 12 ▶ unless (ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 0 12 12
164 0 $self = $self->new();
165 }
166 12 return $self->parse_node(@_);
167 }
168
169 12 ▶ sub parse_node {
Subroutine parse_node: called CC=1 SCAR=0.0
Pod documented
170 12 my $self = shift;
171 12 my $string = shift;
172 12 my %args = @_;
173
174 12 open(my $fh, '<:encoding(UTF-8)', \$string);
175 12 my $l = AtteanX::Parser::Turtle::Lexer->new(file => $fh, %args);
176 12 my $t = $self->_next_nonws($l);
177 12 my $node = $self->_object($l, $t);
178 12 return $node;
179 }
180  
181 30 ▶ sub _parse {
Subroutine _parse: called CC=1 SCAR=0.0
182 30 my $self = shift;
183 30 my $l = shift;
184 30 $self->version(''); # reset the version for a new parse
185 30 $l->check_for_bom;
186 30 $self->_turtleDoc($l);
187 30 $self->version(''); # clear any version specifier found during parsing
188 }
189
190 ################################################################################
191  
192 240 ▶ sub _unget_token {
Subroutine _unget_token: called CC=1 SCAR=0.0
193 240 my $self = shift;
194 240 my $t = shift;
195 240 push(@{ $self->_stack }, $t);
196 # push(@{ $self->{ stack } }, $t);
197 }
198  
199 86 ▶ sub _peek_nonws {
Subroutine _peek_nonws: called CC=1 SCAR=0.0
200 86 my $self = shift;
201 86 my $l = shift;
202 86 my $t = $self->_next_nonws($l);
203 86 $self->_unget_token($t);
204 86 return $t;
205 }
206
207 716 ▶ sub _next_nonws {
Subroutine _next_nonws: called CC=3 SCAR=11.0
208 716 my $self = shift;
209 716 ▶ if (scalar(@{ $self->_stack })) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->_stack;}) 240 476 716
210 240 return pop(@{ $self->_stack });
211 }
212 476 my $l = shift;
213 476 while (1) {
214 476 my $t = $l->get_token;
215 476 ▶ return unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 31 445 476
216 # my $type = $t->type;
217 # next if ($type == WS or $type == COMMENT);
218 # warn decrypt_constant($type) . "\n";
219 445 return $t;
220 }
221 }
222  
223 145 ▶ sub _get_token_type {
Subroutine _get_token_type: called CC=3 SCAR=12.3
224 145 my $self = shift;
225 145 my $l = shift;
226 145 my $type = shift;
227 145 my $t = $self->_next_nonws($l);
228 145 ▶ unless ($t) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($t) 0 145 145
229 0 $l->_throw_error(sprintf("Expecting %s but got EOF", decrypt_constant($type)));
230 0 return;
231 }
232 145 ▶ unless ($t->type eq $type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($t->type eq $type) 0 145 145
233 0 $self->_throw_error(sprintf("Expecting %s but got %s", decrypt_constant($type), decrypt_constant($t->type)), $t, $l);
234 }
235 145 return $t;
236 }
237  
238 ## Methods based on grammar productions:
239
240 30 ▶ sub _turtleDoc {
Subroutine _turtleDoc: called CC=2 SCAR=6.9
241 30 my $self = shift;
242 30 my $l = shift;
243 30 ▶ while (my $t = $self->_next_nonws($l)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = $self->_next_nonws($l)) 80 30 110
244 80 $self->_statement($l, $t);
245 }
246 }
247  
248 80 ▶ sub _statement {
Subroutine _statement: called CC=18 SCAR=40.9
249 80 my $self = shift;
250 80 my $l = shift;
251 80 my $t = shift;
252 80 my $type = $t->type;
253 # when (WS) {}
254 80 ▶ if ($type == TURTLEPREFIX or $type == PREFIX) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type == 31 or $type == 20) { } 31 49 80
elsif ($type == 30 or $type == 3) { } 0 49 49
elsif ($type == 32 or $type == 40) { } 0 49 49
Condition66%2/3
$type == 31 or $type == 20
l!l&&r!l&&!r
31049
MC/DC50%1/2
$type == 31 or $type == 20
$type == 31 $type == 20
Truth table66%2/3
A or B
A= $type == 31B= $type == 20
ABresult
1X1
011
000
255 31 $t = $self->_get_token_type($l, PREFIXNAME);
256 50 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
257 31 ▶ unless (defined($t->value)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t->value) 0 31 31
258 0 my $tname = AtteanX::Parser::Turtle::Constants::decrypt_constant($t->type);
259 0 Carp::confess "undefined $tname token value: " . Dumper($t);
260 }
261 31 my $name = $t->value;
262 31 ▶ chop($name) if (substr($name, -1) eq ':');
Branch: 1 branch
BranchTrueFalseTotal
if substr($name, -1) eq ":" 31 0 31
263 # $name =~ s/:$//;
264 31 $t = $self->_get_token_type($l, IRI);
265 31 my %args = (value => $t->value);
266 31 ▶ if ($self->has_base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_base) 0 31 31
267 0 $args{base} = $self->base;
268 }
269 31 my $r = $self->new_iri(%args);
270 31 my $iri = $r->as_string;
271 31 ▶ if ($type == TURTLEPREFIX) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 31) 31 0 31
272 31 $t = $self->_get_token_type($l, DOT);
273 # $t = $self->_next_nonws($l);
274 # if ($t and $t->type != DOT) {
275 # $self->_unget_token($t);
276 # }
277 }
278 31 $self->_map->{$name} = $iri;
279 31 ▶ if ($self->has_namespaces) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_namespaces) 6 25 31
280 6 my $ns = $self->namespaces;
281 6 ▶ unless ($ns->namespace_uri($name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ns->namespace_uri($name)) 6 0 6
282 6 $ns->add_mapping($name, $iri);
283 }
284 }
285 }
286 ▶ elsif ($type == TURTLEBASE or $type == BASE) {
Condition33%1/3
$type == 30 or $type == 3
l!l&&r!l&&!r
0049
MC/DC0%0/2
$type == 30 or $type == 3
$type == 30 $type == 3
Truth table33%1/3
A or B
A= $type == 30B= $type == 3
ABresult
1X1
011
000
287 0 $t = $self->_get_token_type($l, IRI);
288 0 my %args = (value => $t->value);
289 0 ▶ if ($self->has_base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_base) 0 0 0
290 0 $args{base} = $self->base;
291 }
292 0 my $r = $self->new_iri(%args);
293 0 my $iri = $r->as_string;
294 0 ▶ if ($type == TURTLEBASE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 30) 0 0 0
295 0 $t = $self->_get_token_type($l, DOT);
296 # $t = $self->_next_nonws($l);
297 # if ($t and $t->type != DOT) {
298 # $self->_unget_token($t);
299 # }
300 }
301 0 $self->base($iri);
302 }
303 ▶ elsif ($type == TURTLEVERSION or $type == VERSION) {
Condition33%1/3
$type == 32 or $type == 40
l!l&&r!l&&!r
0049
MC/DC0%0/2
$type == 32 or $type == 40
$type == 32 $type == 40
Truth table33%1/3
A or B
A= $type == 32B= $type == 40
ABresult
1X1
011
000
304 0 my $vt = $self->_peek_nonws($l);
305 0 ▶ unless ($vt->type == STRING1D or $vt->type == STRING1S) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vt->type == 26 or $vt->type == 27) 0 0 0
Condition0%0/3
$vt->type == 26 or $vt->type == 27
l!l&&r!l&&!r
000
MC/DC0%0/2
$vt->type == 26 or $vt->type == 27
$vt->type == 26 $vt->type == 27
Truth table0%0/3
A or B
A= $vt->type == 26B= $vt->type == 27
ABresult
1X1
011
000
306 0 $self->_throw_error("Unexpected version specifier: " . decrypt_constant($type), $vt, $l);
307 }
308 0 $self->_next_nonws($l);
309 0 ▶ if ($type == TURTLEVERSION) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 32) 0 0 0
310 0 $t = $self->_get_token_type($l, DOT);
311 # $t = $self->_next_nonws($l);
312 # if ($t and $t->type != DOT) {
313 # $self->_unget_token($t);
314 # }
315 }
316 0 $self->version($vt->value);
317 }
318 else {
319 49 $self->_triples( $l, $t );
320 49 $t = $self->_get_token_type($l, DOT);
321 }
322 # }
323 }
324  
325 49 ▶ sub _subject {
Subroutine _subject: called CC=14 SCAR=37.4
326 49 my $self = shift;
327 49 my $l = shift;
328 49 my $t = shift;
329 49 my $bnode_plist_ref = shift;
330 49 my $reified_subj_ref = shift;
331 49 my $type = $t->type;
332 49 my $subj;
333 49 my $bnode_plist = 0;
334 49 my $reified_subj = 0;
335 49 ▶ if ($type == LTLT) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type == 35) { } 0 49 49
elsif ($type == 17) { } 0 49 49
elsif ($type == 18) { } 0 49 49
elsif (not $type == 14 || $type == 21 || $type == 4 || $type == 2) { } 0 49 49
336 0 $subj = $self->_reifiedTriple($l);
337 0 $reified_subj++;
338 } elsif ($type == LBRACKET) {
339 0 $bnode_plist = 1;
340 0 $subj = Attean::Blank->new();
341 0 my $t = $self->_next_nonws($l);
342 0 ▶ if ($t->type != RBRACKET) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type != 23) 0 0 0
343 0 $self->_unget_token($t);
344 0 $self->_predicateObjectList( $l, $subj );
345 0 $t = $self->_get_token_type($l, RBRACKET);
346 }
347 } elsif ($type == LPAREN) {
348 0 my $t = $self->_next_nonws($l);
349 0 ▶ if ($t->type == RPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 24) { } 0 0 0
350 0 $subj = Attean::IRI->new(value => "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil", lazy => 1);
351 } else {
352 0 $subj = Attean::Blank->new();
353 0 my @objects = $self->_object($l, $t);
354
355 0 while (1) {
356 0 my $t = $self->_next_nonws($l);
357 0 ▶ if ($t->type == RPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 24) { } 0 0 0
358 0 last;
359 } else {
360 0 push(@objects, $self->_object($l, $t));
361 }
362 }
363 0 $self->_assert_list($subj, @objects);
364 }
365 ▶ } elsif (not($type==IRI or $type==PREFIXNAME or $type==BNODE or $type==ANON)) {
Condition88%8/9
$type == 14 || $type == 21 || $type == 4 || $type == 2
l!l&&r!l&&!r
4810
$type == 14 or $type == 21 or $type == 4
l!l&&r!l&&!r
34141
$type == 14 or $type == 21
l!l&&r!l&&!r
191515
MC/DC0%0/4
$type == 14 || $type == 21 || $type == 4 || $type == 2
$type == 14 $type == 21 $type == 4 $type == 2
Truth table80%4/5
A or B or C || D
A= $type == 14B= $type == 21C= $type == 4D= $type == 2
ABCDresult
1XXX1
01XX1
001X1
00011
00000
366 0 $self->_throw_error("Expecting resource or bnode but got " . decrypt_constant($type), $t, $l);
367 } else {
368 49 $subj = $self->_token_to_node($t);
369 }
370 49 ▶ die 'unexpected undef subject' unless defined($subj);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subj 0 49 49
371 49 ▶ if (ref($bnode_plist_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $bnode_plist_ref) 49 0 49
372 49 $$bnode_plist_ref = $bnode_plist;
373 }
374 49 ▶ if (ref($reified_subj_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $reified_subj_ref) 49 0 49
375 49 $$reified_subj_ref = $reified_subj;
376 }
377 49 return $subj;
378 }
379
380 0 ▶ sub _ttSubject {
Subroutine _ttSubject: not called CC=5 SCAR=34.0
381 0 my $self = shift;
382 0 my $l = shift;
383 0 my $t = shift;
384 0 my $type = $t->type;
385 0 my $subj;
386 0 my $bnode_plist = 0;
387 0 ▶ if (not($type==IRI or $type==PREFIXNAME or $type==BNODE or $type==ANON)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $type == 14 || $type == 21 || $type == 4 || $type == 2) { } 0 0 0
Condition0%0/9
$type == 14 || $type == 21 || $type == 4 || $type == 2
l!l&&r!l&&!r
000
$type == 14 or $type == 21 or $type == 4
l!l&&r!l&&!r
000
$type == 14 or $type == 21
l!l&&r!l&&!r
000
MC/DC0%0/4
$type == 14 || $type == 21 || $type == 4 || $type == 2
$type == 14 $type == 21 $type == 4 $type == 2
Truth table0%0/5
A or B or C || D
A= $type == 14B= $type == 21C= $type == 4D= $type == 2
ABCDresult
1XXX1
01XX1
001X1
00011
00000
388 0 $self->_throw_error("Expecting resource or bnode but got " . decrypt_constant($type), $t, $l);
389 } else {
390 0 $subj = $self->_token_to_node($t);
391 }
392 0 return $subj;
393 }
394
395 49 ▶ sub _triples {
Subroutine _triples: called CC=5 SCAR=20.0
396 49 my $self = shift;
397 49 my $l = shift;
398 49 my $t = shift;
399 49 my $type = $t->type;
400 # subject
401 49 my $reified_subj = 0;
402 49 my $bnode_plist = 0;
403 49 my $subj = $self->_subject($l, $t, \$bnode_plist, \$reified_subj);
404 # warn "Subject: $subj\n"; # XXX
405
406 49 ▶ if ($bnode_plist or $reified_subj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bnode_plist or $reified_subj) { } 0 49 49
Condition33%1/3
$bnode_plist or $reified_subj
l!l&&r!l&&!r
0049
MC/DC0%0/2
$bnode_plist or $reified_subj
$bnode_plist $reified_subj
Truth table33%1/3
A or B
A= $bnode_plistB= $reified_subj
ABresult
1X1
011
000
407 #predicateObjectList?
408 0 $t = $self->_next_nonws($l);
409 0 $self->_unget_token($t);
410 0 ▶ unless ($t->type == DOT) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($t->type == 9) 0 0 0
411 0 $self->_predicateObjectList($l, $subj);
412 }
413 } else {
414 #predicateObjectList
415 49 my $count = $self->_predicateObjectList($l, $subj);
416 49 ▶ unless ($count) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($count) 0 49 49
417 0 $self->_throw_error("Expecting predicate-object list, but found none", $t, $l);
418 }
419 }
420 }
421  
422 0 ▶ sub _verb {
Subroutine _verb: not called CC=4 SCAR=30.0
423 0 my $self = shift;
424 0 my $l = shift;
425 0 my $t = $self->_next_nonws($l);
426 0 my $type = $t->type;
427 0 ▶ unless ($type==IRI or $type==PREFIXNAME or $type==A) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type == 14 or $type == 21 or $type == 1) 0 0 0
Condition0%0/6
$type == 14 or $type == 21 or $type == 1
l!l&&r!l&&!r
000
$type == 14 or $type == 21
l!l&&r!l&&!r
000
MC/DC0%0/3
$type == 14 or $type == 21 or $type == 1
$type == 14 $type == 21 $type == 1
Truth table0%0/4
A or B or C
A= $type == 14B= $type == 21C= $type == 1
ABCresult
1XX1
01X1
0011
0000
428 0 $self->_throw_error("Expecting verb but got " . decrypt_constant($type), $t, $l);
429 }
430 0 my $pred = $self->_token_to_node($t);
431 0 return $pred;
432 }
433
434 0 ▶ sub _tripleTerm {
Subroutine _tripleTerm: not called CC=1 SCAR=6.9
435 0 my $self = shift;
436 0 my $l = shift;
437  
438 0 my $t = $self->_next_nonws($l);
439 0 my $subj = $self->_ttSubject($l, $t);
440 0 my $pred = $self->_verb($l);
441 0 my $obj = $self->_ttObject($l, $self->_next_nonws($l));
442 0 $self->_get_token_type($l, PGTGT);
443 0 my $triple = Attean::Triple->new($subj, $pred, $obj);
444 0 return $triple;
445 }
446
447 0 ▶ sub _reifiedTriple {
Subroutine _reifiedTriple: not called CC=5 SCAR=34.0
448 0 my $self = shift;
449 0 my $l = shift;
450  
451 0 my $t = $self->_next_nonws($l);
452 0 my $subj;
453 0 ▶ if ($t->type == LTLT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 35) { } 0 0 0
454 0 $subj = $self->_reifiedTriple($l);
455 } else {
456 0 $subj = $self->_subject($l, $t);
457 }
458
459 0 my $pred = $self->_verb($l);
460
461
462 0 $t = $self->_peek_nonws($l);
463 0 my $obj;
464 0 ▶ if ($t->type == LPAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->type == 18) { } 0 0 0
elsif ($t->type == 17) { } 0 0 0
465 0 $self->_throw_error("Collections cannot appear inside of reified triples", $t, $l);
466 } elsif ($t->type == LBRACKET) {
467 0 $self->_get_token_type($l, LBRACKET);
468 0 $self->_get_token_type($l, RBRACKET);
469 0 $obj = Attean::Blank->new();
470 } else {
471 0 $obj = $self->_object($l, $self->_next_nonws($l));
472 }
473
474 0 $t = $self->_peek_nonws($l);
475 0 ▶ my $reif = ($t->type == TILDE) ? $self->_reifier($l) : Attean::Blank->new();
Branch: 1 branch
BranchTrueFalseTotal
$t->type == 39 ? : 0 0 0
476 0 $self->_get_token_type($l, GTGT);
477 0 my $triple = Attean::Triple->new($subj, $pred, $obj);
478 0 $self->_assert_triple($reif, Attean::IRI->new(value => "${RDF}reifies", lazy => 1), $triple);
479 0 return $reif;
480 }
481
482 0 ▶ sub _reifier {
Subroutine _reifier: not called CC=6 SCAR=37.4
483 0 my $self = shift;
484 0 my $l = shift;
485 0 my $t = $self->_peek_nonws($l);
486 0 ▶ if ($t->type == TILDE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 39) 0 0 0
487 0 $self->_next_nonws($l);
488 0 my $t = $self->_peek_nonws($l);
489 0 my $type = $t->type;
490 0 ▶ if ($type==IRI or $type==PREFIXNAME or $type==BNODE or $type==ANON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 14 or $type == 21 or $type == 4 or $type == 2) 0 0 0
Condition0%0/9
$type == 14 or $type == 21 or $type == 4 or $type == 2
l!l&&r!l&&!r
000
$type == 14 or $type == 21 or $type == 4
l!l&&r!l&&!r
000
$type == 14 or $type == 21
l!l&&r!l&&!r
000
MC/DC0%0/4
$type == 14 or $type == 21 or $type == 4 or $type == 2
$type == 14 $type == 21 $type == 4 $type == 2
Truth table0%0/5
A or B or C or D
A= $type == 14B= $type == 21C= $type == 4D= $type == 2
ABCDresult
1XXX1
01XX1
001X1
00011
00000
491 0 $self->_get_token_type($l, $type);
492 0 return $self->_token_to_node($t);
493 }
494 }
495 0 return Attean::Blank->new();
496 }
497
498 1 ▶ sub _assert_list {
Subroutine _assert_list: called CC=3 SCAR=11.0
499 1 my $self = shift;
500 1 my $subj = shift;
501 1 my @objects = @_;
502 1 my $head = $subj;
503 1 ▶ while (@objects) {
Branch: 1 branch
BranchTrueFalseTotal
if (@objects) 2 1 3
504 2 my $obj = shift(@objects);
505 2 $self->_assert_triple($head, Attean::IRI->new(value => "${RDF}first", lazy => 1), $obj);
506 2 ▶ my $next = scalar(@objects) ? Attean::Blank->new() : Attean::IRI->new(value => "${RDF}nil", lazy => 1);
Branch: 1 branch
BranchTrueFalseTotal
scalar @objects ? : 1 1 2
507 2 $self->_assert_triple($head, Attean::IRI->new(value => "${RDF}rest", lazy => 1), $next);
508 2 $head = $next;
509 }
510 }
511  
512 52 ▶ sub _predicateObjectList {
Subroutine _predicateObjectList: called CC=12 SCAR=28.2
513 52 my $self = shift;
514 52 my $l = shift;
515 52 my $subj = shift;
516 52 my $t = $self->_next_nonws($l);
517 52 my $counter = 0;
518 52 while (1) {
519 81 my $type = $t->type;
520 81 ▶ if ($type==RBRACE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 22) 0 81 81
521 # needed for TriG parsing which shares this codepath
522 0 $self->_unget_token($t);
523 0 return $counter;
524 }
525
526 81 ▶ unless ($type==IRI or $type==PREFIXNAME or $type==A) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type == 14 or $type == 21 or $type == 1) 0 81 81
Condition83%5/6
$type == 14 or $type == 21 or $type == 1
l!l&&r!l&&!r
59220
$type == 14 or $type == 21
l!l&&r!l&&!r
174222
MC/DC0%0/3
$type == 14 or $type == 21 or $type == 1
$type == 14 $type == 21 $type == 1
Truth table75%3/4
A or B or C
A= $type == 14B= $type == 21C= $type == 1
ABCresult
1XX1
01X1
0011
0000
527 0 $self->_throw_error("Expecting verb but got " . decrypt_constant($type), $t, $l);
528 }
529 81 my $pred = $self->_token_to_node($t);
530 81 $self->_objectList($l, $subj, $pred);
531 81 $counter++;
532
533 81 $t = $self->_next_nonws($l);
534 81 ▶ last unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 81 81
535 81 ▶ if ($t->type == SEMICOLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 25) { } 29 52 81
536 29 my $sc = $t;
537 29 SEMICOLON_REPEAT:
538 $t = $self->_next_nonws($l);
539 29 ▶ unless ($t) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($t) 0 29 29
540 0 $l->_throw_error("Expecting token after semicolon, but got EOF");
541 }
542 29 ▶ goto SEMICOLON_REPEAT if ($t->type == SEMICOLON);
Branch: 1 branch
BranchTrueFalseTotal
if $t->type == 25 0 29 29
543 29 ▶ if ($t->type == IRI or $t->type == PREFIXNAME or $t->type == A) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 14 or $t->type == 21 or $t->type == 1) { } 29 0 29
Condition33%2/6
$t->type == 14 or $t->type == 21 or $t->type == 1
l!l&&r!l&&!r
2900
$t->type == 14 or $t->type == 21
l!l&&r!l&&!r
0290
MC/DC0%0/3
$t->type == 14 or $t->type == 21 or $t->type == 1
$t->type == 14 $t->type == 21 $t->type == 1
Truth table25%1/4
A or B or C
A= $t->type == 14B= $t->type == 21C= $t->type == 1
ABCresult
1XX1
01X1
0011
0000
544 29 next;
545 } else {
546 0 $self->_unget_token($t);
547 0 return $counter;
548 }
549 } else {
550 52 $self->_unget_token($t);
551 52 return $counter;
552 }
553 }
554 0 return $counter;
555 }
556  
557 81 ▶ sub _objectList {
Subroutine _objectList: called CC=4 SCAR=13.9
558 81 my $self = shift;
559 81 my $l = shift;
560 81 my $subj = shift;
561 81 my $pred = shift;
562 81 while (1) {
563 86 my $t = $self->_next_nonws($l);
564 86 ▶ last unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 0 86 86
565 86 my $obj = $self->_object($l, $t);
566 86 $self->_assert_triple($subj, $pred, $obj);
567 86 $self->_annotation($l, $subj, $pred, $obj);
568
569 86 $t = $self->_next_nonws($l);
570 86 ▶ if ($t and $t->type == COMMA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t and $t->type == 6) { } 5 81 86
Condition66%2/3
$t and $t->type == 6
!ll&&!rl&&r
0815
MC/DC50%1/2
$t and $t->type == 6
$t $t->type == 6
Truth table66%2/3
A and B
A= $tB= $t->type == 6
ABresult
0X0
100
111
571 5 next;
572 } else {
573 81 $self->_unget_token($t);
574 81 return;
575 }
576 }
577 }
578
579 86 ▶ sub _annotation {
Subroutine _annotation: called CC=8 SCAR=32.7
580 86 my $self = shift;
581 86 my $l = shift;
582 86 my $subj = shift;
583 86 my $pred = shift;
584 86 my $obj = shift;
585 86 my $t = $self->_peek_nonws($l);
586 86 my $reif;
587 86 my $triple = Attean::Triple->new($subj, $pred, $obj);
588 86 my $need_to_assert_reification = 0;
589 86 ▶ while ($t->type == TILDE or $t->type == LANNOT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 39 or $t->type == 37) 0 86 86
Condition33%1/3
$t->type == 39 or $t->type == 37
l!l&&r!l&&!r
0086
MC/DC0%0/2
$t->type == 39 or $t->type == 37
$t->type == 39 $t->type == 37
Truth table33%1/3
A or B
A= $t->type == 39B= $t->type == 37
ABresult
1X1
011
000
590 0 ▶ if (not defined($reif)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $reif) 0 0 0
591 0 $reif = Attean::Blank->new();
592 }
593 0 ▶ if ($t->type == TILDE) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->type == 39) { } 0 0 0
elsif ($t->type == 37) { } 0 0 0
594 0 ▶ if ($need_to_assert_reification) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_to_assert_reification) 0 0 0
595 # there was a declared reifier, but it didn't have any annotations
596 0 $self->_assert_triple($reif, Attean::IRI->new(value => "${RDF}reifies", lazy => 1), $triple);
597 }
598 0 $reif = $self->_reifier($l);
599 0 $need_to_assert_reification = 1;
600 } elsif ($t->type == LANNOT) {
601 0 $self->_get_token_type($l, LANNOT);
602 0 $self->_assert_triple($reif, Attean::IRI->new(value => "${RDF}reifies", lazy => 1), $triple);
603 0 $self->_predicateObjectList( $l, $reif );
604 0 $self->_get_token_type($l, RANNOT);
605 0 $reif = undef; # we've now already handled the reification triple
606 0 $need_to_assert_reification = 0;
607 }
608 0 $t = $self->_peek_nonws($l);
609 }
610 86 ▶ if ($need_to_assert_reification) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_to_assert_reification) 0 86 86
611 # there was a declared reifier, but it didn't have any annotations
612 0 $self->_assert_triple($reif, Attean::IRI->new(value => "${RDF}reifies", lazy => 1), $triple);
613 }
614 }
615  
616 90 ▶ sub _assert_triple {
Subroutine _assert_triple: called CC=4 SCAR=15.8
617 90 my $self = shift;
618 90 my $subj = shift;
619 90 my $pred = shift;
620 90 my $obj = shift;
621 90 ▶ if ($self->canonicalize and blessed($obj) and $obj->does('Attean::API::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->canonicalize and builtin::blessed($obj) and $obj->does("Attean::API::Literal")) 0 90 90
Condition33%2/6
$self->canonicalize and builtin::blessed($obj) and $obj->does("Attean::API::Literal")
!ll&&!rl&&r
9000
$self->canonicalize and builtin::blessed($obj)
!ll&&!rl&&r
9000
MC/DC0%0/3
$self->canonicalize and builtin::blessed($obj) and $obj->does("Attean::API::Literal")
$self->canonicalize builtin::blessed($obj) $obj->does("Attean::API::Literal")
Truth table25%1/4
A and B and C
A= $self->canonicalizeB= builtin::blessed($obj)C= $obj->does("Attean::API::Literal")
ABCresult
0XX0
10X0
1100
1111
622 0 $obj = $obj->canonicalize;
623 }
624
625 90 my $t = Attean::Triple->new($subj, $pred, $obj);
626 90 $self->handler->($t);
627 }
628  
629 0 ▶ sub _ttObject {
Subroutine _ttObject: not called CC=22 SCAR=62.3
630 0 my $self = shift;
631 0 my $l = shift;
632 0 my $t = shift;
633 0 my $type = $t->type;
634 0 my $obj;
635 0 ▶ if ($type==LBRACKET) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type == 17) { } 0 0 0
elsif ($type == 26 or $type == 28 or $type == 27 or $type == 29) { } 0 0 0
elsif ($type == 14 or $type == 21 or $type == 4 or $type == 2 or $type == 13 or $type == 8 or $type == 10 or $type == 5) { } 0 0 0
elsif ($type == 36) { } 0 0 0
636 0 $obj = Attean::Blank->new();
637 0 $self->_get_token_type($l, RBRACKET);
638 ▶ } elsif ($type==STRING1D or $type==STRING3D or $type==STRING1S or $type==STRING3S) {
Condition0%0/9
$type == 26 or $type == 28 or $type == 27 or $type == 29
l!l&&r!l&&!r
000
$type == 26 or $type == 28 or $type == 27
l!l&&r!l&&!r
000
$type == 26 or $type == 28
l!l&&r!l&&!r
000
MC/DC0%0/4
$type == 26 or $type == 28 or $type == 27 or $type == 29
$type == 26 $type == 28 $type == 27 $type == 29
Truth table0%0/5
A or B or C or D
A= $type == 26B= $type == 28C= $type == 27D= $type == 29
ABCDresult
1XXX1
01XX1
001X1
00011
00000
639 0 my $value = $t->value;
640 0 my $t = $self->_next_nonws($l);
641 0 my $dt;
642 my $lang;
643 0 ▶ if ($t) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t) 0 0 0
644 0 ▶ if ($t->type == HATHAT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->type == 12) { } 0 0 0
elsif ($t->type == 15) { } 0 0 0
645 0 my $t = $self->_next_nonws($l);
646 0 ▶ if ($t->type == IRI or $t->type == PREFIXNAME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 14 or $t->type == 21) 0 0 0
Condition0%0/3
$t->type == 14 or $t->type == 21
l!l&&r!l&&!r
000
MC/DC0%0/2
$t->type == 14 or $t->type == 21
$t->type == 14 $t->type == 21
Truth table0%0/3
A or B
A= $t->type == 14B= $t->type == 21
ABresult
1X1
011
000
647 0 $dt = $self->_token_to_node($t);
648 }
649 } elsif ($t->type == LANG) {
650 0 $lang = $t->value;
651 } else {
652 0 $self->_unget_token($t);
653 }
654 }
655 0 my %args = (value => $value);
656 0 ▶ $args{language} = $lang if (defined($lang));
Branch: 1 branch
BranchTrueFalseTotal
if defined $lang 0 0 0
657 0 ▶ $args{datatype} = $dt if (defined($dt));
Branch: 1 branch
BranchTrueFalseTotal
if defined $dt 0 0 0
658 0 $obj = $self->new_literal(%args);
659 ▶ } elsif ($type==IRI or $type==PREFIXNAME or $type==BNODE or $type==ANON or $type==INTEGER or $type==DECIMAL or $type==DOUBLE or $type==BOOLEAN) {
Condition0%0/21
$type == 14 or $type == 21 or $type == 4 or $type == 2 or $type == 13 or $type == 8 or $type == 10 or $type == 5
l!l&&r!l&&!r
000
$type == 14 or $type == 21 or $type == 4 or $type == 2 or $type == 13 or $type == 8 or $type == 10
l!l&&r!l&&!r
000
$type == 14 or $type == 21 or $type == 4 or $type == 2 or $type == 13 or $type == 8
l!l&&r!l&&!r
000
$type == 14 or $type == 21 or $type == 4 or $type == 2 or $type == 13
l!l&&r!l&&!r
000
$type == 14 or $type == 21 or $type == 4 or $type == 2
l!l&&r!l&&!r
000
$type == 14 or $type == 21 or $type == 4
l!l&&r!l&&!r
000
$type == 14 or $type == 21
l!l&&r!l&&!r
000
MC/DC0%0/8
$type == 14 or $type == 21 or $type == 4 or $type == 2 or $type == 13 or $type == 8 or $type == 10 or $type == 5
$type == 14 $type == 21 $type == 4 $type == 2 $type == 13 $type == 8 $type == 10 $type == 5
Truth table0%0/9
A or B or C or D or E or F or G or H
A= $type == 14B= $type == 21C= $type == 4D= $type == 2E= $type == 13F= $type == 8G= $type == 10H= $type == 5
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
0000001X1
000000011
000000000
660 0 $obj = $self->_token_to_node($t, $type);
661 } elsif ($type==LTLTP) {
662 0 $obj = $self->_tripleTerm($l);
663 } else {
664 0 $self->_throw_error("Expecting object but got " . decrypt_constant($type), $t, $l);
665 }
666 0 return $obj;
667 }
668
669 100 ▶ sub _object {
Subroutine _object: called CC=33 SCAR=40.2
670 100 my $self = shift;
671 100 my $l = shift;
672 100 my $t = shift;
673 100 my $tcopy = $t;
674 100 my $obj;
675 100 my $type = $t->type;
676 100 ▶ if ($type==LTLT) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type == 35) { } 0 100 100
elsif ($type == 36) { } 0 100 100
elsif ($type == 17) { } 3 97 100
elsif ($type == 18) { } 1 96 97
elsif (not $type == 14 || $type == 21 || $type == 26 || $type == 28 || $type == 27 || $type == 29 || $type == 4 || $type == 2 || $type == 13 || $type == 8 || $type == 10 || $type == 5) { } 0 96 96
677 0 return $self->_reifiedTriple($l);
678 } elsif ($type==LTLTP) {
679 0 return $self->_tripleTerm($l);
680 } elsif ($type==LBRACKET) {
681 3 $obj = Attean::Blank->new();
682 3 my $t = $self->_next_nonws($l);
683 3 ▶ unless ($t) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($t) 0 3 3
684 0 $self->_throw_error("Expecting object but got only opening bracket", $tcopy, $l);
685 }
686 3 ▶ if ($t->type != RBRACKET) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type != 23) 3 0 3
687 3 $self->_unget_token($t);
688 3 $self->_predicateObjectList( $l, $obj );
689 3 $t = $self->_get_token_type($l, RBRACKET);
690 }
691 } elsif ($type == LPAREN) {
692 1 my $t = $self->_next_nonws($l);
693 1 ▶ unless ($t) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($t) 0 1 1
694 0 $self->_throw_error("Expecting object but got only opening paren", $tcopy, $l);
695 }
696 1 ▶ if ($t->type == RPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 24) { } 0 1 1
697 0 $obj = Attean::IRI->new(value => "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil", lazy => 1);
698 } else {
699 1 $obj = Attean::Blank->new();
700 1 my @objects = $self->_object($l, $t);
701
702 1 while (1) {
703 2 my $t = $self->_next_nonws($l);
704 2 ▶ if ($t->type == RPAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 24) { } 1 1 2
705 1 last;
706 } else {
707 1 push(@objects, $self->_object($l, $t));
708 }
709 }
710 1 $self->_assert_list($obj, @objects);
711 }
712 ▶ } elsif (not($type==IRI or $type==PREFIXNAME or $type==STRING1D or $type==STRING3D or $type==STRING1S or $type==STRING3S or $type==BNODE or $type==ANON or $type==INTEGER or $type==DECIMAL or $type==DOUBLE or $type==BOOLEAN)) {
Condition69%23/33
$type == 14 || $type == 21 || $type == 26 || $type == 28 || $type == 27 || $type == 29 || $type == 4 || $type == 2 || $type == 13 || $type == 8 || $type == 10 || $type == 5
l!l&&r!l&&!r
9600
$type == 14 or $type == 21 or $type == 26 or $type == 28 or $type == 27 or $type == 29 or $type == 4 or $type == 2 or $type == 13 or $type == 8 or $type == 10
l!l&&r!l&&!r
9600
$type == 14 or $type == 21 or $type == 26 or $type == 28 or $type == 27 or $type == 29 or $type == 4 or $type == 2 or $type == 13 or $type == 8
l!l&&r!l&&!r
9600
$type == 14 or $type == 21 or $type == 26 or $type == 28 or $type == 27 or $type == 29 or $type == 4 or $type == 2 or $type == 13
l!l&&r!l&&!r
86100
$type == 14 or $type == 21 or $type == 26 or $type == 28 or $type == 27 or $type == 29 or $type == 4 or $type == 2
l!l&&r!l&&!r
86010
$type == 14 or $type == 21 or $type == 26 or $type == 28 or $type == 27 or $type == 29 or $type == 4
l!l&&r!l&&!r
761010
$type == 14 or $type == 21 or $type == 26 or $type == 28 or $type == 27 or $type == 29
l!l&&r!l&&!r
76020
$type == 14 or $type == 21 or $type == 26 or $type == 28 or $type == 27
l!l&&r!l&&!r
76020
$type == 14 or $type == 21 or $type == 26 or $type == 28
l!l&&r!l&&!r
75120
$type == 14 or $type == 21 or $type == 26
l!l&&r!l&&!r
532221
$type == 14 or $type == 21
l!l&&r!l&&!r
163743
MC/DC0%0/12
$type == 14 || $type == 21 || $type == 26 || $type == 28 || $type == 27 || $type == 29 || $type == 4 || $type == 2 || $type == 13 || $type == 8 || $type == 10 || $type == 5
$type == 14 $type == 21 $type == 26 $type == 28 $type == 27 $type == 29 $type == 4 $type == 2 $type == 13 $type == 8 $type == 10 $type == 5
Truth table46%6/13
A or B or C or D or E or F or G or H or I or J or K || L
A= $type == 14B= $type == 21C= $type == 26D= $type == 28E= $type == 27F= $type == 29G= $type == 4H= $type == 2I= $type == 13J= $type == 8K= $type == 10L= $type == 5
ABCDEFGHIJKLresult
1XXXXXXXXXXX1
01XXXXXXXXXX1
001XXXXXXXXX1
0001XXXXXXXX1
00001XXXXXXX1
000001XXXXXX1
0000001XXXXX1
00000001XXXX1
000000001XXX1
0000000001XX1
00000000001X1
0000000000011
0000000000000
713 0 $self->_throw_error("Expecting object but got " . decrypt_constant($type), $t, $l);
714 } else {
715 96 ▶ if ($type==STRING1D or $type==STRING3D or $type==STRING1S or $type==STRING3S) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 26 or $type == 28 or $type == 27 or $type == 29) { } 23 73 96
Condition77%7/9
$type == 26 or $type == 28 or $type == 27 or $type == 29
l!l&&r!l&&!r
23073
$type == 26 or $type == 28 or $type == 27
l!l&&r!l&&!r
23073
$type == 26 or $type == 28
l!l&&r!l&&!r
22173
MC/DC50%2/4
$type == 26 or $type == 28 or $type == 27 or $type == 29
$type == 26 $type == 28 $type == 27 $type == 29
Truth table60%3/5
A or B or C or D
A= $type == 26B= $type == 28C= $type == 27D= $type == 29
ABCDresult
1XXX1
01XX1
001X1
00011
00000
716 23 my $value = $t->value;
717 23 my $t = $self->_next_nonws($l);
718 23 my $dt;
719 my $lang;
720 23 ▶ if ($t) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t) 22 1 23
721 22 ▶ if ($t->type == HATHAT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->type == 12) { } 0 22 22
elsif ($t->type == 15) { } 4 18 22
722 0 my $t = $self->_next_nonws($l);
723 0 ▶ if ($t->type == IRI or $t->type == PREFIXNAME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 14 or $t->type == 21) 0 0 0
Condition0%0/3
$t->type == 14 or $t->type == 21
l!l&&r!l&&!r
000
MC/DC0%0/2
$t->type == 14 or $t->type == 21
$t->type == 14 $t->type == 21
Truth table0%0/3
A or B
A= $t->type == 14B= $t->type == 21
ABresult
1X1
011
000
724 0 $dt = $self->_token_to_node($t);
725 }
726 } elsif ($t->type == LANG) {
727 4 $lang = $t->value;
728 } else {
729 18 $self->_unget_token($t);
730 }
731 }
732 23 my %args = (value => $value);
733 23 ▶ $args{language} = $lang if (defined($lang));
Branch: 1 branch
BranchTrueFalseTotal
if defined $lang 4 19 23
734 23 ▶ $args{datatype} = $dt if (defined($dt));
Branch: 1 branch
BranchTrueFalseTotal
if defined $dt 0 23 23
735 23 $obj = $self->new_literal(%args);
736 } else {
737 73 $obj = $self->_token_to_node($t, $type);
738 }
739 }
740 100 return $obj;
741 }
742  
743 203 ▶ sub _token_to_node {
Subroutine _token_to_node: called CC=17 SCAR=30.7
744 203 my $self = shift;
745 203 my $t = shift;
746 203 ▶ my $type = shift || $t->type;
Condition66%2/3
shift() || $t->type
l!l&&r!l&&!r
731300
MC/DC0%0/2
shift() || $t->type
shift() $t->type
Truth table66%2/3
A || B
A= shift()B= $t->type
ABresult
1X1
011
000
747 203 ▶ if ($type eq A) {
Branch: 11 branches
BranchTrueFalseTotal
if ($type eq 1) { } 22 181 203
elsif ($type eq 14) { } 52 129 181
elsif ($type eq 13) { } 10 119 129
elsif ($type eq 8) { } 0 119 119
elsif ($type eq 10) { } 0 119 119
elsif ($type eq 5) { } 0 119 119
elsif ($type eq 21) { } 94 25 119
elsif ($type eq 4) { } 24 1 25
elsif ($type eq 2) { } 1 0 1
elsif ($type eq 26) { } 0 0 0
elsif ($type eq 27) { } 0 0 0
748 22 state $rdftype = Attean::IRI->new(value => "${RDF}type", lazy => 1);
749 22 return $rdftype;
750 }
751 elsif ($type eq IRI) {
752 52 my $value = $t->value;
753 52 my %args = (value => $value);
754 52 my $iri;
755 52 ▶ if ($self->has_base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_base) 5 47 52
756 5 $args{base} = $self->base;
757 5 my $iri = $self->new_iri(%args);
758 5 return $iri;
759 }
760
761 47 state %cache;
762 47 ▶ if (my $n = $cache{$value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $n = $cache{$value}) { } 24 23 47
763 24 return $n;
764 } else {
765 23 my $iri = $self->new_iri(%args);
766 23 ▶ if (rand() < 0.02) {
Branch: 1 branch
BranchTrueFalseTotal
if (rand() < "0.02") 0 23 23
767 # clear out the cache roughly every 50 IRIs
768 0 %cache = ();
769 }
770 23 $cache{$value} = $iri;
771 23 return $iri;
772 }
773 }
774 elsif ($type eq INTEGER) {
775 10 return $self->new_literal(value => $t->value, datatype => Attean::IRI->new(value => "${XSD}integer", lazy => 1));
776 }
777 elsif ($type eq DECIMAL) {
778 0 return $self->new_literal(value => $t->value, datatype => Attean::IRI->new(value => "${XSD}decimal", lazy => 1));
779 }
780 elsif ($type eq DOUBLE) {
781 0 return $self->new_literal(value => $t->value, datatype => Attean::IRI->new(value => "${XSD}double", lazy => 1));
782 }
783 elsif ($type eq BOOLEAN) {
784 0 return $self->new_literal(value => $t->value, datatype => Attean::IRI->new(value => "${XSD}boolean", lazy => 1));
785 }
786 elsif ($type eq PREFIXNAME) {
787 94 my ($ns, $local) = @{ $t->args };
788 94 $ns =~ s/:$//;
789 94 ▶ unless (exists $self->_map->{$ns}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->_map->{$ns}) 0 94 94
790 0 $self->_throw_error("Use of undeclared prefix '$ns'", $t);
791 }
792 94 my $prefix = $self->_map->{$ns};
793 50 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
794 94 my $iri = $self->new_iri("${prefix}${local}");
795 94 return $iri;
796 }
797 elsif ($type eq BNODE) {
798 24 my $b = Attean::Blank->new($t->value);
799 24 $self->blank_nodes->{$t->value} = $b;
800 24 return $b;
801 }
802 elsif ($type eq ANON) {
803 1 return Attean::Blank->new();
804 }
805 elsif ($type eq STRING1D) {
806 0 return $self->new_literal($t->value);
807 }
808 elsif ($type eq STRING1S) {
809 0 return $self->new_literal($t->value);
810 }
811 else {
812 0 $self->_throw_error(sprintf("Converting %s to node not implemented", decrypt_constant($type)), $t);
813 }
814 }
815  
816 0 ▶ sub _throw_error {
Subroutine _throw_error: not called CC=2 SCAR=17.9
817 0 my $self = shift;
818 0 my $message = shift;
819 0 my $t = shift;
820 0 my $l = shift;
821 0 my $line = $t->start_line;
822 0 my $col = $t->start_column;
823 # Carp::cluck "$message at $line:$col";
824 0 my $text = "$message at $line:$col";
825 0 ▶ if (defined($t->value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t->value) 0 0 0
826 0 $text .= " (near '" . $t->value . "')";
827 }
828 # Carp::cluck $text;
829 0 die $text;
830 }
831 }
832  
833 50 1;
834  
835 __END__
« Attean/API/Term.pm ↑ Summary AtteanX/Parser/Trig.pm »