Query/Functions/Xpath.pm

filter: Statementstmt 23.4% 63 / 269 Branchbran 6.7% 7 / 104 Conditioncond 0.0% 0 / 99 MC/DCmcdc 0.0% 0 / 60 Subroutinesub 31.2% 10 / 32 Podpod 100% 1 / 1 totaltotal 14.3% 81 / 565 CC 87 SCAR 36.2
CC
87
Cov
15%
__ANON__
156.0
__ANON__
56.0
__ANON__
42.0
CRAP 37.3
« Query/Plan/Join.pm ↑ Summary Query/Federate/Plan.pm »
1 =head1 NAME
2  
3 RDF::Query::Functions::Xpath - XPath functions
4  
5 =head1 VERSION
6  
7 This document describes RDF::Query::Functions::Xpath version 2.919.
8  
9 =head1 DESCRIPTION
10  
11 Defines the following function:
12  
13 =over
14  
15 =item * http://www.w3.org/2005/xpath-functions#matches
16  
17 =item * http://www.w3.org/2005/xpath-functions#abs
18  
19 =item * http://www.w3.org/2005/xpath-functions#ceiling
20  
21 =item * http://www.w3.org/2005/xpath-functions#floor
22  
23 =item * http://www.w3.org/2005/xpath-functions#round
24  
25 =item * http://www.w3.org/2005/xpath-functions#round-half-to-even
26  
27 =item * http://www.w3.org/2005/xpath-functions#compare
28  
29 =item * http://www.w3.org/2005/xpath-functions#concat
30  
31 =item * http://www.w3.org/2005/xpath-functions#substring
32  
33 =item * http://www.w3.org/2005/xpath-functions#string-length
34  
35 =item * http://www.w3.org/2005/xpath-functions#upper-case
36  
37 =item * http://www.w3.org/2005/xpath-functions#lower-case
38  
39 =item * http://www.w3.org/2005/xpath-functions#encode-for-uri
40  
41 =item * http://www.w3.org/2005/xpath-functions#contains
42  
43 =item * http://www.w3.org/2005/xpath-functions#starts-with
44  
45 =item * http://www.w3.org/2005/xpath-functions#ends-with
46  
47 =item * http://www.w3.org/2005/xpath-functions#year-from-dateTime
48  
49 =item * http://www.w3.org/2005/xpath-functions#month-from-dateTime
50  
51 =item * http://www.w3.org/2005/xpath-functions#day-from-dateTime
52  
53 =item * http://www.w3.org/2005/xpath-functions#hours-from-dateTime
54  
55 =item * http://www.w3.org/2005/xpath-functions#minutes-from-dateTime
56  
57 =item * http://www.w3.org/2005/xpath-functions#seconds-from-dateTime
58  
59 =item * http://www.w3.org/2005/xpath-functions#timezone-from-dateTime
60  
61  
62 =back
63  
64 =cut
65  
66 package RDF::Query::Functions::Xpath;
67  
68 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 35 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 35 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 35 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 35 ▶use RDF::Trine::Namespace qw(xsd);
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 35 our ($VERSION, $l);
77 35 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
78 35 $l = Log::Log4perl->get_logger("rdf.query.functions.xpath");
79 35 $VERSION = '2.919';
80 }
81  
82 35 ▶use Scalar::Util qw(blessed reftype refaddr looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 =begin private
85  
86 =item C<< install >>
87  
88 Documented in L<RDF::Query::Functions>.
89  
90 =end private
91  
92 =cut
93  
94 35 ▶sub install {
Subroutine install: called CC=1 SCAR=5.5
Pod documented
95 # # fn:compare
96 # $RDF::Query::functions{"http://www.w3.org/2005/04/xpath-functionscompare"} = sub {
97 # my $query = shift;
98 # my $nodea = shift;
99 # my $nodeb = shift;
100 # my $cast = 'sop:str';
101 # return ($RDF::Query::functions{$cast}->($query, $nodea) cmp $RDF::Query::functions{$cast}->($query, $nodeb));
102 # };
103 #
104 # # fn:not
105 # $RDF::Query::functions{"http://www.w3.org/2005/04/xpath-functionsnot"} = sub {
106 # my $query = shift;
107 # my $nodea = shift;
108 # my $nodeb = shift;
109 # my $cast = 'sop:str';
110 # return (0 != ($RDF::Query::functions{$cast}->($query, $nodea) cmp $RDF::Query::functions{$cast}->($query, $nodeb)));
111 # };
112  
113 # fn:matches
114 RDF::Query::Functions->install_function(
115 "http://www.w3.org/2005/xpath-functions#matches",
116 1 ▶ sub {
Subroutine __ANON__: called CC=9 SCAR=26.2
117 1 my $query = shift;
118 1 my $node = shift;
119 1 my $match = shift;
120 1 my $f = shift;
121
122 1 my $string;
123 1 ▶ if ($node->isa('RDF::Query::Node::Resource')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($node->isa('RDF::Query::Node::Resource')) { } 1 0 1
elsif ($node->isa('RDF::Query::Node::Literal')) { } 0 0 0
124 1 $string = $node->uri_value;
125 } elsif ($node->isa('RDF::Query::Node::Literal')) {
126 0 $string = $node->literal_value;
127 } else {
128 0 throw RDF::Query::Error::TypeError -text => "xpath:matches called without a literal or resource";
129 }
130
131 1 my $pattern = $match->literal_value;
132 1 ▶ return undef if (index($pattern, '(?{') != -1);
Branch: 1 branch
BranchTrueFalseTotal
if (index($pattern, "(?{") != -1) 0 1 1
133 1 ▶ return undef if (index($pattern, '(??{') != -1);
Branch: 1 branch
BranchTrueFalseTotal
if (index($pattern, "(??{") != -1) 0 1 1
134 1 ▶ my $flags = blessed($f) ? $f->literal_value : '';
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($f) ? : 1 0 1
135
136 1 my $matches;
137 1 ▶ if ($flags) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags) { } 0 1 1
138 0 $pattern = "(?${flags}:${pattern})";
139 0 warn 'pattern: ' . $pattern;
140 0 $matches = $string =~ /$pattern/;
141 } else {
142 1 ▶ $matches = ($string =~ /$pattern/) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /$pattern/ ? : 1 0 1
143 }
144  
145 1 ▶ return ($matches)
Branch: 1 branch
BranchTrueFalseTotal
$matches ? : 1 0 1
146 ? RDF::Query::Node::Literal->new('true', undef, 'http://www.w3.org/2001/XMLSchema#boolean')
147 : RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean');
148  
149 }
150 35 );
151  
152 # fn:abs
153 RDF::Query::Functions->install_function(
154 "http://www.w3.org/2005/xpath-functions#abs",
155 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
156 0 my $query = shift;
157 0 my $node = shift;
158 0 ▶ if (blessed($node) and $node->isa('RDF::Query::Node::Literal') and $node->is_numeric_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa('RDF::Query::Node::Literal') and $node->is_numeric_type) { } 0 0 0
Condition0%0/6
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal") and $node->is_numeric_type
!ll&&!rl&&r
000
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal") and $node->is_numeric_type
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal") $node->is_numeric_type
Truth table0%0/4
A and B and C
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")C= $node->is_numeric_type
ABCresult
0XX0
10X0
1100
1111
159 0 my $value = $node->numeric_value;
160 0 return RDF::Query::Node::Literal->new( abs($value), undef, $node->literal_datatype );
161 } else {
162 0 throw RDF::Query::Error::TypeError -text => "xpath:abs called without a numeric literal";
163 }
164 }
165 35 );
166
167 # fn:ceiling
168 RDF::Query::Functions->install_function(
169 "http://www.w3.org/2005/xpath-functions#ceiling",
170 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
171 0 my $query = shift;
172 0 my $node = shift;
173 0 ▶ if (blessed($node) and $node->isa('RDF::Query::Node::Literal') and $node->is_numeric_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa('RDF::Query::Node::Literal') and $node->is_numeric_type) { } 0 0 0
Condition0%0/6
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal") and $node->is_numeric_type
!ll&&!rl&&r
000
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal") and $node->is_numeric_type
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal") $node->is_numeric_type
Truth table0%0/4
A and B and C
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")C= $node->is_numeric_type
ABCresult
0XX0
10X0
1100
1111
174 0 my $value = $node->numeric_value;
175 0 return RDF::Query::Node::Literal->new( ceil($value), undef, $node->literal_datatype );
176 } else {
177 0 throw RDF::Query::Error::TypeError -text => "xpath:ceiling called without a numeric literal";
178 }
179 }
180 35 );
181
182 # fn:floor
183 RDF::Query::Functions->install_function(
184 "http://www.w3.org/2005/xpath-functions#floor",
185 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
186 0 my $query = shift;
187 0 my $node = shift;
188 0 ▶ if (blessed($node) and $node->isa('RDF::Query::Node::Literal') and $node->is_numeric_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa('RDF::Query::Node::Literal') and $node->is_numeric_type) { } 0 0 0
Condition0%0/6
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal") and $node->is_numeric_type
!ll&&!rl&&r
000
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal") and $node->is_numeric_type
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal") $node->is_numeric_type
Truth table0%0/4
A and B and C
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")C= $node->is_numeric_type
ABCresult
0XX0
10X0
1100
1111
189 0 my $value = $node->numeric_value;
190 0 return RDF::Query::Node::Literal->new( floor($value), undef, $node->literal_datatype );
191 } else {
192 0 throw RDF::Query::Error::TypeError -text => "xpath:floor called without a numeric literal";
193 }
194 }
195 35 );
196
197 # fn:round
198 RDF::Query::Functions->install_function(
199 "http://www.w3.org/2005/xpath-functions#round",
200 0 ▶ sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
201 0 my $query = shift;
202 0 my $node = shift;
203 0 ▶ if (blessed($node) and $node->isa('RDF::Query::Node::Literal') and $node->is_numeric_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa('RDF::Query::Node::Literal') and $node->is_numeric_type) { } 0 0 0
Condition0%0/6
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal") and $node->is_numeric_type
!ll&&!rl&&r
000
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal") and $node->is_numeric_type
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal") $node->is_numeric_type
Truth table0%0/4
A and B and C
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")C= $node->is_numeric_type
ABCresult
0XX0
10X0
1100
1111
204 0 my $value = $node->numeric_value;
205 0 my $mult = 1;
206 0 ▶ if ($value < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < 0) 0 0 0
207 0 $mult = -1;
208 0 $value = -$value;
209 }
210 0 my $round = $mult * POSIX::floor($value + 0.50000000000008);
211 0 return RDF::Query::Node::Literal->new( $round, undef, $node->literal_datatype );
212 } else {
213 0 throw RDF::Query::Error::TypeError -text => "xpath:round called without a numeric literal";
214 }
215 }
216 35 );
217
218 # fn:round-half-to-even
219 RDF::Query::Functions->install_function(
220 "http://www.w3.org/2005/xpath-functions#round-half-to-even",
221 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
222 0 my $query = shift;
223 0 my $node = shift;
224 0 ▶ if (blessed($node) and $node->isa('RDF::Query::Node::Literal') and $node->is_numeric_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa('RDF::Query::Node::Literal') and $node->is_numeric_type) { } 0 0 0
Condition0%0/6
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal") and $node->is_numeric_type
!ll&&!rl&&r
000
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal") and $node->is_numeric_type
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal") $node->is_numeric_type
Truth table0%0/4
A and B and C
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")C= $node->is_numeric_type
ABCresult
0XX0
10X0
1100
1111
225 0 my $value = $node->numeric_value;
226 0 return RDF::Query::Node::Literal->new( sprintf('%.0f', $value), undef, $node->literal_datatype );
227 } else {
228 0 throw RDF::Query::Error::TypeError -text => "xpath:round-half-to-even called without a numeric literal";
229 }
230 }
231 35 );
232
233 # fn:compare
234 RDF::Query::Functions->install_function(
235 "http://www.w3.org/2005/xpath-functions#compare",
236 0 ▶ sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
237 0 my $query = shift;
238 0 my $nodea = shift;
239 0 my $nodeb = shift;
240 0 ▶ unless (blessed($nodea) and $nodea->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($nodea) and $nodea->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($nodea) and $nodea->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($nodea) and $nodea->isa("RDF::Query::Node::Literal")
builtin::blessed($nodea) $nodea->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($nodea)B= $nodea->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
241 0 throw RDF::Query::Error::TypeError -text => "xpath:compare called without a literal arg1 term";
242 }
243 0 ▶ unless (blessed($nodeb) and $nodeb->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($nodeb) and $nodeb->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($nodeb) and $nodeb->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($nodeb) and $nodeb->isa("RDF::Query::Node::Literal")
builtin::blessed($nodeb) $nodeb->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($nodeb)B= $nodeb->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
244 0 throw RDF::Query::Error::TypeError -text => "xpath:compare called without a literal arg2 term";
245 }
246
247 0 my $value = ($nodea->literal_value cmp $nodeb->literal_value);
248 0 return RDF::Query::Node::Literal->new( $value, undef, $xsd->integer );
249 }
250 35 );
251
252 # fn:concat
253 RDF::Query::Functions->install_function(
254 "http://www.w3.org/2005/xpath-functions#concat",
255 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
256 0 my $query = shift;
257 0 my $model = $query->model;
258 0 my @nodes = @_;
259 0 my @strings = map { $query->call_function($model, {}, 'sparql:str', $_) } @nodes;
260 0 my $value = join('', map { $_->literal_value } @strings);
261 0 return RDF::Query::Node::Literal->new($value);
262 }
263 35 );
264
265 # fn:substring
266 RDF::Query::Functions->install_function(
267 "http://www.w3.org/2005/xpath-functions#substring",
268 0 ▶ sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
269 0 my $query = shift;
270 0 my $node = shift;
271 0 my @args = @_;
272 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
273 0 throw RDF::Query::Error::TypeError -text => "xpath:substring called without a literal arg1 term";
274 }
275 0 my $value = $node->literal_value;
276 0 my @nums;
277 0 foreach my $i (0 .. $#args) {
278 0 my $argnum = $i + 2;
279 0 my $arg = $args[ $i ];
280 0 ▶ unless (blessed($arg) and $arg->isa('RDF::Query::Node::Literal') and $arg->is_numeric_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($arg) and $arg->isa("RDF::Query::Node::Literal") and $arg->is_numeric_type) 0 0 0
Condition0%0/6
builtin::blessed($arg) and $arg->isa("RDF::Query::Node::Literal") and $arg->is_numeric_type
!ll&&!rl&&r
000
builtin::blessed($arg) and $arg->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($arg) and $arg->isa("RDF::Query::Node::Literal") and $arg->is_numeric_type
builtin::blessed($arg) $arg->isa("RDF::Query::Node::Literal") $arg->is_numeric_type
Truth table0%0/4
A and B and C
A= builtin::blessed($arg)B= $arg->isa("RDF::Query::Node::Literal")C= $arg->is_numeric_type
ABCresult
0XX0
10X0
1100
1111
281 0 throw RDF::Query::Error::TypeError -text => "xpath:substring called without a numeric literal arg${argnum} term";
282 }
283 0 push(@nums, $arg->numeric_value);
284 }
285 0 my $substring = substr($value, @nums);
286 0 return RDF::Query::Node::Literal->new($substring);
287 }
288 35 );
289
290 # fn:string-length
291 RDF::Query::Functions->install_function(
292 "http://www.w3.org/2005/xpath-functions#string-length",
293 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
294 0 my $query = shift;
295 0 my $node = shift;
296 0 ▶ if (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa('RDF::Query::Node::Literal')) { } 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
297 0 my $value = $node->literal_value;
298 0 return RDF::Query::Node::Literal->new( length($value), undef, $xsd->integer );
299 } else {
300 0 throw RDF::Query::Error::TypeError -text => "xpath:string-length called without a literal term";
301 }
302 }
303 35 );
304
305 # fn:upper-case
306 RDF::Query::Functions->install_function(
307 "http://www.w3.org/2005/xpath-functions#upper-case",
308 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
309 0 my $query = shift;
310 0 my $node = shift;
311 0 ▶ if (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa('RDF::Query::Node::Literal')) { } 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
312 0 my $value = $node->literal_value;
313 0 return RDF::Query::Node::Literal->new( uc($value) );
314 } else {
315 0 throw RDF::Query::Error::TypeError -text => "xpath:upper-case called without a literal term";
316 }
317 }
318 35 );
319
320 # fn:lower-case
321 RDF::Query::Functions->install_function(
322 "http://www.w3.org/2005/xpath-functions#lower-case",
323 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
324 0 my $query = shift;
325 0 my $node = shift;
326 0 ▶ if (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa('RDF::Query::Node::Literal')) { } 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
327 0 my $value = $node->literal_value;
328 0 return RDF::Query::Node::Literal->new( lc($value) );
329 } else {
330 0 throw RDF::Query::Error::TypeError -text => "xpath:lower-case called without a literal term";
331 }
332 }
333 35 );
334
335 # fn:encode-for-uri
336 RDF::Query::Functions->install_function(
337 "http://www.w3.org/2005/xpath-functions#encode-for-uri",
338 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
339 0 my $query = shift;
340 0 my $node = shift;
341 0 ▶ if (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa('RDF::Query::Node::Literal')) { } 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
342 0 my $value = $node->literal_value;
343 0 return RDF::Query::Node::Literal->new( uri_escape($value) );
344 } else {
345 0 throw RDF::Query::Error::TypeError -text => "xpath:escape-for-uri called without a literal term";
346 }
347 }
348 35 );
349
350 # fn:contains
351 RDF::Query::Functions->install_function(
352 "http://www.w3.org/2005/xpath-functions#contains",
353 0 ▶ sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
354 0 my $query = shift;
355 0 my $node = shift;
356 0 my $pat = shift;
357 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
358 0 throw RDF::Query::Error::TypeError -text => "xpath:contains called without a literal arg1 term";
359 }
360 0 ▶ unless (blessed($pat) and $pat->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($pat) and $pat->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($pat) and $pat->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($pat) and $pat->isa("RDF::Query::Node::Literal")
builtin::blessed($pat) $pat->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($pat)B= $pat->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
361 0 throw RDF::Query::Error::TypeError -text => "xpath:contains called without a literal arg2 term";
362 }
363 0 my $lit = $node->literal_value;
364 0 my $plit = $pat->literal_value;
365 0 my $pos = index($lit, $plit);
366 0 ▶ if ($pos >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= 0) { } 0 0 0
367 0 return RDF::Query::Node::Literal->new('true', undef, $xsd->boolean);
368 } else {
369 0 return RDF::Query::Node::Literal->new('false', undef, $xsd->boolean);
370 }
371 }
372 35 );
373
374 # fn:starts-with
375 RDF::Query::Functions->install_function(
376 "http://www.w3.org/2005/xpath-functions#starts-with",
377 0 ▶ sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
378 0 my $query = shift;
379 0 my $node = shift;
380 0 my $pat = shift;
381 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
382 0 throw RDF::Query::Error::TypeError -text => "xpath:starts-with called without a literal arg1 term";
383 }
384 0 ▶ unless (blessed($pat) and $pat->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($pat) and $pat->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($pat) and $pat->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($pat) and $pat->isa("RDF::Query::Node::Literal")
builtin::blessed($pat) $pat->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($pat)B= $pat->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
385 0 throw RDF::Query::Error::TypeError -text => "xpath:starts-with called without a literal arg2 term";
386 }
387 0 ▶ if (index($node->literal_value, $pat->literal_value) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($node->literal_value, $pat->literal_value) == 0) { } 0 0 0
388 0 return RDF::Query::Node::Literal->new('true', undef, $xsd->boolean);
389 } else {
390 0 return RDF::Query::Node::Literal->new('false', undef, $xsd->boolean);
391 }
392 }
393 35 );
394
395 # fn:ends-with
396 RDF::Query::Functions->install_function(
397 "http://www.w3.org/2005/xpath-functions#ends-with",
398 0 ▶ sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
399 0 my $query = shift;
400 0 my $node = shift;
401 0 my $pat = shift;
402 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
403 0 throw RDF::Query::Error::TypeError -text => "xpath:ends-with called without a literal arg1 term";
404 }
405 0 ▶ unless (blessed($pat) and $pat->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($pat) and $pat->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($pat) and $pat->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($pat) and $pat->isa("RDF::Query::Node::Literal")
builtin::blessed($pat) $pat->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($pat)B= $pat->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
406 0 throw RDF::Query::Error::TypeError -text => "xpath:ends-with called without a literal arg2 term";
407 }
408
409 0 my $lit = $node->literal_value;
410 0 my $plit = $pat->literal_value;
411 0 my $pos = length($lit) - length($plit);
412 0 ▶ if (rindex($lit, $plit) == $pos) {
Branch: 1 branch
BranchTrueFalseTotal
if (rindex($lit, $plit) == $pos) { } 0 0 0
413 0 return RDF::Query::Node::Literal->new('true', undef, $xsd->boolean);
414 } else {
415 0 return RDF::Query::Node::Literal->new('false', undef, $xsd->boolean);
416 }
417 }
418 35 );
419
420 # op:dateTime-equal
421 # op:dateTime-less-than
422 # op:dateTime-greater-than
423
424 # fn:year-from-dateTime
425 RDF::Query::Functions->install_function(
426 "http://www.w3.org/2005/xpath-functions#year-from-dateTime",
427 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
428 0 my $query = shift;
429 0 my $node = shift;
430 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
431 0 throw RDF::Query::Error::TypeError -text => "xpath:year-from-dateTime called without a literal term";
432 }
433 0 my $dt = $node->datetime;
434 0 ▶ if ($dt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt) { } 0 0 0
435 0 return RDF::Query::Node::Literal->new($dt->year);
436 } else {
437 0 throw RDF::Query::Error::TypeError -text => "xpath:year-from-dateTime called without a valid dateTime";
438 }
439 }
440 35 );
441
442 # fn:month-from-dateTime
443 RDF::Query::Functions->install_function(
444 "http://www.w3.org/2005/xpath-functions#month-from-dateTime",
445 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
446 0 my $query = shift;
447 0 my $node = shift;
448 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
449 0 throw RDF::Query::Error::TypeError -text => "xpath:month-from-dateTime called without a literal term";
450 }
451 0 my $dt = $node->datetime;
452 0 ▶ if ($dt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt) { } 0 0 0
453 0 return RDF::Query::Node::Literal->new($dt->month);
454 } else {
455 0 throw RDF::Query::Error::TypeError -text => "xpath:month-from-dateTime called without a valid dateTime";
456 }
457 }
458 35 );
459
460 # fn:day-from-dateTime
461 RDF::Query::Functions->install_function(
462 "http://www.w3.org/2005/xpath-functions#day-from-dateTime",
463 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
464 0 my $query = shift;
465 0 my $node = shift;
466 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
467 0 throw RDF::Query::Error::TypeError -text => "xpath:day-from-dateTime called without a literal term";
468 }
469 0 my $dt = $node->datetime;
470 0 ▶ if ($dt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt) { } 0 0 0
471 0 return RDF::Query::Node::Literal->new($dt->day);
472 } else {
473 0 throw RDF::Query::Error::TypeError -text => "xpath:day-from-dateTime called without a valid dateTime";
474 }
475 }
476 35 );
477
478 # fn:hours-from-dateTime
479 RDF::Query::Functions->install_function(
480 "http://www.w3.org/2005/xpath-functions#hours-from-dateTime",
481 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
482 0 my $query = shift;
483 0 my $node = shift;
484 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
485 0 throw RDF::Query::Error::TypeError -text => "xpath:hours-from-dateTime called without a literal term";
486 }
487 0 my $dt = $node->datetime;
488 0 ▶ if ($dt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt) { } 0 0 0
489 0 return RDF::Query::Node::Literal->new($dt->hour);
490 } else {
491 0 throw RDF::Query::Error::TypeError -text => "xpath:hours-from-dateTime called without a valid dateTime";
492 }
493 }
494 35 );
495
496 # fn:minutes-from-dateTime
497 RDF::Query::Functions->install_function(
498 "http://www.w3.org/2005/xpath-functions#minutes-from-dateTime",
499 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
500 0 my $query = shift;
501 0 my $node = shift;
502 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
503 0 throw RDF::Query::Error::TypeError -text => "xpath:minutes-from-dateTime called without a literal term";
504 }
505 0 my $dt = $node->datetime;
506 0 ▶ if ($dt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt) { } 0 0 0
507 0 return RDF::Query::Node::Literal->new($dt->minute);
508 } else {
509 0 throw RDF::Query::Error::TypeError -text => "xpath:minutes-from-dateTime called without a valid dateTime";
510 }
511 }
512 35 );
513
514 # fn:seconds-from-dateTime
515 RDF::Query::Functions->install_function(
516 "http://www.w3.org/2005/xpath-functions#seconds-from-dateTime",
517 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
518 0 my $query = shift;
519 0 my $node = shift;
520 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
521 0 throw RDF::Query::Error::TypeError -text => "xpath:seconds-from-dateTime called without a literal term";
522 }
523 0 my $dt = $node->datetime;
524 0 ▶ if ($dt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt) { } 0 0 0
525 0 return RDF::Query::Node::Literal->new($dt->second);
526 } else {
527 0 throw RDF::Query::Error::TypeError -text => "xpath:seconds-from-dateTime called without a valid dateTime";
528 }
529 }
530 35 );
531
532 # fn:timezone-from-dateTime
533 RDF::Query::Functions->install_function(
534 "http://www.w3.org/2005/xpath-functions#timezone-from-dateTime",
535 0 ▶ sub {
Subroutine __ANON__: not called CC=12 SCAR=50.5
536 0 my $query = shift;
537 0 my $node = shift;
538 0 ▶ unless (blessed($node) and $node->isa('RDF::Query::Node::Literal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")) 0 0 0
Condition0%0/3
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($node) and $node->isa("RDF::Query::Node::Literal")
builtin::blessed($node) $node->isa("RDF::Query::Node::Literal")
Truth table0%0/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Query::Node::Literal")
ABresult
0X0
100
111
539 0 throw RDF::Query::Error::TypeError -text => "xpath:timezone-from-dateTime called without a literal term";
540 }
541 0 my $dt = $node->datetime;
542 0 ▶ if ($dt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt) 0 0 0
543 0 my $tz = $dt->time_zone;
544 0 ▶ if ($tz) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tz) 0 0 0
545 0 my $offset = $tz->offset_for_datetime( $dt );
546 0 my $minus = '';
547 0 ▶ if ($offset < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < 0) 0 0 0
548 0 $minus = '-';
549 0 $offset = -$offset;
550 }
551  
552 0 my $duration = "${minus}PT";
553 0 ▶ if ($offset >= 60*60) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset >= 3600) 0 0 0
554 0 my $h = int($offset / (60*60));
555 0 ▶ $duration .= "${h}H" if ($h > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $h > 0 0 0 0
556 0 $offset = $offset % (60*60);
557 }
558 0 ▶ if ($offset >= 60) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset >= 60) 0 0 0
559 0 my $m = int($offset / 60);
560 0 ▶ $duration .= "${m}M" if ($m > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $m > 0 0 0 0
561 0 $offset = $offset % 60;
562 }
563 0 my $s = int($offset);
564 0 ▶ $duration .= "${s}S" if ($s > 0 or $duration eq 'PT');
Branch: 1 branch
BranchTrueFalseTotal
if $s > 0 or $duration eq "PT" 0 0 0
Condition0%0/3
$s > 0 or $duration eq "PT"
l!l&&r!l&&!r
000
MC/DC0%0/2
$s > 0 or $duration eq "PT"
$s > 0 $duration eq "PT"
Truth table0%0/3
A or B
A= $s > 0B= $duration eq "PT"
ABresult
1X1
011
000
565
566 0 return RDF::Query::Node::Literal->new($duration);
567 }
568 }
569 0 throw RDF::Query::Error::TypeError -text => "xpath:timezone-from-dateTime called without a valid dateTime";
570 }
571 35 );
572  
573 }
574  
575  
576  
577 35 1;
578  
579 __END__
« Query/Plan/Join.pm ↑ Summary Query/Federate/Plan.pm »