Trine/Parser/ShorthandRDF.pm

filter: Statementstmt 66.5% 177 / 266 Branchbran 50.0% 47 / 94 Conditioncond 37.1% 26 / 70 MC/DCmcdc 18.9% 7 / 37 Subroutinesub 86.1% 31 / 36 Podpod n/a totaltotal 57.2% 288 / 503 CC 81 SCAR 38.7
CC
81
Cov
58%
_triple
215.1
_apply_profile
30.0
_at_profile
20.0
CRAP 48.0
↑ Summary Trine/Parser/Notation3.pm »
1 package RDF::Trine::Parser::ShorthandRDF;
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 3 ▶use base qw(RDF::Trine::Parser::Notation3);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use RDF::Trine qw(literal);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use RDF::Trine::Statement;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use RDF::Trine::Namespace;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use RDF::Trine::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use RDF::Trine::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Scalar::Util qw(blessed looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 our ($VERSION, $AUTHORITY);
18  
19 BEGIN
20 3 ▶{
Subroutine BEGIN: called CC=5 SCAR=16.1
21 3 $VERSION = '0.206';
22 3 $AUTHORITY = 'cpan:TOBYINK';
23
24 3 my $class = __PACKAGE__;
25 3 $RDF::Trine::Parser::encodings{$class } = 'utf8';
26 3 $RDF::Trine::Parser::canonical_media_types{ $class } = 'text/x.shorthand-rdf';
27
28 $RDF::Trine::Parser::parser_names{$_} = __PACKAGE__
29 3 foreach ('shorthand', 'shorthandrdf');
30
31 $RDF::Trine::Parser::media_types{$_} = __PACKAGE__
32 3 foreach qw(text/x.shorthand-rdf text/x-shorthand-rdf);
33
34 $RDF::Trine::Parser::file_extensions{$_} = __PACKAGE__
35 3 foreach qw(n3x);
36  
37 $RDF::Trine::Parser::format_uris{$_} = __PACKAGE__
38 3 foreach ('http://buzzword.org.uk/2010/n3x');
39 }
40  
41 # Force the default prefix to be bound to the base URI.
42 1 ▶sub _Document {
Subroutine _Document: called CC=4 SCAR=14.5
43 1 my $self = shift;
44 1 my $uri = $self->{'baseURI'};
45 1 $self->{bindings} = {};
46 1 ▶ $self->{bindings}{''} = ($uri =~ /#$/ ? $uri : "${uri}#");
Branch: 1 branch
BranchTrueFalseTotal
$uri =~ /#$/ ? : 0 1 1
47 1 $self->{keywords} = undef;
48 1 $self->{shorthands} = [];
49 1 $self->{pragmata} = {};
50 $self->_apply_profile($self->{baseURI}, $self->{profile}, 0)
51 1 ▶ if defined $self->{profile} && length $self->{profile};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"profile"} and length $self->{"profile"} 0 1 1
Condition33%1/3
defined $self->{"profile"} and length $self->{"profile"}
!ll&&!rl&&r
100
MC/DC0%0/2
defined $self->{"profile"} and length $self->{"profile"}
defined $self->{"profile"} length $self->{"profile"}
Truth table33%1/3
A and B
A= defined $self->{"profile"}B= length $self->{"profile"}
ABresult
0X0
100
111
52 1 $self->SUPER::_Document(@_);
53 }
54  
55 1 ▶sub _triple {
Subroutine _triple: called CC=22 SCAR=53.7
56 1 my ($self, $s, $p, $o) = @_;
57
58 1 ▶ if (defined $self->{pragmata}{rdf}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"pragmata"}{"rdf"} and $self->{"pragmata"}{"rdf"}->is_literal and lc $self->{"pragmata"}{"rdf"}->literal_value eq "true") 0 1 1
Condition33%2/6
defined $self->{"pragmata"}{"rdf"} and $self->{"pragmata"}{"rdf"}->is_literal and lc $self->{"pragmata"}{"rdf"}->literal_value eq "true"
!ll&&!rl&&r
100
defined $self->{"pragmata"}{"rdf"} and $self->{"pragmata"}{"rdf"}->is_literal
!ll&&!rl&&r
100
MC/DC0%0/3
defined $self->{"pragmata"}{"rdf"} and $self->{"pragmata"}{"rdf"}->is_literal and lc $self->{"pragmata"}{"rdf"}->literal_value eq "true"
defined $self->{"pragmata"}{"rdf"} $self->{"pragmata"}{"rdf"}->is_literal lc $self->{"pragmata"}{"rdf"}->literal_value eq "true"
Truth table25%1/4
A and B and C
A= defined $self->{"pragmata"}{"rdf"}B= $self->{"pragmata"}{"rdf"}->is_literalC= lc $self->{"pragmata"}{"rdf"}->literal_value eq "true"
ABCresult
0XX0
10X0
1100
1111
59 and $self->{pragmata}{rdf}->is_literal
60 and lc $self->{pragmata}{rdf}->literal_value eq 'true')
61 {
62 0 my $st = RDF::Trine::Statement->new($s, $p, $o);
63 0 ▶ throw RDF::Trine::Error::ParserError -text => ("Non-RDF triple in RDF-only mode: ".$st->sse)
Branch: 1 branch
BranchTrueFalseTotal
unless $st->rdf_compatible and not $o->isa("RDF::Trine::Node::Formula") 0 0 0
Condition0%0/3
$st->rdf_compatible and not $o->isa("RDF::Trine::Node::Formula")
!ll&&!rl&&r
000
MC/DC0%0/2
$st->rdf_compatible and not $o->isa("RDF::Trine::Node::Formula")
$st->rdf_compatible not $o->isa("RDF::Trine::Node::Formula")
Truth table0%0/3
A and not(B)
A= $st->rdf_compatibleB= not $o->isa("RDF::Trine::Node::Formula")
ABresult
0X0
100
111
64 unless $st->rdf_compatible && !$o->isa('RDF::Trine::Node::Formula');
65 }
66  
67 1 ▶ if (defined $self->{pragmata}{'blank-nodes'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"pragmata"}{"blank-nodes"} and $self->{"pragmata"}{"blank-nodes"}->is_literal and lc $self->{"pragmata"}{"blank-nodes"}->literal_value eq "false") 0 1 1
Condition33%2/6
defined $self->{"pragmata"}{"blank-nodes"} and $self->{"pragmata"}{"blank-nodes"}->is_literal and lc $self->{"pragmata"}{"blank-nodes"}->literal_value eq "false"
!ll&&!rl&&r
100
defined $self->{"pragmata"}{"blank-nodes"} and $self->{"pragmata"}{"blank-nodes"}->is_literal
!ll&&!rl&&r
100
MC/DC0%0/3
defined $self->{"pragmata"}{"blank-nodes"} and $self->{"pragmata"}{"blank-nodes"}->is_literal and lc $self->{"pragmata"}{"blank-nodes"}->literal_value eq "false"
defined $self->{"pragmata"}{"blank-nodes"} $self->{"pragmata"}{"blank-nodes"}->is_literal lc $self->{"pragmata"}{"blank-nodes"}->literal_value eq "false"
Truth table25%1/4
A and B and C
A= defined $self->{"pragmata"}{"blank-nodes"}B= $self->{"pragmata"}{"blank-nodes"}->is_literalC= lc $self->{"pragmata"}{"blank-nodes"}->literal_value eq "false"
ABCresult
0XX0
10X0
1100
1111
68 and $self->{pragmata}{'blank-nodes'}->is_literal
69 and lc $self->{pragmata}{'blank-nodes'}->literal_value eq 'false')
70 {
71 0 my $st = RDF::Trine::Statement->new($s, $p, $o);
72 throw RDF::Trine::Error::ParserError -text => ("Blank node found: ".$st->sse)
73 0 ▶ if grep { $_->is_blank } ($s, $p, $o);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->is_blank;} $s, $p, $o 0 0 0
74 }
75  
76 1 ▶ if (defined $self->{pragmata}{trig}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"pragmata"}{"trig"} and $self->{"pragmata"}{"trig"}->is_literal and lc $self->{"pragmata"}{"trig"}->literal_value eq "true" and $s->is_resource and $p->is_resource and $p->uri eq "http://www.w3.org/2002/07/owl#sameAs" and $o->isa("RDF::Trine::Node::Formula") and my $code = $self->{"handle_triple"}) 0 1 1
Condition33%7/21
defined $self->{"pragmata"}{"trig"} and $self->{"pragmata"}{"trig"}->is_literal and lc $self->{"pragmata"}{"trig"}->literal_value eq "true" and $s->is_resource and $p->is_resource and $p->uri eq "http://www.w3.org/2002/07/owl#sameAs" and $o->isa("RDF::Trine::Node::Formula") and my $code = $self->{"handle_triple"}
!ll&&!rl&&r
100
defined $self->{"pragmata"}{"trig"} and $self->{"pragmata"}{"trig"}->is_literal and lc $self->{"pragmata"}{"trig"}->literal_value eq "true" and $s->is_resource and $p->is_resource and $p->uri eq "http://www.w3.org/2002/07/owl#sameAs" and $o->isa("RDF::Trine::Node::Formula")
!ll&&!rl&&r
100
defined $self->{"pragmata"}{"trig"} and $self->{"pragmata"}{"trig"}->is_literal and lc $self->{"pragmata"}{"trig"}->literal_value eq "true" and $s->is_resource and $p->is_resource and $p->uri eq "http://www.w3.org/2002/07/owl#sameAs"
!ll&&!rl&&r
100
defined $self->{"pragmata"}{"trig"} and $self->{"pragmata"}{"trig"}->is_literal and lc $self->{"pragmata"}{"trig"}->literal_value eq "true" and $s->is_resource and $p->is_resource
!ll&&!rl&&r
100
defined $self->{"pragmata"}{"trig"} and $self->{"pragmata"}{"trig"}->is_literal and lc $self->{"pragmata"}{"trig"}->literal_value eq "true" and $s->is_resource
!ll&&!rl&&r
100
defined $self->{"pragmata"}{"trig"} and $self->{"pragmata"}{"trig"}->is_literal and lc $self->{"pragmata"}{"trig"}->literal_value eq "true"
!ll&&!rl&&r
100
defined $self->{"pragmata"}{"trig"} and $self->{"pragmata"}{"trig"}->is_literal
!ll&&!rl&&r
100
MC/DC0%0/8
defined $self->{"pragmata"}{"trig"} and $self->{"pragmata"}{"trig"}->is_literal and lc $self->{"pragmata"}{"trig"}->literal_value eq "true" and $s->is_resource and $p->is_resource and $p->uri eq "http://www.w3.org/2002/07/owl#sameAs" and $o->isa("RDF::Trine::Node::Formula") and my $code = $self->{"handle_triple"}
defined $self->{"pragmata"}{"trig"} $self->{"pragmata"}{"trig"}->is_literal lc $self->{"pragmata"}{"trig"}->literal_value eq "true" $s->is_resource $p->is_resource $p->uri eq "http://www.w3.org/2002/07/owl#sameAs" $o->isa("RDF::Trine::Node::Formula") my $code = $self->{"handle_triple"}
Truth table11%1/9
A and B and C and D and E and F and G and H
A= defined $self->{"pragmata"}{"trig"}B= $self->{"pragmata"}{"trig"}->is_literalC= lc $self->{"pragmata"}{"trig"}->literal_value eq "true"D= $s->is_resourceE= $p->is_resourceF= $p->uri eq "http://www.w3.org/2002/07/owl#sameAs"G= $o->isa("RDF::Trine::Node::Formula")H= my $code = $self->{"handle_triple"}
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
77 and $self->{pragmata}{trig}->is_literal
78 and lc $self->{pragmata}{trig}->literal_value eq 'true'
79 and $s->is_resource
80 and $p->is_resource
81 and $p->uri eq 'http://www.w3.org/2002/07/owl#sameAs'
82 and $o->isa('RDF::Trine::Node::Formula')
83 and (my $code = $self->{handle_triple}))
84 {
85 0 foreach my $st ($o->pattern->triples)
86 {
87 0 my ($S, $P, $O) = $st->nodes;
88
89 0 ▶ if ($self->{canonicalize}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"canonicalize"} and $O->isa("RDF::Trine::Node::Literal") and $O->has_datatype) 0 0 0
Condition0%0/6
$self->{"canonicalize"} and $O->isa("RDF::Trine::Node::Literal") and $O->has_datatype
!ll&&!rl&&r
000
$self->{"canonicalize"} and $O->isa("RDF::Trine::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"canonicalize"} and $O->isa("RDF::Trine::Node::Literal") and $O->has_datatype
$self->{"canonicalize"} $O->isa("RDF::Trine::Node::Literal") $O->has_datatype
Truth table0%0/4
A and B and C
A= $self->{"canonicalize"}B= $O->isa("RDF::Trine::Node::Literal")C= $O->has_datatype
ABCresult
0XX0
10X0
1100
1111
90 and $O->isa('RDF::Trine::Node::Literal')
91 and $O->has_datatype)
92 {
93 0 my $canon = RDF::Trine::Node::Literal->canonicalize_literal_value(
94 $O->literal_value, $O->literal_datatype, 1);
95 0 $O = RDF::Trine::Node::Literal->new($canon, undef, $O->literal_datatype);
96 }
97
98 0 my $quad = RDF::Trine::Statement::Quad->new($S, $P, $O, $s);
99 0 $code->($quad);
100 }
101
102 0 return;
103 }
104
105 1 $self->SUPER::_triple($s, $p, $o);
106 }
107  
108 28 ▶sub __consume_ws {
Subroutine __consume_ws: called CC=6 SCAR=25.9
109 28 my $self = shift;
110 28 ▶ BIT: while ($self->{tokens} =~ m/^[\t\r\n #]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"} =~ /^[\t\r\n #]/) 14 28 42
111 {
112 14 ▶ if ($self->{tokens} =~ m/^[#]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tokens"} =~ /^[#]/) 0 14 14
113 {
114 0 foreach my $shorthand ( reverse @{ $self->{shorthands} } )
115 {
116 0 my ($type, $pattern, $full, $basethen) = @$shorthand;
117 0 ▶ last BIT if ($type eq '@pattern' and $self->{tokens} =~ $pattern);
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "\@pattern" and $self->{"tokens"} =~ /$pattern/ 0 0 0
Condition0%0/3
$type eq "\@pattern" and $self->{"tokens"} =~ /$pattern/
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "\@pattern" and $self->{"tokens"} =~ /$pattern/
$type eq "\@pattern" $self->{"tokens"} =~ /$pattern/
Truth table0%0/3
A and B
A= $type eq "\@pattern"B= $self->{"tokens"} =~ /$pattern/
ABresult
0X0
100
111
118 }
119 }
120
121 14 $self->_ws();
122 }
123 }
124  
125  
126 5 ▶sub _directive_test {
Subroutine _directive_test: called CC=2 SCAR=6.9
127 5 my $self = shift;
128 5 ▶ if ($self->{tokens} =~ m/^\@(base|prefix|forSome|forAll|keywords|namepattern|dtpattern|pattern|term|profile|import|pragma)\b/io) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^\@(base|prefix|forSome|forAll|keywords|namepattern|dtpattern|pattern|term|profile|import|pragma)\b/io) { } 4 1 5
129 4 return 1;
130 } else {
131 1 return 0;
132 }
133 }
134  
135 # Shorthand-specific directives
136 4 ▶sub _directive {
Subroutine _directive: called CC=7 SCAR=21.0
137 4 my $self = shift;
138 4 ▶ if ($self->_at_pragma_test()) {
Branch: 6 branches
BranchTrueFalseTotal
if ($self->_at_pragma_test) { } 0 4 4
elsif ($self->_at_namepattern_test) { } 1 3 4
elsif ($self->_at_dtpattern_test) { } 1 2 3
elsif ($self->_at_term_test) { } 1 1 2
elsif ($self->_at_pattern_test) { } 0 1 1
elsif ($self->_at_profile_test) { } 0 1 1
139 0 $self->_at_pragma();
140 } elsif ($self->_at_namepattern_test()) {
141 1 $self->_at_namepattern();
142 } elsif ($self->_at_dtpattern_test()) {
143 1 $self->_at_dtpattern();
144 } elsif ($self->_at_term_test()) {
145 1 $self->_at_term();
146 } elsif ($self->_at_pattern_test()) {
147 0 $self->_at_pattern();
148 } elsif ($self->_at_profile_test()) {
149 0 $self->_at_profile();
150 } else {
151 1 $self->SUPER::_directive(@_);
152 }
153 }
154  
155 4 ▶sub _at_namepattern_test {
Subroutine _at_namepattern_test: called CC=1 SCAR=0.0
156 4 my $self = shift;
157 4 return $self->__startswith('@namepattern');
158 }
159  
160 3 ▶sub _at_dtpattern_test {
Subroutine _at_dtpattern_test: called CC=1 SCAR=0.0
161 3 my $self = shift;
162 3 return $self->__startswith('@dtpattern');
163 }
164  
165 2 ▶sub _at_term_test {
Subroutine _at_term_test: called CC=1 SCAR=0.0
166 2 my $self = shift;
167 2 return $self->__startswith('@term');
168 }
169  
170 4 ▶sub _at_pragma_test {
Subroutine _at_pragma_test: called CC=1 SCAR=0.0
171 4 my $self = shift;
172 4 return $self->__startswith('@pragma');
173 }
174  
175 1 ▶sub _at_pattern_test {
Subroutine _at_pattern_test: called CC=1 SCAR=0.0
176 1 my $self = shift;
177 1 return $self->__startswith('@pattern');
178 }
179  
180 1 ▶sub _at_profile_test {
Subroutine _at_profile_test: called CC=2 SCAR=8.1
181 1 my $self = shift;
182 1 ▶ return $self->__startswith('@profile') || $self->__startswith('@import');
Condition33%1/3
$self->__startswith('@profile') || $self->__startswith('@import')
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->__startswith('@profile') || $self->__startswith('@import')
$self->__startswith('@profile') $self->__startswith('@import')
Truth table33%1/3
A || B
A= $self->__startswith('@profile')B= $self->__startswith('@import')
ABresult
1X1
011
000
183 }
184  
185 1 ▶sub _at_namepattern {
Subroutine _at_namepattern: called CC=1 SCAR=0.0
186 1 my $self = shift;
187
188 1 $self->_eat('@namepattern');
189 1 $self->_ws();
190 1 $self->__consume_ws();
191
192 1 my $pattern = $self->_literal()->literal_value;
193 1 $self->__consume_ws();
194
195 1 my $uri = $self->_uriref();
196 1 $self->__consume_ws();
197  
198 1 push @{ $self->{shorthands} }, ['@pattern', qr/^($pattern)/, RDF::Trine::Node::Resource->new($uri.'$0'), $self->{baseURI}];
199 1 return $self->{shorthands}[-1];
200 }
201  
202 0 ▶sub _at_pattern {
Subroutine _at_pattern: not called CC=2 SCAR=17.9
203 0 my $self = shift;
204
205 0 $self->_eat('@pattern');
206 0 $self->_ws();
207 0 $self->__consume_ws();
208
209 0 my $pattern = $self->_literal()->literal_value;
210 0 $self->__consume_ws();
211
212 0 my $thing;
213 0 local($self->{suspend_callback}) = 1;
214 0 ▶ if ($self->_resource_test)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_resource_test) { } 0 0 0
215 0 { $thing = $self->_resource(); }
216 else
217 0 { $thing = $self->_literal(); }
218 0 $self->__consume_ws();
219  
220 0 push @{ $self->{shorthands} }, ['@pattern', qr/^($pattern)/, $thing, $self->{baseURI}];
221 0 return $self->{shorthands}[-1];
222 }
223  
224 1 ▶sub _at_dtpattern {
Subroutine _at_dtpattern: called CC=1 SCAR=0.0
225 1 my $self = shift;
226
227 1 $self->_eat('@dtpattern');
228 1 $self->_ws();
229 1 $self->__consume_ws();
230
231 1 my $pattern = $self->_literal()->literal_value;
232 1 $self->__consume_ws();
233
234 1 my $uri = $self->_uriref();
235 1 $self->__consume_ws();
236  
237 1 push @{ $self->{shorthands} }, ['@pattern', qr/^($pattern)/, RDF::Trine::Node::Literal->new('$0', undef, $uri), $self->{baseURI}];
238 1 return $self->{shorthands}[-1];
239 }
240  
241 1 ▶sub _at_term {
Subroutine _at_term: called CC=2 SCAR=7.0
242 1 my $self = shift;
243
244 1 $self->_eat('@term');
245 1 $self->_ws();
246 1 $self->__consume_ws();
247
248 1 my $token;
249
250 1 ▶ if ( $self->{'tokens'} =~ m/^([A-Za-z_][A-Za-z0-9_-]*)\s/o )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^([A-Za-z_][A-Za-z0-9_-]*)\s/o) { } 1 0 1
251 {
252 1 $token = $1;
253 1 $self->_eat($token);
254 }
255 else
256 {
257 0 $self->_eat('token_name'); # and die!
258 }
259 1 $self->__consume_ws();
260  
261 1 local($self->{suspend_callback}) = 1;
262 1 my $thing = $self->_any_node();
263 1 $self->__consume_ws();
264  
265 1 push @{ $self->{shorthands} }, ['@term', $token, $thing];
266 1 return $self->{shorthands}[-1];
267 }
268  
269 0 ▶sub _at_pragma {
Subroutine _at_pragma: not called CC=2 SCAR=17.9
270 0 my $self = shift;
271
272 0 $self->_eat('@pragma');
273 0 $self->_ws();
274 0 $self->__consume_ws();
275
276 0 my $token;
277
278 0 ▶ if ( $self->{'tokens'} =~ m/^([A-Za-z_][A-Za-z0-9_-]*)\s/o )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'tokens'} =~ /^([A-Za-z_][A-Za-z0-9_-]*)\s/o) { } 0 0 0
279 {
280 0 $token = $1;
281 0 $self->_eat($token);
282 }
283 else
284 {
285 0 $self->_eat('token_name'); # and die!
286 }
287 0 $self->__consume_ws();
288  
289 0 local($self->{suspend_callback}) = 1;
290 0 my $value = $self->_any_node();
291 0 $self->__consume_ws();
292  
293 0 return $self->{pragmata}{$token} = $value;
294 }
295  
296 0 ▶sub _at_profile {
Subroutine _at_profile: not called CC=4 SCAR=30.0
297 0 my $self = shift;
298
299 0 my $import = 0;
300 0 ▶ if ($self->__startswith('@profile'))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__startswith('@profile')) { } 0 0 0
301 0 { $self->_eat('@profile'); }
302 else
303 0 { $self->_eat('@import'); $import++; }
304
305 0 $self->_ws();
306 0 $self->__consume_ws();
307
308 0 my $url = $self->_uriref();
309 0 $self->__consume_ws();
310
311 0 $url = $self->__URI($url, $self->{baseURI})->uri;
312
313 $self->{handle_triple}->(RDF::Trine::Statement->new(
314 0 ▶ $self->__URI('', $self->{baseURI}),
Branch: 1 branch
BranchTrueFalseTotal
if $import 0 0 0
315 RDF::Trine::Node::Resource->new('http://www.w3.org/2002/07/owl#imports'),
316 RDF::Trine::Node::Resource->new($url),
317 )) if $import;
318  
319 0 my $ua = LWP::UserAgent->new(agent => "RDF::TriN3/$RDF::TriN3::VERSION");
320 0 $ua->default_headers->push_header(Accept => 'text/x.shorthand-rdf, text/x-shorthand-rdf, text/n3, text/turtle');
321 0 my $resp = $ua->get($url);
322 0 ▶ unless ($resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
323 0 throw RDF::Trine::Error::ParserError -text => $resp->status_line;
324 }
325  
326 0 return $self->_apply_profile($resp->base, $resp->decoded_content, $import);
327 }
328  
329 sub _apply_profile
330 0 ▶{
Subroutine _apply_profile: not called CC=5 SCAR=34.0
331 0 my ($self, $base, $data, $import) = @_;
332
333 0 my $class = ref $self;
334 0 my $child = $class->new(profile => '');
335 0 ▶ $child->parse($base, $data, sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
336 0 ▶ $self->{handle_triple}->($_[0]) if $import;
Branch: 1 branch
BranchTrueFalseTotal
if $import 0 0 0
337 0 });
338
339 0 ▶ my %child_bindings = %{ $child->{bindings} || {} };
Condition0%0/2
$child->{'bindings'} || {}
l!l
00
MC/DC0%0/1
$child->{'bindings'} || {}
$child->{'bindings'}
Truth table0%0/2
A
A= $child->{'bindings'}
Aresult
11
00
340 0 ▶ while (my ($prefix, $full) = each %child_bindings)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %child_bindings) 0 0 0
341 {
342 0 ▶ $self->{bindings}{$prefix} = $full
Branch: 1 branch
BranchTrueFalseTotal
if length $prefix 0 0 0
343 if length $prefix;
344 }
345
346 0 ▶ push @{ $self->{shorthands} }, @{ $child->{shorthands} || [] };
Condition0%0/2
$child->{'shorthands'} || []
l!l
00
MC/DC0%0/1
$child->{'shorthands'} || []
$child->{'shorthands'}
Truth table0%0/2
A
A= $child->{'shorthands'}
Aresult
11
00
347 0 return $self->{shorthands}[-1];
348 }
349  
350 6 ▶sub _resource_test {
Subroutine _resource_test: called CC=8 SCAR=21.4
351 6 my $self = shift;
352 6 ▶ return 0 unless (length($self->{tokens}));
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"tokens"} 0 6 6
353
354 6 my $rv = $self->SUPER::_resource_test(@_);
355 6 ▶ return $rv if $rv;
Branch: 1 branch
BranchTrueFalseTotal
if $rv 3 3 6
356
357 3 foreach my $shorthand ( reverse @{ $self->{shorthands} } )
358 {
359 8 my ($type, $pattern, $full, $basethen) = @$shorthand;
360
361 8 ▶ if ($type eq '@pattern' and $self->{'tokens'} =~ $pattern)
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '@pattern' and $self->{'tokens'} =~ /$pattern/) { } 3 5 8
elsif ($type eq '@term' and $self->__startswith($pattern)) { } 0 7 7
Condition100%3/3
$type eq "\@pattern" and $self->{"tokens"} =~ /$pattern/
!ll&&!rl&&r
323
MC/DC100%2/2
$type eq "\@pattern" and $self->{"tokens"} =~ /$pattern/
$type eq "\@pattern" $self->{"tokens"} =~ /$pattern/
Truth table100%3/3
A and B
A= $type eq "\@pattern"B= $self->{"tokens"} =~ /$pattern/
ABresult
0X0
100
111
362 3 { return 1; }
363 ▶ elsif ($type eq '@term' and $self->__startswith($pattern))
Condition66%2/3
$type eq "\@term" and $self->__startswith($pattern)
!ll&&!rl&&r
230
MC/DC0%0/2
$type eq "\@term" and $self->__startswith($pattern)
$type eq "\@term" $self->__startswith($pattern)
Truth table66%2/3
A and B
A= $type eq "\@term"B= $self->__startswith($pattern)
ABresult
0X0
100
111
364 0 { return 1; }
365 }
366  
367 0 return 0;
368 }
369  
370 4 ▶sub _resource {
Subroutine _resource: called CC=11 SCAR=24.4
371 4 my $self = shift;
372  
373 4 foreach my $shorthand ( reverse @{ $self->{shorthands} } )
374 {
375 8 my ($type, $pattern, $full, $basethen) = @$shorthand;
376
377 8 ▶ if ($type eq '@pattern' and $self->{'tokens'} =~ $pattern)
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq '@pattern' and $self->{'tokens'} =~ /$pattern/) { } 2 6 8
elsif ($type eq '@term' and $self->__startswith($pattern)) { } 1 8 9
Condition100%3/3
$type eq "\@pattern" and $self->{"tokens"} =~ /$pattern/
!ll&&!rl&&r
332
MC/DC100%2/2
$type eq "\@pattern" and $self->{"tokens"} =~ /$pattern/
$type eq "\@pattern" $self->{"tokens"} =~ /$pattern/
Truth table100%3/3
A and B
A= $type eq "\@pattern"B= $self->{"tokens"} =~ /$pattern/
ABresult
0X0
100
111
378 {
379 2 my $token = $1;
380 2 $self->_eat($token);
381
382 2 ▶ if ($full->is_literal && $full->has_datatype)
Branch: 3 branches
BranchTrueFalseTotal
if ($full->is_literal and $full->has_datatype) { } 1 1 2
elsif ($full->is_literal) { } 0 1 1
elsif ($full->is_resource) { } 1 0 1
Condition66%2/3
$full->is_literal and $full->has_datatype
!ll&&!rl&&r
101
MC/DC50%1/2
$full->is_literal and $full->has_datatype
$full->is_literal $full->has_datatype
Truth table66%2/3
A and B
A= $full->is_literalB= $full->has_datatype
ABresult
0X0
100
111
383 {
384 1 my $replaced_uri = $self->_PATTERN_($token, $pattern, $full->literal_datatype);
385 1 my $absolute_uri = $self->__URI($replaced_uri, $basethen);
386 1 return $self->__Literal(
387 $self->_PATTERN_($token, $pattern, $full->literal_value),
388 undef,
389 $absolute_uri,
390 );
391 }
392 elsif ($full->is_literal)
393 {
394 0 ▶ return $self->__Literal(
Branch: 1 branch
BranchTrueFalseTotal
$full->has_language ? : 0 0 0
395 $self->_PATTERN_($token, $pattern, $full->literal_value),
396 ($full->has_language ? $self->_PATTERN_($token, $pattern, $full->literal_value_language) : undef),
397 );
398 }
399 elsif ($full->is_resource)
400 {
401 1 my $replaced_uri = $self->_PATTERN_($token, $pattern, $full->uri);
402 1 return $self->__URI($replaced_uri, $basethen);
403 }
404 }
405 ▶ elsif ($type eq '@term' and $self->__startswith($pattern))
Condition100%3/3
$type eq "\@term" and $self->__startswith($pattern)
!ll&&!rl&&r
321
MC/DC100%2/2
$type eq "\@term" and $self->__startswith($pattern)
$type eq "\@term" $self->__startswith($pattern)
Truth table100%3/3
A and B
A= $type eq "\@term"B= $self->__startswith($pattern)
ABresult
0X0
100
111
406 {
407 1 $self->_eat($pattern);
408 1 return $full;
409 }
410 }
411  
412 1 return $self->SUPER::_resource(@_);
413 }
414  
415 sub _PATTERN_
416 3 ▶{
Subroutine _PATTERN_: called CC=12 SCAR=26.3
417 3 my ($self, $thingy, $pattern, $template) = @_;
418  
419 3 ▶ return unless defined $template;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $template 0 3 3
420 3 $template = "$template";
421 3 ▶ return $template unless $template =~ /\$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $template =~ /\$/ 1 2 3
422  
423 2 my %vals = (0 => $thingy);
424 2 my @matches = ($thingy =~ /$pattern/);
425 2 ▶ for (my $i=0; $i <= $#matches; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#matches) 2 2 4
426 {
427 2 $vals{$i + 1} = $matches[$i];
428 }
429 2 foreach my $bufname (keys %-)
430 {
431 0 $vals{$bufname} = $-{$bufname}->[0];
432 }
433
434 2 my $orig_template = $template;
435
436 2 my $rv = '';
437 2 my $count = 0;
438 2 ▶ while (length $template)
Branch: 1 branch
BranchTrueFalseTotal
if (length $template) 3 2 5
439 {
440 3 $count++;
441 3 ▶ die if $count > 300;
Branch: 1 branch
BranchTrueFalseTotal
if $count > 300 0 3 3
442
443 3 ▶ if ((substr $template, 0, 1) eq '$')
Branch: 1 branch
BranchTrueFalseTotal
if (substr($template, 0, 1) eq '$') { } 2 1 3
444 {
445 2 $template = substr $template, 1;
446
447 2 my $buffer;
448 2 ▶ if ($template =~ /^ \{ ([^\}]+) \} (.*) $/xo)
Branch: 3 branches
BranchTrueFalseTotal
if ($template =~ /^ \{ ([^\}]+) \} (.*) $/ox) { } 0 2 2
elsif ($template =~ /^(\d+)/o) { } 2 0 2
elsif ($template =~ /^([_A-Za-z][_A-Za-z0-9]*)/o) { } 0 0 0
449 {
450 0 ($buffer, $template) = ($1, $2);
451 }
452 elsif ($template =~ /^(\d+)/o)
453 {
454 2 $buffer = $1;
455 2 $template = substr($template, length $buffer);
456 }
457 elsif ($template =~ /^([_A-Za-z][_A-Za-z0-9]*)/o)
458 {
459 0 $buffer = $1;
460 0 $template = substr($template, length $buffer);
461 }
462 else
463 {
464 0 throw RDF::Trine::Error::ParserError -text => "Unexpected pattern in replace: ${orig_template}\n";
465 }
466 2 $rv .= $vals{$buffer};
467 }
468 else
469 {
470 1 my ($start, $rest) = split /\$/, $template, 2;
471 1 $rv .= $start;
472 1 ▶ $template = '$'.(defined $rest ? $rest : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $rest ? : 1 0 1
473 }
474 }
475  
476 2 return $rv;
477 }
478  
479 3 1;
480  
481 __END__
↑ Summary Trine/Parser/Notation3.pm »