Attean/API.pm

filter: Statementstmt 85.2% 219 / 257 Branchbran 67.5% 27 / 40 Conditioncond 47.6% 10 / 21 MC/DCmcdc 30.7% 4 / 13 Subroutinesub 89.8% 44 / 49 Podpod 33.3% 3 / 9 totaltotal 78.9% 307 / 389 CC 36 SCAR 27.6
CC
36
Cov
81%
canonical_set_with_mapping
47.1
apply_binding
20.0
apply_binding
4.0
CRAP 15.8
« Attean/API/Query.pm ↑ Summary AtteanX/Serializer/RDFXML.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 - Utility package for loading all Attean role packages.
7  
8 =head1 VERSION
9  
10 This document describes Attean::API version 0.040
11  
12 =head1 SYNOPSIS
13  
14 use v5.14;
15 use Attean;
16  
17 =head1 DESCRIPTION
18  
19 This is a utility package that will load all the Attean-related Moo roles
20 in the Attean::API namespace.
21  
22 =head1 METHODS
23  
24 =over 4
25  
26 =cut
27  
28 50 package Attean::API::ResultOrTerm 0.040 {
29 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 }
31  
32 50 package Attean::API::BlankOrIRI 0.040 {
33 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 50 with 'Attean::API::Term', 'Attean::API::BlankOrIRIOrTriple';
35 }
36  
37 50 package Attean::API::BlankOrIRIOrTriple 0.040 {
38 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 }
40  
41 50 package Attean::API::TermOrTriple 0.040 {
42 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 }
44  
45 50 package Attean::API::TermOrVariable 0.040 {
46 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
47 50 ▶ use Sub::Install;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 50 ▶ use Sub::Util qw(set_subname);
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 50 with 'Attean::API::SPARQLSerializable';
53  
54 178 ▶ sub equals {
Subroutine equals: called CC=1 SCAR=0.0
Pod documented
55 178 my ($a, $b) = @_;
56 178 return ($a->as_string eq $b->as_string);
57 }
58  
59 0 ▶ sub is_bound {
Subroutine is_bound: not called CC=1 SCAR=6.9
Pod documented
60 0 my $self = shift;
61 0 return (! $self->does('Attean::API::Variable'));
62 }
63
64 4 ▶ sub apply_binding {
Subroutine apply_binding: called CC=4 SCAR=13.9
Pod undocumented
65 4 my $self = shift;
66 4 my $class = ref($self);
67 4 my $bind = shift;
68 4 ▶ if ($self->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->does('Attean::API::Variable')) { } 3 1 4
69 3 my $name = $self->value;
70 3 my $replace = $bind->value($name);
71 3 ▶ if (defined($replace) and blessed($replace)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $replace and builtin::blessed($replace)) { } 2 1 3
Condition66%2/3
defined $replace and builtin::blessed($replace)
!ll&&!rl&&r
102
MC/DC50%1/2
defined $replace and builtin::blessed($replace)
defined $replace builtin::blessed($replace)
Truth table66%2/3
A and B
A= defined $replaceB= builtin::blessed($replace)
ABresult
0X0
100
111
72 2 return $replace;
73 } else {
74 1 return $self;
75 }
76 } else {
77 1 return $self;
78 }
79 }
80  
81 50 ▶ BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
82 50 my %types = (
83 variable => 'Variable',
84 blank => 'Blank',
85 literal => 'Literal',
86 resource => 'IRI',
87 iri => 'IRI',
88 );
89 50 ▶ while (my ($name, $role) = each(%types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %types) 250 50 300
90 250 my $method = "is_$name";
91 0 ▶ my $code = sub { return shift->does("Attean::API::$role") };
Subroutine __ANON__: not called CC=1 SCAR=0.4
Subroutine is_resource: called CC=1 SCAR=0.4
92 250 Sub::Install::install_sub({
93 code => set_subname($method, $code),
94 as => $method
95 });
96 }
97 }
98 }
99  
100 50 package Attean::API::TermOrVariableOrTriplePattern 0.040 {
101 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
102 50 ▶ use Sub::Install;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 50 ▶ use Sub::Util qw(set_subname);
Subroutine BEGIN: called CC=1 SCAR=0.0
104  
105 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
106  
107 50 with 'Attean::API::SPARQLSerializable';
108  
109 0 ▶ sub is_bound {
Subroutine is_bound: not called CC=1 SCAR=6.9
Pod undocumented
110 0 my $self = shift;
111 0 return (! $self->does('Attean::API::Variable'));
112 }
113
114 0 ▶ sub apply_binding {
Subroutine apply_binding: not called CC=4 SCAR=30.0
Pod undocumented
115 0 my $self = shift;
116 0 my $class = ref($self);
117 0 my $bind = shift;
118 0 ▶ if ($self->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->does('Attean::API::Variable')) { } 0 0 0
119 0 my $name = $self->value;
120 0 my $replace = $bind->value($name);
121 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
122 0 return $replace;
123 } else {
124 0 return $self;
125 }
126 } else {
127 0 return $self;
128 }
129 }
130  
131 50 ▶ BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
132 50 my %types = (
133 variable => 'Variable',
134 blank => 'Blank',
135 literal => 'Literal',
136 resource => 'IRI',
137 iri => 'IRI',
138 pattern => 'TriplePattern'
139 );
140 50 ▶ while (my ($name, $role) = each(%types)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %types) 300 50 350
141 300 my $method = "is_$name";
142 0 ▶ my $code = sub { return shift->does("Attean::API::$role") };
Subroutine is_pattern: not called CC=1 SCAR=1.2
143 300 Sub::Install::install_sub({
144 code => set_subname($method, $code),
145 as => $method
146 });
147 }
148 }
149 }
150  
151 50 package Attean::Mapper 0.040 {
152 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
153 50 requires 'map'; # my $that = $object->map($this)
154 }
155  
156 50 package Attean::API::Variable 0.040 {
157 50 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
158 50 ▶ use AtteanX::SPARQL::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
159  
160 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
161  
162 50 with 'Attean::API::TermOrVariable';
163  
164 =item C<< as_string >>
165  
166 Returns a string representation of the variable.'
167  
168 =cut
169  
170 17 ▶ sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
171 17 my $self = shift;
172 17 return '?' . $self->value;
173 }
174  
175 170 ▶ sub sparql_tokens {
Subroutine sparql_tokens: called CC=1 SCAR=0.0
Pod undocumented
176 170 my $self = shift;
177 170 my $t = AtteanX::SPARQL::Token->fast_constructor( VAR, -1, -1, -1, -1, [$self->value] );
178 170 return Attean::ListIterator->new( values => [$t], item_type => 'AtteanX::SPARQL::Token' );
179 }
180
181 }
182  
183 50 package Attean::API::CanonicalizingBindingSet 0.040 {
184 50 ▶ use Attean::RDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
185  
186 50 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
187 50 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
188 50 ▶ use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
189  
190 50 with 'MooX::Log::Any';
191 50 requires 'elements';
192  
193 16 ▶ sub canonical_set {
Subroutine canonical_set: called CC=1 SCAR=0.0
Pod undocumented
194 16 my $self = shift;
195 16 my ($set) = $self->canonical_set_with_mapping;
196 16 return $set;
197 }
198
199 20 ▶ sub canonical_set_with_mapping {
Subroutine canonical_set_with_mapping: called CC=28 SCAR=38.5
Pod undocumented
200 20 my $self = shift;
201 20 my @t = $self->elements;
202 20 my @tuples = map { [ $_->tuples_string, $_, {} ] } @t;
203 20 my $replacements = 0;
204 20 foreach my $p (@tuples) {
205 32 my ($str, $t) = @$p;
206 32 foreach my $pos ($t->variables) {
207 104 my $term = $t->value($pos);
208 104 my $tstr = $term->ntriples_string;
209 104 ▶ if ($term->does('Attean::API::Blank') or $term->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does("Attean::API::Blank") or $term->does("Attean::API::Variable")) 58 46 104
Condition100%3/3
$term->does("Attean::API::Blank") or $term->does("Attean::API::Variable")
l!l&&r!l&&!r
203846
MC/DC100%2/2
$term->does("Attean::API::Blank") or $term->does("Attean::API::Variable")
$term->does("Attean::API::Blank") $term->does("Attean::API::Variable")
Truth table100%3/3
A or B
A= $term->does("Attean::API::Blank")B= $term->does("Attean::API::Variable")
ABresult
1X1
011
000
210 58 $str =~ s/\Q$tstr\E/~/;
211 58 $str .= "#$tstr";
212 58 $p->[2]{$pos} = $tstr;
213 58 $replacements++;
214 58 $p->[0] = $str;
215 }
216 }
217 }
218
219 20 @tuples = sort { $a->[0] cmp $b->[0] } @tuples;
220 20 my $counter = 1;
221 20 my %mapping;
222 20 foreach my $i (0 .. $#tuples) {
223 32 my $p = $tuples[$i];
224 32 my ($str, $t) = @$p;
225 32 my $item_class = ref($t);
226 32 my ($next, $last) = ('')x2;
227 32 ▶ $last = $tuples[$i-1][0] if ($i > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $i > 0 12 20 32
228 32 ▶ $next = $tuples[$i+1][0] if ($i < $#tuples);
Branch: 1 branch
BranchTrueFalseTotal
if $i < $#tuples 12 20 32
229 32 ▶ next if ($str eq $last or $str eq $next);
Branch: 1 branch
BranchTrueFalseTotal
if $str eq $last or $str eq $next 0 32 32
Condition33%1/3
$str eq $last or $str eq $next
l!l&&r!l&&!r
0032
MC/DC0%0/2
$str eq $last or $str eq $next
$str eq $last $str eq $next
Truth table33%1/3
A or B
A= $str eq $lastB= $str eq $next
ABresult
1X1
011
000
230 32 foreach my $pos (reverse $t->variables) {
231 104 ▶ if (defined(my $tstr = $p->[2]{$pos})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $tstr = $p->[2]{$pos})) 58 46 104
232 58 $tstr =~ /^([?]|_:)([^#]+)$/;
233 58 my $prefix = $1;
234 58 my $name = $2;
235 58 my $key = "$prefix$name";
236 58 delete $p->[2]{$pos};
237 58 ▶ my $id = (exists($mapping{$key})) ? $mapping{$key}{id} : sprintf("v%03d", $counter++);
Branch: 1 branch
BranchTrueFalseTotal
exists $mapping{$key} ? : 23 35 58
238 58 ▶ my $type = ($prefix eq '?' ? 'variable' : 'blank');
Branch: 1 branch
BranchTrueFalseTotal
$prefix eq '?' ? : 38 20 58
239 58 $mapping{ $key } = { id => $id, prefix => $prefix, type => $type };
240 58 my %t = $p->[1]->mapping;
241 58 ▶ $t{ $pos } = ($type eq 'blank') ? Attean::Blank->new($id) : Attean::Variable->new($id);
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'blank' ? : 20 38 58
242 58 my $t = $item_class->new( %t );
243 58 $p->[1] = $t;
244 58 $p->[0] = $t->tuples_string;
245 }
246 }
247 }
248
249 20 foreach my $p (@tuples) {
250 32 my ($str, $t) = @$p;
251 32 my $item_class = ref($t);
252 32 foreach my $pos (reverse $t->variables) {
253 104 ▶ if (defined(my $tstr = $p->[2]{$pos})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $tstr = $p->[2]{$pos})) 0 104 104
254 0 $tstr =~ /^([?]|_:)([^#]+)$/;
255 0 my $prefix = $1;
256 0 my $name = $2;
257 0 my $key = "$prefix$name";
258 0 delete $p->[2]{$pos};
259 0 ▶ unless (exists($mapping{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $mapping{$key}) 0 0 0
260 0 $self->error("Cannot canonicalize binding set");
261 0 return;
262 }
263 0 my $id = $mapping{$key}{id};
264 0 ▶ my $type = ($prefix eq '?' ? 'variable' : 'blank');
Branch: 1 branch
BranchTrueFalseTotal
$prefix eq '?' ? : 0 0 0
265 0 $mapping{ $key } = { id => $id, prefix => $prefix, type => $type };
266 0 my %t = $p->[1]->mapping;
267 0 ▶ $t{ $pos } = ($type eq 'blank') ? Attean::Blank->new($id) : Attean::Variable->new($id);
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'blank' ? : 0 0 0
268 0 my $t = $item_class->new( %t );
269 0 $p->[1] = $t;
270 0 $p->[0] = $t->tuples_string;
271 }
272 }
273 }
274
275 20 my $parse_id = '1';
276 7 my %bnode_map = map { $_ => Attean::Blank->new( value => $mapping{"_:$_"}{'id'} ) }
277 7 map { substr($_,2) } # remove the leading _:
278 20 grep { /^_:/ }
279 (keys %mapping);
280 20 foreach my $p (@tuples) {
281 32 my ($str, $t) = @$p;
282 32 my $item_class = ref($t);
283 32 foreach my $pos (reverse $t->variables) {
284 104 my $term = $t->$pos();
285 104 ▶ if (blessed($term) and $term->does('Attean::API::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($term) and $term->does("Attean::API::Literal")) 7 97 104
Condition66%2/3
builtin::blessed($term) and $term->does("Attean::API::Literal")
!ll&&!rl&&r
0977
MC/DC50%1/2
builtin::blessed($term) and $term->does("Attean::API::Literal")
builtin::blessed($term) $term->does("Attean::API::Literal")
Truth table66%2/3
A and B
A= builtin::blessed($term)B= $term->does("Attean::API::Literal")
ABresult
0X0
100
111
286 7 my $dt = $term->datatype();
287 7 ▶ if (blessed($dt) and ($dt->value eq 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map' or $dt->value eq 'http://w3id.org/awslabs/neptune/SPARQL-CDTs/List')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($dt) and $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map" || $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/List") 0 7 7
Condition33%2/6
builtin::blessed($dt) and $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map" || $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/List"
!ll&&!rl&&r
070
$dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map" or $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/List"
l!l&&r!l&&!r
007
MC/DC0%0/3
builtin::blessed($dt) and $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map" || $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/List"
builtin::blessed($dt) $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map" $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/List"
Truth table25%1/4
A and B or C
A= builtin::blessed($dt)B= $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/Map"C= $dt->value eq "http://w3id.org/awslabs/neptune/SPARQL-CDTs/List"
ABCresult
0XX0
1000
11X1
1011
288 0 my %t = $p->[1]->mapping;
289 0 my $newterm = AtteanX::Functions::CompositeLists::rewrite_lexical($term, \%bnode_map, $parse_id);
290 0 $t{ $pos } = $newterm;
291 0 my $newt = $item_class->new( %t );
292 0 $t = $newt;
293 0 $p->[1] = $t;
294 }
295 }
296 }
297 }
298
299 20 @tuples = sort { $a->[0] cmp $b->[0] } @tuples;
300 20 my $elements = [ map { $_->[1] } @tuples ];
301 20 return ($elements, \%mapping);
302 }
303 }
304  
305 50 package Attean::API 0.040 {
306 50 ▶ use Attean::API::Term;
Subroutine BEGIN: called CC=1 SCAR=0.0
307 50 ▶ use Attean::API::Store;
Subroutine BEGIN: called CC=1 SCAR=0.0
308 50 ▶ use Attean::API::Model;
Subroutine BEGIN: called CC=1 SCAR=0.0
309 50 ▶ use Attean::API::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
310 50 ▶ use Attean::API::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
311 50 ▶ use Attean::API::Serializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
312 50 ▶ use Attean::API::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
313 50 ▶ use Attean::API::Expression;
Subroutine BEGIN: called CC=1 SCAR=0.0
314 50 ▶ use Attean::API::Plan;
Subroutine BEGIN: called CC=1 SCAR=0.0
315 50 ▶ use Attean::API::QueryPlanner;
Subroutine BEGIN: called CC=1 SCAR=0.0
316
317 50 ▶ use Attean::Variable;
Subroutine BEGIN: called CC=1 SCAR=0.0
318 50 ▶ use Attean::Blank;
Subroutine BEGIN: called CC=1 SCAR=0.0
319 50 ▶ use Attean::IRI;
Subroutine BEGIN: called CC=1 SCAR=0.0
320 }
321  
322 50 1;
323  
324 __END__
« Attean/API/Query.pm ↑ Summary AtteanX/Serializer/RDFXML.pm »