AtteanX/Parser/RDFXML.pm

filter: Statementstmt 65.9% 368 / 558 Branchbran 47.4% 93 / 196 Conditioncond 41.0% 23 / 56 MC/DCmcdc 9.0% 3 / 33 Subroutinesub 96.7% 60 / 62 Podpod 100% 5 / 5 totaltotal 60.6% 552 / 910 CC 131 SCAR 54.2
CC
131
Cov
60%
start_element
778.1
new_literal
52.2
end_element
40.9
CRAP 224.9
« Test/Attean/W3CManifestTestSuite.pm ↑ Summary AtteanX/Functions/CompositeMaps.pm »
1 =head1 NAME
2  
3 AtteanX::Parser::RDFXML - RDF/XML Parser
4  
5 =head1 VERSION
6  
7 This document describes AtteanX::Parser::RDFXML version 0.040
8  
9 =head1 SYNOPSIS
10  
11 use Attean;
12 my $parser = Attean->get_parser('RDFXML')->new(base => $base_iri);
13  
14 use AtteanX::Parser::Turtle;
15 my $parser = AtteanX::Parser::Turtle->new( handler => sub {...}, base => $base_iri );
16
17 # Parse data from a file-handle and handle triples in the 'handler' callback
18 $parser->parse_cb_from_io( $fh );
19
20 # Parse the given byte-string, and return an iterator of triples
21 my $iter = $parser->parse_iter_from_bytes('<rdf:RDF>...</rdf:RDF>');
22 while (my $triple = $iter->next) {
23 print $triple->as_string;
24 }
25  
26 =head1 DESCRIPTION
27  
28 This module implements a parser for the RDF/XML format.
29  
30 =head1 ROLES
31  
32 This class consumes L<Attean::API::Parser>, L<Attean::API::PushParser>,
33 <Attean::API::AbbreviatingParser>, and <Attean::API::TripleParser>.
34  
35 =head1 ATTRIBUTES
36  
37 =over 4
38  
39 =item C<< canonical_media_type >>
40  
41 =item C<< media_types >>
42  
43 =item C<< file_extensions >>
44  
45 =item C<< bnode_prefix >>
46  
47 =item C<< blank_nodes >>
48  
49 A string prefix for identifiers generated for blank nodes.
50  
51 =back
52  
53 =head1 METHODS
54  
55 =over 4
56  
57 =cut
58  
59 4 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 4 package AtteanX::Parser::RDFXML 0.040 {
63 4 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 4 ▶ use Types::Standard qw(Bool HashRef ArrayRef HashRef Str Object Maybe InstanceOf ConsumerOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
65 4 ▶ use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 4 ▶ use Attean::RDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
67
68 4 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 4 ▶ use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 4 ▶ use XML::SAX;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 4 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 4 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
73 4 ▶ use Module::Load::Conditional qw[can_load];
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 =item C<< canonical_media_type >>
76  
77 Returns the canonical media type for SPARQL XML: application/sparql-results+json.
78  
79 =cut
80  
81 1 ▶ sub canonical_media_type { return "application/rdf+xml" }
Subroutine canonical_media_type: called CC=1 SCAR=0.0
Pod documented
82  
83 =item C<< media_types >>
84  
85 Returns a list of media types that may be parsed with the SPARQL XML parser:
86 application/sparql-results+json.
87  
88 =cut
89  
90 4 ▶ sub media_types { return [qw(application/rdf+xml application/octet-stream)]; }
Subroutine media_types: called CC=1 SCAR=0.0
Pod documented
91
92 =item C<< file_extensions >>
93  
94 Returns a list of file extensions that may be parsed with the parser.
95  
96 =cut
97  
98 10 ▶ sub file_extensions { return [qw(rdf xrdf)] }
Subroutine file_extensions: called CC=1 SCAR=0.0
Pod documented
99  
100 4 with 'Attean::API::TripleParser', 'Attean::API::AbbreviatingParser', 'Attean::API::Parser';
101 4 with 'Attean::API::PushParser';
102  
103 4 has 'bnode_prefix' => (is => 'ro', isa => Str, default => '');
104 6 ▶ has 'blank_nodes' => (is => 'ro', isa => HashRef[ConsumerOf['Attean::API::Blank']], default => sub { +{} });
Subroutine __ANON__: called CC=1 SCAR=0.0
105
106 =item C<< parse_cb_from_io( $fh ) >>
107  
108 Calls the C<< $parser->handler >> function once for each
109 L<Attean::API::Binding> object that result from parsing
110 the data read from the L<IO::Handle> object C<< $fh >>.
111  
112 =cut
113  
114 0 ▶ sub parse_cb_from_io {
Subroutine parse_cb_from_io: not called CC=1 SCAR=6.9
Pod documented
115 0 my $self = shift;
116 0 $self->_parse(@_);
117 }
118
119 =item C<< parse_cb_from_bytes( $data ) >>
120  
121 Calls the C<< $parser->handler >> function once for each
122 L<Attean::API::Binding> object that result from parsing
123 the data read from the UTF-8 encoded byte string C<< $data >>.
124  
125 =cut
126  
127 5 ▶ sub parse_cb_from_bytes {
Subroutine parse_cb_from_bytes: called CC=1 SCAR=0.0
Pod documented
128 5 my $self = shift;
129 5 $self->_parse(@_);
130 }
131  
132 5 ▶ sub _parse {
Subroutine _parse: called CC=12 SCAR=25.8
133 5 my $self = shift;
134 5 my $data = shift;
135  
136 5 my @args;
137 5 ▶ if (my $map = $self->namespaces) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $map = $self->namespaces) 1 4 5
138 1 push(@args, namespaces => $map);
139 }
140
141 5 ▶ if ($self->has_base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_base) 1 4 5
142 1 push(@args, base => $self->base);
143 }
144 5 ▶ my $new_iri = sub { $self->new_iri(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
145 5 my $saxhandler = AtteanX::Parser::RDFXML::SAXHandler->new( bnode_prefix => $self->bnode_prefix, blank_nodes => $self->blank_nodes, handler => $self->handler, new_iri => $new_iri, @args );
146 5 my $p = XML::SAX::ParserFactory->parser(Handler => $saxhandler);
147 5 ▶ $saxhandler->push_base( $self->base ) if ($self->has_base);
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_base 1 4 5
148 5 eval {
149 5 ▶ if (ref($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data) { } 0 5 5
150 0 $p->parse_file($data);
151 } else {
152 5 ▶ if (length($data) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data > 0) 4 1 5
153 4 $p->parse_string($data);
154 }
155 }
156 };
157
158 5 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 4 5
159 1 ▶ if ($@ =~ /no element found at line 1, column 0, byte/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /no element found at line 1, column 0, byte/u) { } 0 1 1
160 # silence XML::Parser output on empty input
161 } else {
162 1 die $@;
163 }
164 }
165 4 my $nodes = $saxhandler->{nodes};
166 4 ▶ if ($nodes and scalar(@$nodes)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nodes and scalar @$nodes) 0 4 4
Condition50%1/2
$nodes and scalar @$nodes
!ll
04
MC/DC0%0/1
$nodes and scalar @$nodes
$nodes
Truth table50%1/2
A
A= $nodes
Aresult
00
11
167 0 die "RDFXML parser node stack isn't empty after parse: " . Dumper($nodes);
168 }
169 4 my $expect = $saxhandler->{expect};
170 4 ▶ if ($expect and scalar(@$expect) > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expect and scalar @$expect > 2) 0 4 4
Condition33%1/3
$expect and scalar @$expect > 2
!ll&&!rl&&r
040
MC/DC0%0/2
$expect and scalar @$expect > 2
$expect scalar @$expect > 2
Truth table33%1/3
A and B
A= $expectB= scalar @$expect > 2
ABresult
0X0
100
111
171 0 die "RDFXML parser expect stack isn't empty after parse:" . Dumper($expect);
172 }
173 }
174 }
175  
176 package AtteanX::Parser::RDFXML::SAXHandler;
177  
178 4 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
179 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
180 4 ▶use base qw(XML::SAX::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
181 4 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
182 4 ▶use Module::Load::Conditional qw[can_load];
Subroutine BEGIN: called CC=1 SCAR=0.0
183  
184 4 ▶use Attean::RDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
185 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
186 4 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
187  
188 4 ▶use constant NIL => 0x00;
Subroutine BEGIN: called CC=1 SCAR=0.0
189 4 ▶use constant SUBJECT => 0x01;
Subroutine BEGIN: called CC=1 SCAR=0.0
190 4 ▶use constant PREDICATE => 0x02;
Subroutine BEGIN: called CC=1 SCAR=0.0
191 4 ▶use constant OBJECT => 0x04;
Subroutine BEGIN: called CC=1 SCAR=0.0
192 4 ▶use constant LITERAL => 0x08;
Subroutine BEGIN: called CC=1 SCAR=0.0
193 4 ▶use constant COLLECTION => 0x16;
Subroutine BEGIN: called CC=1 SCAR=0.0
194  
195 4 my $HAS_XML_LIBXML = can_load( modules => { 'XML::LibXML' => 1.70, } );
196  
197 5 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
198 5 my $class = shift;
199 5 my %args = @_;
200 5 ▶ my $prefix = $args{ bnode_prefix } // '';
Condition50%1/2
$args{"bnode_prefix"} // ""
l!l
50
MC/DC0%0/1
$args{"bnode_prefix"} // ""
$args{"bnode_prefix"}
Truth table50%1/2
A
A= $args{"bnode_prefix"}
Aresult
11
00
201 5 ▶ my $bnodes = $args{ blank_nodes } // {};
Condition50%1/2
$args{"blank_nodes"} // {}
l!l
50
MC/DC0%0/1
$args{"blank_nodes"} // {}
$args{"blank_nodes"}
Truth table50%1/2
A
A= $args{"blank_nodes"}
Aresult
11
00
202 my $self = bless( {
203 expect => [ SUBJECT, NIL ],
204 base => [],
205 depth => 0,
206 characters => '',
207 prefix => $prefix,
208 counter => 0,
209 nodes => [],
210 chars_ok => 0,
211 sthandler => $args{handler},
212 new_iri => $args{new_iri},
213 5 named_bnodes => $bnodes
214 }, $class );
215 5 ▶ if (my $ns = $args{ namespaces }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ns = $args{"namespaces"}) 1 4 5
216 1 $self->{namespaces} = $ns;
217 }
218 5 ▶ if (my $base = $args{ base }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $base = $args{"base"}) 1 4 5
219 1 $self->push_base( $base );
220 }
221 5 return $self;
222 }
223  
224 5 ▶sub new_expect {
Subroutine new_expect: called CC=1 SCAR=0.0
225 5 my $self = shift;
226 5 unshift( @{ $self->{expect} }, shift );
227 }
228  
229 8 ▶sub old_expect {
Subroutine old_expect: called CC=1 SCAR=0.0
230 8 shift( @{ shift->{expect} } );
231 }
232  
233 47 ▶sub expect {
Subroutine expect: called CC=1 SCAR=0.0
234 47 return shift->{expect}[0];
235 }
236  
237 3 ▶sub peek_expect {
Subroutine peek_expect: called CC=1 SCAR=0.0
238 3 return shift->{expect}[1];
239 }
240  
241  
242 8 ▶sub start_element {
Subroutine start_element: called CC=53 SCAR=66.6
243 8 my $self = shift;
244 8 my $el = shift;
245  
246 8 foreach my $withdrawn (qw(aboutEach aboutEachPrefix bagID)) {
247 24 ▶ if (exists $el->{Attributes}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}${withdrawn}"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}$withdrawn"}) 0 24 24
248 0 die "XML attribute rdf:${withdrawn} not allowed";
249 }
250 24 ▶ if ($el->{NamespaceURI} eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' and $el->{LocalName} eq $withdrawn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" and $el->{"LocalName"} eq $withdrawn) 0 24 24
Condition66%2/3
$el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" and $el->{"LocalName"} eq $withdrawn
!ll&&!rl&&r
6180
MC/DC0%0/2
$el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" and $el->{"LocalName"} eq $withdrawn
$el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" $el->{"LocalName"} eq $withdrawn
Truth table66%2/3
A and B
A= $el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#"B= $el->{"LocalName"} eq $withdrawn
ABresult
0X0
100
111
251 0 die "XML node rdf:${withdrawn} not allowed";
252 }
253 }
254  
255 8 $self->{depth}++;
256 8 ▶ $self->handle_scoped_values( $el ) unless ($self->expect == LITERAL);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->expect == 8 8 0 8
257 8 ▶ if ($self->{depth} == 1 and $el->{NamespaceURI} eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' and $el->{LocalName} eq 'RDF') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'depth'} == 1 and $el->{'NamespaceURI'} eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' and $el->{'LocalName'} eq 'RDF') { } 3 5 8
Condition66%4/6
$self->{"depth"} == 1 and $el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" and $el->{"LocalName"} eq "RDF"
!ll&&!rl&&r
503
$self->{"depth"} == 1 and $el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
!ll&&!rl&&r
503
MC/DC33%1/3
$self->{"depth"} == 1 and $el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" and $el->{"LocalName"} eq "RDF"
$self->{"depth"} == 1 $el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" $el->{"LocalName"} eq "RDF"
Truth table50%2/4
A and B and C
A= $self->{"depth"} == 1B= $el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#"C= $el->{"LocalName"} eq "RDF"
ABCresult
0XX0
10X0
1100
1111
258 # ignore the wrapping rdf:RDF element
259 } else {
260 5 my $expect = $self->expect;
261 5 ▶ if ($self->{depth} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"depth"} > 1) 5 0 5
262 5 my @props = (qw(RDF ID about aboutEach bagID parseType resource nodeID));
263 5 ▶ push(@props, 'li') if ($expect == SUBJECT);
Branch: 1 branch
BranchTrueFalseTotal
if $expect == 1 3 2 5
264 5 foreach my $prop (@props) {
265 43 ▶ if ($el->{NamespaceURI} eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' and $el->{LocalName} eq $prop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" and $el->{"LocalName"} eq $prop) 0 43 43
Condition66%2/3
$el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" and $el->{"LocalName"} eq $prop
!ll&&!rl&&r
16270
MC/DC0%0/2
$el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" and $el->{"LocalName"} eq $prop
$el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#" $el->{"LocalName"} eq $prop
Truth table66%2/3
A and B
A= $el->{"NamespaceURI"} eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#"B= $el->{"LocalName"} eq $prop
ABresult
0X0
100
111
266 0 die "rdf:${prop} is forbidden as a node element name";
267 }
268 }
269 }
270
271 5 my $prefix = $el->{Prefix};
272 5 ▶ $self->new_expect( $expect = SUBJECT ) if ($expect == NIL);
Branch: 1 branch
BranchTrueFalseTotal
if $expect == 0 0 5 5
273
274 5 ▶ if ($expect == SUBJECT or $expect == OBJECT) {
Branch: 4 branches
BranchTrueFalseTotal
if ($expect == 1 or $expect == 4) { } 3 2 5
elsif ($self->expect == 22) { } 0 2 2
elsif ($self->expect == 2) { } 2 0 2
elsif ($self->expect == 8) { } 0 0 0
Condition66%2/3
$expect == 1 or $expect == 4
l!l&&r!l&&!r
302
MC/DC50%1/2
$expect == 1 or $expect == 4
$expect == 1 $expect == 4
Truth table66%2/3
A or B
A= $expect == 1B= $expect == 4
ABresult
1X1
011
000
275 3 ▶ if (my $data = $el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}li'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $el->{"Attributes"}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}li"}) 0 3 3
276 0 die "rdf:li is not allowed as as an attribute";
277 }
278  
279 3 my $ns = $self->get_namespace( $prefix );
280 3 my $local = $el->{LocalName};
281 3 my $uri = join('', $ns, $local);
282 3 my $node = $self->new_resource( $uri );
283 3 ▶ if ($self->expect == OBJECT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->expect == 4) 0 3 3
284 0 ▶ if (defined($self->{characters}) and length(my $string = $self->{characters})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"characters"} and length(my $string = $self->{"characters"})) 0 0 0
Condition0%0/3
defined $self->{"characters"} and length(my $string = $self->{"characters"})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"characters"} and length(my $string = $self->{"characters"})
defined $self->{"characters"} length(my $string = $self->{"characters"})
Truth table0%0/3
A and B
A= defined $self->{"characters"}B= length(my $string = $self->{"characters"})
ABresult
0X0
100
111
285 0 ▶ die "character data found before object element" if ($string =~ /\S/);
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /\S/u 0 0 0
286 }
287 0 delete($self->{characters}); # get rid of any whitespace we saw before the element
288 }
289 3 my $node_id = $self->node_id( $el );
290
291 3 ▶ if ($self->peek_expect == COLLECTION) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->peek_expect == 22) { } 0 3 3
elsif ($self->expect == 4) { } 0 3 3
292 0 my $list = $self->new_bnode;
293 0 ▶ if (my $last = $self->{ collection_last }[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $last = $self->{"collection_last"}[0]) 0 0 0
294 0 my $st = Attean::Triple->new( $last, iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"), $list );
295 0 $self->assert( $st );
296 }
297 0 $self->{ collection_last }[0] = $list;
298 0 my $st = Attean::Triple->new( $list, iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#first"), $node_id );
299 0 $self->assert( $st );
300 0 ▶ $self->{ collection_head }[0] ||= $list;
Condition0%0/3
$self->{"collection_head"}[0] ||= $list
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"collection_head"}[0] ||= $list
$self->{"collection_head"}[0] $list
Truth table0%0/3
A ||= B
A= $self->{"collection_head"}[0]B= $list
ABresult
1X1
011
000
301 } elsif ($self->expect == OBJECT) {
302 0 my $nodes = $self->{nodes};
303 0 my $st = Attean::Triple->new( @{ $nodes }[ $#{$nodes} - 1, $#{$nodes} ], $node_id );
304 0 $self->assert( $st );
305 }
306
307 3 ▶ if ($uri ne 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Description') {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri ne "http://www.w3.org/1999/02/22-rdf-syntax-ns#Description") 0 3 3
308 0 my $type = $node;
309 0 $self->assert( Attean::Triple->new( $node_id, iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), $node ) );
310 }
311 3 push( @{ $self->{nodes} }, $node_id );
312
313 3 $self->parse_literal_property_attributes( $el, $node_id );
314 3 $self->new_expect( PREDICATE );
315 3 unshift(@{ $self->{seqs} }, 0);
316 } elsif ($self->expect == COLLECTION) {
317 } elsif ($self->expect == PREDICATE) {
318 2 my $ns = $self->get_namespace( $prefix );
319 2 my $local = $el->{LocalName};
320 2 my $uri = join('', $ns, $local);
321 2 my $node = $self->new_resource( $uri );
322  
323 2 ▶ if ($node->value eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Description') {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->value eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#Description") 0 2 2
324 0 die "rdf:Description is forbidden as a property element name";
325 }
326
327 2 ▶ if ($node->value eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#li') {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->value eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#li") 0 2 2
328 0 my $id = ++(${ $self }{seqs}[0]);
329 0 $node = $self->new_resource( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#_' . $id );
330 }
331
332 2 push( @{ $self->{nodes} }, $node );
333 2 ▶ if (my $data = $el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}datatype'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $el->{"Attributes"}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}datatype"}) 0 2 2
334 0 $self->{datatype} = $data->{Value};
335 }
336
337 2 ▶ if (my $data = $el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}ID'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = $el->{'Attributes'}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}ID'}) { } 0 2 2
338 # foreach my $prop (qw(nodeID)) {
339 # if (exists $el->{Attributes}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}${prop}"}) {
340 # die "Node cannot have both rdf:ID and rdf:${prop}";
341 # }
342 # }
343 0 my $id = $data->{Value};
344 0 $self->validate_id($id, 'rdf:ID');
345 0 unshift(@{ $self->{reify_id} }, $id);
346 } else {
347 2 unshift(@{ $self->{reify_id} }, undef);
348 }
349
350 2 ▶ if (my $pt = $el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}parseType'}) {
Branch: 4 branches
BranchTrueFalseTotal
if (my $pt = $el->{'Attributes'}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}parseType'}) { } 0 2 2
elsif (my $data = $el->{'Attributes'}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource'}) { } 1 1 2
elsif (my $ndata = $el->{'Attributes'}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}nodeID'}) { } 0 1 1
elsif (my $node = $self->parse_literal_property_attributes($el)) { } 0 1 1
351 0 ▶ if ($pt->{Value} eq 'Resource') {
Branch: 3 branches
BranchTrueFalseTotal
if ($pt->{'Value'} eq 'Resource') { } 0 0 0
elsif ($pt->{'Value'} eq 'Literal') { } 0 0 0
elsif ($pt->{'Value'} eq 'Collection') { } 0 0 0
352 # fake an enclosing object scope
353 0 my $node = $self->new_bnode;
354 0 my $nodes = $self->{nodes};
355 0 push( @$nodes, $node );
356 0 $self->assert( Attean::Triple->new( @{ $nodes }[ $#{$nodes} - 2 .. $#{$nodes} ] ) );
357
358 0 $self->new_expect( PREDICATE );
359 } elsif ($pt->{Value} eq 'Literal') {
360 0 ▶ if (exists $el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource"}) 0 0 0
361 0 die "specifying an rdf:parseType of 'Literal' and an rdf:resource attribute at the same time is not allowed";
362 }
363
364 0 $self->{datatype} = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral';
365 0 my $depth = $self->{depth};
366 0 $self->{literal_depth} = $depth - 1;
367 0 $self->new_expect( LITERAL );
368 } elsif ($pt->{Value} eq 'Collection') {
369 0 my $depth = $self->{depth};
370 0 unshift( @{ $self->{ collection_head } }, undef );
371 0 unshift( @{ $self->{ collection_last } }, undef );
372 0 $self->new_expect( COLLECTION );
373 0 $self->new_expect( OBJECT );
374 0 unshift(@{ $self->{reify_id} }, undef); # temporarily mask the reifier to allow the collection triples to be non-reified ; this will be restored during the end_element handling that closes the COLLECTION mode
375 }
376 } elsif (my $data = $el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource'}) {
377 1 foreach my $prop (qw(nodeID about)) {
378 2 ▶ if (exists $el->{Attributes}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}${prop}"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}$prop"}) 0 2 2
379 0 die "Node cannot have both rdf:resource and rdf:${prop}";
380 }
381 }
382 # stash the uri away so that we can use it when we get the end_element call for this predicate
383 1 my $uri = $self->new_resource( $data->{Value} );
384 1 $self->parse_literal_property_attributes( $el, $uri );
385 1 $self->{'rdf:resource'} = $uri;
386 1 $self->new_expect( OBJECT );
387 1 $self->{chars_ok} = 1;
388 } elsif (my $ndata = $el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}nodeID'}) {
389 0 foreach my $prop (qw(resource)) {
390 0 ▶ if (exists $el->{Attributes}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}${prop}"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}$prop"}) 0 0 0
391 0 die "Node cannot have both rdf:nodeID and rdf:${prop}";
392 }
393 }
394 0 my $node_name = $ndata->{Value};
395 0 $self->validate_id($node_name, 'rdf:nodeID');
396 # stash the bnode away so that we can use it when we get the end_element call for this predicate
397 0 my $bnode = $self->get_named_bnode( $node_name );
398 0 $self->parse_literal_property_attributes( $el, $uri );
399 0 $self->{'rdf:resource'} = $bnode; # the key 'rdf:resource' is a bit misused here, but both rdf:resource and rdf:nodeID use it for the same purpose, so...
400 0 $self->new_expect( OBJECT );
401 0 $self->{chars_ok} = 1;
402 } elsif (my $node = $self->parse_literal_property_attributes( $el )) {
403 # fake an enclosing object scope
404 0 my $nodes = $self->{nodes};
405 0 push( @$nodes, $node );
406 0 $self->assert( Attean::Triple->new( @{ $nodes }[ $#{$nodes} - 2 .. $#{$nodes} ] ) );
407 0 $self->new_expect( PREDICATE );
408 } else {
409 1 $self->new_expect( OBJECT );
410 1 $self->{chars_ok} = 1;
411 }
412 } elsif ($self->expect == LITERAL) {
413 0 my $tag;
414 0 ▶ if ($el->{Prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($el->{'Prefix'}) { } 0 0 0
415 0 $tag = join(':', @{ $el }{qw(Prefix LocalName)});
416 } else {
417 0 $tag = $el->{LocalName};
418 }
419 0 $self->{characters} .= '<' . $tag;
420 0 my $attr = $el->{Attributes};
421
422 0 ▶ if (my $ns = $el->{NamespaceURI}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ns = $el->{"NamespaceURI"}) 0 0 0
423 0 my $abbr = $el->{Prefix};
424 0 ▶ unless ($self->{defined_literal_namespaces}{$abbr}{$ns}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"defined_literal_namespaces"}{$abbr}{$ns}) 0 0 0
425 0 $self->{characters} .= ' xmlns';
426 0 ▶ if (length($abbr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $abbr) 0 0 0
427 0 $self->{characters} .= ':' . $abbr;
428 }
429 0 $self->{characters} .= '="' . $ns . '"';
430 0 $self->{defined_literal_namespaces}{$abbr}{$ns}++;
431 }
432 }
433 0 ▶ if (%$attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$attr) 0 0 0
434 0 foreach my $k (keys %$attr) {
435 0 $self->{characters} .= ' ';
436 0 my $el = $attr->{ $k };
437 0 my $prop;
438 0 ▶ if ($el->{Prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($el->{'Prefix'}) { } 0 0 0
439 0 $prop = join(':', @{ $el }{qw(Prefix LocalName)});
440 } else {
441 0 $prop = $el->{LocalName};
442 }
443 0 $self->{characters} .= $prop . '="' . $el->{Value} . '"';
444 }
445 }
446 0 $self->{characters} .= '>';
447 } else {
448 0 die "not sure what type of token is expected";
449 }
450 }
451 }
452  
453 8 ▶sub end_element {
Subroutine end_element: called CC=16 SCAR=37.1
454 8 my $self = shift;
455 8 my $el = shift;
456 8 $self->{depth}--;
457  
458 8 my $cleanup = 0;
459 8 my $expect = $self->expect;
460 8 ▶ if ($expect == SUBJECT) {
Branch: 5 branches
BranchTrueFalseTotal
if ($expect == 1) { } 3 5 8
elsif ($expect == 2) { } 3 2 5
elsif ($expect == 4 or $expect == 8 and $self->{'literal_depth'} == $self->{'depth'}) { } 2 0 2
elsif ($expect == 22) { } 0 0 0
elsif ($expect == 8) { } 0 0 0
461 3 $self->old_expect;
462 3 $cleanup = 1;
463 3 $self->{chars_ok} = 0;
464 3 shift(@{ $self->{reify_id} });
465 } elsif ($expect == PREDICATE) {
466 3 $self->old_expect;
467 3 ▶ if ($self->expect == PREDICATE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->expect == 2) { } 0 3 3
468 # we're closing a parseType=Resource block, so take off the extra implicit node.
469 0 pop( @{ $self->{nodes} } );
470 } else {
471 3 shift(@{ $self->{seqs} });
472 }
473 3 $cleanup = 1;
474 3 $self->{chars_ok} = 0;
475 ▶ } elsif ($expect == OBJECT or ($expect == LITERAL and $self->{literal_depth} == $self->{depth})) {
Condition16%1/6
$expect == 4 or $expect == 8 and $self->{"literal_depth"} == $self->{"depth"}
l!l&&r!l&&!r
200
$expect == 8 and $self->{"literal_depth"} == $self->{"depth"}
!ll&&!rl&&r
000
MC/DC0%0/3
$expect == 4 or $expect == 8 and $self->{"literal_depth"} == $self->{"depth"}
$expect == 4 $expect == 8 $self->{"literal_depth"} == $self->{"depth"}
Truth table25%1/4
A or B and C
A= $expect == 4B= $expect == 8C= $self->{"literal_depth"} == $self->{"depth"}
ABCresult
1XX1
0111
00X0
0100
476 2 ▶ if (exists $self->{'rdf:resource'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"rdf:resource"}) 1 1 2
477 1 my $uri = delete $self->{'rdf:resource'};
478 1 my $nodes = $self->{nodes};
479 1 delete $self->{characters};
480 1 $self->assert( Attean::Triple->new( @{ $nodes }[ $#{$nodes} - 1, $#{$nodes} ], $uri ) );
481 }
482 2 $self->old_expect;
483 2 ▶ if (defined($self->{characters})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"characters"}) 1 1 2
484 1 my $string = $self->{characters};
485 1 my $literal = $self->new_literal( $string );
486 1 my $nodes = $self->{nodes};
487 1 $self->assert( Attean::Triple->new( @{ $nodes }[ $#{$nodes} - 1, $#{$nodes} ], $literal ) );
488 1 delete($self->{characters});
489 1 delete $self->{datatype};
490 1 delete $self->{defined_literal_namespaces};
491 }
492
493 2 ▶ if ($self->expect == COLLECTION) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->expect == 22) 0 2 2
494 # We were expecting an object, but got an end_element instead.
495 # after poping the OBJECT expectation, we see we were expecting objects in a COLLECTION.
496 # so we're ending the COLLECTION here:
497 0 $self->old_expect;
498 0 my $nodes = $self->{nodes};
499 0 ▶ my $head = $self->{ collection_head }[0] || iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
Condition0%0/3
$self->{'collection_head'}[0] || iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#nil')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'collection_head'}[0] || iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#nil')
$self->{'collection_head'}[0] iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#nil')
Truth table0%0/3
A || B
A= $self->{'collection_head'}[0]B= iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#nil')
ABresult
1X1
011
000
500 0 my @nodes = (@{ $nodes }[ $#{$nodes} - 1, $#{$nodes} ], $head);
501 0 my $st = Attean::Triple->new( @nodes );
502
503 0 ▶ if (my $last = $self->{ collection_last }[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $last = $self->{"collection_last"}[0]) 0 0 0
504 0 my @nodes = ( $last, iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"), iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil") );
505 0 my $st = Attean::Triple->new( @nodes );
506 0 $self->assert( $st );
507 }
508 0 shift(@{ $self->{reify_id} }); # restore any reifier that was pending for the triple pointing to the collectionhead
509 0 $self->assert( $st );
510
511 0 shift( @{ $self->{ collection_last } } );
512 0 shift( @{ $self->{ collection_head } } );
513 }
514
515 2 $cleanup = 1;
516 2 $self->{chars_ok} = 0;
517 2 shift(@{ $self->{reify_id} });
518 } elsif ($expect == COLLECTION) {
519 0 shift( @{ $self->{collections} } );
520 0 $self->old_expect;
521 } elsif ($expect == LITERAL) {
522 0 my $tag;
523 0 ▶ if ($el->{Prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($el->{'Prefix'}) { } 0 0 0
524 0 $tag = join(':', @{ $el }{qw(Prefix LocalName)});
525 } else {
526 0 $tag = $el->{LocalName};
527 }
528 0 $self->{characters} .= '</' . $tag . '>';
529 0 $cleanup = 0;
530 } else {
531 0 die "how did we get here?";
532 }
533  
534 8 ▶ if ($cleanup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cleanup) 8 0 8
535 8 pop( @{ $self->{nodes} } );
536 8 $self->pop_namespace_pad();
537 8 $self->pop_language();
538 8 $self->pop_base();
539 }
540 }
541  
542 11 ▶sub characters {
Subroutine characters: called CC=4 SCAR=14.0
543 11 my $self = shift;
544 11 my $data = shift;
545 11 my $expect = $self->expect;
546 11 ▶ if ($expect == LITERAL or ($expect == OBJECT and $self->{chars_ok})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expect == 8 or $expect == 4 and $self->{"chars_ok"}) 1 10 11
Condition66%4/6
$expect == 8 or $expect == 4 and $self->{"chars_ok"}
l!l&&r!l&&!r
0110
$expect == 4 and $self->{"chars_ok"}
!ll&&!rl&&r
1001
MC/DC33%1/3
$expect == 8 or $expect == 4 and $self->{"chars_ok"}
$expect == 8 $expect == 4 $self->{"chars_ok"}
Truth table50%2/4
A or B and C
A= $expect == 8B= $expect == 4C= $self->{"chars_ok"}
ABCresult
1XX1
0111
00X0
0100
547 1 my $chars = $data->{Data};
548 1 $self->{characters} .= $chars;
549 }
550 }
551  
552 5 ▶sub parse_literal_property_attributes {
Subroutine parse_literal_property_attributes: called CC=9 SCAR=22.9
553 5 my $self = shift;
554 5 my $el = shift;
555 5 ▶ my $node_id = shift || $self->new_bnode;
Condition66%2/3
shift() || $self->new_bnode
l!l&&r!l&&!r
410
MC/DC0%0/2
shift() || $self->new_bnode
shift() $self->new_bnode
Truth table66%2/3
A || B
A= shift()B= $self->new_bnode
ABresult
1X1
011
000
556 1 my @keys = grep { not(m<[{][}](xmlns|about)>) }
557 4 grep { not(m<[{]http://www.w3.org/1999/02/22-rdf-syntax-ns#[}](resource|about|ID|datatype|nodeID)>) }
558 4 grep { not(m<[{]http://www.w3.org/XML/1998/namespace[}](base|lang)>) }
559 5 keys %{ $el->{Attributes} };
560 5 my $asserted = 0;
561  
562 5 unshift(@{ $self->{reify_id} }, undef); # don't reify any of these triples
563 5 foreach my $k (@keys) {
564 1 my $data = $el->{Attributes}{ $k };
565 1 my $ns = $data->{NamespaceURI};
566 1 ▶ unless ($ns) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ns) 0 1 1
567 0 my $prefix = $data->{Prefix};
568 0 ▶ next unless (length($ns));
Branch: 1 branch
BranchTrueFalseTotal
unless length $ns 0 0 0
569 0 $ns = $self->get_namespace( $prefix );
570 }
571 1 ▶ next if ($ns eq 'http://www.w3.org/XML/1998/namespace');
Branch: 1 branch
BranchTrueFalseTotal
if $ns eq "http://www.w3.org/XML/1998/namespace" 0 1 1
572 1 ▶ next if ($ns eq 'http://www.w3.org/2000/xmlns/');
Branch: 1 branch
BranchTrueFalseTotal
if $ns eq "http://www.w3.org/2000/xmlns/" 0 1 1
573 1 my $local = $data->{LocalName};
574 1 my $uri = join('', $ns, $local);
575 1 my $value = $data->{Value};
576 1 my $pred = $self->new_resource( $uri );
577 1 ▶ my $term = ($uri eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type') ? $self->new_resource( $value ) : $self->new_literal( $value );
Branch: 1 branch
BranchTrueFalseTotal
$uri eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' ? : 0 1 1
578 1 $self->assert( Attean::Triple->new( $node_id, $pred, $term ) );
579 1 $asserted++;
580 }
581 5 shift(@{ $self->{reify_id} });
582 5 ▶ return ($asserted ? $node_id : 0);
Branch: 1 branch
BranchTrueFalseTotal
$asserted ? : 1 4 5
583 }
584  
585 3 ▶sub assert {
Subroutine assert: called CC=4 SCAR=19.8
586 3 my $self = shift;
587 3 my $st = shift;
588  
589 3 ▶ if ($self->{sthandler}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sthandler"}) 3 0 3
590 3 $self->{sthandler}->( $st );
591 3 ▶ if (defined(my $id = $self->{reify_id}[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $id = $self->{"reify_id"}[0])) 0 3 3
592 0 my $stid = $self->new_resource( "#$id" );
593
594 0 my $tst = Attean::Triple->new( $stid, iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement") );
595 0 my $sst = Attean::Triple->new( $stid, iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#subject"), $st->subject );
596 0 my $pst = Attean::Triple->new( $stid, iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate"), $st->predicate );
597 0 my $ost = Attean::Triple->new( $stid, iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#object"), $st->object );
598 0 foreach ($tst, $sst, $pst, $ost) {
599 0 $self->{sthandler}->( $_ );
600 }
601 0 $self->{reify_id}[0] = undef; # now that we've used this reify ID, get rid of it (because we don't want it used again)
602 }
603 }
604 }
605  
606 3 ▶sub node_id {
Subroutine node_id: called CC=11 SCAR=34.5
607 3 my $self = shift;
608 3 my $el = shift;
609  
610 3 ▶ if ($el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}about'}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($el->{'Attributes'}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}about'}) { } 0 3 3
elsif ($el->{'Attributes'}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}ID'}) { } 2 1 3
elsif ($el->{'Attributes'}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}nodeID'}) { } 0 1 1
611 0 foreach my $prop (qw(nodeID)) {
612 0 ▶ if (exists $el->{Attributes}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}${prop}"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}$prop"}) 0 0 0
613 0 die "Node cannot have both rdf:about and rdf:${prop}";
614 }
615 }
616 0 my $uri = $el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}about'}{Value};
617 0 return $self->new_resource( $uri );
618 } elsif ($el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}ID'}) {
619 2 foreach my $prop (qw(nodeID)) {
620 2 ▶ if (exists $el->{Attributes}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}${prop}"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}$prop"}) 0 2 2
621 0 die "Node cannot have both rdf:ID and rdf:${prop}";
622 }
623 }
624 2 my $uri = $el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}ID'}{Value};
625 2 $self->validate_id($uri, 'rdf:ID');
626 2 my $i = $self->new_resource( '#' . $uri );
627 2 ▶ if ($self->{seen_rdf_ID_values}{$i->value}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"seen_rdf_ID_values"}{$i->value}++) 0 2 2
628 0 die "Two nodes cannot use the same rdf:ID value [$uri]";
629 }
630 2 return $i;
631 } elsif ($el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}nodeID'}) {
632 0 foreach my $prop (qw(ID)) {
633 0 ▶ if (exists $el->{Attributes}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}${prop}"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{http://www.w3.org/1999/02/22-rdf-syntax-ns#}$prop"}) 0 0 0
634 0 die "Node cannot have both rdf:nodeID and rdf:${prop}";
635 }
636 }
637 0 my $name = $el->{Attributes}{'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}nodeID'}{Value};
638 0 $self->validate_id($name, 'rdf:nodeID');
639 0 return $self->get_named_bnode( $name );
640 } else {
641 1 return $self->new_bnode;
642 }
643 }
644  
645 2 ▶sub validate_id {
Subroutine validate_id: called CC=2 SCAR=7.1
646 2 my $self = shift;
647 2 my $id = shift;
648 2 my $prop = shift;
649 2 my $startChar = qr/[:A-Za-z\x{00C0}-\x{00D6}\x{00D8}-\x{00F6}\x{00F8}-\x{02FF}\x{0370}-\x{037D}\x{37F}-\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}]/;
650 2 my $nameChar = qr/${startChar}|[-.0-9\x{b7}\x{300}-\x{36f}\x{203f}-\x{2040}]/;
651 2 my $name = qr/^${startChar}(?:$nameChar)*$/;
652 2 ▶ unless ($id =~ $name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id =~ /$name/u) 0 2 2
653 0 die "${prop} value [$id] does not match XML Name production";
654 }
655 }
656  
657 8 ▶sub handle_scoped_values {
Subroutine handle_scoped_values: called CC=7 SCAR=19.7
658 8 my $self = shift;
659 8 my $el = shift;
660 8 my %new;
661  
662 {
663 # xml:base
664 8 my $base = '';
665 8 ▶ if (exists($el->{Attributes}{'{http://www.w3.org/XML/1998/namespace}base'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{http://www.w3.org/XML/1998/namespace}base"}) 1 7 8
666 1 my $uri = $el->{Attributes}{'{http://www.w3.org/XML/1998/namespace}base'}{Value};
667 1 $base = $self->new_resource( $uri );
668 }
669 8 $self->push_base( $base );
670 }
671  
672 {
673 # language
674 8 my $lang = '';
675 8 ▶ if (exists($el->{Attributes}{'{http://www.w3.org/XML/1998/namespace}lang'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{http://www.w3.org/XML/1998/namespace}lang"}) 0 8 8
676 0 $lang = $el->{Attributes}{'{http://www.w3.org/XML/1998/namespace}lang'}{Value};
677 }
678 8 $self->push_language( $lang );
679 }
680  
681 {
682 # namespaces
683 8 my @ns = grep { m<^[{]http://www.w3.org/2000/xmlns/[}]> } (keys %{ $el->{Attributes} });
684 8 foreach my $n (@ns) {
685 6 my ($prefix) = substr($n, 31);
686 6 my $value = $el->{Attributes}{$n}{Value};
687 6 $new{ $prefix } = $value;
688 6 ▶ if (blessed(my $ns = $self->{namespaces})) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed(my $ns = $self->{"namespaces"})) 2 4 6
689 2 ▶ unless ($ns->namespace_uri($prefix)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ns->namespace_uri($prefix)) 2 0 2
690 2 $ns->add_mapping( $prefix => $value );
691 }
692 }
693 }
694
695 8 ▶ if (exists($el->{Attributes}{'{}xmlns'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el->{"Attributes"}{"{}xmlns"}) 0 8 8
696 0 my $value = $el->{Attributes}{'{}xmlns'}{Value};
697 0 $new{ '' } = $value;
698 }
699
700 8 $self->push_namespace_pad( \%new );
701 }
702 }
703  
704 10 ▶sub push_base {
Subroutine push_base: called CC=4 SCAR=14.2
705 10 my $self = shift;
706 10 my $base = shift;
707 10 ▶ if ($base) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base) 3 7 10
708 3 ▶ my $uri = (blessed($base) and $base->isa('URI')) ? $base : URI->new($base->value );
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($base) && $base->isa('URI') ? : 0 3 3
Condition33%1/3
builtin::blessed($base) and $base->isa("URI")
!ll&&!rl&&r
030
MC/DC0%0/2
builtin::blessed($base) and $base->isa("URI")
builtin::blessed($base) $base->isa("URI")
Truth table33%1/3
A and B
A= builtin::blessed($base)B= $base->isa("URI")
ABresult
0X0
100
111
709 3 $uri->fragment( undef );
710 3 $base = iri( "$uri" );
711 }
712 10 unshift( @{ $self->{base} }, $base );
713 }
714  
715 8 ▶sub pop_base {
Subroutine pop_base: called CC=1 SCAR=0.0
716 8 my $self = shift;
717 8 shift( @{ $self->{base} } );
718 }
719  
720 10 ▶sub get_base {
Subroutine get_base: called CC=1 SCAR=0.0
721 10 my $self = shift;
722 10 ▶ return first { length($_) } @{ $self->{base} };
Subroutine __ANON__: called CC=1 SCAR=0.0
723 }
724  
725 8 ▶sub push_language {
Subroutine push_language: called CC=1 SCAR=0.0
726 8 my $self = shift;
727 8 my $lang = shift;
728 8 unshift( @{ $self->{language} }, $lang );
729 }
730  
731 8 ▶sub pop_language {
Subroutine pop_language: called CC=1 SCAR=0.0
732 8 my $self = shift;
733 8 shift( @{ $self->{language} } );
734 }
735  
736 2 ▶sub get_language {
Subroutine get_language: called CC=2 SCAR=7.0
737 2 my $self = shift;
738 2 ▶ my $lang = first { length($_) } @{ $self->{language} };
Subroutine __ANON__: called CC=1 SCAR=0.0
739 2 ▶ return $lang // '';
Condition50%1/2
$lang // ""
l!l
02
MC/DC0%0/1
$lang // ""
$lang
Truth table50%1/2
A
A= $lang
Aresult
11
00
740 }
741  
742 8 ▶sub push_namespace_pad {
Subroutine push_namespace_pad: called CC=1 SCAR=0.0
743 8 my $self = shift;
744 8 my $pad = shift;
745 8 unshift( @{ $self->{_namespaces} }, $pad );
746 }
747  
748 8 ▶sub pop_namespace_pad {
Subroutine pop_namespace_pad: called CC=1 SCAR=0.0
749 8 my $self = shift;
750 8 shift( @{ $self->{_namespaces} } );
751 }
752  
753 5 ▶sub get_namespace {
Subroutine get_namespace: called CC=3 SCAR=11.0
754 5 my $self = shift;
755 5 my $prefix = shift;
756 5 foreach my $level (0 .. $#{ $self->{_namespaces} }) {
757 12 my $pad = $self->{_namespaces}[ $level ];
758 12 ▶ if (exists($pad->{ $prefix })) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pad->{$prefix}) 5 7 12
759 5 my $uri = $pad->{ $prefix };
760 5 return $uri;
761 }
762 }
763 0 die "Unknown namespace: $prefix";
764 }
765  
766 2 ▶sub new_bnode {
Subroutine new_bnode: called CC=2 SCAR=7.4
767 2 my $self = shift;
768 2 ▶ if (my $prefix = $self->{prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prefix = $self->{'prefix'}) { } 2 0 2
769 2 my $id = $prefix . ++$self->{counter};
770 2 return Attean::Blank->new( $id );
771 } else {
772 0 return Attean::Blank->new();
773 }
774 }
775  
776 2 ▶sub new_literal {
Subroutine new_literal: called CC=9 SCAR=39.5
777 2 my $self = shift;
778 2 my $string = shift;
779 2 my %args;
780 2 ▶ if (my $dt = $self->{datatype}) { # datatype
Branch: 2 branches
BranchTrueFalseTotal
if (my $dt = $self->{'datatype'}) { } 0 2 2
elsif (my $lang = $self->get_language) { } 0 2 2
781 0 $args{datatype} = $dt;
782 0 ▶ if ($dt eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral') {
Branch: 2 branches
BranchTrueFalseTotal
if ($dt eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral') { } 0 0 0
elsif ($dt eq 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map' or $dt eq 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/List') { } 0 0 0
783 0 ▶ if ($HAS_XML_LIBXML) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HAS_XML_LIBXML) 0 0 0
784 0 eval {
785 0 ▶ if ($string =~ m/^</) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^</u) 0 0 0
786 0 my $doc = XML::LibXML->load_xml(string => $string);
787 0 my $canon = $doc->toStringEC14N(1);
788 0 $string = $canon;
789 }
790 };
791 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
792 0 warn "Cannot canonicalize XMLLiteral: $@" . Dumper($string);
793 }
794 }
795 ▶ } elsif ($dt eq 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map' or $dt eq 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/List') {
Condition0%0/3
$dt eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map" or $dt eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/List"
l!l&&r!l&&!r
000
MC/DC0%0/2
$dt eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map" or $dt eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/List"
$dt eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map" $dt eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/List"
Truth table0%0/3
A or B
A= $dt eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map"B= $dt eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/List"
ABresult
1X1
011
000
796 0 my $parse_id = '1';
797 0 my $term = Attean::Literal->new( value => $string, %args );
798 0 my $newterm = AtteanX::Functions::CompositeLists::rewrite_lexical($term, $self->{named_bnodes}, $parse_id);
799 0 $string = $newterm->value;
800 }
801 } elsif (my $lang = $self->get_language) {
802 0 $args{language} = $lang;
803 }
804 2 my $literal = Attean::Literal->new( value => $string, %args );
805 }
806  
807 10 ▶sub new_resource {
Subroutine new_resource: called CC=2 SCAR=6.9
808 10 my $self = shift;
809 10 my $uri = shift;
810 10 my ($base) = $self->get_base;
811 10 ▶ return $self->{new_iri}->( value => $uri, $base ? (base => $base) : () );
Branch: 1 branch
BranchTrueFalseTotal
$base ? : 7 3 10
812 }
813  
814 0 ▶sub get_named_bnode {
Subroutine get_named_bnode: not called CC=2 SCAR=17.9
815 0 my $self = shift;
816 0 my $name = shift;
817 0 ▶ if (my $b = $self->{named_bnodes}{ $name }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $b = $self->{"named_bnodes"}{$name}) 0 0 0
818 0 return $b;
819 }
820
821 0 my $b = $self->new_bnode;
822 0 $self->{named_bnodes}{ $name } = $b;
823 0 return $b;
824 }
825  
826 4 1;
827  
828 __END__
« Test/Attean/W3CManifestTestSuite.pm ↑ Summary AtteanX/Functions/CompositeMaps.pm »