Attean/API/Binding.pm

filter: Statementstmt 74.3% 402 / 541 Branchbran 43.8% 71 / 162 Conditioncond 47.9% 23 / 48 MC/DCmcdc 25.8% 8 / 31 Subroutinesub 86.2% 69 / 80 Podpod 44.6% 21 / 47 totaltotal 65.3% 594 / 909 CC 125 SCAR 29.8
CC
125
Cov
66%
equals
110.0
_compare
110.0
sameTerms
56.0
CRAP 19.8
« Attean/DatasetModel.pm ↑ Summary Attean/API/Query.pm »
1 50 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 50 ▶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.040
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 50 ▶use Type::Tiny::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 50 package Attean::API::Binding 0.040 {
75 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
76 50 ▶ use List::Util qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
79
80 50 requires 'value';
81 50 requires 'variables';
82 50 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 3019 ▶ sub values {
Subroutine values: called CC=1 SCAR=0.0
Pod documented
92 3019 my $self = shift;
93 3019 return map { $self->value($_) } $self->variables;
94 }
95
96 409 ▶ sub tuples_string {
Subroutine tuples_string: called CC=1 SCAR=0.0
Pod documented
97 409 my $self = shift;
98 409 my @strs = map { $_->ntriples_string } $self->values;
99 409 return join(' ', @strs) . ' .';
100 }
101 271 ▶ sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
102 271 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 124 ▶ return 1 if ($term->does('Attean::API::Blank'));
Branch: 1 branch
BranchTrueFalseTotal
if $term->does("Attean::API::Blank") 69 55 124
109 55 ▶ if ($term->does('Attean::API::Binding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does("Attean::API::Binding")) 0 55 55
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 50 package Attean::API::TripleOrQuadPattern 0.040 {
290 50 ▶ use Encode qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
291 50 ▶ use List::Util qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
292 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
293 50 ▶ use Attean::RDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
294 50 ▶ use Attean::API::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
295  
296 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
297  
298 50 with 'Attean::API::SPARQLSerializable';
299
300 1467 ▶ around BUILDARGS => sub {
Subroutine __ANON__: called CC=13 SCAR=26.3
301 1467 my $orig = shift;
302 1467 my $class = shift;
303 1467 my @args = @_;
304 1467 ▶ 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 1236 1467
elsif (scalar @args == 2) { } 9 1227 1236
Condition83%5/6
scalar @args == 0 or not defined $_[0] or builtin::blessed($args[0])
l!l&&r!l&&!r
102211236
scalar @args == 0 or not defined $_[0]
l!l&&r!l&&!r
1001457
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 1236 ▶ if (scalar(@_) % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar(@_) % 2) 0 1236 1236
323 0 Carp::cluck;
324 }
325 1236 my %args = @_;
326 1236 foreach my $k ($class->variables) {
327 4472 ▶ if (not(exists $args{$k}) or not($args{$k})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{$k} and $args{$k}) 214 4258 4472
Condition100%3/3
exists $args{$k} and $args{$k}
!ll&&!rl&&r
371774258
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 1236 return $class->$orig(%args);
333 50 };
334  
335 60 ▶ sub apply_map {
Subroutine apply_map: called CC=3 SCAR=11.0
Pod undocumented
336 60 my $self = shift;
337 60 my $class = ref($self);
338 60 my $mapper = shift;
339 60 my %values;
340 60 foreach my $pos ($self->variables) {
341 227 my $value = $self->value($pos);
342 227 ▶ if ($value->does('Attean::API::Binding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->does('Attean::API::Binding')) { } 1 226 227
343 1 $values{$pos} = $value->apply_map($mapper);
344 } else {
345 226 $values{$pos} = $mapper->map($value);
346 }
347 }
348 60 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 50 ▶ 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 50 package Attean::API::TripleOrQuad 0.040 {
472 50 ▶ use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
473 50 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
474  
475 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
476  
477 50 with 'Attean::API::TripleOrQuadPattern';
478  
479 786 ▶ sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
480 786 my $self = shift;
481 786 ▶ 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 784 786
482 2 confess 'Use a Pattern class to construct when using variables';
483 }
484 }
485 }
486  
487 50 package Attean::API::TriplePattern 0.040 {
488 50 ▶ use List::Util qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
489 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
490  
491 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
492
493 50 my @vars = qw(subject predicate object);
494 3083 ▶ sub variables { return @vars }
Subroutine variables: called CC=1 SCAR=0.0
Pod documented
495  
496 4955 ▶ sub value {
Subroutine value: called CC=2 SCAR=6.9
Pod documented
497 4955 my $self = shift;
498 4955 my $key = shift;
499 4955 ▶ return $self->$key() if ($key =~ /^(subject|predicate|object)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^(subject|predicate|object)$/u 4954 1 4955
500 1 die "Unrecognized binding name '$key'";
501 }
502
503 26 ▶ sub as_quad_pattern {
Subroutine as_quad_pattern: called CC=1 SCAR=0.0
Pod documented
504 26 my $self = shift;
505 26 my $graph = shift;
506 26 my @keys = Attean::API::Quad->variables;
507 26 my @values = ($self->values, $graph);
508 26 return Attean::QuadPattern->new(mesh \@keys, \@values);
509 }
510
511 0 ▶ sub as_triple {
Subroutine as_triple: not called CC=3 SCAR=24.8
Pod undocumented
512 0 my $self = shift;
513 0 ▶ unless ($self->is_ground) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_ground) 0 0 0
514 0 die "Not a ground triple: " . $self->as_string;
515 }
516 0 ▶ my @terms = map { $_->does('Attean::API::TriplePattern') ? $_->as_triple : $_ } $self->values;
Branch: 1 branch
BranchTrueFalseTotal
$_->does('Attean::API::TriplePattern') ? : 0 0 0
517 0 my $t = Attean::Triple->new(@terms);
518 0 $t->validate();
519 0 return $t;
520 }
521
522 1 ▶ sub apply_triple {
Subroutine apply_triple: called CC=1 SCAR=0.0
Pod undocumented
523 1 my $self = shift;
524 1 return $self->apply_statement(@_);
525 }
526  
527 4 ▶ sub matches {
Subroutine matches: called CC=9 SCAR=25.4
Pod undocumented
528 4 my $self = shift;
529 4 my $ground = shift;
530 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
531 4 foreach my $method (@vars) {
532 12 my $term = $self->$method();
533 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
534 2 my $gterm = $ground->$method();
535 2 my $eq;
536 2 ▶ if ($term->does('Attean::API::TripleOrQuadPattern')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does('Attean::API::TripleOrQuadPattern')) { } 2 0 2
537 2 $eq = $term->matches($gterm);
538 } else {
539 0 $eq = eval { $term->equals($gterm) };
540 0 ▶ warn $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
541 }
542 2 ▶ return 0 unless ($eq);
Branch: 1 branch
BranchTrueFalseTotal
unless $eq 0 2 2
543 }
544 }
545 4 return 1;
546 }
547
548 103 ▶ sub sparql_tokens {
Subroutine sparql_tokens: called CC=3 SCAR=11.0
Pod undocumented
549 103 my $self = shift;
550 103 my @tokens;
551 103 foreach my $t ($self->values) {
552 309 ▶ if ($t->does('Attean::API::TriplePattern')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->does('Attean::API::TriplePattern')) { } 1 308 309
553 1 push(@tokens, AtteanX::SPARQL::Token->ltltp);
554 1 push(@tokens, $t->sparql_tokens->elements);
555 1 push(@tokens, AtteanX::SPARQL::Token->pgtgt);
556 } else {
557 308 push(@tokens, $t->sparql_tokens->elements);
558 }
559 }
560 103 return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' );
561 }
562
563 50 requires 'subject';
564 50 requires 'predicate';
565 50 requires 'object';
566  
567 50 with 'Attean::API::TripleOrQuadPattern', 'Attean::API::Binding', 'Attean::API::TermOrVariableOrTriplePattern';
568 }
569  
570 50 package Attean::API::Triple 0.040 {
571 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
572 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
573
574 50 my %validation_map = (
575 subject => 'Attean::API::BlankOrIRI',
576 predicate => 'Attean::API::IRI',
577 object => 'Attean::API::TermOrTriple'
578 );
579 50 ▶ if ($ENV{ATTEAN_TYPECHECK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ATTEAN_TYPECHECK"}) 0 50 50
580 0 foreach my $method (keys %validation_map) {
581 0 my $role = $validation_map{$method};
582 0 ▶ around $method => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
583 0 my $orig = shift;
584 0 my $self = shift;
585 0 my $class = ref($self);
586 0 my $term = $self->$orig(@_);
587 0 my $type = Type::Tiny::Role->new( role => $role );
588 0 my $err = $type->validate($term);
589 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
590 0 die "${class}'s $method failed conformance check for role $role: " . $term->as_string;
591 }
592 0 return $term;
593 0 };
594 }
595 }
596
597 37 ▶ sub validate {
Subroutine validate: called CC=3 SCAR=11.2
Pod undocumented
598 37 my $self = shift;
599 37 my $class = ref($self);
600 37 foreach my $method (keys %validation_map) {
601 111 my $role = $validation_map{$method};
602 111 my $term = $self->$method();
603 111 ▶ unless ($term->does($role)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($term->does($role)) 0 111 111
604 0 die "${class}'s $method failed conformance check for role $role: " . $term->as_string . "\n";
605 }
606 }
607 37 return $self;
608 }
609
610 127 ▶ sub as_quad {
Subroutine as_quad: called CC=2 SCAR=7.0
Pod documented
611 127 my $self = shift;
612 127 my $graph = shift;
613 127 ▶ my @terms = map { $_->does('Attean::API::TriplePattern') ? $_->as_triple : $_ } $self->values;
Branch: 1 branch
BranchTrueFalseTotal
$_->does('Attean::API::TriplePattern') ? : 0 381 381
614 127 return Attean::Quad->new(@terms[0..2], $graph);
615 }
616  
617 3 ▶ sub ntriples_string {
Subroutine ntriples_string: called CC=1 SCAR=0.0
Pod undocumented
618 3 my $self = shift;
619 3 my @values = $self->values;
620 3 return join(' ', '<<(', (map { $_->ntriples_string } @values), ')>>');
621 }
622  
623 0 ▶ sub order {
Subroutine order: not called CC=1 SCAR=6.9
Pod undocumented
624 0 my $self = shift;
625 0 return _compare('order', $self, @_);
626 }
627
628 0 ▶ sub compare {
Subroutine compare: not called CC=1 SCAR=6.9
Pod undocumented
629 0 my $self = shift;
630 0 return _compare('compare', $self, @_);
631 }
632
633 0 ▶ sub _compare {
Subroutine _compare: not called CC=10 SCAR=47.0
634 0 my $cmp_method = shift;
635 0 my ($a, $b) = @_;
636 0 ▶ return 1 unless blessed($b);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($b) 0 0 0
637 0 ▶ if (not $b->does('Attean::API::Triple')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($b->does("Attean::API::Triple")) 0 0 0
638 # 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)
639 0 die "TypeError: cannot compare an RDF-star triple and a non-triple";
640 }
641
642 0 foreach my $pos ($a->variables) {
643 0 my $at = $a->$pos();
644 0 my $bt = $b->$pos();
645 0 my $c = $at->$cmp_method($bt);
646
647 # If they are equal, continue. otherwise check if either term is an IRI.
648 # This is because term equality is defined for IRIs, but < and > isn't.
649 0 ▶ next unless ($c);
Branch: 1 branch
BranchTrueFalseTotal
unless $c 0 0 0
650
651 0 ▶ unless ($Attean::API::Binding::ALLOW_IRI_COMPARISON) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Attean::API::Binding::ALLOW_IRI_COMPARISON) 0 0 0
652 0 for ($at, $bt) {
653 0 ▶ if ($_->does('Attean::API::IRI')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->does("Attean::API::IRI")) 0 0 0
654 # Carp::cluck "TypeError comparison of IRI " . $at->ntriples_string . " <=> " . $bt->ntriples_string . "\n";
655 # last;
656 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
657 }
658 }
659 }
660  
661 0 ▶ if ($c) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c) 0 0 0
662 0 return $c;
663 }
664 }
665
666 0 return 0;
667 # return $a->ntriples_string cmp $b->ntriples_string;
668 }
669  
670 50 with 'Attean::API::TriplePattern', 'Attean::API::TripleOrQuad', 'Attean::API::Binding', 'Attean::API::TermOrVariableOrTriplePattern';
671 50 with 'Attean::API::BlankOrIRIOrTriple';
672 50 with 'Attean::API::TermOrTriple';
673 }
674  
675 50 package Attean::API::QuadPattern 0.040 {
676 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
677 50 ▶ use List::Util qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
678  
679 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
680
681 50 my @vars = qw(subject predicate object graph);
682 3141 ▶ sub variables { return @vars }
Subroutine variables: called CC=1 SCAR=0.0
Pod documented
683 5718 ▶ sub value {
Subroutine value: called CC=3 SCAR=11.0
Pod documented
684 5718 my $self = shift;
685 5718 my $key = shift;
686 5718 ▶ 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 5717 1 5718
Condition66%2/3
defined $key and $key =~ /^(subject|predicate|object|graph)$/u
!ll&&!rl&&r
015717
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
687 1 die "Unrecognized binding name '$key'";
688 }
689
690 0 ▶ sub as_quad {
Subroutine as_quad: not called CC=3 SCAR=24.8
Pod undocumented
691 0 my $self = shift;
692 0 ▶ unless ($self->is_ground) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_ground) 0 0 0
693 0 die "Not a ground quad: " . $self->as_string;
694 }
695 0 ▶ my @terms = map { $_->does('Attean::API::TriplePattern') ? $_->as_triple : $_ } $self->values;
Branch: 1 branch
BranchTrueFalseTotal
$_->does('Attean::API::TriplePattern') ? : 0 0 0
696 0 return Attean::Quad->new(@terms);
697 }
698
699 1 ▶ sub apply_quad {
Subroutine apply_quad: called CC=1 SCAR=0.0
Pod undocumented
700 1 my $self = shift;
701 1 return $self->apply_statement(@_);
702 }
703  
704 0 ▶ sub as_triple_pattern {
Subroutine as_triple_pattern: not called CC=1 SCAR=6.9
Pod undocumented
705 0 my $self = shift;
706 0 my @keys = Attean::API::Triple->variables;
707 0 my @values = $self->values;
708 0 @values = @values[0 .. scalar(@keys)-1];
709 0 return Attean::TriplePattern->new(mesh \@keys, \@values);
710 }
711  
712 1 ▶ sub matches {
Subroutine matches: called CC=9 SCAR=23.4
Pod undocumented
713 1 my $self = shift;
714 1 my $ground = shift;
715 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
716 1 foreach my $method (@vars) {
717 4 my $term = $self->$method();
718 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
719 4 my $gterm = $ground->$method();
720 4 my $eq;
721 4 ▶ if ($term->does('Attean::API::TripleOrQuadPattern')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does('Attean::API::TripleOrQuadPattern')) { } 1 3 4
722 1 $eq = $term->matches($gterm);
723 } else {
724 3 $eq = eval { $term->equals($gterm) };
725 3 ▶ warn $@ if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
726 }
727 4 ▶ return 0 unless ($eq);
Branch: 1 branch
BranchTrueFalseTotal
unless $eq 0 4 4
728 }
729 }
730 1 return 1;
731 }
732
733 2 ▶ sub sparql_tokens {
Subroutine sparql_tokens: called CC=2 SCAR=6.9
Pod undocumented
734 2 my $self = shift;
735 2 my @tokens;
736 2 push(@tokens, AtteanX::SPARQL::Token->keyword('GRAPH'));
737 2 push(@tokens, $self->graph->sparql_tokens->elements);
738 2 push(@tokens, AtteanX::SPARQL::Token->lbrace());
739 2 my @values = ($self->values)[0..2];
740 2 foreach my $t (@values) {
741 6 push(@tokens, $t->sparql_tokens->elements);
742 }
743 2 push(@tokens, AtteanX::SPARQL::Token->rbrace());
744 2 return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' );
745 }
746
747 50 requires 'subject';
748 50 requires 'predicate';
749 50 requires 'object';
750 50 requires 'graph';
751  
752 50 with 'Attean::API::TripleOrQuadPattern', 'Attean::API::Binding';
753 }
754  
755 50 package Attean::API::Quad 0.040 {
756 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
757
758 50 my %validation_map = (
759 subject => 'Attean::API::BlankOrIRI',
760 predicate => 'Attean::API::IRI',
761 object => 'Attean::API::TermOrTriple',
762 graph => 'Attean::API::BlankOrIRI'
763 );
764  
765 50 ▶ if ($ENV{ATTEAN_TYPECHECK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ATTEAN_TYPECHECK"}) 0 50 50
766 0 my $type = Type::Tiny::Role->new( role => 'Attean::API::BlankOrIRI' );
767 0 ▶ around 'graph' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
768 0 my $orig = shift;
769 0 my $self = shift;
770 0 my $class = ref($self);
771 0 my $term = $self->$orig(@_);
772 0 my $err = $type->validate($term);
773 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
774 0 return $term;
775 0 };
776 }
777  
778 99 ▶ sub validate {
Subroutine validate: called CC=3 SCAR=11.2
Pod undocumented
779 99 my $self = shift;
780 99 my $class = ref($self);
781 99 foreach my $method (keys %validation_map) {
782 396 my $role = $validation_map{$method};
783 396 my $term = $self->$method();
784 396 ▶ unless ($term->does($role)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($term->does($role)) 0 396 396
785 0 Carp::confess "${class}'s $method failed conformance check for role $role: " . $term->as_string;
786 }
787 }
788 99 return $self;
789 }
790  
791 15 ▶ sub as_triple {
Subroutine as_triple: called CC=1 SCAR=0.0
Pod undocumented
792 15 my $self = shift;
793 15 my @values = $self->values;
794 15 my $t = Attean::Triple->new(@values[0..2]);
795 15 $t->validate();
796 15 return $t;
797 }
798  
799 50 with 'Attean::API::QuadPattern';
800 50 with 'Attean::API::TripleOrQuad', 'Attean::API::TripleOrQuadPattern', 'Attean::API::Triple';
801 }
802  
803  
804 50 package Attean::API::Result 0.040 {
805 50 ▶ use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
806 50 ▶ use Types::Standard qw(HashRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
807  
808 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
809
810 50 has 'eval_stash' => (is => 'rw', isa => HashRef);
811  
812 593 ▶ sub BUILD {
Subroutine BUILD: called CC=2 SCAR=7.1
Pod undocumented
813 593 my $self = shift;
814 593 ▶ if (not $self->eval_stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->eval_stash) 593 0 593
815 593 $self->eval_stash({});
816 }
817 }
818
819 35 ▶ sub shared_domain {
Subroutine shared_domain: called CC=1 SCAR=0.0
Pod undocumented
820 35 my $self = shift;
821 35 my $class = ref($self);
822 35 my $rowb = shift;
823
824 35 my %keysa;
825 35 my @keysa = $self->variables;
826 35 @keysa{ @keysa } = (1) x scalar(@keysa);
827 35 my @shared = grep { exists $keysa{ $_ } } ($rowb->variables);
828 35 return @shared;
829 }
830
831 33 ▶ sub join {
Subroutine join: called CC=4 SCAR=13.9
Pod documented
832 33 my $self = shift;
833 33 my $class = ref($self);
834 33 my $rowb = shift;
835 33 my @shared = $self->shared_domain($rowb);
836 33 foreach my $key (@shared) {
837 9 my $val_a = $self->value($key);
838 9 my $val_b = $rowb->value($key);
839 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
840 9 ▶ unless ($equal) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($equal) 3 6 9
841 3 return;
842 }
843 }
844
845 30 my $row = { (map { $_ => $self->value($_) } grep { defined($self->value($_)) } $self->variables), (map { $_ => $rowb->value($_) } grep { defined($rowb->value($_)) } $rowb->variables) };
846 30 my $joined = Attean::Result->new( bindings => $row );
847 30 return $joined;
848 }
849
850 =item C<< project( @keys ) >>
851  
852 Returns a new L<Attean::Result> binding which contains variable-value mappings
853 from the invocant for every variable name in C<< @keys >>.
854  
855 =cut
856  
857 86 ▶ sub project {
Subroutine project: called CC=3 SCAR=11.0
Pod undocumented
858 86 my $self = shift;
859 86 my @vars = @_;
860 86 my %bindings;
861 86 foreach my $v (@vars) {
862 190 my $term = $self->value($v);
863 190 ▶ $bindings{ $v } = $term if ($term);
Branch: 1 branch
BranchTrueFalseTotal
if $term 190 0 190
864 }
865 86 return Attean::Result->new( bindings => \%bindings );
866 }
867  
868 61 ▶ sub project_complement {
Subroutine project_complement: called CC=3 SCAR=11.0
Pod undocumented
869 61 my $self = shift;
870 61 my %vars = map { $_ => 1 } @_;
871 61 my %bindings;
872 61 foreach my $v ($self->variables) {
873 161 ▶ unless ($vars{$v}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vars{$v}) 158 3 161
874 158 my $term = $self->value($v);
875 158 $bindings{ $v } = $term;
876 }
877 }
878 61 return Attean::Result->new( bindings => \%bindings );
879 }
880
881 14 ▶ sub apply_map {
Subroutine apply_map: called CC=4 SCAR=14.1
Pod documented
882 14 my $self = shift;
883 14 my $class = ref($self);
884 14 my $mapper = shift;
885 14 my %values;
886 14 foreach my $var ($self->variables) {
887 26 my $value = $self->value($var);
888 26 ▶ if ($value->does('Attean::API::Binding')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->does('Attean::API::Binding')) { } 0 26 26
889 0 $values{$var} = $value->apply_map($mapper);
890 } else {
891 26 my $term = $mapper->map($value);
892 26 ▶ if ($term) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term) 26 0 26
893 26 $values{$var} = $term;
894 }
895 }
896 }
897 14 return $class->new( bindings => \%values );
898 }
899  
900 50 with 'Attean::API::Binding', 'Attean::API::ResultOrTerm';
901 }
902  
903 50 1;
904  
905 __END__
« Attean/DatasetModel.pm ↑ Summary Attean/API/Query.pm »