Attean/API/Binding.pm

filter: Statementstmt 74.6% 410 / 549 Branchbran 43.8% 71 / 162 Conditioncond 47.9% 23 / 48 MC/DCmcdc 25.8% 8 / 31 Subroutinesub 86.9% 73 / 84 Podpod 49.0% 25 / 51 totaltotal 65.9% 610 / 925 CC 125 SCAR 29.7
CC
125
Cov
66%
equals
110.0
_compare
110.0
sameTerms
56.0
CRAP 19.4
« Attean/DatasetModel.pm ↑ Summary Attean/API/Query.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  
4 =head1 NAME
5  
6 Attean::API::Binding - Name to term bindings
7  
8 =head1 VERSION
9  
10 This document describes Attean::API::Binding version 0.041
11  
12 =head1 DESCRIPTION
13  
14 The Attean::API::Binding role defines a common API for all objects that map
15 names to L<Attean::API::Term> objects. This includes triples, quads, and
16 SPARQL results (variable bindings).
17  
18 =head1 REQUIRED METHODS
19  
20 Classes consuming this role must provide the following methods:
21  
22 =over 4
23  
24 =item C<< value( $name ) >>
25  
26 Returns the L<Attean::API::Term> object mapped to the variable named C<< $name >>,
27 or C<< undef >> if no such term is mapped.
28  
29 =item C<< variables >>
30  
31 Returns a list of the variable names mapped to L<Attean::API::Term> objects in
32 this mapping.
33  
34 =item C<< apply_map( $mapper ) >>
35  
36 Returns a new mapping object (of the same class as the referent) with term
37 objects rewritten using the supplied L<Attean::Mapper> object C<< $mapper >>.
38  
39 =back
40  
41 =head1 METHODS
42  
43 This role provides default implementations of the following methods:
44  
45 =over 4
46  
47 =item C<< mapping >>
48  
49 Returns a HASH mapping variable names to L<Attean::API::Term> objects.
50  
51 =item C<< values >>
52  
53 Returns a list of L<Attean::API::Term> objects corresponding to the variable
54 names returned by the referent's C<< variables >> method.
55  
56 =item C<< tuples_string >>
57  
58 Returns a string serialization of the L<Attean::API::Term> objects in the order
59 they are returned by the referent's C<< values >> method.
60  
61 =item C<< as_string >>
62  
63 Returns a string serialization of the variable bindings.
64  
65 =item C<< has_blanks >>
66  
67 Returns true if any variable is bound to an L<Attean::API::Blank> term, false
68 otherwise.
69  
70 =cut
71  
72 51 ▶use Type::Tiny::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 51 package Attean::API::Binding 0.041 {
75 51 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
76 51 ▶ use List::Util qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
79
80 51 requires 'value';
81 51 requires 'variables';
82 51 requires 'apply_map';
83
84 61 ▶ sub mapping {
Subroutine mapping: called CC=1 SCAR=0.0
Pod documented
85 61 my $self = shift;
86 61 my @k = $self->variables;
87 61 my @v = $self->values;
88 61 return mesh \@k, \@v;
89 }
90
91 34 ▶ sub values {
Subroutine values: called CC=1 SCAR=0.0
Pod documented
92 34 my $self = shift;
93 34 return map { $self->value($_) } $self->variables;
94 }
95
96 406 ▶ sub tuples_string {
Subroutine tuples_string: called CC=1 SCAR=0.0
Pod documented
97 406 my $self = shift;
98 406 my @strs = map { $_->ntriples_string } $self->values;
99 406 return join(' ', @strs) . ' .';
100 }
101 268 ▶ sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
102 268 shift->tuples_string();
103 }
104
105 86 ▶ sub has_blanks {
Subroutine has_blanks: called CC=5 SCAR=17.8
Pod documented
106 86 my $self = shift;
107 86 foreach my $term ($self->values) {
108 126 ▶ return 1 if ($term->does('Attean::API::Blank'));
Branch: 1 branch
BranchTrueFalseTotal
if $term->does("Attean::API::Blank") 69 57 126
109 57 ▶ if ($term->does('Attean::API::Binding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does("Attean::API::Binding")) 0 57 57
110 0 ▶ return 1 if ($term->has_blanks);
Branch: 1 branch
BranchTrueFalseTotal
if $term->has_blanks 0 0 0
111 }
112 }
113 17 return 0;
114 }
115
116 =item C<< sameTerms( $other ) >>
117  
118 =cut
119  
120 0 ▶ sub sameTerms {
Subroutine sameTerms: not called CC=7 SCAR=40.3
Pod documented
121 0 my $self = shift;
122 0 my $other = shift;
123 0 ▶ return 0 unless ($other->does('Attean::API::Binding'));
Branch: 1 branch
BranchTrueFalseTotal
unless $other->does("Attean::API::Binding") 0 0 0
124 0 my @variables = sort $self->variables;
125 0 my @other_vars = sort $other->variables;
126 0 ▶ return 0 unless (scalar(@variables) == scalar(@other_vars));
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @variables == scalar @other_vars 0 0 0
127 0 foreach my $i (0 .. $#variables) {
128 0 ▶ return 0 unless $variables[$i] eq $other_vars[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $variables[$i] eq $other_vars[$i] 0 0 0
129 }
130
131 0 foreach my $v (@variables) {
132 0 my $value = $self->value($v);
133 0 my $other_value = $other->value($v);
134 0 ▶ return 0 unless $value->sameTerms($other_value);
Branch: 1 branch
BranchTrueFalseTotal
unless $value->sameTerms($other_value) 0 0 0
135 }
136 0 return 1;
137 }
138
139 =item C<< equals( $other ) >>
140  
141 =cut
142  
143 0 ▶ sub equals {
Subroutine equals: not called CC=10 SCAR=47.0
Pod documented
144 0 my $self = shift;
145 0 my $other = shift;
146 0 ▶ return 0 unless ($other->does('Attean::API::Binding'));
Branch: 1 branch
BranchTrueFalseTotal
unless $other->does("Attean::API::Binding") 0 0 0
147 0 my @variables = sort $self->variables;
148 0 my @other_vars = sort $other->variables;
149 0 ▶ unless (scalar(@variables) == scalar(@other_vars)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @variables == scalar @other_vars) 0 0 0
150 0 return 0;
151 }
152 0 foreach my $i (0 .. $#variables) {
153 0 ▶ unless ($variables[$i] eq $other_vars[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($variables[$i] eq $other_vars[$i]) 0 0 0
154 0 return 0;
155 }
156 }
157
158 0 foreach my $v (@variables) {
159 0 my $value = $self->value($v);
160 0 my $other_value = $other->value($v);
161 0 ▶ if ($value->does('Attean::API::Binding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->does('Attean::API::Binding')) { } 0 0 0
162 0 ▶ unless ($value->equals($other_value)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value->equals($other_value)) 0 0 0
163 0 return 0;
164 }
165 } else {
166 0 my $cmp = eval { $value->compare($other_value) };
167 0 ▶ unless (defined($cmp) and 0 == $cmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cmp and 0 == $cmp) 0 0 0
Condition0%0/3
defined $cmp and 0 == $cmp
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cmp and 0 == $cmp
defined $cmp 0 == $cmp
Truth table0%0/3
A and B
A= defined $cmpB= 0 == $cmp
ABresult
0X0
100
111
168 0 return 0;
169 }
170 }
171 }
172 0 return 1;
173 }
174
175 =item C<< blanks >>
176  
177 Returns all the values in this mapping (recursively, if any values are embedded
178 bindings) that are blank nodes.
179  
180 =cut
181  
182 60 ▶ sub blanks {
Subroutine blanks: called CC=5 SCAR=16.7
Pod documented
183 60 my $self = shift;
184 60 my %nodes;
185 60 foreach my $term ($self->values) {
186 220 ▶ if ($term->does('Attean::API::Blank')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does("Attean::API::Blank")) 80 140 220
187 80 $nodes{ $term->value } = $term;
188 }
189 220 ▶ if ($term->does('Attean::API::Binding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does("Attean::API::Binding")) 0 220 220
190 0 foreach my $b ($term->blanks) {
191 0 $nodes{ $b->value } = $b;
192 }
193 }
194 }
195 60 return CORE::values %nodes;
196 }
197
198 =item C<< referenced_variables >>
199  
200 Returns a list of the names of any variable values that are referenced in this
201 binding (recursively, if any values are embedded bindings).
202  
203 =cut
204  
205 120 ▶ sub referenced_variables {
Subroutine referenced_variables: called CC=5 SCAR=16.1
Pod documented
206 120 my $self = shift;
207 120 my %vars;
208 120 foreach my $v ($self->values) {
209 360 ▶ if ($v->does('Attean::API::Variable')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v->does('Attean::API::Variable')) { } 153 207 360
elsif ($v->does('Attean::API::Binding')) { } 11 196 207
210 153 $vars{$v->value}++;
211 } elsif ($v->does('Attean::API::Binding')) {
212 11 foreach my $name ($v->referenced_variables) {
213 11 $vars{$name}++;
214 }
215 }
216 }
217 120 return keys %vars;
218 }
219
220 =item C<< is_ground >>
221  
222 Returns tue is all the bound values consume L<Attean::API::Term>, false otherwise.
223  
224 =cut
225  
226 164 ▶ sub is_ground {
Subroutine is_ground: called CC=2 SCAR=7.1
Pod documented
227 164 my $self = shift;
228 164 my @non_terms = grep { not($_->does('Attean::API::Term')) } $self->values;
229 164 ▶ my @bad = grep { not($_->does('Attean::API::Binding') and $_->is_ground) } @non_terms;
Condition33%1/3
$_->does('Attean::API::Binding') && $_->is_ground
!ll&&!rl&&r
1700
MC/DC0%0/2
$_->does('Attean::API::Binding') && $_->is_ground
$_->does('Attean::API::Binding') $_->is_ground
Truth table33%1/3
A && B
A= $_->does('Attean::API::Binding')B= $_->is_ground
ABresult
0X0
100
111
230 164 return (scalar(@bad) == 0);
231 }
232
233 =item C<< values_consuming_role( $role ) >>
234  
235 Returns the list of bound values that consume C<< $role >>.
236  
237 =cut
238  
239 294 ▶ sub values_consuming_role {
Subroutine values_consuming_role: called CC=1 SCAR=0.0
Pod documented
240 294 my $self = shift;
241 294 my $role = shift;
242 294 return grep { $_->does($role) } $self->values;
243 }
244
245 =item C<< tree_attributes >>
246  
247 Returns the variables which are bound in this object.
248  
249 =cut
250  
251 2 ▶ sub tree_attributes {
Subroutine tree_attributes: called CC=1 SCAR=0.0
Pod documented
252 2 my $self = shift;
253 2 return $self->variables;
254 }
255
256 =item C<< apply_bindings( $binding ) >>
257  
258 Construct a new binding by replacing variables with their bound values from
259 C<< $binding >>.
260  
261 =cut
262  
263 0 ▶ sub apply_bindings {
Subroutine apply_bindings: not called CC=6 SCAR=37.4
Pod documented
264 0 my $self = shift;
265 0 my $class = ref($self);
266 0 my $bind = shift;
267 0 my %data;
268 0 foreach my $k ($self->variables) {
269 0 my $v = $self->value($k);
270 0 ▶ if ($v->does('Attean::API::TriplePattern')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v->does('Attean::API::TriplePattern')) { } 0 0 0
elsif ($v->does('Attean::API::Variable')) { } 0 0 0
271 0 my $replace = $v->apply_bindings($bind);
272 0 $data{ $k } = $replace;
273 } elsif ($v->does('Attean::API::Variable')) {
274 0 my $name = $v->value;
275 0 my $replace = $bind->value($name);
276 0 ▶ if (defined($replace) and blessed($replace)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $replace and builtin::blessed($replace)) { } 0 0 0
Condition0%0/3
defined $replace and builtin::blessed($replace)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $replace and builtin::blessed($replace)
defined $replace builtin::blessed($replace)
Truth table0%0/3
A and B
A= defined $replaceB= builtin::blessed($replace)
ABresult
0X0
100
111
277 0 $data{ $k } = $replace;
278 } else {
279 0 $data{ $k } = $v;
280 }
281 } else {
282 0 $data{ $k } = $v;
283 }
284 }
285 0 return $class->new( bindings => \%data );
286 }
287 }
288  
289 51 package Attean::API::TripleOrQuadPattern 0.041 {
290 51 ▶ use Encode qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
291 51 ▶ use List::Util qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
292 51 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
293 51 ▶ use Attean::RDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
294 51 ▶ use Attean::API::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
295  
296 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
297  
298 51 with 'Attean::API::SPARQLSerializable';
299
300 1464 ▶ around BUILDARGS => sub {
Subroutine __ANON__: called CC=13 SCAR=26.3
301 1464 my $orig = shift;
302 1464 my $class = shift;
303 1464 my @args = @_;
304 1464 ▶ if (scalar(@args) == 0 or not(defined($_[0])) or blessed($args[0])) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args == 0 or not defined $_[0] or builtin::blessed($args[0])) { } 231 1233 1464
elsif (scalar @args == 2) { } 9 1224 1233
Condition83%5/6
scalar @args == 0 or not defined $_[0] or builtin::blessed($args[0])
l!l&&r!l&&!r
102211233
scalar @args == 0 or not defined $_[0]
l!l&&r!l&&!r
1001454
MC/DC66%2/3
scalar @args == 0 or not defined $_[0] or builtin::blessed($args[0])
scalar @args == 0 not defined $_[0] builtin::blessed($args[0])
Truth table75%3/4
A or not(B) or C
A= scalar @args == 0B= not defined $_[0]C= builtin::blessed($args[0])
ABCresult
1XX1
01X1
0011
0000
305 231 my @names = $class->variables;
306 231 foreach my $i (0 .. $#names) {
307 711 my $k = $names[$i];
308 711 my $v = $args[$i];
309 711 ▶ unless (defined($v)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $v) 40 671 711
310 40 $args[$i] = Attean::RDF::variable($k);
311 }
312 }
313 231 my %args;
314 231 @args{ $class->variables } = @args;
315 231 return $class->$orig(%args);
316 } elsif (scalar(@args) == 2) {
317 9 ▶ if (defined($args[0]) and $args[0] eq 'bindings') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args[0] and $args[0] eq "bindings") 0 9 9
Condition33%1/3
defined $args[0] and $args[0] eq "bindings"
!ll&&!rl&&r
090
MC/DC0%0/2
defined $args[0] and $args[0] eq "bindings"
defined $args[0] $args[0] eq "bindings"
Truth table33%1/3
A and B
A= defined $args[0]B= $args[0] eq "bindings"
ABresult
0X0
100
111
318 0 return $class->$orig(%{ $args[1] });
319 }
320 }
321
322 1233 ▶ if (scalar(@_) % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar(@_) % 2) 0 1233 1233
323 0 Carp::cluck;
324 }
325 1233 my %args = @_;
326 1233 foreach my $k ($class->variables) {
327 4460 ▶ if (not(exists $args{$k}) or not($args{$k})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{$k} and $args{$k}) 214 4246 4460
Condition100%3/3
exists $args{$k} and $args{$k}
!ll&&!rl&&r
371774246
MC/DC100%2/2
exists $args{$k} and $args{$k}
exists $args{$k} $args{$k}
Truth table100%3/3
A and B
A= exists $args{$k}B= $args{$k}
ABresult
0X0
100
111
328 214 $args{$k} = Attean::RDF::variable($k);
329 }
330 }
331
332 1233 return $class->$orig(%args);
333 51 };
334  
335 57 ▶ sub apply_map {
Subroutine apply_map: called CC=3 SCAR=11.0
Pod undocumented
336 57 my $self = shift;
337 57 my $class = ref($self);
338 57 my $mapper = shift;
339 57 my %values;
340 57 foreach my $pos ($self->variables) {
341 215 my $value = $self->value($pos);
342 215 ▶ if ($value->does('Attean::API::Binding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->does('Attean::API::Binding')) { } 1 214 215
343 1 $values{$pos} = $value->apply_map($mapper);
344 } else {
345 214 $values{$pos} = $mapper->map($value);
346 }
347 }
348 57 return $class->new( %values );
349 }
350
351 2 ▶ sub apply_statement {
Subroutine apply_statement: called CC=5 SCAR=16.5
Pod undocumented
352 2 my $self = shift;
353 2 my $class = ref($self);
354 2 my $bind = shift;
355 2 my %data;
356 2 foreach my $k ($self->variables) {
357 7 my $v = $self->value($k);
358 7 ▶ if ($v->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->does("Attean::API::Variable")) 3 4 7
359 3 my $name = $v->value;
360 3 my $replace = $bind->value($name);
361 3 ▶ if (defined($replace) and blessed($replace)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $replace and builtin::blessed($replace)) { } 3 0 3
Condition33%1/3
defined $replace and builtin::blessed($replace)
!ll&&!rl&&r
003
MC/DC0%0/2
defined $replace and builtin::blessed($replace)
defined $replace builtin::blessed($replace)
Truth table33%1/3
A and B
A= defined $replaceB= builtin::blessed($replace)
ABresult
0X0
100
111
362 3 $data{ $k } = $replace;
363 } else {
364 0 $data{ $k } = $v;
365 }
366 }
367 }
368 2 return Attean::Result->new( bindings => \%data );
369 }
370  
371 14 ▶ sub canonicalize {
Subroutine canonicalize: called CC=2 SCAR=6.9
Pod undocumented
372 14 my $self = shift;
373 14 my $type = ref($self);
374 14 ▶ my $role = $self->does('Attean::API::TriplePattern') ? 'Attean::API::TriplePattern' : 'Attean::API::QuadPattern';
Branch: 1 branch
BranchTrueFalseTotal
$self->does('Attean::API::TriplePattern') ? : 6 8 14
375 14 my $iter = Attean::ListIterator->new( values => [$self], item_type => $role );
376 14 my $triples = $iter->canonical_set();
377 14 my ($t) = @$triples;
378 14 return $t;
379 }
380  
381 85 ▶ sub ground {
Subroutine ground: called CC=6 SCAR=18.9
Pod undocumented
382 85 my $self = shift;
383 85 ▶ my $result = shift || Attean::Result->new(bindings => {});
Condition33%1/3
shift() || 'Attean::Result'->new('bindings', {})
l!l&&r!l&&!r
8500
MC/DC0%0/2
shift() || 'Attean::Result'->new('bindings', {})
shift() 'Attean::Result'->new('bindings', {})
Truth table33%1/3
A || B
A= shift()B= 'Attean::Result'->new('bindings', {})
ABresult
1X1
011
000
384
385 85 my %bindings;
386 85 my @vars = $self->variables();
387 85 foreach my $pos (@vars) {
388 340 my $pp = $self->$pos();
389 340 ▶ if ($pp->does('Attean::API::Variable')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pp->does('Attean::API::Variable')) { } 200 140 340
elsif ($pp->does('Attean::API::TriplePattern')) { } 0 140 140
390 200 $bindings{ $pos } = $result->value($pp->value);
391 } elsif ($pp->does('Attean::API::TriplePattern')) {
392 0 my $sub_ground = $pp->ground($result);
393 0 $bindings{ $pos } = $sub_ground;
394 } else {
395 140 $bindings{ $pos } = $pp;
396 }
397 }
398
399 85 ▶ my $st = scalar(@vars) == 3
Branch: 1 branch
BranchTrueFalseTotal
scalar @vars == 3 ? : 0 85 85
400 ? Attean::Triple->new( %bindings )
401 : Attean::Quad->new( %bindings );
402 85 $st->validate;
403 85 return $st;
404 }
405
406 316 ▶ sub unify {
Subroutine unify: called CC=12 SCAR=34.4
Pod undocumented
407 316 my $self = shift;
408 316 my $quad = shift;
409 316 my %binding;
410 316 foreach my $pos ($self->variables) {
411 1221 my $pp = $self->$pos();
412 1221 my $qp = $quad->$pos();
413 1221 ▶ if ($pp->does('Attean::API::Variable')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pp->does('Attean::API::Variable')) { } 849 372 1221
elsif ($pp->does('Attean::API::TriplePattern')) { } 0 372 372
414 849 ▶ if (my $already = $binding{ $pp->value }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $already = $binding{$pp->value}) 0 849 849
415 0 ▶ return unless $already->equals($qp);
Branch: 1 branch
BranchTrueFalseTotal
unless $already->equals($qp) 0 0 0
416 }
417 849 $binding{ $pp->value } = $qp;
418 } elsif ($pp->does('Attean::API::TriplePattern')) {
419 0 ▶ return unless ($qp->does('Attean::API::Triple'));
Branch: 1 branch
BranchTrueFalseTotal
unless $qp->does("Attean::API::Triple") 0 0 0
420 0 my $sub_binding = $pp->unify($qp);
421 0 ▶ return unless $sub_binding;
Branch: 1 branch
BranchTrueFalseTotal
unless $sub_binding 0 0 0
422 0 my $bkeys = Set::Scalar->new(keys %binding);
423 0 my $sbkeys = Set::Scalar->new($sub_binding->variables);
424 0 my $i = $bkeys->intersection($sbkeys);
425 0 for my $key ($i->elements) {
426 # variable bound in multiple places with different values
427 0 ▶ return unless ($binding{$key}->equals($sub_binding->value($key)));
Branch: 1 branch
BranchTrueFalseTotal
unless $binding{$key}->equals($sub_binding->value($key)) 0 0 0
428 }
429 0 my $mapping = {$sub_binding->mapping};
430 0 @binding{ keys %$mapping } = values %$mapping;
431 } else {
432 # bound position doesn't match
433 51 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
434 372 ▶ if ($pp->does('Attean::API::QuadPattern')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pp->does("Attean::API::QuadPattern")) 0 372 372
435 0 Carp::cluck 'XXX unify: ' . Dumper($self);
436 }
437
438 372 ▶ return unless ($pp->equals($qp));
Branch: 1 branch
BranchTrueFalseTotal
unless $pp->equals($qp) 15 357 372
439 }
440 }
441
442 # warn 'final mapping: ' . Dumper(\%binding);
443 301 return Attean::Result->new( bindings => \%binding );
444 }
445  
446 =item C<< parse ( $string ) >>
447  
448 Returns a triple or quad pattern object using the variables and/or terms
449 parsed from C<< $string >> in SPARQL syntax.
450  
451 =cut
452  
453 4 ▶ sub parse {
Subroutine parse: called CC=3 SCAR=11.4
Pod undocumented
454 4 my $self = shift;
455 4 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
456 4 my $string = shift;
457 4 my $bytes = encode('UTF-8', $string, Encode::FB_CROAK);
458 4 my $parser = Attean->get_parser('SPARQL')->new(@_);
459 4 my @values = $parser->parse_nodes($bytes);
460 4 my @keys = $self->variables;
461
462 4 my $f = scalar(@values);
463 4 my $e = scalar(@keys);
464 4 ▶ unless ($e == $f) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($e == $f) 0 4 4
465 0 die "${class}->parse found wrong number of nodes (found $f but expecting $e)";
466 }
467 4 return $self->new(mesh \@keys, \@values);
468 }
469 }
470  
471 51 package Attean::API::TripleOrQuad 0.041 {
472 51 ▶ use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
473 51 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
474  
475 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
476  
477 51 with 'Attean::API::TripleOrQuadPattern';
478  
479 783 ▶ sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
480 783 my $self = shift;
481 783 ▶ if (any { $_->does('Attean::API::Variable') } $self->values) {
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_->does("Attean::API::Variable"); } , $self->values)) 2 781 783
482 2 confess 'Use a Pattern class to construct when using variables';
483 }
484 }
485 }
486  
487 51 package Attean::API::TriplePattern 0.041 {
488 51 ▶ use List::Util qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
489 51 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
490  
491 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
492
493 51 my @vars = qw(subject predicate object);
494 1471 ▶ sub variables { return @vars }
Subroutine variables: called CC=1 SCAR=0.0
Pod documented
495  
496 119 ▶ sub value {
Subroutine value: called CC=2 SCAR=6.9
Pod documented
497 119 my $self = shift;
498 119 my $key = shift;
499 119 ▶ return $self->$key() if ($key =~ /^(subject|predicate|object)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^(subject|predicate|object)$/u 118 1 119
500 1 die "Unrecognized binding name '$key'";
501 }
502
503 892 ▶ sub values {
Subroutine values: called CC=1 SCAR=0.0
Pod documented
504 892 my $self = shift;
505 return (
506 892 $self->subject,
507 $self->predicate,
508 $self->object
509 );
510 }
511
512 26 ▶ sub as_quad_pattern {
Subroutine as_quad_pattern: called CC=1 SCAR=0.0
Pod documented
513 26 my $self = shift;
514 26 my $graph = shift;
515 26 my @keys = Attean::API::Quad->variables;
516 26 my @values = ($self->values, $graph);
517 26 return Attean::QuadPattern->new(mesh \@keys, \@values);
518 }
519
520 0 ▶ sub as_triple {
Subroutine as_triple: not called CC=3 SCAR=24.8
Pod undocumented
521 0 my $self = shift;
522 0 ▶ unless ($self->is_ground) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_ground) 0 0 0
523 0 die "Not a ground triple: " . $self->as_string;
524 }
525 0 ▶ my @terms = map { $_->does('Attean::API::TriplePattern') ? $_->as_triple : $_ } $self->values;
Branch: 1 branch
BranchTrueFalseTotal
$_->does('Attean::API::TriplePattern') ? : 0 0 0
526 0 my $t = Attean::Triple->new(@terms);
527 0 $t->validate();
528 0 return $t;
529 }
530
531 1 ▶ sub apply_triple {
Subroutine apply_triple: called CC=1 SCAR=0.0
Pod undocumented
532 1 my $self = shift;
533 1 return $self->apply_statement(@_);
534 }
535  
536 4 ▶ sub matches {
Subroutine matches: called CC=9 SCAR=25.4
Pod undocumented
537 4 my $self = shift;
538 4 my $ground = shift;
539 4 ▶ return 0 unless (ref($ground) eq 'Attean::Triple' or $ground->does('Attean::API::Triple'));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ground eq "Attean::Triple" or $ground->does("Attean::API::Triple") 0 4 4
Condition33%1/3
ref $ground eq "Attean::Triple" or $ground->does("Attean::API::Triple")
l!l&&r!l&&!r
400
MC/DC0%0/2
ref $ground eq "Attean::Triple" or $ground->does("Attean::API::Triple")
ref $ground eq "Attean::Triple" $ground->does("Attean::API::Triple")
Truth table33%1/3
A or B
A= ref $ground eq "Attean::Triple"B= $ground->does("Attean::API::Triple")
ABresult
1X1
011
000
540 4 foreach my $method (@vars) {
541 12 my $term = $self->$method();
542 12 ▶ unless (ref($term) eq 'Attean::Variable' or $term->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $term eq "Attean::Variable" or $term->does("Attean::API::Variable")) 2 10 12
Condition66%2/3
ref $term eq "Attean::Variable" or $term->does("Attean::API::Variable")
l!l&&r!l&&!r
1002
MC/DC50%1/2
ref $term eq "Attean::Variable" or $term->does("Attean::API::Variable")
ref $term eq "Attean::Variable" $term->does("Attean::API::Variable")
Truth table66%2/3
A or B
A= ref $term eq "Attean::Variable"B= $term->does("Attean::API::Variable")
ABresult
1X1
011
000
543 2 my $gterm = $ground->$method();
544 2 my $eq;
545 2 ▶ if ($term->does('Attean::API::TripleOrQuadPattern')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does('Attean::API::TripleOrQuadPattern')) { } 2 0 2
546 2 $eq = $term->matches($gterm);
547 } else {
548 0 $eq = eval { $term->equals($gterm) };
549 0 ▶ warn $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
550 }
551 2 ▶ return 0 unless ($eq);
Branch: 1 branch
BranchTrueFalseTotal
unless $eq 0 2 2
552 }
553 }
554 4 return 1;
555 }
556
557 103 ▶ sub sparql_tokens {
Subroutine sparql_tokens: called CC=3 SCAR=11.0
Pod undocumented
558 103 my $self = shift;
559 103 my @tokens;
560 103 foreach my $t ($self->values) {
561 309 ▶ if ($t->does('Attean::API::TriplePattern')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->does('Attean::API::TriplePattern')) { } 1 308 309
562 1 push(@tokens, AtteanX::SPARQL::Token->ltltp);
563 1 push(@tokens, $t->sparql_tokens->elements);
564 1 push(@tokens, AtteanX::SPARQL::Token->pgtgt);
565 } else {
566 308 push(@tokens, $t->sparql_tokens->elements);
567 }
568 }
569 103 return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' );
570 }
571
572 51 requires 'subject';
573 51 requires 'predicate';
574 51 requires 'object';
575  
576 51 with 'Attean::API::TripleOrQuadPattern', 'Attean::API::Binding', 'Attean::API::TermOrVariableOrTriplePattern';
577 }
578  
579 51 package Attean::API::Triple 0.041 {
580 51 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
581 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
582
583 51 my %validation_map = (
584 subject => 'Attean::API::BlankOrIRI',
585 predicate => 'Attean::API::IRI',
586 object => 'Attean::API::TermOrTriple'
587 );
588 51 ▶ if ($ENV{ATTEAN_TYPECHECK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ATTEAN_TYPECHECK"}) 0 51 51
589 0 foreach my $method (keys %validation_map) {
590 0 my $role = $validation_map{$method};
591 0 ▶ around $method => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
592 0 my $orig = shift;
593 0 my $self = shift;
594 0 my $class = ref($self);
595 0 my $term = $self->$orig(@_);
596 0 my $type = Type::Tiny::Role->new( role => $role );
597 0 my $err = $type->validate($term);
598 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
599 0 die "${class}'s $method failed conformance check for role $role: " . $term->as_string;
600 }
601 0 return $term;
602 0 };
603 }
604 }
605
606 37 ▶ sub validate {
Subroutine validate: called CC=3 SCAR=11.2
Pod undocumented
607 37 my $self = shift;
608 37 my $class = ref($self);
609 37 foreach my $method (keys %validation_map) {
610 111 my $role = $validation_map{$method};
611 111 my $term = $self->$method();
612 111 ▶ unless ($term->does($role)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($term->does($role)) 0 111 111
613 0 die "${class}'s $method failed conformance check for role $role: " . $term->as_string . "\n";
614 }
615 }
616 37 return $self;
617 }
618
619 720 ▶ sub values {
Subroutine values: called CC=1 SCAR=0.0
Pod documented
620 720 my $self = shift;
621 return (
622 720 $self->subject,
623 $self->predicate,
624 $self->object
625 );
626 }
627  
628 127 ▶ sub as_quad {
Subroutine as_quad: called CC=2 SCAR=7.0
Pod documented
629 127 my $self = shift;
630 127 my $graph = shift;
631 127 ▶ my @terms = map { $_->does('Attean::API::TriplePattern') ? $_->as_triple : $_ } $self->values;
Branch: 1 branch
BranchTrueFalseTotal
$_->does('Attean::API::TriplePattern') ? : 0 381 381
632 127 return Attean::Quad->new(@terms[0..2], $graph);
633 }
634  
635 3 ▶ sub ntriples_string {
Subroutine ntriples_string: called CC=1 SCAR=0.0
Pod undocumented
636 3 my $self = shift;
637 3 my @values = $self->values;
638 3 return join(' ', '<<(', (map { $_->ntriples_string } @values), ')>>');
639 }
640  
641 0 ▶ sub order {
Subroutine order: not called CC=1 SCAR=6.9
Pod undocumented
642 0 my $self = shift;
643 0 return _compare('order', $self, @_);
644 }
645
646 0 ▶ sub compare {
Subroutine compare: not called CC=1 SCAR=6.9
Pod undocumented
647 0 my $self = shift;
648 0 return _compare('compare', $self, @_);
649 }
650
651 0 ▶ sub _compare {
Subroutine _compare: not called CC=10 SCAR=47.0
652 0 my $cmp_method = shift;
653 0 my ($a, $b) = @_;
654 0 ▶ return 1 unless blessed($b);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($b) 0 0 0
655 0 ▶ if (not $b->does('Attean::API::Triple')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($b->does("Attean::API::Triple")) 0 0 0
656 # this is a type-error for equality testing, but special handling is needed in calling code for ORDER BY in which Triples sort last (after literals)
657 0 die "TypeError: cannot compare an RDF-star triple and a non-triple";
658 }
659
660 0 foreach my $pos ($a->variables) {
661 0 my $at = $a->$pos();
662 0 my $bt = $b->$pos();
663 0 my $c = $at->$cmp_method($bt);
664
665 # If they are equal, continue. otherwise check if either term is an IRI.
666 # This is because term equality is defined for IRIs, but < and > isn't.
667 0 ▶ next unless ($c);
Branch: 1 branch
BranchTrueFalseTotal
unless $c 0 0 0
668
669 0 ▶ unless ($Attean::API::Binding::ALLOW_IRI_COMPARISON) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Attean::API::Binding::ALLOW_IRI_COMPARISON) 0 0 0
670 0 for ($at, $bt) {
671 0 ▶ if ($_->does('Attean::API::IRI')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->does("Attean::API::IRI")) 0 0 0
672 # Carp::cluck "TypeError comparison of IRI " . $at->ntriples_string . " <=> " . $bt->ntriples_string . "\n";
673 # last;
674 0 ▶ die "TypeError comparison of IRI" if ($_->does('Attean::API::IRI')); # comparison of IRIs is only defined for `ORDER BY`, not for general expressions
Branch: 1 branch
BranchTrueFalseTotal
if $_->does("Attean::API::IRI") 0 0 0
675 }
676 }
677 }
678  
679 0 ▶ if ($c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) 0 0 0
680 0 return $c;
681 }
682 }
683
684 0 return 0;
685 # return $a->ntriples_string cmp $b->ntriples_string;
686 }
687  
688 51 with 'Attean::API::TriplePattern', 'Attean::API::TripleOrQuad', 'Attean::API::Binding', 'Attean::API::TermOrVariableOrTriplePattern';
689 51 with 'Attean::API::BlankOrIRIOrTriple';
690 51 with 'Attean::API::TermOrTriple';
691 }
692  
693 51 package Attean::API::QuadPattern 0.041 {
694 51 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
695 51 ▶ use List::Util qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
696  
697 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
698
699 51 my @vars = qw(subject predicate object graph);
700 1763 ▶ sub variables { return @vars }
Subroutine variables: called CC=1 SCAR=0.0
Pod documented
701 214 ▶ sub value {
Subroutine value: called CC=3 SCAR=11.0
Pod documented
702 214 my $self = shift;
703 214 my $key = shift;
704 214 ▶ return $self->$key() if (defined($key) and $key =~ /^(subject|predicate|object|graph)$/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $key and $key =~ /^(subject|predicate|object|graph)$/u 213 1 214
Condition66%2/3
defined $key and $key =~ /^(subject|predicate|object|graph)$/u
!ll&&!rl&&r
01213
MC/DC50%1/2
defined $key and $key =~ /^(subject|predicate|object|graph)$/u
defined $key $key =~ /^(subject|predicate|object|graph)$/u
Truth table66%2/3
A and B
A= defined $keyB= $key =~ /^(subject|predicate|object|graph)$/u
ABresult
0X0
100
111
705 1 die "Unrecognized binding name '$key'";
706 }
707
708 371 ▶ sub values {
Subroutine values: called CC=1 SCAR=0.0
Pod documented
709 371 my $self = shift;
710 return (
711 371 $self->subject,
712 $self->predicate,
713 $self->object,
714 $self->graph
715 );
716 }
717
718 0 ▶ sub as_quad {
Subroutine as_quad: not called CC=3 SCAR=24.8
Pod undocumented
719 0 my $self = shift;
720 0 ▶ unless ($self->is_ground) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_ground) 0 0 0
721 0 die "Not a ground quad: " . $self->as_string;
722 }
723 0 ▶ my @terms = map { $_->does('Attean::API::TriplePattern') ? $_->as_triple : $_ } $self->values;
Branch: 1 branch
BranchTrueFalseTotal
$_->does('Attean::API::TriplePattern') ? : 0 0 0
724 0 return Attean::Quad->new(@terms);
725 }
726
727 1 ▶ sub apply_quad {
Subroutine apply_quad: called CC=1 SCAR=0.0
Pod undocumented
728 1 my $self = shift;
729 1 return $self->apply_statement(@_);
730 }
731  
732 0 ▶ sub as_triple_pattern {
Subroutine as_triple_pattern: not called CC=1 SCAR=6.9
Pod undocumented
733 0 my $self = shift;
734 0 my @keys = Attean::API::Triple->variables;
735 0 my @values = $self->values;
736 0 @values = @values[0 .. scalar(@keys)-1];
737 0 return Attean::TriplePattern->new(mesh \@keys, \@values);
738 }
739  
740 1 ▶ sub matches {
Subroutine matches: called CC=9 SCAR=23.4
Pod undocumented
741 1 my $self = shift;
742 1 my $ground = shift;
743 1 ▶ return 0 unless (ref($ground) eq 'Attean::Quad' or $ground->does('Attean::API::Quad'));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ground eq "Attean::Quad" or $ground->does("Attean::API::Quad") 0 1 1
Condition33%1/3
ref $ground eq "Attean::Quad" or $ground->does("Attean::API::Quad")
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $ground eq "Attean::Quad" or $ground->does("Attean::API::Quad")
ref $ground eq "Attean::Quad" $ground->does("Attean::API::Quad")
Truth table33%1/3
A or B
A= ref $ground eq "Attean::Quad"B= $ground->does("Attean::API::Quad")
ABresult
1X1
011
000
744 1 foreach my $method (@vars) {
745 4 my $term = $self->$method();
746 4 ▶ unless (ref($term) eq 'Attean::Variable' or $term->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $term eq "Attean::Variable" or $term->does("Attean::API::Variable")) 4 0 4
Condition33%1/3
ref $term eq "Attean::Variable" or $term->does("Attean::API::Variable")
l!l&&r!l&&!r
004
MC/DC0%0/2
ref $term eq "Attean::Variable" or $term->does("Attean::API::Variable")
ref $term eq "Attean::Variable" $term->does("Attean::API::Variable")
Truth table33%1/3
A or B
A= ref $term eq "Attean::Variable"B= $term->does("Attean::API::Variable")
ABresult
1X1
011
000
747 4 my $gterm = $ground->$method();
748 4 my $eq;
749 4 ▶ if ($term->does('Attean::API::TripleOrQuadPattern')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does('Attean::API::TripleOrQuadPattern')) { } 1 3 4
750 1 $eq = $term->matches($gterm);
751 } else {
752 3 $eq = eval { $term->equals($gterm) };
753 3 ▶ warn $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
754 }
755 4 ▶ return 0 unless ($eq);
Branch: 1 branch
BranchTrueFalseTotal
unless $eq 0 4 4
756 }
757 }
758 1 return 1;
759 }
760
761 2 ▶ sub sparql_tokens {
Subroutine sparql_tokens: called CC=2 SCAR=6.9
Pod undocumented
762 2 my $self = shift;
763 2 my @tokens;
764 2 push(@tokens, AtteanX::SPARQL::Token->keyword('GRAPH'));
765 2 push(@tokens, $self->graph->sparql_tokens->elements);
766 2 push(@tokens, AtteanX::SPARQL::Token->lbrace());
767 2 my @values = ($self->values)[0..2];
768 2 foreach my $t (@values) {
769 6 push(@tokens, $t->sparql_tokens->elements);
770 }
771 2 push(@tokens, AtteanX::SPARQL::Token->rbrace());
772 2 return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' );
773 }
774
775 51 requires 'subject';
776 51 requires 'predicate';
777 51 requires 'object';
778 51 requires 'graph';
779  
780 51 with 'Attean::API::TripleOrQuadPattern', 'Attean::API::Binding';
781 }
782  
783 51 package Attean::API::Quad 0.041 {
784 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
785
786 51 my %validation_map = (
787 subject => 'Attean::API::BlankOrIRI',
788 predicate => 'Attean::API::IRI',
789 object => 'Attean::API::TermOrTriple',
790 graph => 'Attean::API::BlankOrIRI'
791 );
792  
793 51 ▶ if ($ENV{ATTEAN_TYPECHECK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ATTEAN_TYPECHECK"}) 0 51 51
794 0 my $type = Type::Tiny::Role->new( role => 'Attean::API::BlankOrIRI' );
795 0 ▶ around 'graph' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
796 0 my $orig = shift;
797 0 my $self = shift;
798 0 my $class = ref($self);
799 0 my $term = $self->$orig(@_);
800 0 my $err = $type->validate($term);
801 0 ▶ die "${class}'s graph failed conformance check for role Attean::API::BlankOrIRI: $term" if ($err);
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
802 0 return $term;
803 0 };
804 }
805  
806 99 ▶ sub validate {
Subroutine validate: called CC=3 SCAR=11.2
Pod undocumented
807 99 my $self = shift;
808 99 my $class = ref($self);
809 99 foreach my $method (keys %validation_map) {
810 396 my $role = $validation_map{$method};
811 396 my $term = $self->$method();
812 396 ▶ unless ($term->does($role)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($term->does($role)) 0 396 396
813 0 Carp::confess "${class}'s $method failed conformance check for role $role: " . $term->as_string;
814 }
815 }
816 99 return $self;
817 }
818  
819 996 ▶ sub values {
Subroutine values: called CC=1 SCAR=0.0
Pod documented
820 996 my $self = shift;
821 return (
822 996 $self->subject,
823 $self->predicate,
824 $self->object,
825 $self->graph
826 );
827 }
828  
829 15 ▶ sub as_triple {
Subroutine as_triple: called CC=1 SCAR=0.0
Pod undocumented
830 15 my $self = shift;
831 15 my @values = $self->values;
832 15 my $t = Attean::Triple->new(@values[0..2]);
833 15 $t->validate();
834 15 return $t;
835 }
836  
837 51 with 'Attean::API::QuadPattern';
838 51 with 'Attean::API::TripleOrQuad', 'Attean::API::TripleOrQuadPattern', 'Attean::API::Triple';
839 }
840  
841  
842 51 package Attean::API::Result 0.041 {
843 51 ▶ use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
844 51 ▶ use Types::Standard qw(HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
845  
846 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
847
848 51 has 'eval_stash' => (is => 'rw', isa => HashRef);
849  
850 596 ▶ sub BUILD {
Subroutine BUILD: called CC=2 SCAR=7.1
Pod undocumented
851 596 my $self = shift;
852 596 ▶ if (not $self->eval_stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->eval_stash) 596 0 596
853 596 $self->eval_stash({});
854 }
855 }
856
857 35 ▶ sub shared_domain {
Subroutine shared_domain: called CC=1 SCAR=0.0
Pod undocumented
858 35 my $self = shift;
859 35 my $class = ref($self);
860 35 my $rowb = shift;
861
862 35 my %keysa;
863 35 my @keysa = $self->variables;
864 35 @keysa{ @keysa } = (1) x scalar(@keysa);
865 35 my @shared = grep { exists $keysa{ $_ } } ($rowb->variables);
866 35 return @shared;
867 }
868
869 33 ▶ sub join {
Subroutine join: called CC=4 SCAR=13.9
Pod documented
870 33 my $self = shift;
871 33 my $class = ref($self);
872 33 my $rowb = shift;
873 33 my @shared = $self->shared_domain($rowb);
874 33 foreach my $key (@shared) {
875 9 my $val_a = $self->value($key);
876 9 my $val_b = $rowb->value($key);
877 9 ▶ my $equal = (refaddr($val_a) == refaddr($val_b)) || eval { $val_a->equals( $val_b ) };
Condition100%3/3
builtin::refaddr($val_a) == builtin::refaddr($val_b) || eval { do { $val_a->equals($val_b) } }
l!l&&r!l&&!r
513
MC/DC100%2/2
builtin::refaddr($val_a) == builtin::refaddr($val_b) || eval { do { $val_a->equals($val_b) } }
builtin::refaddr($val_a) == builtin::refaddr($val_b) eval { do { $val_a->equals($val_b) } }
Truth table100%3/3
A || B
A= builtin::refaddr($val_a) == builtin::refaddr($val_b)B= eval { do { $val_a->equals($val_b) } }
ABresult
1X1
011
000
878 9 ▶ unless ($equal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($equal) 3 6 9
879 3 return;
880 }
881 }
882
883 30 my $row = { (map { $_ => $self->value($_) } grep { defined($self->value($_)) } $self->variables), (map { $_ => $rowb->value($_) } grep { defined($rowb->value($_)) } $rowb->variables) };
884 30 my $joined = Attean::Result->new( bindings => $row );
885 30 return $joined;
886 }
887
888 =item C<< project( @keys ) >>
889  
890 Returns a new L<Attean::Result> binding which contains variable-value mappings
891 from the invocant for every variable name in C<< @keys >>.
892  
893 =cut
894  
895 86 ▶ sub project {
Subroutine project: called CC=3 SCAR=11.0
Pod undocumented
896 86 my $self = shift;
897 86 my @vars = @_;
898 86 my %bindings;
899 86 foreach my $v (@vars) {
900 190 my $term = $self->value($v);
901 190 ▶ $bindings{ $v } = $term if ($term);
Branch: 1 branch
BranchTrueFalseTotal
if $term 190 0 190
902 }
903 86 return Attean::Result->new( bindings => \%bindings );
904 }
905  
906 61 ▶ sub project_complement {
Subroutine project_complement: called CC=3 SCAR=11.0
Pod undocumented
907 61 my $self = shift;
908 61 my %vars = map { $_ => 1 } @_;
909 61 my %bindings;
910 61 foreach my $v ($self->variables) {
911 161 ▶ unless ($vars{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vars{$v}) 158 3 161
912 158 my $term = $self->value($v);
913 158 $bindings{ $v } = $term;
914 }
915 }
916 61 return Attean::Result->new( bindings => \%bindings );
917 }
918
919 15 ▶ sub apply_map {
Subroutine apply_map: called CC=4 SCAR=14.1
Pod documented
920 15 my $self = shift;
921 15 my $class = ref($self);
922 15 my $mapper = shift;
923 15 my %values;
924 15 foreach my $var ($self->variables) {
925 29 my $value = $self->value($var);
926 29 ▶ if ($value->does('Attean::API::Binding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->does('Attean::API::Binding')) { } 0 29 29
927 0 $values{$var} = $value->apply_map($mapper);
928 } else {
929 29 my $term = $mapper->map($value);
930 29 ▶ if ($term) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term) 29 0 29
931 29 $values{$var} = $term;
932 }
933 }
934 }
935 15 return $class->new( bindings => \%values );
936 }
937  
938 51 with 'Attean::API::Binding', 'Attean::API::ResultOrTerm';
939 }
940  
941 51 1;
942  
943 __END__
« Attean/DatasetModel.pm ↑ Summary Attean/API/Query.pm »