Attean/API/Term.pm

filter: Statementstmt 62.7% 377 / 601 Branchbran 36.1% 133 / 368 Conditioncond 30.5% 26 / 85 MC/DCmcdc 5.8% 3 / 51 Subroutinesub 83.7% 67 / 80 Podpod 21.6% 8 / 37 totaltotal 50.2% 614 / 1222 CC 218 SCAR 45.4
CC
218
Cov
51%
_canonicalized_term
524.9
argument_compatible
210.0
_lowest_base_type
81.2
CRAP 94.1
« AtteanX/Functions/CompositeMaps.pm ↑ Summary AtteanX/Serializer/TextTable.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::Term - RDF Terms
7  
8 =head1 VERSION
9  
10 This document describes Attean::API::Term version 0.041
11  
12 =head1 DESCRIPTION
13  
14 The Attean::API::Term role defines a common API for all RDF terms.
15  
16 =head1 REQUIRED METHODS
17  
18 The following methods are required by the L<Attean::API::Term> role:
19  
20 =over 4
21  
22 =item C<< value >>
23  
24 Returns the term's value string.
25  
26 =item C<< ntriples_string >>
27  
28 Returns an N-Triples-compatible string serialization.
29  
30 =back
31  
32 =head1 METHODS
33  
34 This role provides default implementations of the following methods:
35  
36 =over 4
37  
38 =item C<< as_string >>
39  
40 Returns a string serialization of the term.
41  
42 =cut
43  
44 51 package Attean::API::Term 0.041 {
45 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
46
47 51 with 'Attean::API::TermOrVariable', 'Attean::API::ResultOrTerm';
48 51 with 'Attean::API::TermOrVariableOrTriplePattern';
49
50 51 requires 'value'; # => (is => 'ro', isa => 'Str', required => 1);
51 51 requires 'ntriples_string';
52 865 ▶ sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
53 865 shift->ntriples_string();
54 }
55  
56 =item C<< ebv >>
57  
58 Returns true if the term has a true SPARQL "effective boolean value", false otherwise.
59  
60 =cut
61  
62 51 requires 'ebv';
63 51 requires 'compare';
64 51 requires 'sameTerms';
65
66 =item C<< order ( $other ) >>
67  
68 Similar to C<< compare >>, but provides the ordering semantics of ORDER BY.
69  
70 =cut
71  
72 16 ▶ sub order {
Subroutine order: called CC=1 SCAR=0.0
Pod documented
73 16 my $self = shift;
74 16 return $self->compare(@_);
75 }
76
77 481 ▶ sub __ntriples_string {
Subroutine __ntriples_string: called CC=15 SCAR=33.3
78 481 my $self = shift;
79 481 my $value = $self->value;
80 481 ▶ if ($value =~ m/^[\x20\x23-\x5a\x5d-\x7e]*$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^[\x20\x23-\x5a\x5d-\x7e]*$/ou) 480 1 481
81 480 return $value;
82 }
83
84 1 my @chars = split(//, $value);
85 1 my $string = '';
86 1 ▶ while (scalar(@chars)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @chars) 20 1 21
87 20 my $c = shift(@chars);
88 20 my $o = ord($c);
89 20 ▶ if ($o < 0x8) {
Branch: 12 branches
BranchTrueFalseTotal
if ($o < 8) { } 0 20 20
elsif ($o == 9) { } 0 20 20
elsif ($o == 10) { } 0 20 20
elsif ($o < 12) { } 0 20 20
elsif ($o == 13) { } 0 20 20
elsif ($o < 31) { } 0 20 20
elsif ($o < 33) { } 0 20 20
elsif ($o == 34) { } 0 20 20
elsif ($o < 91) { } 5 15 20
elsif ($o == 92) { } 0 15 15
elsif ($o < 126) { } 14 1 15
elsif ($o < 65535) { } 1 0 1
90 0 $string .= sprintf("\\u%04X", $o);
91 } elsif ($o == 0x9) {
92 0 $string .= "\\t";
93 } elsif ($o == 0xA) {
94 0 $string .= "\\n";
95 } elsif ($o < 0xC) {
96 0 $string .= sprintf("\\u%04X", $o);
97 } elsif ($o == 0xD) {
98 0 $string .= "\\r";
99 } elsif ($o < 0x1F) {
100 0 $string .= sprintf("\\u%04X", $o);
101 } elsif ($o < 0x21) {
102 0 $string .= $c;
103 } elsif ($o == 0x22) {
104 0 $string .= "\"";
105 } elsif ($o < 0x5B) {
106 5 $string .= $c;
107 } elsif ($o == 0x5C) {
108 0 $string .= "\\";
109 } elsif ($o < 0x7E) {
110 14 $string .= $c;
111 } elsif ($o < 0xFFFF) {
112 1 $string .= sprintf("\\u%04X", $o);
113 } else {
114 0 $string .= sprintf("\\U%08X", $o);
115 }
116 }
117 1 return $string;
118 }
119  
120 51 with 'Attean::API::TermOrTriple';
121 }
122  
123 51 package Attean::API::Literal 0.041 {
124 51 ▶ use IRI;
Subroutine BEGIN: called CC=1 SCAR=0.0
125 51 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
126 51 ▶ use Types::Standard qw(Maybe Str ConsumerOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
127 51 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
128 51 ▶ use AtteanX::SPARQL::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 51 ▶ use Attean::API::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
130  
131 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
132
133 51 with 'Attean::API::Term';
134 51 with 'Attean::API::SPARQLSerializable';
135 51 with 'Attean::API::TermOrVariableOrTriplePattern';
136
137 51 requires 'language'; # => (is => 'ro', isa => 'Maybe[Str]', predicate => 'has_language');
138 51 requires 'base_dir'; # => (is => 'ro', isa => 'Maybe[Str]');
139 51 requires 'datatype'; # => (is => 'ro', isa => 'Attean::API::IRI', required => 1, coerce => 1, default => sub { IRI->new(value => 'http://www.w3.org/2001/XMLSchema#string') });
140
141 491 ▶ sub BUILD {}
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
142 502 ▶ around 'BUILDARGS' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
143 502 my $orig = shift;
144 502 my $class = shift;
145 502 my $args = $class->$orig(@_);
146 491 ▶ if (my $lang = $args->{language}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lang = $args->{"language"}) 40 451 491
147 40 my $oldlang = $lang;
148 # http://tools.ietf.org/html/bcp47#section-2.1.1
149 # All subtags use lowercase letters
150 40 $lang = lc($lang);
151  
152 # with 2 exceptions: subtags that neither appear at the start of the tag nor occur after singletons
153 # i.e. there's a subtag of length at least 2 preceding the exception; and a following subtag or end-of-tag
154  
155 # 1. two-letter subtags are all uppercase
156 40 $lang =~ s{(?<=\w\w-)(\w\w)(?=($|-))}{\U$1}g;
157  
158 # 2. four-letter subtags are titlecase
159 40 $lang =~ s{(?<=\w\w-)(\w\w\w\w)(?=($|-))}{\u\L$1}g;
160 40 $args->{language} = $lang;
161 }
162 491 return $args;
163 51 };
164 491 ▶ around 'BUILD' => sub {
Subroutine __ANON__: called CC=6 SCAR=18.1
165 491 my $orig = shift;
166 491 my $self = shift;
167 491 $self->$orig(@_);
168 491 ▶ if (my $dt = $self->datatype) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dt = $self->datatype) 491 0 491
169 491 my $type = $dt->value;
170 491 ▶ if ($type =~ qr<^http://www[.]w3[.]org/2001/XMLSchema#(?:integer|decimal|float|double|non(?:Positive|Negative)Integer|(?:positive|negative)Integer|long|int|short|byte|unsigned(?:Long|Int|Short|Byte))$>) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type =~ qr"^http://www[.]w3[.]org/2001/XMLSchema#(?:integer|decimal|float|double|non(?:Positive|Negative)Integer|(?:positive|negative)Integer|long|int|short|byte|unsigned(?:Long|Int|Short|Byte))$"u) { } 148 343 491
elsif ($type eq 'http://www.w3.org/2001/XMLSchema#boolean') { } 17 326 343
elsif ($type eq 'http://www.w3.org/2001/XMLSchema#dateTime') { } 3 323 326
elsif (my $role = 'Attean'->get_datatype_role($type)) { } 0 323 323
171 148 Moo::Role->apply_roles_to_object($self, 'Attean::API::NumericLiteral');
172 } elsif ($type eq 'http://www.w3.org/2001/XMLSchema#boolean') {
173 17 Moo::Role->apply_roles_to_object($self, 'Attean::API::BooleanLiteral');
174 } elsif ($type eq 'http://www.w3.org/2001/XMLSchema#dateTime') {
175 3 Moo::Role->apply_roles_to_object($self, 'Attean::API::DateTimeLiteral');
176 } elsif (my $role = Attean->get_datatype_role($type)) {
177 0 Moo::Role->apply_roles_to_object($self, $role);
178 }
179 }
180 51 };
181  
182 192 ▶ sub is_recognized_type {
Subroutine is_recognized_type: called CC=7 SCAR=31.1
Pod undocumented
183 192 my $self = shift;
184 192 ▶ if (my $dt = $self->datatype) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dt = $self->datatype) 192 0 192
185 192 my $type = $dt->value;
186 192 ▶ if ($type eq 'http://www.w3.org/2001/XMLSchema#string') {
Branch: 5 branches
BranchTrueFalseTotal
if ($type eq 'http://www.w3.org/2001/XMLSchema#string') { } 192 0 192
elsif ($type =~ qr"^http://www[.]w3[.]org/2001/XMLSchema#(?:integer|decimal|float|double|non(?:Positive|Negative)Integer|(?:positive|negative)Integer|long|int|short|byte|unsigned(?:Long|Int|Short|Byte))$"u) { } 0 0 0
elsif ($type eq 'http://www.w3.org/2001/XMLSchema#boolean') { } 0 0 0
elsif ($type eq 'http://www.w3.org/2001/XMLSchema#dateTime') { } 0 0 0
elsif (my $role = 'Attean'->get_datatype_role($type)) { } 0 0 0
187 192 return 1;
188 } elsif ($type =~ qr<^http://www[.]w3[.]org/2001/XMLSchema#(?:integer|decimal|float|double|non(?:Positive|Negative)Integer|(?:positive|negative)Integer|long|int|short|byte|unsigned(?:Long|Int|Short|Byte))$>) {
189 0 return 1;
190 } elsif ($type eq 'http://www.w3.org/2001/XMLSchema#boolean') {
191 0 return 1;
192 } elsif ($type eq 'http://www.w3.org/2001/XMLSchema#dateTime') {
193 0 return 1;
194 } elsif (my $role = Attean->get_datatype_role($type)) {
195 0 return 1;
196 }
197 0 return 0;
198 }
199 }
200
201 103 ▶ sub sparql_tokens {
Subroutine sparql_tokens: called CC=8 SCAR=20.9
Pod undocumented
202 103 my $self = shift;
203 103 my @tokens;
204
205 103 my $dt = $self->datatype;
206 103 ▶ if ($self->does('Attean::API::NumericLiteral') and $dt->value eq 'http://www.w3.org/2001/XMLSchema#integer') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->does("Attean::API::NumericLiteral") and $dt->value eq "http://www.w3.org/2001/XMLSchema#integer") 17 86 103
Condition66%2/3
$self->does("Attean::API::NumericLiteral") and $dt->value eq "http://www.w3.org/2001/XMLSchema#integer"
!ll&&!rl&&r
86017
MC/DC50%1/2
$self->does("Attean::API::NumericLiteral") and $dt->value eq "http://www.w3.org/2001/XMLSchema#integer"
$self->does("Attean::API::NumericLiteral") $dt->value eq "http://www.w3.org/2001/XMLSchema#integer"
Truth table66%2/3
A and B
A= $self->does("Attean::API::NumericLiteral")B= $dt->value eq "http://www.w3.org/2001/XMLSchema#integer"
ABresult
0X0
100
111
207 17 ▶ if ($self->value =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->value =~ /^\d+$/u) 17 0 17
208 17 my $t = AtteanX::SPARQL::Token->fast_constructor( INTEGER, -1, -1, -1, -1, [$self->value] );
209 17 return Attean::ListIterator->new( values => [$t], item_type => 'AtteanX::SPARQL::Token' );
210 }
211 }
212
213 86 ▶ my $qtype = ($self->value =~ /\n/) ? STRING3D : STRING1D;
Branch: 1 branch
BranchTrueFalseTotal
$self->value =~ /\n/u ? : 1 85 86
214 86 my $t = AtteanX::SPARQL::Token->fast_constructor( $qtype, -1, -1, -1, -1, [$self->value] );
215 86 push(@tokens, $t);
216 86 ▶ if (my $lang = $self->language) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lang = $self->language) { } 6 80 86
217 6 my $lex = "$lang";
218 6 ▶ if (my $d = $self->base_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $self->base_dir) 0 6 6
219 0 $lex .= '--' . $d;
220 }
221 6 my $l = AtteanX::SPARQL::Token->fast_constructor( LANG, -1, -1, -1, -1, ["$lang"] );
222 6 push(@tokens, $l);
223 } else {
224 80 ▶ if ($dt->value ne 'http://www.w3.org/2001/XMLSchema#string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt->value ne "http://www.w3.org/2001/XMLSchema#string") 5 75 80
225 5 push(@tokens, AtteanX::SPARQL::Token->hathat);
226 5 push(@tokens, $dt->sparql_tokens->elements);
227 }
228 }
229 86 return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' );
230 }
231
232 28 ▶ sub ebv {
Subroutine ebv: called CC=8 SCAR=24.2
Pod documented
233 28 my $self = shift;
234 28 my $value = $self->value;
235 28 my $dt = $self->datatype->value;
236 28 ▶ if ($dt eq 'http://www.w3.org/2001/XMLSchema#boolean') {
Branch: 3 branches
BranchTrueFalseTotal
if ($dt eq 'http://www.w3.org/2001/XMLSchema#boolean') { } 26 2 28
elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#string') { } 2 0 2
elsif ($self->language) { } 0 0 0
237 26 ▶ if ($value eq 'true' or $value eq '1') {
Branch: 2 branches
BranchTrueFalseTotal
if ($value eq 'true' or $value eq '1') { } 14 12 26
elsif ($value eq 'false' or $value eq '0') { } 12 0 12
Condition66%2/3
$value eq "true" or $value eq 1
l!l&&r!l&&!r
14012
MC/DC50%1/2
$value eq "true" or $value eq 1
$value eq "true" $value eq 1
Truth table66%2/3
A or B
A= $value eq "true"B= $value eq 1
ABresult
1X1
011
000
238 14 return 1;
239 ▶ } elsif ($value eq 'false' or $value eq '0') {
Condition33%1/3
$value eq "false" or $value eq 0
l!l&&r!l&&!r
1200
MC/DC0%0/2
$value eq "false" or $value eq 0
$value eq "false" $value eq 0
Truth table33%1/3
A or B
A= $value eq "false"B= $value eq 0
ABresult
1X1
011
000
240 12 return 0;
241 } else {
242 0 die "TypeError: EBV of an xsd:boolean with invalid lexical form";
243 }
244 } elsif ($dt eq 'http://www.w3.org/2001/XMLSchema#string') {
245 2 return (length($value) > 0);
246 } elsif ($self->language) {
247 0 die "TypeError: EBV of a language-tagged literal";
248 } else {
249 0 die "TypeError: EBV of a datatyped literal: $dt";
250 }
251 }
252
253 1 ▶ sub compare {
Subroutine compare: called CC=9 SCAR=27.7
Pod documented
254 1 my ($a, $b) = @_;
255 1 ▶ return 1 unless blessed($b);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($b) 0 1 1
256 1 ▶ return 1 unless ($b->does('Attean::API::Literal') or $b->does('Attean::API::Binding'));
Branch: 1 branch
BranchTrueFalseTotal
unless $b->does("Attean::API::Literal") or $b->does("Attean::API::Binding") 0 1 1
Condition33%1/3
$b->does("Attean::API::Literal") or $b->does("Attean::API::Binding")
l!l&&r!l&&!r
100
MC/DC0%0/2
$b->does("Attean::API::Literal") or $b->does("Attean::API::Binding")
$b->does("Attean::API::Literal") $b->does("Attean::API::Binding")
Truth table33%1/3
A or B
A= $b->does("Attean::API::Literal")B= $b->does("Attean::API::Binding")
ABresult
1X1
011
000
257 1 ▶ return -1 if ($b->does('Attean::API::Binding'));
Branch: 1 branch
BranchTrueFalseTotal
if $b->does("Attean::API::Binding") 0 1 1
258 1 ▶ my $c = ((($a->language // '') cmp ($b->language // '')) || ($a->datatype->value cmp $b->datatype->value) || ($a->value cmp $b->value));
Condition40%4/10
($a->language // '') cmp ($b->language // '') || $a->datatype->value cmp $b->datatype->value || $a->value cmp $b->value
l!l&&r!l&&!r
010
($a->language // "") cmp ($b->language // "") or $a->datatype->value cmp $b->datatype->value
l!l&&r!l&&!r
001
$a->language // ""
l!l
01
$b->language // ""
l!l
01
MC/DC0%0/3
($a->language // '') cmp ($b->language // '') || $a->datatype->value cmp $b->datatype->value || $a->value cmp $b->value
$a->language $a->datatype->value cmp $b->datatype->value $a->value cmp $b->value
MC/DC0%0/1
$b->language // ""
$b->language
Truth table25%1/4
A or B || C
A= $a->languageB= $a->datatype->value cmp $b->datatype->valueC= $a->value cmp $b->value
ABCresult
1XX1
01X1
0011
0000
Truth table50%1/2
A
A= $b->language
Aresult
11
00
259 1 return $c;
260 }
261
262 104 ▶ sub equals {
Subroutine equals: called CC=8 SCAR=25.5
Pod undocumented
263 104 my $a = shift;
264 104 my $b = shift;
265 104 ▶ if ($a->as_string eq $b->as_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->as_string eq $b->as_string) 8 96 104
266 8 return 1;
267 }
268 96 ▶ if ($a->can('datatype') and $b->can('datatype') and my $adt = $a->datatype and my $bdt = $b->datatype) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->can("datatype") and $b->can("datatype") and my $adt = $a->datatype and my $bdt = $b->datatype) 96 0 96
Condition33%3/9
$a->can("datatype") and $b->can("datatype") and my $adt = $a->datatype and my $bdt = $b->datatype
!ll&&!rl&&r
0096
$a->can("datatype") and $b->can("datatype") and my $adt = $a->datatype
!ll&&!rl&&r
0096
$a->can("datatype") and $b->can("datatype")
!ll&&!rl&&r
0096
MC/DC0%0/4
$a->can("datatype") and $b->can("datatype") and my $adt = $a->datatype and my $bdt = $b->datatype
$a->can("datatype") $b->can("datatype") my $adt = $a->datatype my $bdt = $b->datatype
Truth table20%1/5
A and B and C and D
A= $a->can("datatype")B= $b->can("datatype")C= my $adt = $a->datatypeD= my $bdt = $b->datatype
ABCDresult
0XXX0
10XX0
110X0
11100
11111
269 96 ▶ if (!$a->is_recognized_type or !$b->is_recognized_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($a->is_recognized_type and $b->is_recognized_type) 0 96 96
Condition33%1/3
$a->is_recognized_type and $b->is_recognized_type
!ll&&!rl&&r
0096
MC/DC0%0/2
$a->is_recognized_type and $b->is_recognized_type
$a->is_recognized_type $b->is_recognized_type
Truth table33%1/3
A and B
A= $a->is_recognized_typeB= $b->is_recognized_type
ABresult
0X0
100
111
270 # Either different lexical values in the same datatype, or different
271 # datatypes. Either way, it's datatypes that were not caught by some
272 # some more-specific implementation of equals(). So we don't know
273 # anything about the value space, so we raise a type error, indicating
274 # that we can't say whether the values are equal or not.
275 0 die 'TypeError';
276 }
277 }
278 96 return 0;
279 }
280
281 =item C<< sameTerms( $other ) >>
282  
283 =cut
284  
285 0 ▶ sub sameTerms {
Subroutine sameTerms: not called CC=4 SCAR=30.0
Pod undocumented
286 0 my $lhs = shift;
287 0 my $rhs = shift;
288 0 ▶ return 0 unless ($rhs->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $rhs->does("Attean::API::Literal") 0 0 0
289 0 ▶ return 0 unless ($lhs->value eq $rhs->value);
Branch: 1 branch
BranchTrueFalseTotal
unless $lhs->value eq $rhs->value 0 0 0
290 0 ▶ return 0 unless ($lhs->datatype->value eq $rhs->datatype->value);
Branch: 1 branch
BranchTrueFalseTotal
unless $lhs->datatype->value eq $rhs->datatype->value 0 0 0
291 0 return 1;
292 }
293
294 51 ▶ if ($ENV{ATTEAN_TYPECHECK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"ATTEAN_TYPECHECK"}) 0 51 51
295 0 my %map = (
296 language => Maybe[Str],
297 datatype => ConsumerOf['Attean::API::IRI'],
298 );
299 0 foreach my $method (keys %map) {
300 0 my $type = $map{$method};
301 0 ▶ around $method => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
302 0 my $orig = shift;
303 0 my $self = shift;
304 0 my $class = ref($self);
305 0 my $value = $self->$orig(@_);
306 0 my $err = $type->validate($value);
307 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
308 0 my $name = $type->display_name;
309 0 die "${class}'s $method failed conformance check for $name: $value";
310 }
311 0 return $value;
312 0 };
313 }
314 }
315
316 0 ▶ sub construct_args {
Subroutine construct_args: not called CC=3 SCAR=24.8
Pod undocumented
317 0 my $self = shift;
318 0 my %args;
319 0 ▶ $args{language} = $self->language if ($self->language);
Branch: 1 branch
BranchTrueFalseTotal
if $self->language 0 0 0
320 0 ▶ $args{datatype} = $self->datatype if ($self->datatype);
Branch: 1 branch
BranchTrueFalseTotal
if $self->datatype 0 0 0
321 0 return %args;
322 }
323
324 0 ▶ sub argument_compatible {
Subroutine argument_compatible: not called CC=14 SCAR=53.5
Pod undocumented
325 0 my $self = shift;
326 0 my @terms = @_;
327
328 0 ▶ if (my $l = $self->language) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $l = $self->language) { } 0 0 0
elsif ($self->datatype->value eq 'http://www.w3.org/2001/XMLSchema#string') { } 0 0 0
329 0 foreach my $t (@terms) {
330 0 ▶ return 0 unless ($t->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $t->does("Attean::API::Literal") 0 0 0
331 0 ▶ if ($t->language) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->language) { } 0 0 0
332 0 ▶ return 0 unless (defined($t->language));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t->language 0 0 0
333 0 ▶ return 0 unless ($t->language eq $l);
Branch: 1 branch
BranchTrueFalseTotal
unless $t->language eq $l 0 0 0
334 } else {
335 0 ▶ return 0 unless ($t->datatype->value eq 'http://www.w3.org/2001/XMLSchema#string');
Branch: 1 branch
BranchTrueFalseTotal
unless $t->datatype->value eq "http://www.w3.org/2001/XMLSchema#string" 0 0 0
336 }
337 }
338 0 return 1;
339 } elsif ($self->datatype->value eq 'http://www.w3.org/2001/XMLSchema#string') {
340 0 foreach my $t (@terms) {
341 0 ▶ return 0 unless ($t->does('Attean::API::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
unless $t->does("Attean::API::Literal") 0 0 0
342 0 ▶ return 0 if ($t->language);
Branch: 1 branch
BranchTrueFalseTotal
if $t->language 0 0 0
343 0 ▶ return 0 unless (blessed($t->datatype));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($t->datatype) 0 0 0
344 0 ▶ return 0 unless ($t->datatype->value eq 'http://www.w3.org/2001/XMLSchema#string');
Branch: 1 branch
BranchTrueFalseTotal
unless $t->datatype->value eq "http://www.w3.org/2001/XMLSchema#string" 0 0 0
345 }
346 0 return 1;
347 }
348
349 0 return 0;
350 }
351
352 63 ▶ sub _ntriples_string {
Subroutine _ntriples_string: called CC=4 SCAR=17.9
353 63 my $self = shift;
354 63 my $str = sprintf('"%s"', $self->__ntriples_string);
355 63 ▶ if (my $l = $self->language) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = $self->language) { } 0 63 63
356 0 ▶ if (my $d = $self->base_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $self->base_dir) { } 0 0 0
357 0 return join('', $str, '@', $l, '--', $d);
358 } else {
359 0 return join('@', $str, $l);
360 }
361 } else {
362 63 my $dt = $self->datatype;
363 63 ▶ if ($dt->value eq 'http://www.w3.org/2001/XMLSchema#string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt->value eq 'http://www.w3.org/2001/XMLSchema#string') { } 0 63 63
364 0 return $str;
365 } else {
366 63 return join('^^', $str, $dt->ntriples_string);
367 }
368 }
369 }
370  
371 0 ▶ around as_sparql => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
372 0 my $orig = shift;
373 0 my $self = shift;
374 0 my $s = $self->$orig(@_);
375
376 0 ▶ if ($s =~ m[^"(true|false)"\^\^<http://www[.]w3[.]org/2001/XMLSchema#boolean>$]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ m[^"(true|false)"\^\^<http://www[.]w3[.]org/2001/XMLSchema#boolean>$]u) 0 0 0
377 0 return $1;
378 }
379
380 0 return $s;
381 51 };
382  
383 1400 ▶ sub has_base_dir {
Subroutine has_base_dir: called CC=2 SCAR=7.6
Pod undocumented
384 1400 my $self = shift;
385 1400 my $base_dir = $self->base_dir;
386 1400 ▶ return (defined($base_dir) and length($base_dir) > 0);
Condition33%1/3
defined $base_dir && length $base_dir > 0
!ll&&!rl&&r
140000
MC/DC0%0/2
defined $base_dir && length $base_dir > 0
defined $base_dir length $base_dir > 0
Truth table33%1/3
A && B
A= defined $base_dirB= length $base_dir > 0
ABresult
0X0
100
111
387 }
388  
389 0 ▶ sub lang_dir {
Subroutine lang_dir: not called CC=3 SCAR=24.8
Pod undocumented
390 0 my $self = shift;
391 0 my $lang_key = '';
392 0 ▶ if (my $l = $self->language) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $l = $self->language) 0 0 0
393 0 $lang_key = $l;
394 0 ▶ if (my $d = $self->base_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $self->base_dir) 0 0 0
395 0 $lang_key .= '--' . $d;
396 }
397 }
398 0 return $lang_key;
399 }
400  
401 }
402  
403 51 package Attean::API::DateTimeLiteral 0.041 {
404 51 ▶ use DateTime::Format::W3CDTF;
Subroutine BEGIN: called CC=1 SCAR=0.0
405  
406 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
407  
408 3 ▶ sub datetime {
Subroutine datetime: called CC=3 SCAR=11.0
Pod undocumented
409 3 my $self = shift;
410 3 my $w3c = DateTime::Format::W3CDTF->new;
411 3 my $lex = $self->value;
412 3 my $add = 0;
413 3 ▶ if ($lex =~ /T24:00:00/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lex =~ /T24:00:00/u) 1 2 3
414 1 $add++;
415 1 $lex =~ s/24:00:00/00:00:00/;
416 }
417 3 my $dt = $w3c->parse_datetime( $lex );
418 3 ▶ if ($add) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add) 1 2 3
419 1 $dt->add( days => 1 );
420 }
421 3 return $dt;
422 }
423
424 0 ▶ sub equals {
Subroutine equals: not called CC=3 SCAR=24.8
Pod undocumented
425 0 my $self = shift;
426 0 my $other = shift;
427 0 ▶ return 0 unless ($other->does('Attean::API::DateTimeLiteral'));
Branch: 1 branch
BranchTrueFalseTotal
unless $other->does("Attean::API::DateTimeLiteral") 0 0 0
428 0 my $dt = $self->datetime;
429 0 my $odt = $other->datetime;
430 0 ▶ return 0 if ($dt->time_zone->is_floating != $odt->time_zone->is_floating);
Branch: 1 branch
BranchTrueFalseTotal
if $dt->time_zone->is_floating != $odt->time_zone->is_floating 0 0 0
431 0 return (0 == $dt->compare($odt));
432 }
433  
434 0 ▶ sub compare {
Subroutine compare: not called CC=4 SCAR=30.0
Pod undocumented
435 0 my ($a, $b) = @_;
436 0 ▶ if ($b->does('Attean::API::DateTimeLiteral')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b->does("Attean::API::DateTimeLiteral")) 0 0 0
437 0 ▶ if (my $adt = $a->datetime and my $bdt = $b->datetime) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $adt = $a->datetime and my $bdt = $b->datetime) 0 0 0
Condition0%0/3
my $adt = $a->datetime and my $bdt = $b->datetime
!ll&&!rl&&r
000
MC/DC0%0/2
my $adt = $a->datetime and my $bdt = $b->datetime
my $adt = $a->datetime my $bdt = $b->datetime
Truth table0%0/3
A and B
A= my $adt = $a->datetimeB= my $bdt = $b->datetime
ABresult
0X0
100
111
438 0 my $af = $adt->time_zone->is_floating;
439 0 my $bf = $bdt->time_zone->is_floating;
440 # TODO: handle case of one floating datetime
441 0 return DateTime->compare($adt, $bdt);
442 }
443 }
444 0 return $a->SUPER::compare($b);
445 }
446
447 }
448  
449 51 package Attean::API::CanonicalizingLiteral 0.041 {
450 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
451 51 requires 'canonicalized_term';
452 51 requires 'canonicalized_term_strict';
453 }
454  
455 51 package Attean::API::BooleanLiteral 0.041 {
456 51 ▶ use Scalar::Util qw(blessed looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
457  
458 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
459  
460 0 ▶ sub boolean_value {
Subroutine boolean_value: not called CC=3 SCAR=24.8
Pod undocumented
461 0 my $self = shift;
462 0 my $value = $self->value;
463 0 ▶ return $value if ($value =~ m/^(0|1)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(0|1)$/u 0 0 0
464 0 ▶ return 1 if ($value =~ m/^true$/);
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^true$/u 0 0 0
465 0 return 0;
466 }
467  
468 0 ▶ sub canonicalized_term_strict {
Subroutine canonicalized_term_strict: not called CC=4 SCAR=30.0
Pod undocumented
469 0 my $self = shift;
470 0 my $value = $self->value;
471 0 ▶ if ($value =~ m/^(true|false|0|1)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(true|false|0|1)$/u) { } 0 0 0
472 0 ▶ return ($value eq 'true' or $value eq '1')
Branch: 1 branch
BranchTrueFalseTotal
$value eq 'true' || $value eq '1' ? : 0 0 0
Condition0%0/3
$value eq "true" or $value eq 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$value eq "true" or $value eq 1
$value eq "true" $value eq 1
Truth table0%0/3
A or B
A= $value eq "true"B= $value eq 1
ABresult
1X1
011
000
473 ? Attean::Literal->true
474 : Attean::Literal->false;
475 } else {
476 0 die "Bad lexical form for xsd:boolean: '$value'";
477 }
478 }
479  
480 8 ▶ sub canonicalized_term {
Subroutine canonicalized_term: called CC=4 SCAR=16.4
Pod undocumented
481 8 my $self = shift;
482 8 my $value = $self->value;
483 8 ▶ if ($value =~ m/^(true|false|0|1)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(true|false|0|1)$/u) { } 8 0 8
484 8 ▶ return ($value eq 'true' or $value eq '1')
Branch: 1 branch
BranchTrueFalseTotal
$value eq 'true' || $value eq '1' ? : 8 0 8
Condition33%1/3
$value eq "true" or $value eq 1
l!l&&r!l&&!r
800
MC/DC0%0/2
$value eq "true" or $value eq 1
$value eq "true" $value eq 1
Truth table33%1/3
A or B
A= $value eq "true"B= $value eq 1
ABresult
1X1
011
000
485 ? Attean::Literal->true
486 : Attean::Literal->false;
487 } else {
488 0 return $self;
489 }
490 }
491  
492 2 ▶ sub equals {
Subroutine equals: called CC=6 SCAR=24.7
Pod undocumented
493 2 my ($a, $b) = @_;
494 2 my $does_bool = $b->does('Attean::API::BooleanLiteral');
495 2 ▶ if ($b->does('Attean::API::Literal') and not($does_bool)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b->does("Attean::API::Literal") and not $does_bool) 0 2 2
Condition33%1/3
$b->does("Attean::API::Literal") and not $does_bool
!ll&&!rl&&r
020
MC/DC0%0/2
$b->does("Attean::API::Literal") and not $does_bool
$b->does("Attean::API::Literal") not $does_bool
Truth table33%1/3
A and not(B)
A= $b->does("Attean::API::Literal")B= not $does_bool
ABresult
0X0
100
111
496 0 ▶ if (!$a->is_recognized_type or !$b->is_recognized_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($a->is_recognized_type and $b->is_recognized_type) 0 0 0
Condition0%0/3
$a->is_recognized_type and $b->is_recognized_type
!ll&&!rl&&r
000
MC/DC0%0/2
$a->is_recognized_type and $b->is_recognized_type
$a->is_recognized_type $b->is_recognized_type
Truth table0%0/3
A and B
A= $a->is_recognized_typeB= $b->is_recognized_type
ABresult
0X0
100
111
497 # Either different lexical values in the same datatype, or different
498 # datatypes. Either way, it's datatypes that were not caught by some
499 # some more-specific implementation of equals(). So we don't know
500 # anything about the value space, so we raise a type error, indicating
501 # that we can't say whether the values are equal or not.
502 0 die "TypeError: boolean and non-boolean literals are not comparable";
503 }
504 }
505 2 ▶ if ($does_bool) {
Branch: 1 branch
BranchTrueFalseTotal
if ($does_bool) 2 0 2
506 2 my $l = $a->canonicalized_term;
507 2 my $r = $b->canonicalized_term;
508 2 return $l->value eq $r->value;
509 }
510 0 return 0;
511 }
512  
513 51 with 'Attean::API::Literal', 'Attean::API::CanonicalizingLiteral';
514 }
515  
516 51 package Attean::API::NumericLiteral 0.041 {
517 51 ▶ use Scalar::Util qw(blessed looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
518  
519 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
520  
521 0 ▶ sub equals {
Subroutine equals: not called CC=8 SCAR=42.8
Pod undocumented
522 0 my ($a, $b) = @_;
523 0 my $does_num = $b->does('Attean::API::NumericLiteral');
524 0 ▶ if ($b->does('Attean::API::Literal') and not($does_num)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b->does("Attean::API::Literal") and not $does_num) 0 0 0
Condition0%0/3
$b->does("Attean::API::Literal") and not $does_num
!ll&&!rl&&r
000
MC/DC0%0/2
$b->does("Attean::API::Literal") and not $does_num
$b->does("Attean::API::Literal") not $does_num
Truth table0%0/3
A and not(B)
A= $b->does("Attean::API::Literal")B= not $does_num
ABresult
0X0
100
111
525 0 ▶ if (!$a->is_recognized_type or !$b->is_recognized_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($a->is_recognized_type and $b->is_recognized_type) 0 0 0
Condition0%0/3
$a->is_recognized_type and $b->is_recognized_type
!ll&&!rl&&r
000
MC/DC0%0/2
$a->is_recognized_type and $b->is_recognized_type
$a->is_recognized_type $b->is_recognized_type
Truth table0%0/3
A and B
A= $a->is_recognized_typeB= $b->is_recognized_type
ABresult
0X0
100
111
526 # Either different lexical values in the same datatype, or different
527 # datatypes. Either way, it's datatypes that were not caught by some
528 # some more-specific implementation of equals(). So we don't know
529 # anything about the value space, so we raise a type error, indicating
530 # that we can't say whether the values are equal or not.
531 0 die "TypeError: numeric and non-numeric literals are not comparable";
532 }
533 }
534 0 ▶ return 0 unless ($b->does('Attean::API::NumericLiteral'));
Branch: 1 branch
BranchTrueFalseTotal
unless $b->does("Attean::API::NumericLiteral") 0 0 0
535 0 ▶ return 0 unless (defined $a->numeric_value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $a->numeric_value 0 0 0
536 0 ▶ return 0 unless (defined $b->numeric_value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b->numeric_value 0 0 0
537 0 return $a->numeric_value == $b->numeric_value;
538 }
539  
540 1 ▶ sub compare {
Subroutine compare: called CC=8 SCAR=25.5
Pod undocumented
541 1 my ($a, $b) = @_;
542 1 my $does_num = $b->does('Attean::API::NumericLiteral');
543 1 ▶ if ($b->does('Attean::API::Literal') and not($does_num)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b->does("Attean::API::Literal") and not $does_num) 0 1 1
Condition33%1/3
$b->does("Attean::API::Literal") and not $does_num
!ll&&!rl&&r
010
MC/DC0%0/2
$b->does("Attean::API::Literal") and not $does_num
$b->does("Attean::API::Literal") not $does_num
Truth table33%1/3
A and not(B)
A= $b->does("Attean::API::Literal")B= not $does_num
ABresult
0X0
100
111
544 0 die "TypeError: numeric and non-numeric literals are not comparable";
545 }
546 1 ▶ return 1 unless blessed($b);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($b) 0 1 1
547 1 ▶ return 1 unless ($b->does('Attean::API::Literal') or $b->does('Attean::API::Binding'));
Branch: 1 branch
BranchTrueFalseTotal
unless $b->does("Attean::API::Literal") or $b->does("Attean::API::Binding") 0 1 1
Condition33%1/3
$b->does("Attean::API::Literal") or $b->does("Attean::API::Binding")
l!l&&r!l&&!r
100
MC/DC0%0/2
$b->does("Attean::API::Literal") or $b->does("Attean::API::Binding")
$b->does("Attean::API::Literal") $b->does("Attean::API::Binding")
Truth table33%1/3
A or B
A= $b->does("Attean::API::Literal")B= $b->does("Attean::API::Binding")
ABresult
1X1
011
000
548 1 ▶ return -1 if ($b->does('Attean::API::Binding'));
Branch: 1 branch
BranchTrueFalseTotal
if $b->does("Attean::API::Binding") 0 1 1
549 1 ▶ if ($b->does('Attean::API::NumericLiteral')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b->does('Attean::API::NumericLiteral')) { } 1 0 1
550 1 return $a->numeric_value <=> $b->numeric_value;
551 } else {
552 0 return 1;
553 # Attean::API::Literal::compare($a, $b);
554 }
555 }
556  
557 4 ▶ sub canonicalized_term_strict {
Subroutine canonicalized_term_strict: called CC=1 SCAR=0.0
Pod undocumented
558 4 my $self = shift;
559 4 return $self->_canonicalized_term(1, @_);
560 }
561
562 2 ▶ sub canonicalized_term {
Subroutine canonicalized_term: called CC=1 SCAR=0.0
Pod undocumented
563 2 my $self = shift;
564 2 return $self->_canonicalized_term(0, @_);
565 }
566
567 6 ▶ sub _canonicalized_term {
Subroutine _canonicalized_term: called CC=36 SCAR=62.6
568 6 my $self = shift;
569 6 my $strict = shift;
570 6 my $value = $self->value;
571 6 my $type = $self->datatype->value;
572 6 $type =~ s/^.*#//;
573 6 ▶ if ($type eq 'integer') {
Branch: 6 branches
BranchTrueFalseTotal
if ($type eq 'integer') { } 2 4 6
elsif ($type eq 'negativeInteger') { } 0 4 4
elsif ($type eq 'decimal') { } 4 0 4
elsif ($type eq 'float') { } 0 0 0
elsif ($type eq 'boolean') { } 0 0 0
elsif ($type eq 'double') { } 0 0 0
574 2 ▶ if ($value =~ m/^([-+])?(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^([-+])?(\d+)$/u) { } 2 0 2
575 2 ▶ my $sign = $1 || '';
Condition50%1/2
$1 || ''
l!l
20
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
576 2 my $num = $2;
577 2 ▶ $sign = '' if ($sign eq '+');
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "+" 2 0 2
578 2 $num =~ s/^0+(\d)/$1/;
579 2 return Attean::Literal->integer("${sign}${num}");
580 } else {
581 0 ▶ die "Bad lexical form for xsd:integer: '$value'" if ($strict);
Branch: 1 branch
BranchTrueFalseTotal
if $strict 0 0 0
582 0 return $self;
583 }
584 } elsif ($type eq 'negativeInteger') {
585 0 ▶ if ($value =~ m/^-(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^-(\d+)$/u) { } 0 0 0
586 0 my $num = $1;
587 0 $num =~ s/^0+(\d)/$1/;
588 0 return Attean::Literal->new(value => "-${num}", datatype => 'http://www.w3.org/2001/XMLSchema#negativeInteger');
589 } else {
590 0 ▶ die "Bad lexical form for xsd:integer: '$value'" if ($strict);
Branch: 1 branch
BranchTrueFalseTotal
if $strict 0 0 0
591 0 return $self;
592 }
593 } elsif ($type eq 'decimal') {
594 4 ▶ if ($value =~ m/^([-+])?((\d+)([.]\d*)?)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value =~ /^([-+])?((\d+)([.]\d*)?)$/u) { } 4 0 4
elsif ($value =~ /^([-+])?([.]\d+)$/u) { } 0 0 0
595 4 ▶ my $sign = $1 || '';
Condition50%1/2
$1 || ''
l!l
04
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
596 4 my $num = $2;
597 4 my $int = $3;
598 4 my $frac = $4;
599 4 ▶ $sign = '' if ($sign eq '+');
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "+" 0 4 4
600 4 $num =~ s/^0+(\d)/$1/;
601 4 $num =~ s/[.](\d+)0+$/.$1/;
602 4 ▶ if ($num =~ /^[.]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num =~ /^[.]/u) 0 4 4
603 0 $num = "0$num";
604 }
605 4 ▶ if ($num !~ /[.]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($num =~ /[.]/u) 4 0 4
606 4 $num = "${num}.0";
607 }
608 4 return Attean::Literal->decimal("${sign}${num}");
609 } elsif ($value =~ m/^([-+])?([.]\d+)$/) {
610 0 ▶ my $sign = $1 || '';
Condition0%0/2
$1 || ''
l!l
00
MC/DC0%0/1
$1 || ''
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
611 0 my $num = $2;
612 0 ▶ $sign = '' if ($sign eq '+');
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "+" 0 0 0
613 0 $num =~ s/^0+(.)/$1/;
614 0 return Attean::Literal->decimal("${sign}${num}");
615 } else {
616 0 ▶ die "Bad lexical form for xsd:deciaml: '$value'" if ($strict);
Branch: 1 branch
BranchTrueFalseTotal
if $strict 0 0 0
617 0 return $self;
618 }
619 } elsif ($type eq 'float') {
620 0 ▶ if ($value =~ m/^(?:([-+])?(?:(\d+(?:\.\d*)?|\.\d+)([Ee][-+]?\d+)?|(INF)))|(NaN)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(?:([-+])?(?:(\d+(?:\.\d*)?|\.\d+)([Ee][-+]?\d+)?|(INF)))|(NaN)$/u) { } 0 0 0
621 0 my $sign = $1;
622 0 my $inf = $4;
623 0 my $nan = $5;
624 51 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
625 0 ▶ $sign = '' if ($sign eq '+');
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "+" 0 0 0
626 0 ▶ return Attean::Literal->float("${sign}$inf") if ($inf);
Branch: 1 branch
BranchTrueFalseTotal
if $inf 0 0 0
627 0 ▶ return Attean::Literal->float($nan) if ($nan);
Branch: 1 branch
BranchTrueFalseTotal
if $nan 0 0 0
628  
629 51 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
630 0 $value = sprintf('%E', $value);
631 0 $value =~ m/^(?:([-+])?(?:(\d+(?:\.\d*)?|\.\d+)([Ee][-+]?\d+)?|(INF)))|(NaN)$/;
632 0 $sign = $1;
633 0 $inf = $4;
634 0 $nan = $5;
635 0 my $num = $2;
636 0 my $exp = $3;
637 0 $num =~ s/[.](\d+?)0+/.$1/;
638 0 $exp =~ tr/e/E/;
639 0 $exp =~ s/E[+]/E/;
640 0 $exp =~ s/E(-?)0+([1-9])$/E$1$2/;
641 0 $exp =~ s/E(-?)0+$/E${1}0/;
642 0 return Attean::Literal->float("${sign}${num}${exp}");
643 } else {
644 0 ▶ die "Bad lexical form for xsd:float: '$value'" if ($strict);
Branch: 1 branch
BranchTrueFalseTotal
if $strict 0 0 0
645 0 return $self;
646 }
647 } elsif ($type eq 'boolean') {
648 0 ▶ if ($value =~ m/^(true|false|0|1)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(true|false|0|1)$/u) { } 0 0 0
649 0 ▶ return ($value eq 'true' or $value eq '1')
Branch: 1 branch
BranchTrueFalseTotal
$value eq 'true' || $value eq '1' ? : 0 0 0
Condition0%0/3
$value eq "true" or $value eq 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$value eq "true" or $value eq 1
$value eq "true" $value eq 1
Truth table0%0/3
A or B
A= $value eq "true"B= $value eq 1
ABresult
1X1
011
000
650 ? Attean::Literal->true
651 : Attean::Literal->false;
652 } else {
653 0 ▶ die "Bad lexical form for xsd:boolean: '$value'" if ($strict);
Branch: 1 branch
BranchTrueFalseTotal
if $strict 0 0 0
654 0 return $self;
655 }
656 } elsif ($type eq 'double') {
657 0 ▶ if ($value =~ m/^(?:([-+])?(?:(\d+(?:\.\d*)?|\.\d+)([Ee][-+]?\d+)?|(INF)))|(NaN)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^(?:([-+])?(?:(\d+(?:\.\d*)?|\.\d+)([Ee][-+]?\d+)?|(INF)))|(NaN)$/u) { } 0 0 0
658 0 my $sign = $1;
659 0 my $inf = $4;
660 0 my $nan = $5;
661 51 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
662 0 ▶ $sign = '' if ($sign eq '+');
Branch: 1 branch
BranchTrueFalseTotal
if $sign eq "+" 0 0 0
663 0 ▶ return Attean::Literal->double("${sign}$inf") if ($inf);
Branch: 1 branch
BranchTrueFalseTotal
if $inf 0 0 0
664 0 ▶ return Attean::Literal->double($nan) if ($nan);
Branch: 1 branch
BranchTrueFalseTotal
if $nan 0 0 0
665  
666 51 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
667 0 $value = sprintf('%E', $value);
668 0 $value =~ m/^(?:([-+])?(?:(\d+(?:\.\d*)?|\.\d+)([Ee][-+]?\d+)?|(INF)))|(NaN)$/;
669 0 $sign = $1;
670 0 $inf = $4;
671 0 $nan = $5;
672 0 my $num = $2;
673 0 my $exp = $3;
674 0 $num =~ s/[.](\d+?)0+/.$1/;
675 0 $exp =~ tr/e/E/;
676 0 $exp =~ s/E[+]/E/;
677 0 $exp =~ s/E(-?)0+([1-9])$/E$1$2/;
678 0 $exp =~ s/E(-?)0+$/E${1}0/;
679 0 return Attean::Literal->double("${sign}${num}${exp}");
680 } else {
681 0 ▶ die "Bad lexical form for xsd:double: '$value'" if ($strict);
Branch: 1 branch
BranchTrueFalseTotal
if $strict 0 0 0
682 0 return $self;
683 }
684 } else {
685 0 warn "No canonicalization for type $type";
686 }
687 0 return $self;
688 }
689
690 29 ▶ sub is_integer_type {
Subroutine is_integer_type: called CC=1 SCAR=0.0
Pod undocumented
691 29 my $self = shift;
692 29 my $type = $self->datatype->value;
693 29 return scalar($type =~ qr<^http://www[.]w3[.]org/2001/XMLSchema#(?:integer|non(?:Positive|Negative)Integer|(?:positive|negative)Integer|long|int|short|byte|unsigned(?:Long|Int|Short|Byte))$>);
694 }
695
696 6 ▶ sub ebv {
Subroutine ebv: called CC=1 SCAR=0.0
Pod undocumented
697 6 my $self = shift;
698 6 return ($self->numeric_value != 0);
699 }
700  
701 50 ▶ sub numeric_value {
Subroutine numeric_value: called CC=2 SCAR=7.1
Pod undocumented
702 50 my $self = shift;
703 50 my $v = $self->value;
704 50 ▶ return (looks_like_number($v)) ? eval $v : undef;
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($v) ? : 50 0 50
705 }
706  
707 {
708 51 my %type_hierarchy = (
709 'integer' => 'decimal',
710 'nonPositiveInteger' => 'integer',
711 'negativeInteger' => 'nonPositiveInteger',
712 'long' => 'integer',
713 'int' => 'long',
714 'short' => 'int',
715 'byte' => 'short',
716 'nonNegativeInteger' => 'integer',
717 'unsignedLong' => 'nonNegativeInteger',
718 'unsignedInt' => 'unsignedLong',
719 'unsignedShort' => 'unsignedInt',
720 'unsignedByte' => 'unsignedShort',
721 'positiveInteger' => 'nonNegativeInteger',
722 );
723 12 ▶ sub is_base_type {
Subroutine is_base_type: called CC=1 SCAR=0.0
Pod undocumented
724 12 my $type = shift;
725 12 return ($type =~ m/\b(integer|decimal|float|double)$/);
726 }
727 14 ▶ sub _lowest_base_type {
Subroutine _lowest_base_type: called CC=30 SCAR=44.0
728 14 my ($lhs, $rhs) = @_;
729 14 for ($lhs, $rhs) {
730 28 s/^.*#//;
731 }
732 14 ▶ if ($lhs eq $rhs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lhs eq $rhs) 6 8 14
733 6 ▶ if (is_base_type($lhs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_base_type($lhs)) 6 0 6
734 6 return "http://www.w3.org/2001/XMLSchema#$lhs";
735 }
736 }
737 8 my $cur = $lhs;
738 8 my %ancestors;
739 do {
740 18 $ancestors{$cur}++;
741 18 ▶ if ($cur eq $rhs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cur eq $rhs) 1 17 18
742 1 ▶ if (is_base_type($cur)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_base_type($cur)) 1 0 1
743 1 return "http://www.w3.org/2001/XMLSchema#$cur";
744 }
745 }
746 8 ▶ } while ($cur = $type_hierarchy{$cur});
Branch: 1 branch
BranchTrueFalseTotal
$cur = $type_hierarchy{$cur} and do { do { ++$ancestors{$cur}; if ($cur eq $rhs) { if (is_base_type($cur)) { return "http://www.w3.org/2001/XMLSchema#$cur"; } ; } } } 10 7 17
747  
748 7 $cur = $rhs;
749 7 my $seen_float = 0;
750 7 my $seen_decimal = 0;
751
752 7 ▶ while ($cur = $type_hierarchy{$cur}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cur = $type_hierarchy{$cur}) 13 3 16
753 13 ▶ if (exists $ancestors{$cur}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ancestors{$cur}) 5 8 13
754 5 ▶ if (is_base_type($cur)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_base_type($cur)) 3 2 5
755 3 return "http://www.w3.org/2001/XMLSchema#$cur";
756 }
757 }
758 10 ▶ if ($cur eq 'float') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cur eq "float") 0 10 10
759 0 $seen_float++;
760 0 ▶ if (my $r = _lowest_base_type($lhs, 'double')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = _lowest_base_type($lhs, "double")) 0 0 0
761 0 return $r;
762 }
763 }
764 10 ▶ if ($cur eq 'decimal') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cur eq "decimal") 1 9 10
765 1 $seen_decimal++;
766 1 ▶ if (my $r = _lowest_base_type($lhs, 'float')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = _lowest_base_type($lhs, "float")) 1 0 1
767 1 return $r;
768 }
769 0 ▶ if (my $r = _lowest_base_type($lhs, 'double')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = _lowest_base_type($lhs, "double")) 0 0 0
770 0 return $r;
771 }
772 }
773 }
774 3 ▶ if ($ancestors{'float'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ancestors{'float'}) { } 2 1 3
elsif ($seen_float) { } 0 1 1
775 # seen a float type on the lhs
776 2 ▶ return "http://www.w3.org/2001/XMLSchema#double" if ($rhs eq 'float');
Branch: 1 branch
BranchTrueFalseTotal
if $rhs eq "float" 0 2 2
777 } elsif ($seen_float) {
778 # seen a float type on the rhs
779 0 ▶ return "http://www.w3.org/2001/XMLSchema#double" if (exists $ancestors{'float'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $ancestors{"float"} 0 0 0
780 }
781 3 ▶ if ($ancestors{'decimal'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ancestors{'decimal'}) { } 1 2 3
elsif ($seen_decimal) { } 0 2 2
782 # seen a decimal type on the lhs
783 1 ▶ return "http://www.w3.org/2001/XMLSchema#float" if ($rhs eq "float");
Branch: 1 branch
BranchTrueFalseTotal
if $rhs eq "float" 1 0 1
784 0 ▶ return "http://www.w3.org/2001/XMLSchema#double" if ($rhs eq "double");
Branch: 1 branch
BranchTrueFalseTotal
if $rhs eq "double" 0 0 0
785 } elsif ($seen_decimal) {
786 # seen a decimal type on the rhs
787 0 ▶ return "http://www.w3.org/2001/XMLSchema#float" if (exists $ancestors{"float"});
Branch: 1 branch
BranchTrueFalseTotal
if exists $ancestors{"float"} 0 0 0
788 0 ▶ return "http://www.w3.org/2001/XMLSchema#double" if (exists $ancestors{"double"});
Branch: 1 branch
BranchTrueFalseTotal
if exists $ancestors{"double"} 0 0 0
789 }
790 2 ▶ if ($rhs eq 'float') {
Branch: 2 branches
BranchTrueFalseTotal
if ($rhs eq 'float') { } 0 2 2
elsif ($rhs eq 'decimal') { } 1 1 2
791 0 $seen_float++;
792 0 ▶ if (my $r = _lowest_base_type($lhs, 'double')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = _lowest_base_type($lhs, "double")) 0 0 0
793 0 return $r;
794 }
795 } elsif ($rhs eq 'decimal') {
796 1 $seen_decimal++;
797 1 ▶ if (my $r = _lowest_base_type($lhs, 'float')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = _lowest_base_type($lhs, "float")) 1 0 1
798 1 return $r;
799 }
800 0 ▶ if (my $r = _lowest_base_type($lhs, 'double')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = _lowest_base_type($lhs, "double")) 0 0 0
801 0 return $r;
802 }
803 }
804 1 return;
805 }
806 2 ▶ sub _lca {
Subroutine _lca: called CC=15 SCAR=42.5
807 2 my ($lhs, $rhs) = @_;
808 2 for ($lhs, $rhs) {
809 4 s/^.*#//;
810 }
811 2 ▶ return "http://www.w3.org/2001/XMLSchema#$lhs" if ($lhs eq $rhs);
Branch: 1 branch
BranchTrueFalseTotal
if $lhs eq $rhs 0 2 2
812 2 my $cur = $lhs;
813 2 my %ancestors = ($cur => 1);
814 2 ▶ while ($cur = $type_hierarchy{$cur}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cur = $type_hierarchy{$cur}) 0 2 2
815 0 $ancestors{$cur}++;
816 0 ▶ return "http://www.w3.org/2001/XMLSchema#$cur" if ($cur eq $rhs);
Branch: 1 branch
BranchTrueFalseTotal
if $cur eq $rhs 0 0 0
817 }
818 2 $cur = $rhs;
819 2 my $seen_float = 0;
820 2 my $seen_decimal = 0;
821 2 ▶ while ($cur = $type_hierarchy{$cur}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cur = $type_hierarchy{$cur}) 0 2 2
822 0 ▶ $seen_float++ if ($cur eq 'float');
Branch: 1 branch
BranchTrueFalseTotal
if $cur eq "float" 0 0 0
823 0 ▶ $seen_decimal++ if ($cur eq 'decimal');
Branch: 1 branch
BranchTrueFalseTotal
if $cur eq "decimal" 0 0 0
824 0 ▶ return "http://www.w3.org/2001/XMLSchema#$cur" if exists $ancestors{$cur};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ancestors{$cur} 0 0 0
825 }
826 2 ▶ if ($ancestors{'decimal'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ancestors{'decimal'}) { } 0 2 2
elsif ($seen_decimal) { } 0 2 2
827 # seen decimal on the lhs
828 0 ▶ return "http://www.w3.org/2001/XMLSchema#float" if ($rhs eq "float");
Branch: 1 branch
BranchTrueFalseTotal
if $rhs eq "float" 0 0 0
829 0 ▶ return "http://www.w3.org/2001/XMLSchema#double" if ($rhs eq "double");
Branch: 1 branch
BranchTrueFalseTotal
if $rhs eq "double" 0 0 0
830 } elsif ($seen_decimal) {
831 # seen decimal on the rhs
832 0 ▶ return "http://www.w3.org/2001/XMLSchema#float" if (exists $ancestors{"float"});
Branch: 1 branch
BranchTrueFalseTotal
if exists $ancestors{"float"} 0 0 0
833 0 ▶ return "http://www.w3.org/2001/XMLSchema#double" if (exists $ancestors{"double"});
Branch: 1 branch
BranchTrueFalseTotal
if exists $ancestors{"double"} 0 0 0
834 }
835 2 return;
836 }
837 27 ▶ sub binary_promotion_type {
Subroutine binary_promotion_type: called CC=12 SCAR=28.7
Pod undocumented
838 27 my $self = shift;
839 27 my $rhs = shift;
840 27 my $op = shift;
841
842 27 ▶ if ($op =~ m<^[-+*]$>) {
Branch: 2 branches
BranchTrueFalseTotal
if ($op =~ /^[-+*]$/u) { } 12 15 27
elsif ($op eq '/') { } 15 0 15
843 # return common numeric type
844 12 ▶ if (my $lbtype = _lowest_base_type($self->datatype->value, $rhs->datatype->value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $lbtype = _lowest_base_type($self->datatype->value, $rhs->datatype->value)) { } 11 1 12
elsif (my $lctype = _lca($self->datatype->value, $rhs->datatype->value)) { } 0 1 1
845 11 return $lbtype;
846 } elsif (my $lctype = _lca($self->datatype->value, $rhs->datatype->value)) {
847 0 return $lctype;
848 }
849 1 return 'http://www.w3.org/2001/XMLSchema#double';
850 } elsif ($op eq '/') {
851 15 ▶ if ($self->is_integer_type and $rhs->is_integer_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_integer_type and $rhs->is_integer_type) 14 1 15
Condition66%2/3
$self->is_integer_type and $rhs->is_integer_type
!ll&&!rl&&r
1014
MC/DC50%1/2
$self->is_integer_type and $rhs->is_integer_type
$self->is_integer_type $rhs->is_integer_type
Truth table66%2/3
A and B
A= $self->is_integer_typeB= $rhs->is_integer_type
ABresult
0X0
100
111
852 # return xsd:decimal if both operands are integers
853 14 return 'http://www.w3.org/2001/XMLSchema#decimal';
854 }
855 1 ▶ if (my $type = _lca($self->datatype->value, $rhs->datatype->value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = _lca($self->datatype->value, $rhs->datatype->value)) { } 0 1 1
856 0 return $type;
857 } else {
858 1 my $lt = $self->datatype->value;
859 1 my $rt = $rhs->datatype->value;
860 1 ▶ if ($lt =~ /#double$/ or $rt =~ /#double$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lt =~ /#double$/u or $rt =~ /#double$/u) { } 0 1 1
elsif ($lt =~ /#float$/u or $rt =~ /#float$/u) { } 1 0 1
Condition33%1/3
$lt =~ /#double$/u or $rt =~ /#double$/u
l!l&&r!l&&!r
001
MC/DC0%0/2
$lt =~ /#double$/u or $rt =~ /#double$/u
$lt =~ /#double$/u $rt =~ /#double$/u
Truth table33%1/3
A or B
A= $lt =~ /#double$/uB= $rt =~ /#double$/u
ABresult
1X1
011
000
861 0 return "http://www.w3.org/2001/XMLSchema#double";
862 ▶ } elsif ($lt =~ /#float$/ or $rt =~ /#float$/) {
Condition33%1/3
$lt =~ /#float$/u or $rt =~ /#float$/u
l!l&&r!l&&!r
100
MC/DC0%0/2
$lt =~ /#float$/u or $rt =~ /#float$/u
$lt =~ /#float$/u $rt =~ /#float$/u
Truth table33%1/3
A or B
A= $lt =~ /#float$/uB= $rt =~ /#float$/u
ABresult
1X1
011
000
863 1 return "http://www.w3.org/2001/XMLSchema#float";
864 }
865 }
866 0 return 'http://www.w3.org/2001/XMLSchema#double';
867 }
868 0 die "Unexpected numeric operation in binary_promotion_type: $op";
869 }
870 }
871 51 with 'Attean::API::Literal', 'Attean::API::CanonicalizingLiteral';
872 }
873  
874 51 package Attean::API::Blank 0.041 {
875 51 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
876 51 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
877 51 ▶ use AtteanX::SPARQL::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
878 51 ▶ use Attean::API::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
879  
880 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
881
882 1 ▶ sub ebv {
Subroutine ebv: called CC=1 SCAR=0.0
Pod documented
883 1 die "TypeError: EBV of a blank";
884 }
885 51 with 'Attean::API::Term', 'Attean::API::BlankOrIRI', 'Attean::API::BlankOrIRIOrTriple';
886 ;
887 51 with 'Attean::API::SPARQLSerializable';
888
889 28 ▶ sub sparql_tokens {
Subroutine sparql_tokens: called CC=1 SCAR=0.0
Pod undocumented
890 28 my $self = shift;
891 28 my $t = AtteanX::SPARQL::Token->fast_constructor( BNODE, -1, -1, -1, -1, [$self->value] );
892 28 return Attean::ListIterator->new( values => [$t], item_type => 'AtteanX::SPARQL::Token' );
893 }
894
895 3 ▶ sub compare {
Subroutine compare: called CC=3 SCAR=11.4
Pod documented
896 3 my ($a, $b) = @_;
897 3 ▶ return 1 unless blessed($b);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($b) 0 3 3
898 3 ▶ return -1 unless ($b->does('Attean::API::Blank'));
Branch: 1 branch
BranchTrueFalseTotal
unless $b->does("Attean::API::Blank") 0 3 3
899 3 return ($a->value cmp $b->value);
900 }
901  
902 =item C<< sameTerms( $other ) >>
903  
904 =cut
905  
906 0 ▶ sub sameTerms {
Subroutine sameTerms: not called CC=3 SCAR=24.8
Pod undocumented
907 0 my $lhs = shift;
908 0 my $rhs = shift;
909 0 ▶ return 0 unless ($rhs->does('Attean::API::Blank'));
Branch: 1 branch
BranchTrueFalseTotal
unless $rhs->does("Attean::API::Blank") 0 0 0
910 0 ▶ return 0 unless ($lhs->value eq $rhs->value);
Branch: 1 branch
BranchTrueFalseTotal
unless $lhs->value eq $rhs->value 0 0 0
911 0 return 1;
912 }
913 }
914  
915 51 package Attean::API::IRI 0.041 {
916 51 ▶ use IRI;
Subroutine BEGIN: called CC=1 SCAR=0.0
917 51 ▶ use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
918 51 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
919 51 ▶ use AtteanX::SPARQL::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
920 51 ▶ use Attean::API::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
921  
922 51 ▶ use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
923
924 1 ▶ sub ebv {
Subroutine ebv: called CC=1 SCAR=0.0
Pod documented
925 1 die "TypeError: EBV of a blank";
926 }
927 51 with 'Attean::API::Term', 'Attean::API::BlankOrIRI', 'Attean::API::BlankOrIRIOrTriple';
928 51 with 'Attean::API::SPARQLSerializable';
929
930 251 ▶ sub sparql_tokens {
Subroutine sparql_tokens: called CC=2 SCAR=7.2
Pod undocumented
931 251 my $self = shift;
932 251 my @tokens;
933 251 ▶ if ($self->value eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->value eq '') { } 0 251 251
934 0 push(@tokens, AtteanX::Parser::Turtle::Token->a);
935 } else {
936 251 push(@tokens, AtteanX::SPARQL::Token->fast_constructor( IRI, -1, -1, -1, -1, [$self->value] ));
937 }
938 251 return Attean::ListIterator->new( values => \@tokens, item_type => 'AtteanX::SPARQL::Token' );
939 }
940
941 16 ▶ sub compare {
Subroutine compare: called CC=5 SCAR=18.1
Pod documented
942 16 my ($a, $b) = @_;
943 16 ▶ return 1 unless blessed($b);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($b) 0 16 16
944 16 ▶ return -1 if ($b->does('Attean::API::Literal') or $b->does('Attean::API::Binding'));
Branch: 1 branch
BranchTrueFalseTotal
if $b->does("Attean::API::Literal") or $b->does("Attean::API::Binding") 0 16 16
Condition33%1/3
$b->does("Attean::API::Literal") or $b->does("Attean::API::Binding")
l!l&&r!l&&!r
0016
MC/DC0%0/2
$b->does("Attean::API::Literal") or $b->does("Attean::API::Binding")
$b->does("Attean::API::Literal") $b->does("Attean::API::Binding")
Truth table33%1/3
A or B
A= $b->does("Attean::API::Literal")B= $b->does("Attean::API::Binding")
ABresult
1X1
011
000
945 16 ▶ return 1 unless ($b->does('Attean::API::IRI'));
Branch: 1 branch
BranchTrueFalseTotal
unless $b->does("Attean::API::IRI") 0 16 16
946 16 return ($a->value cmp $b->value);
947 }
948
949 =item C<< sameTerms( $other ) >>
950  
951 =cut
952  
953 0 ▶ sub sameTerms {
Subroutine sameTerms: not called CC=3 SCAR=24.8
Pod undocumented
954 0 my $lhs = shift;
955 0 my $rhs = shift;
956 0 ▶ return 0 unless ($rhs->does('Attean::API::IRI'));
Branch: 1 branch
BranchTrueFalseTotal
unless $rhs->does("Attean::API::IRI") 0 0 0
957 0 ▶ return 0 unless ($lhs->value eq $rhs->value);
Branch: 1 branch
BranchTrueFalseTotal
unless $lhs->value eq $rhs->value 0 0 0
958 0 return 1;
959 }
960  
961 418 ▶ sub _ntriples_string {
Subroutine _ntriples_string: called CC=1 SCAR=0.0
962 418 my $self = shift;
963 418 return sprintf('<%s>', $self->__ntriples_string);
964 }
965  
966 1 ▶ around as_sparql => sub {
Subroutine __ANON__: called CC=2 SCAR=7.4
967 1 my $orig = shift;
968 1 my $self = shift;
969
970 1 ▶ if ($self->value eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->value eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#type") 0 1 1
971 0 return 'a';
972 }
973  
974 1 return $self->$orig(@_);
975 51 };
976 }
977  
978 51 1;
979  
980 __END__
« AtteanX/Functions/CompositeMaps.pm ↑ Summary AtteanX/Serializer/TextTable.pm »