Trine/Parser/Notation3.pm

filter: Statementstmt 55.4% 425 / 767 Branchbran 36.6% 104 / 284 Conditioncond 46.3% 19 / 41 MC/DCmcdc 12.5% 3 / 24 Subroutinesub 69.1% 74 / 107 Podpod 83.3% 5 / 6 totaltotal 51.2% 630 / 1229 CC 165 SCAR 25.8
CC
165
Cov
50%
_unescape
56.0
_predicateObjectList
51.9
_verb_test
42.0
CRAP 13.3
« Trine/Parser/ShorthandRDF.pm ↑ Summary Trine/Serializer/Notation3.pm »
1 package RDF::Trine::Parser::Notation3;
2  
3 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Data::UUID;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use RDF::Trine qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use RDF::Trine::Statement;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use RDF::Trine::Namespace qw[rdf rdfs owl xsd];
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use RDF::Trine::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use RDF::Trine::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Scalar::Util qw(blessed looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use URI::Escape qw(uri_unescape);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 ▶use base 'RDF::Trine::Parser';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 3 our ($VERSION, $AUTHORITY);
25  
26 BEGIN
27 3 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 $VERSION = '0.206';
29 3 $AUTHORITY = 'cpan:TOBYINK';
30 }
31  
32 PARSER_SETUP: {
33 3 my $class = __PACKAGE__;
34 3 $RDF::Trine::Parser::encodings{$class } = 'utf8';
35 3 $RDF::Trine::Parser::canonical_media_types{ $class } = 'text/n3';
36
37 $RDF::Trine::Parser::parser_names{$_} = __PACKAGE__
38 3 foreach ('notation3', 'notation 3', 'n3');
39
40 $RDF::Trine::Parser::media_types{$_} = __PACKAGE__
41 3 foreach qw(text/n3 text/rdf+n3);
42
43 $RDF::Trine::Parser::file_extensions{$_} = __PACKAGE__
44 3 foreach qw(n3);
45  
46 $RDF::Trine::Parser::format_uris{$_} = __PACKAGE__
47 3 foreach ('http://www.w3.org/ns/formats/N3');
48 }
49  
50 3 my ($logic, $rdf, $xsd) = do {
51 3 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 3 map { RDF::Trine::Namespace->new($_) }
53 qw(
54 http://www.w3.org/2000/10/swap/log#
55 http://www.w3.org/1999/02/22-rdf-syntax-ns#
56 http://www.w3.org/2001/XMLSchema#
57 )
58 };
59  
60 3 my $r_boolean = qr'(?:true|false)'i;
61 3 my $r_comment = qr'#[^\r\n]*';
62 3 my $r_decimal = qr'[+-]?([0-9]+\.[0-9]*|\.([0-9])+)';
63 3 my $r_double = qr'[+-]?([0-9]+\.[0-9]*[eE][+-]?[0-9]+|\.[0-9]+[eE][+-]?[0-9]+|[0-9]+[eE][+-]?[0-9]+)';
64 3 my $r_integer = qr'[+-]?[0-9]+';
65 3 my $r_language = qr'[a-z]+(-[a-z0-9]+)*'i;
66 3 my $r_lcharacters = qr'(?s)[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*';
67 3 my $r_lcharacters2 = qr{(?s)[^'\\]*(?:(?:\\.|"(?!''))[^'\\]*)*};
68 3 my $r_line = qr'(?:[^\r\n]+[\r\n]+)(?=[^\r\n])';
69 3 my $r_nameChar_extra = qr'[-0-9\x{B7}\x{0300}-\x{036F}\x{203F}-\x{2040}]';
70 3 my $r_nameStartChar_minus_underscore = qr'[A-Za-z\x{00C0}-\x{00D6}\x{00D8}-\x{00F6}\x{00F8}-\x{02FF}\x{0370}-\x{037D}\x{037F}-\x{1FFF}\x{200C}-\x{200D}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{00010000}-\x{000EFFFF}]';
71 3 my $r_scharacters = qr'[^"\\]*(?:\\.[^"\\]*)*';
72 3 my $r_scharacters2 = qr{[^'\\]*(?:\\.[^'\\]*)*};
73 3 my $r_ucharacters = qr'[^>\\]*(?:\\.[^>\\]*)*';
74 3 my $r_booltest = qr'(?:true|false)\b'i;
75 3 my $r_nameStartChar = qr/[A-Za-z_\x{00C0}-\x{00D6}\x{00D8}-\x{00F6}\x{00F8}-\x{02FF}\x{0370}-\x{037D}\x{037F}-\x{1FFF}\x{200C}-\x{200D}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{10000}-\x{EFFFF}]/;
76 3 my $r_nameChar = qr/${r_nameStartChar}|[-0-9\x{b7}\x{0300}-\x{036f}\x{203F}-\x{2040}]/;
77 3 my $r_prefixName = qr/(?:(?!_)${r_nameStartChar})($r_nameChar)*/;
78 3 my $r_qname = qr/(?:${r_prefixName})?:/;
79 3 my $r_resource_test = qr/<|$r_qname/;
80 3 my $r_nameChar_test = qr"(?:$r_nameStartChar|$r_nameChar_extra)";
81  
82 5 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
83 5 my $class = shift;
84 5 my %args = @_;
85 5 my $prefix = '';
86 5 ▶ if (defined($args{ bnode_prefix })) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'bnode_prefix'}) { } 0 5 5
87 0 $prefix = $args{ bnode_prefix };
88 } else {
89 5 $prefix = $class->new_bnode_prefix();
90 }
91 5 my $self = bless({
92 bindings => {},
93 bnode_id => 0,
94 bnode_prefix => $prefix,
95 @_
96 }, $class);
97 5 return $self;
98 }
99  
100 3 ▶sub parse {
Subroutine parse: called CC=3 SCAR=11.0
Pod documented
101 3 my $self = shift;
102 3 my $uri = shift;
103 3 my $input = shift;
104 3 my $handler = shift;
105 3 local($self->{handle_triple});
106 3 ▶ if ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) 3 0 3
107 3 $self->{handle_triple} = $handler;
108 }
109 3 local($self->{baseURI}) = $uri;
110
111 3 ▶ $input = '' unless (defined($input));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input 0 3 3
112 3 $input =~ s/^\x{FEFF}//;
113
114 3 local($self->{tokens}) = $input;
115 3 $self->_Document();
116 3 return;
117 }
118  
119 0 ▶sub parse_node {
Subroutine parse_node: not called CC=1 SCAR=6.9
Pod undocumented
120 0 my $self = shift;
121 0 my $input = shift;
122 0 my $uri = shift;
123 0 local($self->{handle_triple});
124 0 local($self->{baseURI}) = $uri;
125 0 $input =~ s/^\x{FEFF}//;
126 0 local($self->{tokens}) = $input;
127 0 return $self->_object();
128 }
129  
130 2 ▶sub _eat_re {
Subroutine _eat_re: called CC=3 SCAR=12.5
131 2 my $self = shift;
132 2 my $thing = shift;
133 2 my $l = Log::Log4perl->get_logger("rdf.trine.parser.turtle");
134 2 ▶ if (not(length($self->{tokens}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->{"tokens"}) 0 2 2
135 0 $l->error("no tokens left ($thing)");
136 0 throw RDF::Trine::Error::ParserError -text => "No tokens";
137 }
138
139 2 ▶ if ($self->{tokens} =~ m/^($thing)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"} =~ /^($thing)/) 2 0 2
140 2 my $match = $1;
141 2 substr($self->{tokens}, 0, length($match)) = '';
142 2 return;
143 }
144 0 $l->error("Expected ($thing) with remaining: $self->{tokens}");
145 0 throw RDF::Trine::Error::ParserError -text => "Expected: $thing";
146 }
147  
148 116 ▶sub _eat_re_save {
Subroutine _eat_re_save: called CC=3 SCAR=12.5
149 116 my $self = shift;
150 116 my $thing = shift;
151 116 my $l = Log::Log4perl->get_logger("rdf.trine.parser.turtle");
152 116 ▶ if (not(length($self->{tokens}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->{"tokens"}) 0 116 116
153 0 $l->error("no tokens left ($thing)");
154 0 throw RDF::Trine::Error::ParserError -text => "No tokens";
155 }
156
157 116 ▶ if ($self->{tokens} =~ m/^($thing)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"} =~ /^($thing)/) 116 0 116
158 116 my $match = $1;
159 116 substr($self->{tokens}, 0, length($match)) = '';
160 116 return $match;
161 }
162 0 $l->error("Expected ($thing) with remaining: $self->{tokens}");
163 0 throw RDF::Trine::Error::ParserError -text => "Expected: $thing";
164 }
165  
166 78 ▶sub _eat {
Subroutine _eat: called CC=3 SCAR=12.7
167 78 my $self = shift;
168 78 my $thing = shift;
169 78 my $l = Log::Log4perl->get_logger("rdf.trine.parser.turtle");
170 78 ▶ if (not(length($self->{tokens}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->{"tokens"}) 0 78 78
171 0 $l->error("no tokens left ($thing)");
172 0 throw RDF::Trine::Error::ParserError -text => "No tokens";
173 }
174
175 ### thing is a string
176 78 ▶ if (substr($self->{tokens}, 0, length($thing)) eq $thing) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->{'tokens'}, 0, length $thing) eq $thing) { } 78 0 78
177 78 substr($self->{tokens}, 0, length($thing)) = '';
178 78 return;
179 } else {
180 0 $l->logcluck("expected: $thing, got: $self->{tokens}");
181 0 throw RDF::Trine::Error::ParserError -text => "Expected: $thing";
182 }
183 }
184  
185 179 ▶sub _test {
Subroutine _test: called CC=2 SCAR=6.9
186 179 my $self = shift;
187 179 my $thing = shift;
188 179 ▶ if (substr($self->{tokens}, 0, length($thing)) eq $thing) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->{'tokens'}, 0, length $thing) eq $thing) { } 23 156 179
189 23 return 1;
190 } else {
191 156 return 0;
192 }
193 }
194  
195 9 ▶sub _triple {
Subroutine _triple: called CC=8 SCAR=28.2
196 9 my $self = shift;
197 9 my $s = shift;
198 9 my $p = shift;
199 9 my $o = shift;
200 9 foreach my $n ($s, $p, $o) {
201 27 ▶ unless ($n->isa('RDF::Trine::Node')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($n->isa("RDF::Trine::Node")) 0 27 27
202 0 throw RDF::Trine::Error::ParserError;
203 }
204 }
205
206 9 ▶ if ($self->{canonicalize})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"canonicalize"}) 0 9 9
207 {
208 0 foreach my $n ($s, $p, $o)
209 {
210 0 ▶ if ($n->isa('RDF::Trine::Node::Literal') and $n->has_datatype)
Branch: 1 branch
BranchTrueFalseTotal
if ($n->isa("RDF::Trine::Node::Literal") and $n->has_datatype) 0 0 0
Condition0%0/3
$n->isa("RDF::Trine::Node::Literal") and $n->has_datatype
!ll&&!rl&&r
000
MC/DC0%0/2
$n->isa("RDF::Trine::Node::Literal") and $n->has_datatype
$n->isa("RDF::Trine::Node::Literal") $n->has_datatype
Truth table0%0/3
A and B
A= $n->isa("RDF::Trine::Node::Literal")B= $n->has_datatype
ABresult
0X0
100
111
211 {
212 0 my $value = $n->literal_value;
213 0 my $dt = $n->literal_datatype;
214 0 my $canon = RDF::Trine::Node::Literal->canonicalize_literal_value($value, $dt, 1);
215 0 $n = RDF::Trine::Node::Literal->new($canon, undef, $dt);
216 }
217 }
218 }
219
220 9 my $st = RDF::Trine::Statement->new( $s, $p, $o );
221 9 ▶ if (my $code = $self->{handle_triple}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->{"handle_triple"}) 9 0 9
222 9 $code->( $st );
223 }
224
225 9 my $count = ++$self->{triple_count};
226 }
227  
228 # Force the default prefix to be bound to the base URI.
229 3 ▶sub _Document {
Subroutine _Document: called CC=3 SCAR=11.0
230 3 my $self = shift;
231 3 my $uri = $self->{'baseURI'};
232 3 ▶ local($self->{bindings}{''}) = ($uri =~ /#$/ ? $uri : "$uri#");
Branch: 1 branch
BranchTrueFalseTotal
$uri =~ /#$/ ? : 0 3 3
233 3 local($self->{'keywords'}) = undef;
234 3 ▶ while ($self->_statement_test()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_statement_test) 9 3 12
235 9 $self->_statement();
236 }
237 }
238  
239 12 ▶sub _statement_test {
Subroutine _statement_test: called CC=2 SCAR=6.9
240 12 my $self = shift;
241 12 ▶ if (length($self->{tokens})) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{'tokens'}) { } 9 3 12
242 9 return 1;
243 } else {
244 3 return 0;
245 }
246 }
247  
248 9 ▶sub _statement {
Subroutine _statement: called CC=3 SCAR=11.2
249 9 my $self = shift;
250 9 ▶ if ($self->_directive_test()) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_directive_test) { } 6 3 9
elsif ($self->_triples_test) { } 3 0 3
251 6 $self->_directive();
252 6 $self->__consume_ws();
253 6 $self->_eat('.');
254 6 $self->__consume_ws();
255 } elsif ($self->_triples_test()) {
256 3 $self->_triples();
257 3 $self->__consume_ws();
258 3 $self->_eat('.');
259 3 $self->__consume_ws();
260 } else {
261 0 $self->_ws();
262 0 $self->__consume_ws();
263 }
264 }
265  
266 4 ▶sub _directive_test {
Subroutine _directive_test: called CC=2 SCAR=6.9
267 4 my $self = shift;
268 ### between directive | triples | ws
269 ### directives must start with @, triples must not
270 4 ▶ if ($self->__startswith('@')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__startswith('@')) { } 2 2 4
271 2 return 1;
272 } else {
273 2 return 0;
274 }
275 }
276  
277 # N3-specific directives
278 3 ▶sub _directive {
Subroutine _directive: called CC=4 SCAR=15.2
279 3 my $self = shift;
280 ### prefixID | base
281 3 ▶ if ($self->_prefixID_test()) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_prefixID_test) { } 2 1 3
elsif ($self->_quantifier_test) { } 0 1 1
elsif ($self->_keywords_test) { } 1 0 1
282 2 $self->_prefixID();
283 } elsif ($self->_quantifier_test()) {
284 0 $self->_quantifier();
285 } elsif ($self->_keywords_test()) {
286 1 $self->_keywords();
287 } else {
288 0 $self->_base();
289 }
290 }
291  
292 3 ▶sub _prefixID_test {
Subroutine _prefixID_test: called CC=2 SCAR=6.9
293 3 my $self = shift;
294 ### between prefixID | base. prefixID is @prefix, base is @base
295 3 ▶ if ($self->__startswith('@prefix')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__startswith('@prefix')) { } 2 1 3
296 2 return 1;
297 } else {
298 1 return 0;
299 }
300 }
301  
302 2 ▶sub _prefixID {
Subroutine _prefixID: called CC=4 SCAR=15.1
303 2 my $self = shift;
304 ### '@prefix' ws+ prefixName? ':' ws+ uriref
305 2 $self->_eat('@prefix');
306 2 $self->_ws();
307 2 $self->__consume_ws();
308
309 2 my $prefix;
310 2 ▶ if ($self->_prefixName_test()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_prefixName_test) { } 2 0 2
311 2 $prefix = $self->_prefixName();
312 } else {
313 0 $prefix = '';
314 }
315
316 2 $self->_eat(':');
317 2 $self->_ws();
318 2 $self->__consume_ws();
319
320 2 my $uri = $self->_uriref();
321 2 $self->{bindings}{$prefix} = $uri;
322
323 2 ▶ if (blessed(my $ns = $self->{namespaces})) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed(my $ns = $self->{"namespaces"})) 0 2 2
324 0 ▶ unless ($ns->namespace_uri($prefix)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ns->namespace_uri($prefix)) 0 0 0
325 0 $ns->add_mapping( $prefix => $uri );
326 }
327 }
328 }
329  
330  
331  
332 0 ▶sub _base {
Subroutine _base: not called CC=2 SCAR=17.9
333 0 my $self = shift;
334 ### '@base' ws+ uriref
335 0 $self->_eat('@base');
336 0 $self->_ws();
337 0 $self->__consume_ws();
338 0 my $uri = $self->_uriref();
339 0 ▶ if (ref($uri)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $uri) 0 0 0
340 0 $uri = $uri->uri_value;
341 }
342 0 $self->{baseURI} = $self->_join_uri($self->{baseURI}, $uri);
343 }
344  
345 # Allow any type of node to begin a set of triples.
346 18 ▶sub _triples_test {
Subroutine _triples_test: called CC=10 SCAR=35.2
347 18 my $self = shift;
348 18 ▶ return 1 if $self->_resource_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_resource_test 4 14 18
349 14 ▶ return 1 if $self->_blank_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_blank_test 0 14 14
350 14 ▶ return 1 if $self->_variable_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_variable_test 12 2 14
351 2 ▶ return 1 if $self->_formula_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_formula_test 2 0 2
352 0 ▶ return 1 if $self->_quotedString_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_quotedString_test 0 0 0
353 0 ▶ return 1 if $self->_double_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_double_test 0 0 0
354 0 ▶ return 1 if $self->_decimal_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_decimal_test 0 0 0
355 0 ▶ return 1 if $self->_integer_test;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_integer_test 0 0 0
356 0 ▶ return 1 if $self->{'tokens'} =~ m{^$r_booltest};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tokens"} =~ /^$r_booltest/ 0 0 0
357 0 return 0;
358 }
359  
360 3 *_predicate_test = \&_triples_test;
361  
362 # Need to override _triples and _predicateObjectList to implement "is ... of".
363 9 ▶sub _triples {
Subroutine _triples: called CC=3 SCAR=11.2
364 9 my $self = shift;
365 ### subject ws+ predicateObjectList
366 9 my $subj = $self->_subject();
367 9 $self->_ws();
368 9 $self->__consume_ws;
369 9 foreach my $data ($self->_predicateObjectList()) {
370 9 my ($pred, $objt, $direction) = @$data;
371 # direction: 0=forwards; 1=backwards.
372 9 ▶ if ($direction) {
Branch: 1 branch
BranchTrueFalseTotal
if ($direction) { } 0 9 9
373 0 $self->_triple( $objt, $pred, $subj );
374 } else {
375 9 $self->_triple( $subj, $pred, $objt );
376 }
377 }
378 }
379  
380 9 ▶sub _objectList {
Subroutine _objectList: called CC=2 SCAR=8.7
381 9 my $self = shift;
382 ### object (ws* ',' ws* object)*
383 9 my @list;
384 9 push(@list, $self->_object());
385 9 $self->__consume_ws();
386 9 ▶ while ($self->_test(',')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test(",")) 0 9 9
387 0 $self->__consume_ws();
388 0 $self->_eat(',');
389 0 $self->__consume_ws();
390 0 push(@list, $self->_object());
391 0 $self->__consume_ws();
392 }
393 9 return @list;
394 }
395  
396 # Notation 3 has additional keywords
397 0 ▶sub _verb_test {
Subroutine _verb_test: not called CC=6 SCAR=37.4
398 0 my $self = shift;
399 0 ▶ return 0 unless (length($self->{tokens}));
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"tokens"} 0 0 0
400 0 ▶ return 1 if ($self->{tokens} =~ /^a\b/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tokens"} =~ /^a\b/ 0 0 0
401 0 ▶ return 1 if ($self->{tokens} =~ /^=>\b/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tokens"} =~ /^=>\b/ 0 0 0
402 0 ▶ return 1 if ($self->{tokens} =~ /^<=\b/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tokens"} =~ /^<=\b/ 0 0 0
403 0 ▶ return 1 if ($self->{tokens} =~ /^=\b/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tokens"} =~ /^=\b/ 0 0 0
404 0 return $self->_predicate_test();
405 }
406  
407 # Verb now also returns directionality.
408 9 ▶sub _verb {
Subroutine _verb: called CC=6 SCAR=20.5
409 9 my $self = shift;
410 9 ▶ if ($self->_test('<=')) {
Branch: 5 branches
BranchTrueFalseTotal
if ($self->_test('<=')) { } 0 9 9
elsif ($self->_test('=>')) { } 2 7 9
elsif ($self->_test('=')) { } 0 7 7
elsif ($self->{'tokens'} =~ /^a\b/) { } 4 3 7
elsif ($self->_predicate_test) { } 3 0 3
411 0 $self->_eat('<=');
412 0 return [ $logic->implies , 1 ];
413 } elsif ($self->_test('=>')) {
414 2 $self->_eat('=>');
415 2 return [ $logic->implies , 0 ];
416 } elsif ($self->_test('=')) {
417 0 $self->_eat('=');
418 0 return [ $owl->sameAs, 0 ];
419 } elsif ($self->{tokens} =~ m'^a\b') {
420 4 $self->_eat('a');
421 4 return [ $rdf->type , 0 ];
422 } elsif ($self->_predicate_test()) {
423 3 return [ $self->_predicate(), 0] ;
424 } else {
425 0 $self->_eat('<PREDICATE>');
426 }
427 }
428  
429 2 ▶sub _comment {
Subroutine _comment: called CC=1 SCAR=0.0
430 2 my $self = shift;
431 ### '#' ( [^#xA#xD] )*
432 2 $self->_eat_re($r_comment);
433 2 return 1;
434 }
435  
436 2 ▶sub _literal {
Subroutine _literal: called CC=7 SCAR=31.8
437 2 my $self = shift;
438 ### quotedString ( '@' language )? | datatypeString | integer |
439 ### double | decimal | boolean
440 ### datatypeString = quotedString '^^' resource
441 ### (so we change this around a bit to make it parsable without a huge
442 ### multiple lookahead)
443
444 2 ▶ if ($self->_quotedString_test()) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->_quotedString_test) { } 2 0 2
elsif ($self->_double_test) { } 0 0 0
elsif ($self->_decimal_test) { } 0 0 0
elsif ($self->_integer_test) { } 0 0 0
445 2 my $value = $self->_quotedString();
446 2 ▶ if ($self->_test('@')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_test('@')) { } 0 2 2
elsif ($self->_test('^^')) { } 0 2 2
447 0 $self->_eat('@');
448 0 my $lang = $self->_language();
449 0 return $self->__Literal($value, $lang);
450 } elsif ($self->_test('^^')) {
451 0 $self->_eat('^^');
452 0 my $dtype = $self->_resource();
453 0 return $self->_typed($value, $dtype);
454 } else {
455 2 return $self->__Literal($value);
456 }
457 } elsif ($self->_double_test()) {
458 0 return $self->_double();
459 } elsif ($self->_decimal_test()) {
460 0 return $self->_decimal();
461 } elsif ($self->_integer_test()) {
462 0 return $self->_integer();
463 } else {
464 0 return $self->_boolean();
465 }
466 }
467  
468 0 ▶sub _double_test {
Subroutine _double_test: not called CC=2 SCAR=17.9
469 0 my $self = shift;
470 0 ▶ if ($self->{tokens} =~ /^$r_double/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^$r_double/) { } 0 0 0
471 0 return 1;
472 } else {
473 0 return 0;
474 }
475 }
476  
477 0 ▶sub _double {
Subroutine _double: not called CC=1 SCAR=6.9
478 0 my $self = shift;
479 ### ('-' | '+') ? ( [0-9]+ '.' [0-9]* exponent | '.' ([0-9])+ exponent
480 ### | ([0-9])+ exponent )
481 ### exponent = [eE] ('-' | '+')? [0-9]+
482 0 my $token = $self->_eat_re_save( $r_double );
483 0 return $self->_typed( $token, $xsd->double );
484 }
485  
486 0 ▶sub _decimal_test {
Subroutine _decimal_test: not called CC=2 SCAR=17.9
487 0 my $self = shift;
488 0 ▶ if ($self->{tokens} =~ /^$r_decimal/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^$r_decimal/) { } 0 0 0
489 0 return 1;
490 } else {
491 0 return 0;
492 }
493 }
494  
495 0 ▶sub _decimal {
Subroutine _decimal: not called CC=1 SCAR=6.9
496 0 my $self = shift;
497 ### ('-' | '+')? ( [0-9]+ '.' [0-9]* | '.' ([0-9])+ | ([0-9])+ )
498 0 my $token = $self->_eat_re_save( $r_decimal );
499 0 return $self->_typed( $token, $xsd->decimal );
500 }
501  
502 0 ▶sub _integer_test {
Subroutine _integer_test: not called CC=2 SCAR=17.9
503 0 my $self = shift;
504 0 ▶ if ($self->{tokens} =~ /^$r_integer/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^$r_integer/) { } 0 0 0
505 0 return 1;
506 } else {
507 0 return 0;
508 }
509 }
510  
511 0 ▶sub _integer {
Subroutine _integer: not called CC=1 SCAR=6.9
512 0 my $self = shift;
513 ### ('-' | '+')? ( [0-9]+ '.' [0-9]* | '.' ([0-9])+ | ([0-9])+ )
514 0 my $token = $self->_eat_re_save( $r_integer );
515 0 return $self->_typed( $token, $xsd->integer );
516 }
517  
518 0 ▶sub _boolean {
Subroutine _boolean: not called CC=1 SCAR=6.9
519 0 my $self = shift;
520 ### 'true' | 'false'
521 0 my $token = $self->_eat_re_save( $r_boolean );
522 0 return $self->_typed( lc $token, $xsd->boolean );
523 }
524  
525 24 ▶sub _blank_test {
Subroutine _blank_test: called CC=2 SCAR=7.6
526 24 my $self = shift;
527 ### between this and literal. urgh!
528 ### this can start with...
529 ### _ | [ | (
530 ### literal can start with...
531 ### * " | + | - | digit | t | f
532 24 ▶ if ($self->{tokens} =~ m/^[_[(]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^[_[(]/) { } 0 24 24
533 0 return 1;
534 } else {
535 24 return 0;
536 }
537 }
538  
539 0 ▶sub _blank {
Subroutine _blank: not called CC=5 SCAR=34.0
540 0 my $self = shift;
541 ### nodeID | '[]' | '[' ws* predicateObjectList ws* ']' | collection
542 0 ▶ if ($self->_nodeID_test) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_nodeID_test) { } 0 0 0
elsif ($self->_test('[]')) { } 0 0 0
elsif ($self->_test('[')) { } 0 0 0
543 0 return $self->__bNode( $self->__anonimize_bnode_id( $self->_nodeID() ) );
544 } elsif ($self->_test('[]')) {
545 0 $self->_eat('[]');
546 0 return $self->__bNode( $self->__generate_bnode_id() );
547 } elsif ($self->_test('[')) {
548 0 $self->_eat('[');
549 0 my $subj = $self->__bNode( $self->__generate_bnode_id() );
550 0 $self->__consume_ws();
551 0 foreach my $data ($self->_predicateObjectList()) {
552 0 my ($pred, $objt) = @$data;
553 0 $self->_triple( $subj, $pred, $objt );
554 }
555 0 $self->__consume_ws();
556 0 $self->_eat(']');
557 0 return $subj;
558 } else {
559 0 return $self->_collection();
560 }
561 }
562  
563 0 ▶sub _itemList_test {
Subroutine _itemList_test: not called CC=3 SCAR=24.8
564 0 my $self = shift;
565 ### between this and whitespace or ')'
566 0 ▶ return 0 unless (length($self->{tokens}));
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"tokens"} 0 0 0
567 0 ▶ if ($self->{tokens} !~ m/^[\r\n\t #)]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'tokens'} =~ /^[\r\n\t #)]/) { } 0 0 0
568 0 return 1;
569 } else {
570 0 return 0;
571 }
572 }
573  
574 0 ▶sub _itemList {
Subroutine _itemList: not called CC=3 SCAR=24.8
575 0 my $self = shift;
576 ### object (ws+ object)*
577 0 my @list;
578 0 push(@list, $self->_object());
579 0 ▶ while ($self->_ws_test()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_ws_test) 0 0 0
580 0 $self->__consume_ws();
581 0 ▶ if (not $self->_test(')')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test(")")) 0 0 0
582 0 push(@list, $self->_object());
583 }
584 }
585 0 return @list;
586 }
587  
588 0 ▶sub _collection {
Subroutine _collection: not called CC=5 SCAR=34.0
589 0 my $self = shift;
590 ### '(' ws* itemList? ws* ')'
591 0 my $b = $self->__bNode( $self->__generate_bnode_id() );
592 0 my ($this, $rest) = ($b, undef);
593 0 $self->_eat('(');
594 0 $self->__consume_ws();
595 0 ▶ if ($self->_itemList_test()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_itemList_test) 0 0 0
596 # while (my $objt = $self->_itemList()) {
597 0 foreach my $objt ($self->_itemList()) {
598 0 ▶ if (defined($rest)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rest) 0 0 0
599 0 $this = $self->__bNode( $self->__generate_bnode_id() );
600 0 $self->_triple( $rest, $rdf->rest, $this)
601 }
602 0 $self->_triple( $this, $rdf->first, $objt );
603 0 $rest = $this;
604 }
605 }
606 0 ▶ if (defined($rest)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rest) { } 0 0 0
607 0 $self->_triple( $rest, $rdf->rest, $rdf->nil );
608 } else {
609 0 $b = $rdf->nil;
610 }
611 0 $self->__consume_ws();
612 0 $self->_eat(')');
613 0 return $b;
614 }
615  
616 0 ▶sub _ws_test {
Subroutine _ws_test: not called CC=3 SCAR=24.8
617 0 my $self = shift;
618 0 ▶ unless (length($self->{tokens})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->{"tokens"}) 0 0 0
619 0 return 0;
620 }
621
622 0 ▶ if ($self->{tokens} =~ m/^[\t\r\n #]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^[\t\r\n #]/) { } 0 0 0
623 0 return 1;
624 } else {
625 0 return 0;
626 }
627 }
628  
629 70 ▶sub _ws {
Subroutine _ws: called CC=3 SCAR=11.2
630 70 my $self = shift;
631 ### #x9 | #xA | #xD | #x20 | comment
632 70 ▶ if ($self->_test('#')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test('#')) { } 2 68 70
633 2 $self->_comment();
634 } else {
635 68 my $ws = $self->_eat_re_save( qr/[\n\r\t ]+/ );
636 68 ▶ unless ($ws =~ /^[\n\r\t ]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ws =~ /^[\n\r\t ]/) 0 68 68
637 0 throw RDF::Trine::Error::ParserError -text => 'Not whitespace';
638 }
639 }
640 }
641  
642 0 ▶sub _nodeID_test {
Subroutine _nodeID_test: not called CC=2 SCAR=17.9
643 0 my $self = shift;
644 ### between this (_) and []
645 0 ▶ if (substr($self->{tokens}, 0, 1) eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->{'tokens'}, 0, 1) eq '_') { } 0 0 0
646 0 return 1;
647 } else {
648 0 return 0;
649 }
650 }
651  
652 0 ▶sub _nodeID {
Subroutine _nodeID: not called CC=1 SCAR=6.9
653 0 my $self = shift;
654 ### '_:' name
655 0 $self->_eat('_:');
656 0 return $self->_name();
657 }
658  
659 5 ▶sub _qname {
Subroutine _qname: called CC=4 SCAR=14.2
660 5 my $self = shift;
661 ### prefixName? ':' name?
662 5 ▶ my $prefix = ($self->{tokens} =~ /^$r_nameStartChar_minus_underscore/) ? $self->_prefixName() : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'tokens'} =~ /^$r_nameStartChar_minus_underscore/ ? : 4 1 5
663 5 $self->_eat(':');
664 5 ▶ my $name = ($self->{tokens} =~ /^$r_nameStartChar/) ? $self->_name() : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'tokens'} =~ /^$r_nameStartChar/ ? : 5 0 5
665 5 ▶ unless (exists $self->{bindings}{$prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"bindings"}{$prefix}) 0 5 5
666 0 throw RDF::Trine::Error::ParserError -text => "Undeclared prefix $prefix";
667 }
668 5 my $uri = $self->{bindings}{$prefix};
669 5 return $uri . $name
670 }
671  
672 9 ▶sub _uriref_test {
Subroutine _uriref_test: called CC=2 SCAR=6.9
673 9 my $self = shift;
674 ### between this and qname
675 9 ▶ if ($self->__startswith('<')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__startswith('<')) { } 4 5 9
676 4 return 1;
677 } else {
678 5 return 0;
679 }
680 }
681  
682 8 ▶sub _uriref {
Subroutine _uriref: called CC=1 SCAR=0.0
683 8 my $self = shift;
684 ### '<' relativeURI '>'
685 8 $self->_eat('<');
686 8 my $value = $self->_relativeURI();
687 8 $self->_eat('>');
688 8 my $uri = uri_unescape(encode_utf8($value));
689 8 my $uni = decode_utf8($uri);
690 8 return $uni;
691 }
692  
693 0 ▶sub _language {
Subroutine _language: not called CC=1 SCAR=6.9
694 0 my $self = shift;
695 ### [a-z]+ ('-' [a-z0-9]+ )*
696 0 my $token = $self->_eat_re_save( $r_language );
697 0 return $token;
698 }
699  
700 0 ▶sub _nameStartChar_test {
Subroutine _nameStartChar_test: not called CC=2 SCAR=17.9
701 0 my $self = shift;
702 0 ▶ if ($self->{tokens} =~ /^$r_nameStartChar/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^$r_nameStartChar/) { } 0 0 0
703 0 return 1;
704 } else {
705 0 return 0;
706 }
707 }
708  
709 18 ▶sub _nameStartChar {
Subroutine _nameStartChar: called CC=1 SCAR=0.0
710 18 my $self = shift;
711 ### [A-Z] | "_" | [a-z] | [#x00C0-#x00D6] | [#x00D8-#x00F6] |
712 ### [#x00F8-#x02FF] | [#x0370-#x037D] | [#x037F-#x1FFF] | [#x200C-#x200D]
713 ### | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] |
714 ### [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
715 18 my $nc = $self->_eat_re_save( $r_nameStartChar );
716 18 return $nc;
717 }
718  
719 0 ▶sub _nameChar_test {
Subroutine _nameChar_test: not called CC=3 SCAR=24.8
720 0 my $self = shift;
721 0 ▶ if ($self->{tokens} =~ /^$r_nameStartChar/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^$r_nameStartChar/) { } 0 0 0
elsif ($self->{'tokens'} =~ /^$r_nameChar_extra/) { } 0 0 0
722 0 return 1;
723 } elsif ($self->{tokens} =~ /^$r_nameChar_extra/) {
724 0 return 1;
725 } else {
726 0 return 0;
727 }
728 }
729  
730 18 ▶sub _nameChar {
Subroutine _nameChar: called CC=2 SCAR=7.9
731 18 my $self = shift;
732 ### nameStartChar | '-' | [0-9] | #x00B7 | [#x0300-#x036F] |
733 ### [#x203F-#x2040]
734 # if ($self->_nameStartChar_test()) {
735 18 ▶ if ($self->{tokens} =~ /^$r_nameStartChar/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^$r_nameStartChar/) { } 18 0 18
736 18 my $nc = $self->_nameStartChar();
737 18 return $nc;
738 } else {
739 0 my $nce = $self->_eat_re_save( $r_nameChar_extra );
740 0 return $nce;
741 }
742 }
743  
744 14 ▶sub _name {
Subroutine _name: called CC=1 SCAR=0.0
745 14 my $self = shift;
746 ### nameStartChar nameChar*
747 14 my $name = $self->_eat_re_save( qr/^${r_nameStartChar}(${r_nameStartChar}|${r_nameChar_extra})*/ );
748 14 return $name;
749 }
750  
751 2 ▶sub _prefixName_test {
Subroutine _prefixName_test: called CC=2 SCAR=7.6
752 2 my $self = shift;
753 ### between this and colon
754 2 ▶ if ($self->{tokens} =~ /^$r_nameStartChar_minus_underscore/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^$r_nameStartChar_minus_underscore/) { } 2 0 2
755 2 return 1;
756 } else {
757 0 return 0;
758 }
759 }
760  
761 6 ▶sub _prefixName {
Subroutine _prefixName: called CC=2 SCAR=6.9
762 6 my $self = shift;
763 ### ( nameStartChar - '_' ) nameChar*
764 6 my @parts;
765 6 my $nsc = $self->_eat_re_save( $r_nameStartChar_minus_underscore );
766 6 push(@parts, $nsc);
767 # while ($self->_nameChar_test()) {
768 6 ▶ while ($self->{tokens} =~ /^$r_nameChar_test/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"} =~ /^$r_nameChar_test/) 18 6 24
769 18 my $nc = $self->_nameChar();
770 18 push(@parts, $nc);
771 }
772 6 return join('', @parts);
773 }
774  
775 8 ▶sub _relativeURI {
Subroutine _relativeURI: called CC=1 SCAR=0.0
776 8 my $self = shift;
777 ### ucharacter*
778 8 my $token = $self->_eat_re_save( $r_ucharacters );
779 8 return $token;
780 }
781  
782 2 ▶sub _quotedString_test {
Subroutine _quotedString_test: called CC=3 SCAR=15.1
783 2 my $self = shift;
784 2 ▶ if (substr($self->{tokens}, 0, 1) eq '"') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($self->{'tokens'}, 0, 1) eq '"') { } 2 0 2
elsif (substr($self->{'tokens'}, 0, 1) eq q[']) { } 0 0 0
785 2 return 1;
786 } elsif (substr($self->{tokens}, 0, 1) eq "'") {
787 0 return 1;
788 } else {
789 0 return 0;
790 }
791 }
792  
793 2 ▶sub _quotedString {
Subroutine _quotedString: called CC=2 SCAR=7.6
794 2 my $self = shift;
795 ### string | longString
796 2 ▶ if ($self->_longString_test()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_longString_test) { } 0 2 2
797 0 return $self->_longString();
798 } else {
799 2 return $self->_string();
800 }
801 }
802  
803 2 ▶sub _string {
Subroutine _string: called CC=2 SCAR=7.5
804 2 my $self = shift;
805 ### #x22 scharacter* #x22
806 2 my $value;
807 2 ▶ if ($self->__startswith( '"' )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__startswith('"')) { } 2 0 2
808 2 $self->_eat('"');
809 2 $value = $self->_eat_re_save( $r_scharacters );
810 2 $self->_eat('"');
811 } else {
812 0 $self->_eat("'");
813 0 $value = $self->_eat_re_save( $r_scharacters2 );
814 0 $self->_eat("'");
815 }
816 2 my $string = $self->_parse_short( $value );
817 2 return $string;
818 }
819  
820 2 ▶sub _longString_test {
Subroutine _longString_test: called CC=3 SCAR=13.3
821 2 my $self = shift;
822 2 ▶ if ($self->__startswith( '"""' )) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->__startswith('"""')) { } 0 2 2
elsif ($self->__startswith(q['''])) { } 0 2 2
823 0 return 1;
824 } elsif ($self->__startswith( "'''" )) {
825 0 return 1;
826 } else {
827 2 return 0;
828 }
829 }
830  
831 0 ▶sub _longString {
Subroutine _longString: not called CC=2 SCAR=17.9
832 0 my $self = shift;
833 # #x22 #x22 #x22 lcharacter* #x22 #x22 #x22
834 0 my $value;
835 0 ▶ if ($self->__startswith( '"""' )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__startswith('"""')) { } 0 0 0
836 0 $self->_eat('"""');
837 0 $value = $self->_eat_re_save( $r_lcharacters );
838 0 $self->_eat('"""');
839 } else {
840 0 $self->_eat("'''");
841 0 $value = $self->_eat_re_save( $r_lcharacters2 );
842 0 $self->_eat("'''");
843 }
844 0 my $string = $self->_parse_long( $value );
845 0 return $string;
846 }
847  
848 ################################################################################
849  
850 {
851 3 my %easy = (
852 q[\\] => qq[\\],
853 r => qq[\r],
854 n => qq[\n],
855 t => qq[\t],
856 q["] => qq["],
857 );
858
859 2 ▶ sub _parse_short {
Subroutine _parse_short: called CC=4 SCAR=20.7
860 2 my $self = shift;
861 2 my $s = shift;
862 2 ▶ return '' unless length($s);
Branch: 1 branch
BranchTrueFalseTotal
unless length $s 0 2 2
863  
864 2 $s =~ s{ \\ ( [\\tnr"] | u.{4} | U.{8} ) }{
865 0 ▶ if (exists $easy{$1})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $easy{$1}) { } 0 0 0
866 {
867 0 $easy{$1};
868 }
869 else
870 {
871 0 my $hex = substr($1, 1);
872 0 ▶ die "invalid hexadecimal escape: $hex"
Branch: 1 branch
BranchTrueFalseTotal
unless $hex =~ /^[0-9A-Fa-f]+$/ 0 0 0
873 unless $hex =~ m{^[0-9A-Fa-f]+$};
874 0 chr(hex($hex));
875 }
876 }gex;
877
878 2 return $s;
879 }
880  
881 # they're the same
882 3 *_parse_long = \&_parse_short;
883 }
884  
885 0 ▶sub _join_uri {
Subroutine _join_uri: not called CC=2 SCAR=17.9
886 0 my $self = shift;
887 0 my $base = shift;
888 0 my $uri = shift;
889 0 ▶ if ($base eq $uri) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base eq $uri) 0 0 0
890 0 return $uri;
891 }
892 0 return URI->new_abs( $uri, $base );
893 }
894  
895 0 ▶sub _typed {
Subroutine _typed: not called CC=3 SCAR=24.8
896 0 my $self = shift;
897 0 my $value = shift;
898 0 my $type = shift;
899 0 my $datatype = $type->uri_value;
900
901 0 ▶ if ($datatype eq "${xsd}decimal") {
Branch: 1 branch
BranchTrueFalseTotal
if ($datatype eq "${xsd}decimal") 0 0 0
902 0 $value =~ s/[.]0+$//;
903 0 ▶ if ($value !~ /[.]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /[.]/) 0 0 0
904 0 $value = $value . '.0';
905 }
906 }
907
908 0 return $self->__Literal($value, undef, $datatype)
909 }
910  
911 0 ▶sub __anonimize_bnode_id {
Subroutine __anonimize_bnode_id: not called CC=2 SCAR=17.9
912 0 my $self = shift;
913 0 my $id = shift;
914 0 ▶ if (my $aid = $self->{ bnode_map }{ $id }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $aid = $self->{'bnode_map'}{$id}) { } 0 0 0
915 0 return $aid;
916 } else {
917 0 my $aid = $self->__generate_bnode_id;
918 0 $self->{ bnode_map }{ $id } = $aid;
919 0 return $aid;
920 }
921 }
922  
923 0 ▶sub __generate_bnode_id {
Subroutine __generate_bnode_id: not called CC=1 SCAR=6.9
924 0 my $self = shift;
925 0 my $id = $self->{ bnode_id }++;
926 0 return 'r' . $self->{bnode_prefix} . 'r' . $id;
927 }
928  
929 54 ▶sub __consume_ws {
Subroutine __consume_ws: called CC=2 SCAR=6.9
930 54 my $self = shift;
931 54 ▶ while ($self->{tokens} =~ m/^[\t\r\n #]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"} =~ /^[\t\r\n #]/) 30 54 84
932 30 $self->_ws()
933 }
934 }
935  
936 11 ▶sub __URI {
Subroutine __URI: called CC=1 SCAR=0.0
937 11 my $self = shift;
938 11 my $uri = shift;
939 11 my $base = shift;
940 11 return RDF::Trine::Node::Resource->new( $uri, $base )
941 }
942  
943 0 ▶sub __bNode {
Subroutine __bNode: not called CC=1 SCAR=6.9
944 0 my $self = shift;
945 0 return RDF::Trine::Node::Blank->new( @_ )
946 }
947  
948 3 ▶sub __Literal {
Subroutine __Literal: called CC=6 SCAR=24.5
949 3 my $self = shift;
950 3 my $lit = RDF::Trine::Node::Literal->new( @_ );
951
952 3 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
953 3 ▶ if (!$self->{suspend_callback}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"suspend_callback"} and $lit->has_datatype and my $code = $self->{"datatype_callback"}{$lit->literal_datatype}) 0 3 3
Condition66%4/6
not $self->{"suspend_callback"} and $lit->has_datatype and my $code = $self->{"datatype_callback"}{$lit->literal_datatype}
!ll&&!rl&&r
210
not $self->{"suspend_callback"} and $lit->has_datatype
!ll&&!rl&&r
021
MC/DC0%0/3
not $self->{"suspend_callback"} and $lit->has_datatype and my $code = $self->{"datatype_callback"}{$lit->literal_datatype}
not $self->{"suspend_callback"} $lit->has_datatype my $code = $self->{"datatype_callback"}{$lit->literal_datatype}
Truth table50%2/4
not(A) and B and C
A= not $self->{"suspend_callback"}B= $lit->has_datatypeC= my $code = $self->{"datatype_callback"}{$lit->literal_datatype}
ABCresult
0XX0
10X0
1100
1111
954 and $lit->has_datatype
955 and my $code = $self->{datatype_callback}{$lit->literal_datatype})
956 {
957 0 ▶ my $triple_callback = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
958 0 my ($s, $p, $o) = shift->nodes;
959 0 $self->_triple($s, $p, $o);
960 0 };
961 0 my $return = $code->($lit, $triple_callback);
962 0 ▶ if (blessed $return and $return->isa('RDF::Trine::Node'))
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($return) and $return->isa("RDF::Trine::Node")) 0 0 0
Condition0%0/3
builtin::blessed($return) and $return->isa("RDF::Trine::Node")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($return) and $return->isa("RDF::Trine::Node")
builtin::blessed($return) $return->isa("RDF::Trine::Node")
Truth table0%0/3
A and B
A= builtin::blessed($return)B= $return->isa("RDF::Trine::Node")
ABresult
0X0
100
111
963 {
964 0 return $return;
965 }
966 }
967
968 3 return $lit;
969 }
970  
971 47 ▶sub __startswith {
Subroutine __startswith: called CC=2 SCAR=6.9
972 47 my $self = shift;
973 47 my $thing = shift;
974 47 ▶ if (substr($self->{tokens}, 0, length($thing)) eq $thing) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->{'tokens'}, 0, length $thing) eq $thing) { } 15 32 47
975 15 return 1;
976 } else {
977 32 return 0;
978 }
979 }
980  
981 0 ▶sub _unescape {
Subroutine _unescape: not called CC=7 SCAR=40.3
982 0 my $str = shift;
983 0 my @chars = split(//, $str);
984 0 my $us = '';
985 0 ▶ while(defined(my $char = shift(@chars))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $char = shift @chars)) 0 0 0
986 0 ▶ if($char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq '\\') { } 0 0 0
987 0 ▶ if(($char = shift(@chars)) eq 'u') {
Branch: 1 branch
BranchTrueFalseTotal
if (($char = shift @chars) eq 'u') { } 0 0 0
988 0 my $i = 0;
989 0 ▶ for(; $i < 4; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 4) 0 0 0
990 0 ▶ unless($chars[$i] =~ /[0-9a-fA-F]/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($chars[$i] =~ /[0-9a-fA-F]/) 0 0 0
991 0 last;
992 }
993 }
994 0 ▶ if($i == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 4) { } 0 0 0
995 0 my $hex = join('', splice(@chars, 0, 4));
996 0 my $cp = hex($hex);
997 0 my $char = chr($cp);
998 0 $us .= $char;
999 }
1000 else {
1001 0 $us .= 'u';
1002 }
1003 }
1004 else {
1005 0 $us .= '\\' . $char;
1006 }
1007 }
1008 else {
1009 0 $us .= $char;
1010 }
1011 }
1012 0 return $us;
1013 }
1014  
1015  
1016 1 ▶sub _keywords_test {
Subroutine _keywords_test: called CC=1 SCAR=0.0
1017 1 my $self = shift;
1018 1 return $self->__startswith('@keywords');
1019 }
1020  
1021 1 ▶sub _keywords {
Subroutine _keywords: called CC=2 SCAR=6.9
1022 1 my $self = shift;
1023
1024 1 $self->_eat('@keywords');
1025 1 $self->_ws();
1026 1 $self->__consume_ws();
1027
1028 1 my @kw;
1029 1 push @kw, $self->_name();
1030 1 $self->__consume_ws();
1031
1032 1 ▶ while (! $self->_test('.')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test(".")) 2 1 3
1033 2 $self->_eat(',');
1034 2 $self->__consume_ws();
1035 2 push @kw, $self->_name();
1036 2 $self->__consume_ws();
1037 }
1038
1039 1 $self->{'keywords'} = \@kw;
1040 1 return @kw;
1041 }
1042  
1043 1 ▶sub _quantifier_test {
Subroutine _quantifier_test: called CC=2 SCAR=8.1
1044 1 my $self = shift;
1045 1 ▶ return $self->__startswith('@forAll') || $self->__startswith('@forSome');
Condition33%1/3
$self->__startswith('@forAll') || $self->__startswith('@forSome')
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->__startswith('@forAll') || $self->__startswith('@forSome')
$self->__startswith('@forAll') $self->__startswith('@forSome')
Truth table33%1/3
A || B
A= $self->__startswith('@forAll')B= $self->__startswith('@forSome')
ABresult
1X1
011
000
1046 }
1047  
1048 0 ▶sub _quantifier {
Subroutine _quantifier: not called CC=5 SCAR=34.0
1049 0 my $self = shift;
1050
1051 0 my $quantifier;
1052 0 ▶ if ($self->_test('@forSome')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test('@forSome')) { } 0 0 0
1053 0 $quantifier = 'forSome';
1054 0 $self->_eat('@forSome');
1055 0 $self->_ws();
1056 0 $self->__consume_ws();
1057 } else {
1058 0 $quantifier = 'forAll';
1059 0 $self->_eat('@forAll');
1060 0 $self->_ws();
1061 0 $self->__consume_ws();
1062 }
1063
1064 0 my @terms;
1065 0 push @terms, $self->_resource();
1066 0 $self->__consume_ws();
1067
1068 0 ▶ while (! $self->_test('.')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test(".")) 0 0 0
1069 0 $self->_eat(',');
1070 0 $self->__consume_ws();
1071 0 push @terms, $self->_resource();
1072 0 $self->__consume_ws();
1073 }
1074
1075 0 my $code = $self->{'handle_'.lc $quantifier};
1076 0 ▶ if (ref $code eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $code eq 'CODE') { } 0 0 0
1077 0 foreach my $resource (@terms) {
1078 0 $code->($resource);
1079 }
1080 } else {
1081 0 warn "Encountered \@${quantifier} but no handler set up";
1082 }
1083
1084 0 return { $quantifier => [@terms] };
1085 }
1086  
1087 0 ▶sub forAll {
Subroutine forAll: not called CC=2 SCAR=17.9
Pod documented
1088 0 my $self = shift;
1089 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1090 0 $self->{handle_forall} = shift;
1091 }
1092 0 return $self->{handle_forall};
1093 }
1094  
1095 0 ▶sub forSome {
Subroutine forSome: not called CC=2 SCAR=17.9
Pod documented
1096 0 my $self = shift;
1097 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1098 0 $self->{handle_forsome} = shift;
1099 }
1100 0 return $self->{handle_forsome};
1101 }
1102  
1103  
1104 9 ▶sub _predicateObjectList {
Subroutine _predicateObjectList: called CC=11 SCAR=39.5
1105 9 my $self = shift;
1106
1107 9 ▶ if ($self->{'tokens'} =~ /^is\b/)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^is\b/) { } 0 9 9
elsif ($self->{'tokens'} =~ /^has\b/ and grep {$_ eq 'has';} @{$$self{'keywords'};}) { } 0 18 18
1108 {
1109 0 $self->_eat('is');
1110 0 $self->__consume_ws;
1111 }
1112 ▶ elsif ($self->{'tokens'} =~ /^has\b/
Condition33%1/3
$self->{"tokens"} =~ /^has\b/ and grep {$_ eq "has";} @{$$self{"keywords"};}
!ll&&!rl&&r
900
MC/DC0%0/2
$self->{"tokens"} =~ /^has\b/ and grep {$_ eq "has";} @{$$self{"keywords"};}
$self->{"tokens"} =~ /^has\b/ grep {$_ eq "has";} @{$$self{"keywords"};}
Truth table33%1/3
A and B
A= $self->{"tokens"} =~ /^has\b/B= grep {$_ eq "has";} @{$$self{"keywords"};}
ABresult
0X0
100
111
1113 0 and grep {$_ eq 'has'} @{$self->{'keywords'}})
1114 {
1115 0 $self->_eat('has');
1116 0 $self->__consume_ws;
1117 }
1118
1119 9 my ($pred, $reverse) = @{ $self->_verb() };
1120 9 $self->_ws();
1121 9 $self->__consume_ws();
1122
1123 9 ▶ if ($self->{'tokens'} =~ /^of\b/)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"} =~ /^of\b/) 0 9 9
1124 {
1125 0 $reverse = !$reverse;
1126 0 $self->_eat('of');
1127 0 $self->__consume_ws;
1128 }
1129
1130 9 my @list;
1131 9 foreach my $objt ($self->_objectList()) {
1132 9 push(@list, [$pred, $objt, $reverse]);
1133 }
1134
1135 9 ▶ while ($self->{tokens} =~ m/^[\t\r\n #]*;/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"} =~ /^[\t\r\n #]*;/) 0 9 9
1136 0 $self->__consume_ws();
1137 0 $self->_eat(';');
1138 0 $self->__consume_ws();
1139 0 ▶ if ($self->_verb_test()) { # @@
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_verb_test) { } 0 0 0
1140 0 ▶ if ($self->{'tokens'} =~ /^is\b/)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"} =~ /^is\b/) 0 0 0
1141 {
1142 0 $self->_eat('is');
1143 0 $self->__consume_ws;
1144 }
1145 0 my ($pred, $reverse) = @{ $self->_verb() };
1146 0 $self->_ws();
1147 0 $self->__consume_ws();
1148 0 ▶ if ($self->{'tokens'} =~ /^of\b/)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"} =~ /^of\b/) 0 0 0
1149 {
1150 0 $reverse = !$reverse;
1151 0 $self->_eat('of');
1152 0 $self->__consume_ws;
1153 }
1154 0 foreach my $objt ($self->_objectList()) {
1155 0 push(@list, [$pred, $objt, $reverse]);
1156 }
1157 } else {
1158 last
1159 0 }
1160 }
1161
1162 9 return @list;
1163 }
1164  
1165 # Notation 3 allows keywords to be treated as resources in the default namespace... sometimes.
1166 40 ▶sub _resource_test {
Subroutine _resource_test: called CC=7 SCAR=19.7
1167 40 my $self = shift;
1168 40 ▶ return 0 unless (length($self->{tokens}));
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"tokens"} 0 40 40
1169 40 ▶ return 0 if $self->{tokens} =~ m/^(true|false)\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"tokens"} =~ /^(true|false)\b/ 0 40 40
1170 40 ▶ if ($self->{tokens} =~ m/^${r_resource_test}/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^$r_resource_test/) { } 11 29 40
elsif (defined $self->{'keywords'} and $self->{'tokens'} =~ /^$r_prefixName/ and not $self->{'tokens'} =~ /^$r_qname/) { } 2 27 29
1171 11 return 1;
1172 ▶ } elsif (defined $self->{'keywords'}
Condition83%5/6
defined $self->{"keywords"} and $self->{"tokens"} =~ /^$r_prefixName/ and not $self->{"tokens"} =~ /^$r_qname/
!ll&&!rl&&r
2702
defined $self->{"keywords"} and $self->{"tokens"} =~ /^$r_prefixName/
!ll&&!rl&&r
2432
MC/DC66%2/3
defined $self->{"keywords"} and $self->{"tokens"} =~ /^$r_prefixName/ and not $self->{"tokens"} =~ /^$r_qname/
defined $self->{"keywords"} $self->{"tokens"} =~ /^$r_prefixName/ not $self->{"tokens"} =~ /^$r_qname/
Truth table75%3/4
A and B and not(C)
A= defined $self->{"keywords"}B= $self->{"tokens"} =~ /^$r_prefixName/C= not $self->{"tokens"} =~ /^$r_qname/
ABCresult
0XX0
10X0
1100
1111
1173 && $self->{'tokens'} =~ m/^${r_prefixName}/
1174 && $self->{'tokens'} !~ m/^${r_qname}/) {
1175 2 return 1;
1176 } else {
1177 27 return 0;
1178 }
1179 }
1180  
1181 9 ▶sub _resource {
Subroutine _resource: called CC=6 SCAR=25.0
1182 9 my $self = shift;
1183 9 ▶ if ($self->_uriref_test()) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_uriref_test) { } 4 5 9
elsif (defined $self->{'keywords'} and $self->{'tokens'} =~ /^$r_prefixName/ and not $self->{'tokens'} =~ /^$r_qname/) { } 0 5 5
1184 4 return $self->__URI($self->_uriref(), $self->{baseURI});
1185 ▶ } elsif (defined $self->{'keywords'}
Condition50%3/6
defined $self->{"keywords"} and $self->{"tokens"} =~ /^$r_prefixName/ and not $self->{"tokens"} =~ /^$r_qname/
!ll&&!rl&&r
500
defined $self->{"keywords"} and $self->{"tokens"} =~ /^$r_prefixName/
!ll&&!rl&&r
410
MC/DC0%0/3
defined $self->{"keywords"} and $self->{"tokens"} =~ /^$r_prefixName/ and not $self->{"tokens"} =~ /^$r_qname/
defined $self->{"keywords"} $self->{"tokens"} =~ /^$r_prefixName/ not $self->{"tokens"} =~ /^$r_qname/
Truth table50%2/4
A and B and not(C)
A= defined $self->{"keywords"}B= $self->{"tokens"} =~ /^$r_prefixName/C= not $self->{"tokens"} =~ /^$r_qname/
ABCresult
0XX0
10X0
1100
1111
1186 && $self->{'tokens'} =~ m/^${r_prefixName}/
1187 && $self->{'tokens'} !~ m/^${r_qname}/) {
1188 0 my $name = $self->_name();
1189 0 ▶ if (grep { lc $name eq lc $_ } @{$self->{'keywords'}})
Branch: 1 branch
BranchTrueFalseTotal
if (grep {lc $name eq lc $_;} @{$$self{"keywords"};}) 0 0 0
1190 {
1191 0 throw RDF::Trine::Error::ParserError -text => "Unexpected keyword: $name.";
1192 }
1193 0 $self->{tokens} = ':'.$name.$self->{tokens}; # cheat!
1194 0 my $qname = $self->_qname();
1195 0 my $base = $self->{baseURI};
1196 0 return $self->__URI($qname, $base);
1197 } else {
1198 5 my $qname = $self->_qname();
1199 5 my $base = $self->{baseURI};
1200 5 return $self->__URI($qname, $base);
1201 }
1202 }
1203  
1204 # What do I mean by "any node"?.
1205 22 ▶sub _any_node {
Subroutine _any_node: called CC=11 SCAR=33.8
1206 22 my $self = shift;
1207 22 my $ignore_paths = shift;
1208
1209 22 my $node;
1210 22 ▶ if (length($self->{tokens}) and $self->_resource_test()) {
Branch: 4 branches
BranchTrueFalseTotal
if (length $self->{'tokens'} and $self->_resource_test) { } 12 10 22
elsif ($self->_blank_test) { } 0 10 10
elsif ($self->_formula_test) { } 4 6 10
elsif ($self->_variable_test) { } 6 0 6
Condition66%2/3
length $self->{"tokens"} and $self->_resource_test
!ll&&!rl&&r
01012
MC/DC50%1/2
length $self->{"tokens"} and $self->_resource_test
length $self->{"tokens"} $self->_resource_test
Truth table66%2/3
A and B
A= length $self->{"tokens"}B= $self->_resource_test
ABresult
0X0
100
111
1211 12 $node = $self->_resource();
1212 } elsif ($self->_blank_test()) {
1213 0 $node = $self->_blank();
1214 } elsif ($self->_formula_test()) {
1215 4 $node = $self->_formula();
1216 } elsif ($self->_variable_test()) {
1217 6 $node = $self->_variable();
1218 } else {
1219 0 $node = $self->_literal();
1220 }
1221
1222 22 ▶ return $node if $ignore_paths;
Branch: 1 branch
BranchTrueFalseTotal
if $ignore_paths 0 22 22
1223
1224 22 ▶ while ($self->_test('^') || $self->_test('!')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_test("^") or $self->_test("!")) 0 22 22
Condition33%1/3
$self->_test("^") or $self->_test("!")
l!l&&r!l&&!r
0022
MC/DC0%0/2
$self->_test("^") or $self->_test("!")
$self->_test("^") $self->_test("!")
Truth table33%1/3
A or B
A= $self->_test("^")B= $self->_test("!")
ABresult
1X1
011
000
1225 0 ▶ if ($self->_test('^')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_test('^')) { } 0 0 0
elsif ($self->_test('!')) { } 0 0 0
1226 0 $self->_eat('^');
1227 0 my $pred = $self->_predicate(1);
1228 0 my $subj = $self->__bNode( $self->__generate_bnode_id() );
1229 0 $self->_triple( $subj, $pred, $node );
1230 0 $node = $subj;
1231 } elsif ($self->_test('!')) {
1232 0 $self->_eat('!');
1233 0 my $pred = $self->_predicate(1);
1234 0 my $objt = $self->__bNode( $self->__generate_bnode_id() );
1235 0 $self->_triple( $node, $pred, $objt );
1236 0 $node = $objt;
1237 }
1238 }
1239
1240 22 return $node;
1241 }
1242  
1243 3 *_subject = \&_any_node;
1244 3 *_predicate = \&_any_node;
1245 3 *_object = \&_any_node;
1246  
1247 # Support variables
1248 20 ▶sub _variable_test {
Subroutine _variable_test: called CC=1 SCAR=0.0
1249 20 my $self = shift;
1250 20 return $self->{'tokens'} =~ /^\?/;
1251 }
1252  
1253 6 ▶sub _variable {
Subroutine _variable: called CC=1 SCAR=0.0
1254 6 my $self = shift;
1255 6 $self->_eat('?');
1256 6 return RDF::Trine::Node::Variable->new( $self->_name() );
1257 }
1258  
1259 # Support formulae
1260 12 ▶sub _formula_test {
Subroutine _formula_test: called CC=1 SCAR=0.0
1261 12 my $self = shift;
1262 12 return $self->{'tokens'} =~ /^\{/;
1263 }
1264  
1265 6 ▶sub _formula {
Subroutine _formula: called CC=9 SCAR=23.7
1266 6 my $self = shift;
1267
1268 # blank node identifiers don't carry into formulae.
1269 6 my $uuid = Data::UUID->new->create_str;
1270 6 $uuid =~ s/-//g;
1271 6 local($self->{bnode_prefix}) = 'G'. $uuid;
1272 6 local($self->{bnode_map}) = {};
1273 6 local($self->{bnode_id}) = 0;
1274  
1275 # Formula pragmata is a clone of current pragmata, so that it can't leak.
1276 6 ▶ my %old_pragmata = %{ $self->{pragmata} || {} };
Condition50%1/2
$self->{'pragmata'} || {}
l!l
06
MC/DC0%0/1
$self->{'pragmata'} || {}
$self->{'pragmata'}
Truth table50%1/2
A
A= $self->{'pragmata'}
Aresult
11
00
1277 6 local($self->{pragmata}) = { %old_pragmata };
1278  
1279 # divert triples inside the formula into @triples.
1280 6 my @triples;
1281 my @forAll;
1282 6 my @forSome;
1283 6 ▶ local($self->{handle_triple}) = sub { push @triples, $_[0]; };
Subroutine __ANON__: called CC=1 SCAR=0.0
1284 0 ▶ local($self->{handle_forsome}) = sub { push @forSome, $_[0]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1285 0 ▶ local($self->{handle_forall}) = sub { push @forAll, $_[0]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1286
1287 6 $self->_eat('{');
1288
1289 6 ▶ while (!$self->_test('}'))
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test("}")) 6 6 12
1290 {
1291 6 $self->__consume_ws;
1292
1293 STATEMENTLIST:
1294 6 ▶ while ($self->_triples_test || $self->_directive_test())
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_triples_test or $self->_directive_test) 6 0 6
Condition33%1/3
$self->_triples_test or $self->_directive_test
l!l&&r!l&&!r
600
MC/DC0%0/2
$self->_triples_test or $self->_directive_test
$self->_triples_test $self->_directive_test
Truth table33%1/3
A or B
A= $self->_triples_testB= $self->_directive_test
ABresult
1X1
011
000
1295 {
1296 6 ▶ if ($self->_triples_test)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_triples_test) { } 6 0 6
1297 {
1298 6 $self->_triples;
1299 6 $self->__consume_ws;
1300 }
1301 else
1302 {
1303 0 $self->_directive();
1304 0 $self->__consume_ws();
1305 }
1306
1307 6 ▶ if ($self->_test('.'))
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_test('.')) { } 6 0 6
elsif ($self->_test('}')) { } 0 0 0
1308 {
1309 6 $self->_eat('.');
1310 6 $self->__consume_ws;
1311 6 ▶ last STATEMENTLIST if $self->_test('}');
Branch: 1 branch
BranchTrueFalseTotal
if $self->_test("}") 6 0 6
1312 }
1313 elsif ($self->_test('}'))
1314 {
1315 0 last STATEMENTLIST;
1316 }
1317 else
1318 {
1319 0 throw RDF::Trine::Error::ParserError -text => "Unexpected content in formula: ".$self->{tokens};
1320 }
1321 }
1322 }
1323 6 $self->_eat('}');
1324
1325 # return a formula. can it really be that easy?
1326 #warn Dumper([@triples]) . " being saved as a Formula\n";
1327 6 my $formula = RDF::Trine::Node::Formula->new( RDF::Trine::Pattern->new(@triples) );
1328 #warn Dumper($formula);
1329 6 $formula->[3] = \@forAll;
1330 6 $formula->[4] = \@forSome;
1331 6 return $formula;
1332 }
1333  
1334 2 ▶sub parse_formula {
Subroutine parse_formula: called CC=1 SCAR=0.0
Pod documented
1335 2 my $self = shift;
1336 2 my $uri = shift;
1337 2 my $input = shift;
1338
1339 2 local($self->{baseURI}) = $uri;
1340 2 local($self->{tokens}) = "{ ".$input." }";
1341
1342 2 return $self->_formula;
1343 }
1344  
1345 3 1;
1346  
1347 __END__
« Trine/Parser/ShorthandRDF.pm ↑ Summary Trine/Serializer/Notation3.pm »