AtteanX/Functions/CompositeLists.pm

filter: Statementstmt 28.9% 133 / 459 Branchbran 10.4% 20 / 192 Conditioncond 3.7% 2 / 54 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 46.0% 23 / 50 Podpod 83.3% 25 / 30 totaltotal 24.8% 203 / 817 CC 123 SCAR 47.3
CC
123
Cov
22%
_compare
306.0
rewrite_lexical
272.0
equals
272.0
CRAP 113.8
« AtteanX/Parser/RDFXML.pm ↑ Summary AtteanX/Functions/CompositeMaps.pm »
1 51 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 51 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 51 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =head1 NAME
6  
7 AtteanX::Functions::CompositeLists - Functions and aggregates to work with composite lists
8  
9 =head1 VERSION
10  
11 This document describes AtteanX::Functions::CompositeLists version 0.041
12  
13 =head1 SYNOPSIS
14  
15 use v5.14;
16 use Attean;
17  
18 =head1 DESCRIPTION
19  
20 This is a utility package that defines functions and aggregates to work with
21 composite list datatypes.
22  
23 =over 4
24  
25 =cut
26  
27 51 package AtteanX::Functions::CompositeLists::TurtleLexerWithNull {
28 51 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 51 ▶ use AtteanX::Parser::Turtle;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 51 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 51 extends 'AtteanX::Parser::Turtle::Lexer';
32  
33 42 ▶ sub get_token {
Subroutine get_token: called CC=7 SCAR=20.0
Pod documented
34 42 my $self = shift;
35 42 while (1) {
36 59 ▶ $self->fill_buffer unless (length($self->buffer));
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->buffer 4 55 59
37  
38 59 ▶ if ($self->buffer =~ /^[ \r\n\t]+/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^[ \r\n\t]+/ou) 17 42 59
39 17 my $start_column = $self->column;
40 17 my $start_line = $self->line;
41 17 my $ws = $self->read_length($+[0]);
42 # we're ignoring whitespace tokens, but we could return them here instead of falling through to the 'next':
43 17 ▶ unless ($self->ignore_whitespace) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->ignore_whitespace) 0 17 17
44 0 return $self->new_token(WS, $start_line, $start_column, $ws);
45 }
46 17 next;
47 }
48  
49 42 my $c = $self->peek_char();
50 42 ▶ return unless (defined($c));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 42 42
51 42 ▶ if ($c eq ':') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq ":") 3 39 42
52 3 $self->read_length(1);
53 3 return AtteanX::Parser::Turtle::Token->fast_constructor(PREFIXNAME, -1, -1, -1, -1, [':']);
54 }
55 39 ▶ if ($self->buffer =~ /^null\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^null\b/u) 0 39 39
56 0 $self->read_length($+[0]);
57 0 return 1;
58 }
59 39 return $self->SUPER::get_token();
60 }
61 }
62 }
63  
64 51 package AtteanX::Functions::CompositeLists 0.041 {
65  
66 51 ▶ use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 51 ▶ use Attean::RDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 51 ▶ use Encode qw(decode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
69 51 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
70 51 ▶ use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
71 51 ▶ use AtteanX::Serializer::TurtleTokens;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 51 ▶ use AtteanX::Parser::Turtle;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 51 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 51 ▶ use AtteanX::Functions::CompositeMaps;
Subroutine BEGIN: called CC=1 SCAR=0.0
75
76 51 our $CDT_BASE = 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/';
77 51 our $LIST_TYPE_IRI = "${CDT_BASE}List";
78  
79 =item C<< lex_to_list($literal) >>
80  
81 =cut
82 4 ▶ sub lex_to_list {
Subroutine lex_to_list: called CC=7 SCAR=20.3
Pod documented
83 4 my $l = shift;
84 4 ▶ die 'TypeError: Cannot parse non-literal to cdt:List: ' . $l->as_string unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 4 4
85 4 my $dt = $l->datatype;
86 4 ▶ die 'TypeError: not a datatype literal' unless ($dt);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt 0 4 4
87 4 ▶ die 'TypeError: Expecting a List but found ' . $dt->value unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 4 4
88 4 my $lex = $l->value;
89 4 $lex =~ s/^\s*//g;
90 4 $lex =~ s/\s*$//g;
91
92 4 ▶ unless ($lex =~ m<^\[(.*)\]$>s) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lex =~ /^\[(.*)\]$/su) 0 4 4
93 0 die 'TypeError: Invalid lexical form for cdt:List literal: ' . $dt->value;
94 }
95
96 4 open(my $fh, '<:encoding(UTF-8)', \$lex);
97 4 my $p = AtteanX::Parser::Turtle->new();
98 4 local($p->{enable_cdt_rewriting}) = 0;
99
100 4 my $lexer = AtteanX::Functions::CompositeLists::TurtleLexerWithNull->new(file => $fh);
101 4 my @nodes;
102 4 eval {
103 4 my $t = $p->_next_nonws($lexer);
104 4 ▶ if ($t->type == LBRACKET or $t->type == ANON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 17 or $t->type == 2) 4 0 4
Condition33%1/3
$t->type == 17 or $t->type == 2
l!l&&r!l&&!r
400
MC/DC0%0/2
$t->type == 17 or $t->type == 2
$t->type == 17 $t->type == 2
Truth table33%1/3
A or B
A= $t->type == 17B= $t->type == 2
ABresult
1X1
011
000
105 4 push(@nodes, @{AtteanX::Functions::CompositeMaps::_recursive_lexer_parse_cdt($p, $lexer)});
106 }
107 # while (my $t = $p->_next_nonws($lexer)) {
108 #
109 # # warn "TOKEN: $t\n";
110 # if ($t and not blessed($t)) {
111 # # this is the special value returned from our lexer subclass that indicates a null values
112 # push(@nodes, undef);
113 # } else {
114 # next if ($t->type == COMMA);
115 # push(@nodes, $p->_object($lexer, $t));
116 # }
117 # }
118 };
119  
120 4 return @nodes;
121
122 # this would create fresh bnodes on each access:
123 # my $mapper = Attean::TermMap->uuid_blank_map;
124 # return map { blessed($_) ? $mapper->map($_) : $_ } @nodes;
125 }
126  
127 =item C<< list_to_lex(@terms) >>
128  
129 =cut
130 4 ▶ sub list_to_lex {
Subroutine list_to_lex: called CC=4 SCAR=14.1
Pod documented
131 4 my @terms = @_;
132 4 my $s = AtteanX::Serializer::TurtleTokens->new( suppress_whitespace => 1 );
133 4 my $bytes = '';
134 4 open(my $io, '>', \$bytes);
135 4 my $first = 1;
136 4 foreach my $t (@terms) {
137 12 my @tokens;
138 12 ▶ unless ($first) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($first) 8 4 12
139 8 push(@tokens, AtteanX::Parser::Turtle::Token->fast_constructor(COMMA, -1, -1, -1, -1, [',']));
140 }
141 12 $first = 0;
142 12 ▶ if (blessed($t)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($t)) { } 12 0 12
143 12 push(@tokens, $t->sparql_tokens->elements);
144 12 my $iter = Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::Parser::Turtle::Token' );
145 12 $s->serialize_iter_to_io($io, $iter);
146 } else {
147 0 my $iter = Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::Parser::Turtle::Token' );
148 0 $s->serialize_iter_to_io($io, $iter);
149 0 print {$io} "null";
150 }
151 }
152 4 close($io);
153 4 my $str = decode_utf8($bytes);
154 4 chomp($str);
155 4 return dtliteral("[${str}]", $LIST_TYPE_IRI);
156 }
157  
158  
159  
160  
161  
162  
163  
164 =item C<< stringSplit($string, $pattern) >>
165  
166 =cut
167 0 ▶ sub stringSplit {
Subroutine stringSplit: not called CC=1 SCAR=6.9
Pod documented
168 0 my $model = shift;
169 0 my $active_graph = shift;
170 0 my $string = shift;
171 0 my $pattern = shift;
172 0 my @parts = map { literal($_) } split(quotemeta($pattern->value), $string->value);
173 0 return list_to_lex(@parts);
174 }
175
176 =item C<< listCreate(@list) >>
177  
178 =cut
179 0 ▶ sub listCreate {
Subroutine listCreate: not called CC=2 SCAR=17.9
Pod documented
180 0 my $model = shift;
181 0 my $active_graph = shift;
182 0 my $literal = eval { list_to_lex(@_) };
183 0 ▶ warn "cdt:List constructor error: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
184 0 return $literal;
185 }
186  
187 =item C<< ctGet($ct, $key) >>
188  
189 =cut
190 0 ▶ sub ctGet {
Subroutine ctGet: not called CC=4 SCAR=30.0
Pod documented
191 0 my $model = shift;
192 0 my $active_graph = shift;
193 0 my $ct = shift;
194 0 my $pos = shift;
195 0 ▶ die 'TypeError: Cannot interpret non-literal as CDT type' unless ($ct->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $ct->does("Attean::API::Literal") 0 0 0
196 0 my $dt = $ct->datatype;
197 0 ▶ if ($dt->value eq $LIST_TYPE_IRI) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI) { } 0 0 0
elsif ($dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI) { } 0 0 0
198 0 return listGet($model, $active_graph, $ct, $pos);
199 } elsif ($dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI) {
200 0 return AtteanX::Functions::CompositeMaps::mapGet($model, $active_graph, $ct, $pos);
201 } else {
202 0 die 'TypeError: Unexpected non-CDT type: ' . $dt->value;
203 }
204 }
205  
206 =item C<< map_terms ( $map ) >>
207  
208 Map the terms contained in this CDT value using the supplied L<Attean::TermMap>
209 map, returning a new CDT value.
210  
211 =cut
212  
213 4 ▶ sub map_terms {
Subroutine map_terms: called CC=5 SCAR=16.7
Pod documented
214 4 my $self = shift;
215 4 my $map = shift;
216 4 my $l = shift;
217 4 ▶ return $l unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 4 4
218 4 my $dt = $l->datatype;
219 4 ▶ return $l unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 4 4
220 4 my @nodes = lex_to_list($l);
221 4 ▶ my @mapped = map { ($map->map($_) || $_) } @nodes;
Condition33%1/3
$map->map($_) || $_
l!l&&r!l&&!r
1200
MC/DC0%0/2
$map->map($_) || $_
$map->map($_) $_
Truth table33%1/3
A || B
A= $map->map($_)B= $_
ABresult
1X1
011
000
222 4 my $literal = eval { list_to_lex(@mapped) };
223 4 ▶ warn "cdt:List term-mapping error: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4 4
224 4 return $literal;
225 }
226  
227 =item C<< listGet($list, $pos) >>
228  
229 =cut
230 0 ▶ sub listGet {
Subroutine listGet: not called CC=6 SCAR=37.4
Pod documented
231 0 my $model = shift;
232 0 my $active_graph = shift;
233 0 my $l = shift;
234 0 my $pos = shift;
235 0 ▶ die 'TypeError: Cannot interpret non-literal as cdt:List' unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 0 0
236 0 my $dt = $l->datatype;
237 0 ▶ die 'TypeError: Unexpected non-List type: ' . $dt->value unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
238 0 my @nodes = lex_to_list($l);
239 0 ▶ die 'TypeError' unless ($pos->does('Attean::API::NumericLiteral') and $pos->datatype->value eq 'http://www.w3.org/2001/XMLSchema#integer');
Branch: 1 branch
BranchTrueFalseTotal
unless $pos->does("Attean::API::NumericLiteral") and $pos->datatype->value eq "http://www.w3.org/2001/XMLSchema#integer" 0 0 0
Condition0%0/3
$pos->does("Attean::API::NumericLiteral") and $pos->datatype->value eq "http://www.w3.org/2001/XMLSchema#integer"
!ll&&!rl&&r
000
MC/DC0%0/2
$pos->does("Attean::API::NumericLiteral") and $pos->datatype->value eq "http://www.w3.org/2001/XMLSchema#integer"
$pos->does("Attean::API::NumericLiteral") $pos->datatype->value eq "http://www.w3.org/2001/XMLSchema#integer"
Truth table0%0/3
A and B
A= $pos->does("Attean::API::NumericLiteral")B= $pos->datatype->value eq "http://www.w3.org/2001/XMLSchema#integer"
ABresult
0X0
100
111
240 0 my $i = int($pos->value) - 1; # cdt:get is 1-based, while the array index below is 0-based
241 0 ▶ die 'Unexpected non-positive get index' unless ($i >= 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $i >= 0 0 0 0
242 0 return $nodes[$i];
243 }
244  
245 =item C<< listSubseq($list, $pos, $len) >>
246  
247 =cut
248 0 ▶ sub listSubseq {
Subroutine listSubseq: not called CC=15 SCAR=54.8
Pod documented
249 0 my $model = shift;
250 0 my $active_graph = shift;
251 0 my $l = shift;
252 0 foreach my $term (@_) {
253 0 ▶ die 'TypeError' unless ($term->does('Attean::API::NumericLiteral') and $term->datatype->value eq 'http://www.w3.org/2001/XMLSchema#integer');
Branch: 1 branch
BranchTrueFalseTotal
unless $term->does("Attean::API::NumericLiteral") and $term->datatype->value eq "http://www.w3.org/2001/XMLSchema#integer" 0 0 0
Condition0%0/3
$term->does("Attean::API::NumericLiteral") and $term->datatype->value eq "http://www.w3.org/2001/XMLSchema#integer"
!ll&&!rl&&r
000
MC/DC0%0/2
$term->does("Attean::API::NumericLiteral") and $term->datatype->value eq "http://www.w3.org/2001/XMLSchema#integer"
$term->does("Attean::API::NumericLiteral") $term->datatype->value eq "http://www.w3.org/2001/XMLSchema#integer"
Truth table0%0/3
A and B
A= $term->does("Attean::API::NumericLiteral")B= $term->datatype->value eq "http://www.w3.org/2001/XMLSchema#integer"
ABresult
0X0
100
111
254 }
255 0 my $pos = shift;
256 0 my @len = @_;
257 0 ▶ die 'TypeError' unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 0 0
258 0 my $dt = $l->datatype;
259 0 ▶ die 'TypeError' unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
260 0 my @nodes = lex_to_list($l);
261 0 my $start = int($pos->value);
262 0 ▶ die 'Unexpected non-positive subseq start argument' unless ($start > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $start > 0 0 0 0
263  
264 0 my @length = map { int($_->value) } @len;
265 0 ▶ if ($start == (1+scalar(@nodes))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start == 1 + scalar(@nodes)) { } 0 0 0
266 0 ▶ die 'Unexpected subseq start argument at end of list with non-zero length' unless ((scalar(@length) and $length[0] == 0) or not(scalar(@length)))
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @length and $length[0] == 0 or not scalar @length 0 0 0
Condition0%0/6
scalar @length and $length[0] == 0 or not scalar @length
l!l&&r!l&&!r
000
scalar @length and $length[0] == 0
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @length and $length[0] == 0 or not scalar @length
scalar @length $length[0] == 0 not scalar @length
Truth table0%0/5
A and B or not(C)
A= scalar @lengthB= $length[0] == 0C= not scalar @length
ABCresult
11X1
0X11
1011
0X00
1000
267 } else {
268 0 ▶ die 'Unexpected subseq start argument past end of list' unless ($start < (1+scalar(@nodes)));
Branch: 1 branch
BranchTrueFalseTotal
unless $start < 1 + scalar(@nodes) 0 0 0
269 }
270 0 ▶ if (scalar(@length)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @length) 0 0 0
271 0 my $end = $start + $length[0];
272 0 ▶ die 'Subseq start+length is beyond the end of the array' if ($end > (1+scalar(@nodes)));
Branch: 1 branch
BranchTrueFalseTotal
if $end > 1 + scalar(@nodes) 0 0 0
273 }
274 0 my @orig = @nodes;
275
276 0 my $from = $start-1;
277 0 ▶ my $to = scalar(@length) ? ($from + $length[0] - 1) : $#nodes;
Branch: 1 branch
BranchTrueFalseTotal
scalar @length ? : 0 0 0
278 0 my @seq = @nodes[$from .. $to];
279 0 return list_to_lex(@seq);
280 }
281  
282 =item C<< listConcat(@lists) >>
283  
284 =cut
285 0 ▶ sub listConcat {
Subroutine listConcat: not called CC=4 SCAR=30.0
Pod documented
286 0 my $model = shift;
287 0 my $active_graph = shift;
288 0 my @lists = @_;
289 0 my @nodes;
290 0 foreach my $l (@lists) {
291 0 ▶ die 'TypeError' unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 0 0
292 0 my $dt = $l->datatype;
293 0 ▶ die 'TypeError' unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
294 0 push(@nodes, lex_to_list($l));
295 }
296
297 0 return list_to_lex(@nodes);
298 }
299  
300 =item C<< listReverse($list, $pos) >>
301  
302 =cut
303 0 ▶ sub listReverse {
Subroutine listReverse: not called CC=3 SCAR=24.8
Pod documented
304 0 my $model = shift;
305 0 my $active_graph = shift;
306 0 my $l = shift;
307 0 ▶ die 'TypeError' unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 0 0
308 0 my $dt = $l->datatype;
309 0 ▶ die 'TypeError' unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
310 0 my @nodes = lex_to_list($l);
311 0 return list_to_lex(reverse @nodes);
312 }
313  
314 =item C<< listHead($list, $pos) >>
315  
316 =cut
317 0 ▶ sub listHead {
Subroutine listHead: not called CC=3 SCAR=24.8
Pod documented
318 0 my $model = shift;
319 0 my $active_graph = shift;
320 0 my $l = shift;
321 0 ▶ die 'TypeError' unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 0 0
322 0 my $dt = $l->datatype;
323 0 ▶ die 'TypeError' unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
324 0 my @nodes = lex_to_list($l);
325 0 return shift(@nodes);
326 }
327  
328 =item C<< listTail($list, $pos) >>
329  
330 =cut
331 0 ▶ sub listTail {
Subroutine listTail: not called CC=4 SCAR=30.0
Pod documented
332 0 my $model = shift;
333 0 my $active_graph = shift;
334 0 my $l = shift;
335 0 ▶ die 'TypeError' unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 0 0
336 0 my $dt = $l->datatype;
337 0 ▶ die 'TypeError' unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
338 0 my @nodes = lex_to_list($l);
339 0 ▶ unless (scalar(@nodes)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @nodes) 0 0 0
340 0 die 'cdt:tail called on an empty list';
341 }
342 0 shift(@nodes);
343 0 return list_to_lex(@nodes);
344 }
345  
346 =item C<< listContains($list, $term) >>
347  
348 =cut
349 0 ▶ sub listContains {
Subroutine listContains: not called CC=6 SCAR=37.4
Pod documented
350 0 my $model = shift;
351 0 my $active_graph = shift;
352 0 my $l = shift;
353 0 my $term = shift;
354 0 ▶ die 'TypeError: Not a literal' unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 0 0
355 0 my $dt = $l->datatype;
356 0 ▶ die 'TypeError: Not a cdt:List' unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
357 0 my @nodes = lex_to_list($l);
358
359 0 foreach my $n (@nodes) {
360 0 ▶ next unless (defined($n)); # null list elements cannot be tested for with CONTAINS
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 0 0
361 0 my $equals = eval { $n->equals($term) };
362 # warn $@ if ($@);
363 0 ▶ return Attean::Literal->true if ($equals);
Branch: 1 branch
BranchTrueFalseTotal
if $equals 0 0 0
364 }
365 0 return Attean::Literal->false;
366 }
367  
368 =item C<< listContainsTerm($list, $term) >>
369  
370 =cut
371 0 ▶ sub listContainsTerm {
Subroutine listContainsTerm: not called CC=9 SCAR=45.0
Pod documented
372 0 my $model = shift;
373 0 my $active_graph = shift;
374 0 my $l = shift;
375 0 my $term = shift;
376 0 ▶ die 'TypeError' unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 0 0
377 0 my $dt = $l->datatype;
378 0 ▶ die 'TypeError' unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
379 0 my @nodes = lex_to_list($l);
380
381 0 foreach my $n (@nodes) {
382 0 ▶ next unless (defined($n)); # null list elements cannot be tested for with CONTAINSTERM
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 0 0
383 0 ▶ if ($n->compare($term)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->compare($term)) 0 0 0
384 0 next;
385 }
386 0 ▶ if ($n->does('Attean::API::Binding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->does('Attean::API::Binding')) { } 0 0 0
387 0 ▶ return Attean::Literal->true if ($n->sameTerms($term));
Branch: 1 branch
BranchTrueFalseTotal
if $n->sameTerms($term) 0 0 0
388 } else {
389 0 ▶ return Attean::Literal->true if ($n->value eq $term->value);
Branch: 1 branch
BranchTrueFalseTotal
if $n->value eq $term->value 0 0 0
390 }
391 }
392 0 return Attean::Literal->false;
393 }
394  
395 =item C<< ctSize($ct) >>
396  
397 =cut
398 0 ▶ sub ctSize {
Subroutine ctSize: not called CC=4 SCAR=30.0
Pod documented
399 0 my $model = shift;
400 0 my $active_graph = shift;
401 0 my $ct = shift;
402 0 my $pos = shift;
403 0 ▶ die 'TypeError' unless ($ct->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $ct->does("Attean::API::Literal") 0 0 0
404 0 my $dt = $ct->datatype;
405 0 ▶ if ($dt->value eq $LIST_TYPE_IRI) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI) { } 0 0 0
elsif ($dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI) { } 0 0 0
406 0 return listSize($model, $active_graph, $ct, $pos);
407 } elsif ($dt->value eq $AtteanX::Functions::CompositeMaps::MAP_TYPE_IRI) {
408 0 return AtteanX::Functions::CompositeMaps::mapSize($model, $active_graph, $ct, $pos);
409 } else {
410 0 die 'TypeError';
411 }
412 }
413  
414 =item C<< listSize($list) >>
415  
416 =cut
417 0 ▶ sub listSize {
Subroutine listSize: not called CC=3 SCAR=24.8
Pod documented
418 0 my $model = shift;
419 0 my $active_graph = shift;
420 0 my $l = shift;
421 0 ▶ die 'TypeError' unless ($l->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $l->does("Attean::API::Literal") 0 0 0
422 0 my $dt = $l->datatype;
423 0 ▶ die 'TypeError' unless ($dt->value eq $LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $dt->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
424 0 my @nodes = lex_to_list($l);
425 0 return Attean::Literal->integer(scalar(@nodes));
426 }
427  
428 =item C<< sequence($start, $end) >>
429  
430 =cut
431 0 ▶ sub sequence {
Subroutine sequence: not called CC=2 SCAR=17.9
Pod documented
432 0 my $model = shift;
433 0 my $active_graph = shift;
434 0 my $start = 1;
435 0 my $end = 1;
436 0 ▶ if (scalar(@_) == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 2) { } 0 0 0
437 0 $start = shift->numeric_value;
438 0 $end = shift->numeric_value;
439 } else {
440 0 $end = shift->numeric_value;
441 }
442 0 my @values = ($start .. $end);
443 0 return list_to_lex(map { Attean::Literal->integer($_) } @values);
444 }
445  
446 =item C<< zip($list, $list) >>
447  
448 =cut
449 0 ▶ sub zip {
Subroutine zip: not called CC=3 SCAR=24.8
Pod documented
450 0 my $model = shift;
451 0 my $active_graph = shift;
452 0 my $lhs = shift;
453 0 my $rhs = shift;
454 0 my @lhs_nodes = lex_to_list($lhs);
455 0 my @rhs_nodes = lex_to_list($rhs);
456 0 ▶ die 'zip operands are not the same length' unless (scalar(@lhs_nodes) == scalar(@rhs_nodes));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @lhs_nodes == scalar @rhs_nodes 0 0 0
457  
458 0 my @elements;
459 0 ▶ while (scalar(@lhs_nodes)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @lhs_nodes) 0 0 0
460 0 my @list = (shift(@lhs_nodes), shift(@rhs_nodes));
461 0 my $l = list_to_lex(@list);
462 0 push(@elements, $l);
463 }
464 0 return list_to_lex(@elements);
465 }
466  
467 =item C<< listCreate_agg_start() >>
468  
469 =cut
470 0 ▶ sub listCreate_agg_start {
Subroutine listCreate_agg_start: not called CC=1 SCAR=6.9
Pod documented
471 0 my $model = shift;
472 0 my $active_graph = shift;
473 return {
474 0 values => []
475 };
476 }
477  
478 =item C<< listCreate_agg_process($thunk, $term) >>
479  
480 =cut
481 0 ▶ sub listCreate_agg_process {
Subroutine listCreate_agg_process: not called CC=1 SCAR=6.9
Pod documented
482 0 my $thunk = shift;
483 0 my ($term) = @_;
484 0 push(@{ $thunk->{'values' }}, $term);
485 }
486  
487 =item C<< listCreate_agg_finalize($thunk) >>
488  
489 =cut
490 0 ▶ sub listCreate_agg_finalize {
Subroutine listCreate_agg_finalize: not called CC=1 SCAR=6.9
Pod documented
491 0 my $thunk = shift;
492 0 my @terms = @{ $thunk->{'values' }};
493 0 return list_to_lex(@terms);
494 }
495  
496 =item C<< list_from_head($head) >>
497  
498 =cut
499 0 ▶ sub list_from_head {
Subroutine list_from_head: not called CC=1 SCAR=6.9
Pod documented
500 0 my $model = shift;
501 0 my $active_graph = shift;
502 0 my $head = shift;
503 0 my $list = $model->get_list($active_graph, $head);
504 0 return list_to_lex($list->elements);
505 }
506  
507 =item C<< rewrite_lexical( $literal, \%bnode_map, $parse_id ) >>
508  
509 =cut
510  
511 # lexer-based rewrite that will preserve the lexical representation of the literal for everything but the blank nodes
512 0 ▶ sub rewrite_lexical {
Subroutine rewrite_lexical: not called CC=16 SCAR=56.1
Pod documented
513 0 my $term = shift;
514 0 my $bnode_map = shift;
515 0 my $parse_id = shift;
516 0 my %bnode_map = %{ $bnode_map };
517 0 ▶ my $rewrite_tokens = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
518 0 my $l = shift;
519 0 my $t = shift;
520 0 ▶ return $t unless (blessed($t));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($t) 0 0 0
521 0 ▶ if ($t->type == BNODE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->type == 4) { } 0 0 0
522 0 my $v = $t->value;
523 0 ▶ if (my $b = $bnode_map{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $b = $bnode_map{$v}) { } 0 0 0
524 0 return $l->new_token(BNODE, $t->start_line, $t->start_column, $b->value);
525 } else {
526 0 my $value = 'b' . sha1_hex($parse_id . $v);
527 0 my $b = Attean::Blank->new(value => $value);
528 0 $bnode_map{$value} = $b;
529 0 return $l->new_token(BNODE, $t->start_line, $t->start_column, $b->value);
530 }
531 } else {
532 0 return $t;
533 }
534 0 };
535 0 my $r = eval {
536 0 my %seen_hathat;
537 my %seen_cdt_iri;
538 0 my %seen_cdt_list_iri;
539 0 my %seen_cdt_map_iri;
540 0 my $lex = $term->value;
541 0 open(my $fh, '<:encoding(UTF-8)', \$lex);
542 0 my $lexer = AtteanX::Functions::CompositeLists::TurtleLexerWithNull->new(file => $fh, ignore_whitespace => 0);
543 0 my $p = AtteanX::Parser::Turtle->new();
544 0 my @rewritten_tokens;
545 0 my $i = 0;
546 0 ▶ while (my $t = $rewrite_tokens->($lexer, $lexer->get_token())) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = &$rewrite_tokens($lexer, $lexer->get_token)) 0 0 0
547 0 ▶ if (blessed($t)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($t)) 0 0 0
548 0 ▶ if ($t->type == HATHAT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->type == 12) { } 0 0 0
elsif ($t->type == 14) { } 0 0 0
549 0 $seen_hathat{$i-1}++;
550 } elsif ($t->type == IRI) {
551 0 ▶ if ($t->value eq 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map') {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->value eq 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map') { } 0 0 0
elsif ($t->value eq 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/List') { } 0 0 0
552 0 $seen_cdt_map_iri{$i-2}++;
553 0 $seen_cdt_iri{$i-2}++;
554 } elsif ($t->value eq 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/List') {
555 0 $seen_cdt_list_iri{$i-2}++;
556 0 $seen_cdt_iri{$i-2}++;
557 }
558 }
559 }
560 0 push(@rewritten_tokens, $t);
561 0 $i++;
562 }
563
564 0 my @rewritten;
565 0 my $j = 0;
566 0 my $s = AtteanX::Serializer::SPARQL->new();
567 0 foreach my $t (@rewritten_tokens) {
568 0 ▶ if (blessed($t) and $t->is_string and $seen_hathat{$j} and $seen_cdt_iri{$j}) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($t) and $t->is_string and $seen_hathat{$j} and $seen_cdt_iri{$j}) 0 0 0
Condition0%0/9
builtin::blessed($t) and $t->is_string and $seen_hathat{$j} and $seen_cdt_iri{$j}
!ll&&!rl&&r
000
builtin::blessed($t) and $t->is_string and $seen_hathat{$j}
!ll&&!rl&&r
000
builtin::blessed($t) and $t->is_string
!ll&&!rl&&r
000
MC/DC0%0/4
builtin::blessed($t) and $t->is_string and $seen_hathat{$j} and $seen_cdt_iri{$j}
builtin::blessed($t) $t->is_string $seen_hathat{$j} $seen_cdt_iri{$j}
Truth table0%0/5
A and B and C and D
A= builtin::blessed($t)B= $t->is_stringC= $seen_hathat{$j}D= $seen_cdt_iri{$j}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
569 0 ▶ my $ct_type = $seen_cdt_list_iri{$j}
Branch: 1 branch
BranchTrueFalseTotal
$seen_cdt_list_iri{$j} ? : 0 0 0
570 ? 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/List'
571 : 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map';
572 0 my $literal = Attean::Literal->new(value => $t->value, datatype => $ct_type);
573 0 my $rewritten = AtteanX::Functions::CompositeLists::rewrite_lexical($literal, $bnode_map, $parse_id);
574 0 my ($t) = $rewritten->sparql_tokens->elements;
575 0 my $i = Attean::ListIterator->new( values => [$t], item_type => 'AtteanX::SPARQL::Token' );
576 0 my $str = decode_utf8($s->serialize_iter_to_bytes($i));
577 0 chomp($str);
578 0 push(@rewritten, $str);
579 0 $j++;
580 0 next;
581 }
582 0 ▶ push(@rewritten, blessed($t) ? $t->token_as_string() : "null");
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($t) ? : 0 0 0
583 0 $j++;
584 }
585 0 my $rewritten = join('', @rewritten);
586 0 Attean::Literal->new(value => $rewritten, datatype => $term->datatype);
587 };
588 0 ▶ warn $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
589 0 ▶ return $r || $term;
Condition0%0/3
$r || $term
l!l&&r!l&&!r
000
MC/DC0%0/2
$r || $term
$r $term
Truth table0%0/3
A || B
A= $rB= $term
ABresult
1X1
011
000
590 }
591  
592 =item C<< register() >>
593  
594 =cut
595 23 ▶ sub register {
Subroutine register: called CC=1 SCAR=0.0
Pod documented
596 23 Attean->register_datatype_role(
597 "${CDT_BASE}List" => 'AtteanX::Functions::CompositeLists::ListLiteral'
598 );
599
600 23 Attean->register_global_functional_form(
601 "${CDT_BASE}List" => \&listCreate,
602 "${CDT_BASE}listCreate" => \&listCreate,
603 );
604 23 Attean->register_global_function(
605 "${CDT_BASE}get" => \&ctGet,
606 "${CDT_BASE}listGet" => \&listGet,
607 "${CDT_BASE}subseq" => \&listSubseq,
608 "${CDT_BASE}size" => \&ctSize,
609 "${CDT_BASE}listSize" => \&listSize,
610 "${CDT_BASE}reverse" => \&listReverse,
611 "${CDT_BASE}head" => \&listHead,
612 "${CDT_BASE}tail" => \&listTail,
613 "${CDT_BASE}contains" => \&listContains,
614 "${CDT_BASE}concat" => \&listConcat,
615 "${CDT_BASE}containsTerm" => \&listContainsTerm,
616 "${CDT_BASE}sequence" => \&sequence,
617 "${CDT_BASE}zip" => \&zip,
618 "${CDT_BASE}split" => \&stringSplit,
619 "${CDT_BASE}list_from_head" => \&list_from_head,
620 );
621  
622 23 Attean->register_global_aggregate(
623 "${CDT_BASE}listAgg" => {
624 start => \&listCreate_agg_start,
625 process => \&listCreate_agg_process,
626 finalize => \&listCreate_agg_finalize,
627 },
628 );
629 }
630 }
631  
632 51 package AtteanX::Functions::CompositeLists::ListLiteral {
633 51 ▶ use Scalar::Util qw(blessed looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
634  
635 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
636 51 ▶ use List::Util qw(min);
Subroutine BEGIN: called CC=1 SCAR=0.0
637  
638 0 ▶ sub equals {
Subroutine equals: not called CC=16 SCAR=56.1
Pod undocumented
639 0 my $lhs = shift;
640 0 my $rhs = shift;
641 # warn "LIST EQUALS?";
642 # warn "- " . $lhs->as_string . "\n";
643 # warn "- " . $rhs->as_string . "\n";
644 0 ▶ return 0 unless ($rhs->does('Attean::API::Literal') and $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless $rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
Condition0%0/3
$rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI
!ll&&!rl&&r
000
MC/DC0%0/2
$rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI
$rhs->does("Attean::API::Literal") $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI
Truth table0%0/3
A and B
A= $rhs->does("Attean::API::Literal")B= $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI
ABresult
0X0
100
111
645 0 my $lhs_size = eval { AtteanX::Functions::CompositeLists::listSize(undef, undef, $lhs)->value };
646 0 ▶ return 0 if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
647 0 my $rhs_size = eval { AtteanX::Functions::CompositeLists::listSize(undef, undef, $rhs)->value };
648 0 ▶ return 0 if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
649 0 ▶ return 0 unless ($lhs_size == $rhs_size);
Branch: 1 branch
BranchTrueFalseTotal
unless $lhs_size == $rhs_size 0 0 0
650
651 0 my $seen_error = 0;
652 0 foreach my $i (0 .. $lhs_size-1) {
653 0 my $li = AtteanX::Functions::CompositeLists::listGet(undef, undef, $lhs, Attean::Literal->integer($i+1));
654 0 my $ri = AtteanX::Functions::CompositeLists::listGet(undef, undef, $rhs, Attean::Literal->integer($i+1));
655 0 ▶ if (not blessed($li) and not blessed($ri)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not builtin::blessed($li) || builtin::blessed($ri)) { } 0 0 0
elsif (not builtin::blessed($li) && builtin::blessed($ri)) { } 0 0 0
Condition0%0/3
builtin::blessed($li) || builtin::blessed($ri)
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($li) || builtin::blessed($ri)
builtin::blessed($li) builtin::blessed($ri)
Truth table0%0/3
A || B
A= builtin::blessed($li)B= builtin::blessed($ri)
ABresult
1X1
011
000
656 # both null
657 0 next;
658 ▶ } elsif (not blessed($li) or not blessed($ri)) {
Condition0%0/3
builtin::blessed($li) && builtin::blessed($ri)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($li) && builtin::blessed($ri)
builtin::blessed($li) builtin::blessed($ri)
Truth table0%0/3
A && B
A= builtin::blessed($li)B= builtin::blessed($ri)
ABresult
0X0
100
111
659 0 return 0;
660 }
661  
662 0 ▶ if ($li->does('Attean::API::Blank') and $ri->does('Attean::API::Blank')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($li->does("Attean::API::Blank") and $ri->does("Attean::API::Blank")) 0 0 0
Condition0%0/3
$li->does("Attean::API::Blank") and $ri->does("Attean::API::Blank")
!ll&&!rl&&r
000
MC/DC0%0/2
$li->does("Attean::API::Blank") and $ri->does("Attean::API::Blank")
$li->does("Attean::API::Blank") $ri->does("Attean::API::Blank")
Truth table0%0/3
A and B
A= $li->does("Attean::API::Blank")B= $ri->does("Attean::API::Blank")
ABresult
0X0
100
111
663 0 ▶ if ($li->value eq $ri->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($li->value eq $ri->value) { } 0 0 0
664 0 next;
665 } else {
666 0 $seen_error++;
667 0 next;
668 }
669 }
670 0 ▶ return 0 unless ($li->equals($ri));
Branch: 1 branch
BranchTrueFalseTotal
unless $li->equals($ri) 0 0 0
671 }
672 0 ▶ if ($seen_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_error) 0 0 0
673 0 die 'TypeError: Cannot compare cdt:List values with blank nodes';
674 }
675 0 return 1;
676 }
677
678 0 ▶ sub order {
Subroutine order: not called CC=1 SCAR=6.9
Pod undocumented
679 0 my $self = shift;
680 0 return _compare('order', $self, @_);
681 }
682
683 0 ▶ sub compare {
Subroutine compare: not called CC=1 SCAR=6.9
Pod undocumented
684 0 my $self = shift;
685 0 return _compare('compare', $self, @_);
686 }
687
688 0 ▶ sub _compare {
Subroutine _compare: not called CC=17 SCAR=57.2
689 0 my $cmp_method = shift;
690 0 my $lhs = shift;
691 0 my $rhs = shift;
692 # warn "LIST-LESS-THAN?";
693 # warn "- " . $lhs->as_string . "\n";
694 # warn "- " . $rhs->as_string . "\n";
695 0 ▶ die 'TypeError' unless (blessed($rhs) and $rhs->does('Attean::API::Literal') and $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($rhs) and $rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI 0 0 0
Condition0%0/6
builtin::blessed($rhs) and $rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI
!ll&&!rl&&r
000
builtin::blessed($rhs) and $rhs->does("Attean::API::Literal")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($rhs) and $rhs->does("Attean::API::Literal") and $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI
builtin::blessed($rhs) $rhs->does("Attean::API::Literal") $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI
Truth table0%0/4
A and B and C
A= builtin::blessed($rhs)B= $rhs->does("Attean::API::Literal")C= $rhs->datatype->value eq $AtteanX::Functions::CompositeLists::LIST_TYPE_IRI
ABCresult
0XX0
10X0
1100
1111
696
697 0 my @lhs = AtteanX::Functions::CompositeLists::lex_to_list($lhs);
698 0 my @rhs = AtteanX::Functions::CompositeLists::lex_to_list($rhs);
699
700 0 my $lhs_size = scalar(@lhs);
701 0 my $rhs_size = scalar(@rhs);
702  
703 0 my $seen_error = 0;
704 0 my $length = min($lhs_size, $rhs_size);
705 0 foreach my $i (0 .. $length-1) {
706 0 my $li = AtteanX::Functions::CompositeLists::listGet(undef, undef, $lhs, Attean::Literal->integer($i+1));
707 0 my $ri = AtteanX::Functions::CompositeLists::listGet(undef, undef, $rhs, Attean::Literal->integer($i+1));
708
709 0 ▶ if (not blessed($li) and not blessed($ri)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not builtin::blessed($li) || builtin::blessed($ri)) { } 0 0 0
elsif (not builtin::blessed($li)) { } 0 0 0
elsif (not builtin::blessed($ri)) { } 0 0 0
Condition0%0/3
builtin::blessed($li) || builtin::blessed($ri)
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($li) || builtin::blessed($ri)
builtin::blessed($li) builtin::blessed($ri)
Truth table0%0/3
A || B
A= builtin::blessed($li)B= builtin::blessed($ri)
ABresult
1X1
011
000
710 # both null
711 0 next;
712 } elsif (not blessed($li)) {
713 0 ▶ if ($cmp_method eq 'order') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp_method eq 'order') { } 0 0 0
714 0 return -1;
715 } else {
716 0 die 'TypeError';
717 0 $seen_error++;
718 0 next;
719 }
720 } elsif (not blessed($ri)) {
721 0 ▶ if ($cmp_method eq 'order') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmp_method eq 'order') { } 0 0 0
722 0 return 1;
723 } else {
724 0 die 'TypeError';
725 0 $seen_error++;
726 0 next;
727 }
728 }
729  
730 0 ▶ if ($li->does('Attean::API::Blank') and $ri->does('Attean::API::Blank')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($li->does("Attean::API::Blank") and $ri->does("Attean::API::Blank")) 0 0 0
Condition0%0/3
$li->does("Attean::API::Blank") and $ri->does("Attean::API::Blank")
!ll&&!rl&&r
000
MC/DC0%0/2
$li->does("Attean::API::Blank") and $ri->does("Attean::API::Blank")
$li->does("Attean::API::Blank") $ri->does("Attean::API::Blank")
Truth table0%0/3
A and B
A= $li->does("Attean::API::Blank")B= $ri->does("Attean::API::Blank")
ABresult
0X0
100
111
731 0 die 'TypeError';
732 0 $seen_error++;
733 0 next;
734 }
735
736 0 my $icmp = $li->$cmp_method($ri);
737 0 ▶ next if ($icmp == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $icmp == 0 0 0 0
738 0 return $icmp;
739 }
740
741 0 ▶ if ($seen_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_error) 0 0 0
742 0 die 'TypeError';
743 }
744
745 0 ▶ if ($lhs_size == $rhs_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lhs_size == $rhs_size) { } 0 0 0
746 0 return 0;
747 } else {
748 0 ▶ return ($lhs_size > $rhs_size) ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$lhs_size > $rhs_size ? : 0 0 0
749 }
750 }
751  
752 0 ▶ sub canonicalized_term {
Subroutine canonicalized_term: not called CC=1 SCAR=6.9
Pod undocumented
753 0 my $self = shift;
754 0 return $self->canonicalized_term_strict();
755 }
756  
757 0 ▶ sub canonicalized_term_strict {
Subroutine canonicalized_term_strict: not called CC=1 SCAR=6.9
Pod undocumented
758 0 my $self = shift;
759 0 my @values = AtteanX::Functions::CompositeLists::lex_to_list($self);
760 0 return AtteanX::Functions::CompositeLists::list_to_lex(@values);
761 }
762  
763 51 with 'Attean::API::Literal';
764 51 with 'Attean::API::CanonicalizingLiteral';
765 }
766  
767 51 1;
768  
769 __END__
« AtteanX/Parser/RDFXML.pm ↑ Summary AtteanX/Functions/CompositeMaps.pm »