XPath/Token.pm

filter: Statementstmt 89.1% 417 / 468 Branchbran 68.5% 237 / 346 Conditioncond 77.0% 37 / 48 MC/DCmcdc 60.0% 18 / 30 Subroutinesub 100% 40 / 40 Podpod 0.0% 0 / 34 totaltotal 77.5% 749 / 966 CC 204 SCAR 43.0
CC
204
Cov
80%
eval
142.6
compare_op
140.2
function_string
13.5
CRAP 73.7
↑ Summary XPath/Test.pm »
1 package XML::Parser::Lite::Tree::XPath::Token;
2
3 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 32 ▶use XML::Parser::Lite::Tree::XPath::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 32 ▶use XML::Parser::Lite::Tree::XPath::Axis;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 32 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 2470 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
9 2470 my $class = shift;
10 2470 my $self = bless {}, $class;
11 2470 return $self;
12 }
13
14 55524 ▶sub match {
Subroutine match: called CC=4 SCAR=13.9
Pod undocumented
15 55524 my ($self, $type, $content) = @_;
16
17 55524 ▶ return 0 unless $self->{type} eq $type;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"type"} eq $type 48153 7371 55524
18
19 7371 ▶ return 0 if (defined($content) && ($self->{content} ne $content));
Branch: 1 branch
BranchTrueFalseTotal
if defined $content and $self->{"content"} ne $content 2985 4386 7371
Condition100%3/3
defined $content and $self->{"content"} ne $content
!ll&&!rl&&r
288714992985
MC/DC100%2/2
defined $content and $self->{"content"} ne $content
defined $content $self->{"content"} ne $content
Truth table100%3/3
A and B
A= defined $contentB= $self->{"content"} ne $content
ABresult
0X0
100
111
20
21 4386 return 1;
22 }
23
24 12 ▶sub is_expression {
Subroutine is_expression: called CC=4 SCAR=13.9
Pod undocumented
25 12 my ($self) = @_;
26
27 12 ▶ return 1 if $self->{type} eq 'Number';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"type"} eq "Number" 6 6 12
28 6 ▶ return 1 if $self->{type} eq 'Literal';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"type"} eq "Literal" 1 5 6
29 5 ▶ return 0 if $self->{type} eq 'Operator';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"type"} eq "Operator" 4 1 5
30
31 1 warn "Not sure if $self->{type} is an expression";
32
33 1 return 0;
34 }
35
36 279 ▶sub dump {
Subroutine dump: called CC=4 SCAR=13.9
Pod undocumented
37 279 my ($self) = @_;
38
39 279 my $ret = $self->{type};
40 279 ▶ $ret .= ':absolute' if $self->{absolute};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"absolute"} 39 240 279
41 279 ▶ $ret .= ':'.$self->{content} if defined $self->{content};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"content"} 138 141 279
42 279 ▶ $ret .= '::'.$self->{axis} if defined $self->{axis};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"axis"} 17 262 279
43
44 279 return $ret;
45 }
46
47 1090 ▶sub ret {
Subroutine ret: called CC=1 SCAR=0.0
Pod undocumented
48 1090 my ($self, $a, $b) = @_;
49 1090 return XML::Parser::Lite::Tree::XPath::Result->new($a, $b);
50 }
51
52 1696 ▶sub eval {
Subroutine eval: called CC=94 SCAR=49.6
Pod undocumented
53 1696 my ($self, $context) = @_;
54
55 1696 ▶ return $context if $context->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $context->is_error 1 1695 1696
56 1695 $self->{context} = $context;
57
58 1695 ▶ if ($self->{type} eq 'LocationPath'){
Branch: 15 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'LocationPath') { } 154 1541 1695
elsif ($self->{'type'} eq 'Step') { } 279 1262 1541
elsif ($self->{'type'} eq 'NameTest') { } 221 1041 1262
elsif ($self->{'type'} eq 'NodeTypeTest') { } 58 983 1041
elsif ($self->{'type'} eq 'Predicate') { } 31 952 983
elsif ($self->{'type'} eq 'Number') { } 173 779 952
elsif ($self->{'type'} eq 'FunctionCall') { } 280 499 779
elsif ($self->{'type'} eq 'FunctionArg') { } 196 303 499
elsif ($self->{'type'} eq 'EqualityExpr' or $self->{'type'} eq 'RelationalExpr') { } 120 183 303
elsif ($self->{'type'} eq 'Literal') { } 93 90 183
elsif ($self->{'type'} eq 'UnionExpr') { } 9 81 90
elsif ($self->{'type'} eq 'MultiplicativeExpr') { } 36 45 81
elsif ($self->{'type'} eq 'OrExpr' or $self->{'type'} eq 'AndExpr') { } 11 34 45
elsif ($self->{'type'} eq 'AdditiveExpr') { } 27 7 34
elsif ($self->{'type'} eq 'UnaryExpr') { } 6 1 7
59
60 # a LocationPath should just be a list of Steps, so eval them in order
61
62 154 my $ret;
63
64 154 ▶ if ($self->{absolute}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'absolute'}) { } 92 62 154
65 92 $ret = $self->{root};
66 }else{
67 62 $ret = $context->get_nodeset;
68 62 ▶ return $ret if $ret->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $ret->is_error 0 62 62
69 }
70
71
72 154 for my $step(@{$self->{tokens}}){
73
74 279 ▶ unless ($step->match('Step')){
Branch: 1 branch
BranchTrueFalseTotal
unless ($step->match("Step")) 0 279 279
75 0 return $self->ret('Error', "Found a non-Step token ('$step->{type}') in a LocationPath");
76 }
77
78 279 $ret = $step->eval($ret);
79
80 279 ▶ return $ret if $ret->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $ret->is_error 0 279 279
81
82 279 $ret->normalize();
83 }
84
85 154 return $ret;
86
87 }elsif ($self->{type} eq 'Step'){
88
89 # for a step, loop through it's children
90
91 # my $axis = defined($self->{axis}) ? $self->{axis} : 'child';
92 # my $ret = $self->filter_axis($axis, $context);
93
94 279 my $ret = XML::Parser::Lite::Tree::XPath::Axis::instance->filter($self, $context);
95
96 279 for my $step(@{$self->{tokens}}){
97
98 310 ▶ unless ($step->match('AxisSpecifier') || $step->match('NameTest') || $step->match('Predicate') || $step->match('NodeTypeTest')){
Branch: 1 branch
BranchTrueFalseTotal
unless ($step->match("AxisSpecifier") or $step->match("NameTest") or $step->match("Predicate") or $step->match("NodeTypeTest")) 0 310 310
Condition77%7/9
$step->match("AxisSpecifier") or $step->match("NameTest") or $step->match("Predicate") or $step->match("NodeTypeTest")
l!l&&r!l&&!r
252580
$step->match("AxisSpecifier") or $step->match("NameTest") or $step->match("Predicate")
l!l&&r!l&&!r
2213158
$step->match("AxisSpecifier") or $step->match("NameTest")
l!l&&r!l&&!r
022189
MC/DC0%0/4
$step->match("AxisSpecifier") or $step->match("NameTest") or $step->match("Predicate") or $step->match("NodeTypeTest")
$step->match("AxisSpecifier") $step->match("NameTest") $step->match("Predicate") $step->match("NodeTypeTest")
Truth table60%3/5
A or B or C or D
A= $step->match("AxisSpecifier")B= $step->match("NameTest")C= $step->match("Predicate")D= $step->match("NodeTypeTest")
ABCDresult
1XXX1
01XX1
001X1
00011
00000
99
100 0 return $self->ret('Error', "Found an unexpected token ('$step->{type}') in a Step");
101 }
102
103 310 $ret = $step->eval($ret);
104
105 310 ▶ return $ret if $ret->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $ret->is_error 0 310 310
106 }
107
108 279 return $ret;
109
110
111 }elsif ($self->{type} eq 'NameTest'){
112
113 221 ▶ return $context if $self->{content} eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"content"} eq "*" 87 134 221
114
115 134 ▶ if ($self->{content} =~ m!\:\*$!){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"} =~ /\:\*$/) 0 134 134
116 0 return $self->ret('Error', "Can't do NCName:* NameTests");
117 }
118
119 134 ▶ if ($context->{type} eq 'nodeset'){
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{"type"} eq "nodeset") 134 0 134
120 134 my $out = $self->ret('nodeset', []);
121
122 134 for my $tag(@{$context->{value}}){
123
124 608 ▶ if (($tag->{'type'} eq 'element') && ($tag->{'name'} eq $self->{content})){
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->{"type"} eq "element" and $tag->{"name"} eq $self->{"content"}) 188 420 608
Condition100%3/3
$tag->{"type"} eq "element" and $tag->{"name"} eq $self->{"content"}
!ll&&!rl&&r
24396188
MC/DC100%2/2
$tag->{"type"} eq "element" and $tag->{"name"} eq $self->{"content"}
$tag->{"type"} eq "element" $tag->{"name"} eq $self->{"content"}
Truth table100%3/3
A and B
A= $tag->{"type"} eq "element"B= $tag->{"name"} eq $self->{"content"}
ABresult
0X0
100
111
125 188 push @{$out->{value}}, $tag;
126 }
127
128 608 ▶ if (($tag->{'type'} eq 'attribute') && ($tag->{'name'} eq $self->{content})){
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->{"type"} eq "attribute" and $tag->{"name"} eq $self->{"content"}) 12 596 608
Condition100%3/3
$tag->{"type"} eq "attribute" and $tag->{"name"} eq $self->{"content"}
!ll&&!rl&&r
5841212
MC/DC100%2/2
$tag->{"type"} eq "attribute" and $tag->{"name"} eq $self->{"content"}
$tag->{"type"} eq "attribute" $tag->{"name"} eq $self->{"content"}
Truth table100%3/3
A and B
A= $tag->{"type"} eq "attribute"B= $tag->{"name"} eq $self->{"content"}
ABresult
0X0
100
111
129 12 push @{$out->{value}}, $tag;
130 }
131 }
132
133 134 return $out;
134 }
135
136 0 return $self->ret('Error', "filter by name $self->{content} on context $context->{type}");
137
138
139 }elsif ($self->{type} eq 'NodeTypeTest'){
140
141 58 ▶ if ($self->{content} eq 'node'){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"} eq "node") 58 0 58
142 58 ▶ if ($context->{type} eq 'nodeset'){
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{'type'} eq 'nodeset') { } 58 0 58
143 58 return $context;
144 }else{
145 0 return $self->ret('Error', "can't filter node() on a non-nodeset value.");
146 }
147 }
148
149 0 return $self->ret('Error', "NodeTypeTest with an unknown filter ($self->{content})");
150
151
152 }elsif ($self->{type} eq 'Predicate'){
153
154 31 my $expr = $self->{tokens}->[0];
155
156 31 my $out = $self->ret('nodeset', []);
157 31 my $i = 1;
158 31 my $c = scalar @{$context->{value}};
159
160 31 for my $child(@{$context->{value}}){
161
162 171 $child->{proximity_position} = $i;
163 171 $child->{context_size} = $c;
164 171 $i++;
165
166 171 my $ret = $expr->eval($self->ret('node', $child));
167
168 171 ▶ if ($ret->{type} eq 'boolean'){
Branch: 4 branches
BranchTrueFalseTotal
if ($ret->{'type'} eq 'boolean') { } 133 38 171
elsif ($ret->{'type'} eq 'number') { } 26 12 38
elsif ($ret->{'type'} eq 'nodeset') { } 12 0 12
elsif ($ret->{'type'} eq 'Error') { } 0 0 0
169
170 133 ▶ if ($ret->{value}){
Branch: 1 branch
BranchTrueFalseTotal
if ($ret->{"value"}) 45 88 133
171 45 push @{$out->{value}}, $child;
172 }
173
174 }elsif ($ret->{type} eq 'number'){
175
176 26 ▶ if ($ret->{value} == $child->{proximity_position}){
Branch: 1 branch
BranchTrueFalseTotal
if ($ret->{"value"} == $child->{"proximity_position"}) 8 18 26
177 8 push @{$out->{value}}, $child;
178 }
179
180 }elsif ($ret->{type} eq 'nodeset'){
181
182 12 ▶ if (scalar @{$ret->{value}}){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$ret->{"value"};}) 6 6 12
183 6 push @{$out->{value}}, $child;
184 }
185
186 }elsif ($ret->{type} eq 'Error'){
187
188 0 return $ret;
189
190 }else{
191 0 return $self->ret('Error', "unexpected predicate result type ($ret->{type})");
192 }
193
194 171 delete $child->{proximity_position};
195 171 delete $child->{context_size};
196 }
197
198 31 return $out;
199
200 }elsif ($self->{type} eq 'Number'){
201
202 173 return $self->ret('number', $self->{content});
203
204 }elsif ($self->{type} eq 'FunctionCall'){
205
206 280 my $handler = $self->get_function_handler($self->{content});
207
208 280 ▶ if ((!defined $handler) || (!defined $handler->[0])){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $handler and defined $handler->[0]) 0 280 280
Condition33%1/3
defined $handler and defined $handler->[0]
!ll&&!rl&&r
00280
MC/DC0%0/2
defined $handler and defined $handler->[0]
defined $handler defined $handler->[0]
Truth table33%1/3
A and B
A= defined $handlerB= defined $handler->[0]
ABresult
0X0
100
111
209 0 return $self->ret('Error', "No handler for function call '$self->{content}'");
210 }
211
212
213 #
214 # evaluate each of the supplied args first
215 #
216
217 280 my @in_args;
218 280 for my $source (@{$self->{tokens}}){
219 196 my $out = $source->eval($context);
220 196 ▶ return $out if $out->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $out->is_error 0 196 196
221 196 push @in_args, $out;
222 }
223
224
225 #
226 # now check them against the function signature
227 #
228
229 280 my $func = $handler->[0];
230 280 my $sig = $handler->[1];
231 280 my @sig = split /,/, $sig;
232 280 my @out_args;
233
234 280 my $position = 0;
235
236 280 for my $sig(@sig){
237
238 261 my $repeat = 0;
239 261 my $optional = 0;
240
241 261 ▶ if ($sig =~ m/\+$/){ $repeat = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($sig =~ /\+$/) 5 256 261
242 261 ▶ if ($sig =~ m/\?$/){ $optional = 1; }
Branch: 1 branch
BranchTrueFalseTotal
if ($sig =~ /\?$/) 107 154 261
243 261 $sig =~ s/[?+]$//;
244
245 #
246 # repeating args are somewhat tricky
247 #
248
249 261 ▶ if ($repeat){
Branch: 1 branch
BranchTrueFalseTotal
if ($repeat) { } 5 256 261
250
251 5 my $count = 0;
252
253 5 while (1){
254 10 $count++;
255
256 10 ▶ unless (defined $in_args[$position]){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in_args[$position]) 5 5 10
257 5 ▶ if ($count == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 1) 1 4 5
258 1 return $self->ret('Error', "Argument $position to function $self->{content} is required (type $sig)");
259 }
260 4 last;
261 }
262
263 5 my $value = $self->coerce($in_args[$position], $sig);
264 5 $position++;
265 5 ▶ if (defined $value){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 5 0 5
266 5 ▶ return $value if $value->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $value->is_error 0 5 5
267 5 push @out_args, $value;
268
269 }else{
270 0 ▶ if ($count == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 1) 0 0 0
271 0 return $self->ret('Error', "Can't coerce argument $position to a $sig in function $self->{content}");
272 }
273 0 last;
274 }
275 }
276
277 }else{
278
279 256 ▶ unless (defined $in_args[$position]){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $in_args[$position]) 65 191 256
280 65 ▶ if ($optional){
Branch: 1 branch
BranchTrueFalseTotal
if ($optional) { } 65 0 65
281 65 next;
282 }else{
283 0 return $self->ret('Error', "Argument $position to function $self->{content} is required (type $sig)");
284 }
285 }
286
287 191 my $value = $self->coerce($in_args[$position], $sig);
288 191 $position++;
289
290 191 ▶ if (defined $value){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 191 0 191
291
292 191 ▶ return $value if $value->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $value->is_error 0 191 191
293 191 push @out_args, $value;
294 }else{
295 0 return $self->ret('Error', "Can't coerce argument $position to a $sig in function $self->{content}");
296 }
297 }
298 }
299
300 279 return &{$func}($self, \@out_args);
301
302 }elsif ($self->{type} eq 'FunctionArg'){
303
304 # a FunctionArg should have a single child
305
306 196 ▶ return $self->ret('Error', 'FunctionArg should have 1 token') unless 1 == scalar @{$self->{tokens}};
Branch: 1 branch
BranchTrueFalseTotal
unless 1 == scalar @{$self->{"tokens"};} 0 196 196
307
308 196 return $self->{tokens}->[0]->eval($context);
309
310 ▶ }elsif (($self->{type} eq 'EqualityExpr') || ($self->{type} eq 'RelationalExpr')){
Condition100%3/3
$self->{"type"} eq "EqualityExpr" or $self->{"type"} eq "RelationalExpr"
l!l&&r!l&&!r
10614183
MC/DC100%2/2
$self->{"type"} eq "EqualityExpr" or $self->{"type"} eq "RelationalExpr"
$self->{"type"} eq "EqualityExpr" $self->{"type"} eq "RelationalExpr"
Truth table100%3/3
A or B
A= $self->{"type"} eq "EqualityExpr"B= $self->{"type"} eq "RelationalExpr"
ABresult
1X1
011
000
311
312 120 my $v1 = $self->{tokens}->[0]->eval($context);
313 120 my $v2 = $self->{tokens}->[1]->eval($context);
314 120 my $t = "$v1->{type}/$v2->{type}";
315
316 120 ▶ return $v1 if $v1->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $v1->is_error 0 120 120
317 120 ▶ return $v2 if $v2->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $v2->is_error 0 120 120
318
319 120 ▶ if ($v1->{type} gt $v2->{type}){
Branch: 1 branch
BranchTrueFalseTotal
if ($v1->{"type"} gt $v2->{"type"}) 0 120 120
320 0 $t = "$v2->{type}/$v1->{type}";
321 0 ($v1, $v2) = ($v2, $v1);
322 }
323
324 120 ▶ if ($t eq 'nodeset/string'){
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "nodeset/string") 6 114 120
325
326 6 for my $node(@{$v1->{value}}){;
327
328 5 my $v1_s = $self->ret('node', $node)->get_string;
329 5 ▶ return $v1_s if $v1_s->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $v1_s->is_error 0 5 5
330
331 5 my $ok = $self->compare_op($self->{content}, $v1_s, $v2);
332 5 ▶ return $ok if $ok->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $ok->is_error 0 5 5
333
334 5 ▶ return $ok if $ok->{value};
Branch: 1 branch
BranchTrueFalseTotal
if $ok->{"value"} 2 3 5
335 }
336
337 4 return $self->ret('boolean', 0);
338 }
339
340 114 ▶ if ($t eq 'string/string'){
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "string/string") 22 92 114
341
342 22 return $self->compare_op($self->{content}, $v1, $v2);
343 }
344
345 92 ▶ if ($t eq 'number/number'){
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "number/number") 92 0 92
346
347 92 return $self->compare_op($self->{content}, $v1, $v2);
348 }
349
350 0 return $self->ret('Error', "can't do an EqualityExpr on $t");
351
352 }elsif ($self->{type} eq 'Literal'){
353
354 93 return $self->ret('string', $self->{content});
355
356
357 }elsif ($self->{type} eq 'UnionExpr'){
358
359 9 my $a1 = $self->get_child_arg(0, 'nodeset');
360 9 my $a2 = $self->get_child_arg(1, 'nodeset');
361
362 9 ▶ return $a1 if $a1->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $a1->is_error 0 9 9
363 9 ▶ return $a2 if $a2->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $a2->is_error 0 9 9
364
365 9 my $out = $self->ret('nodeset', []);
366
367 9 map{ push @{$out->{value}}, $_ } @{$a1->{value}};
368 9 map{ push @{$out->{value}}, $_ } @{$a2->{value}};
369
370 9 $out->normalize();
371
372 9 return $out;
373
374 }elsif ($self->{type} eq 'MultiplicativeExpr'){
375
376 36 my $a1 = $self->get_child_arg(0, 'number');
377 36 my $a2 = $self->get_child_arg(1, 'number');
378
379 36 ▶ return $a1 if $a1->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $a1->is_error 0 36 36
380 36 ▶ return $a2 if $a2->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $a2->is_error 0 36 36
381
382 36 my $result = 0;
383 36 ▶ $result = $a1->{value} * $a2->{value} if $self->{content} eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"content"} eq "*" 1 35 36
384 36 ▶ $result = $self->op_mod($a1->{value}, $a2->{value}) if $self->{content} eq 'mod';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"content"} eq "mod" 12 24 36
385 36 ▶ $result = $self->op_div($a1->{value}, $a2->{value}) if $self->{content} eq 'div';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"content"} eq "div" 23 13 36
386
387 36 return $self->ret('number', $result);
388
389 ▶ }elsif (($self->{type} eq 'OrExpr') || ($self->{type} eq 'AndExpr')){
Condition66%2/3
$self->{"type"} eq "OrExpr" or $self->{"type"} eq "AndExpr"
l!l&&r!l&&!r
11034
MC/DC50%1/2
$self->{"type"} eq "OrExpr" or $self->{"type"} eq "AndExpr"
$self->{"type"} eq "OrExpr" $self->{"type"} eq "AndExpr"
Truth table66%2/3
A or B
A= $self->{"type"} eq "OrExpr"B= $self->{"type"} eq "AndExpr"
ABresult
1X1
011
000
390
391 11 my $a1 = $self->get_child_arg(0, 'boolean');
392 11 my $a2 = $self->get_child_arg(1, 'boolean');
393
394 11 ▶ return $a1 if $a1->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $a1->is_error 0 11 11
395 11 ▶ return $a2 if $a2->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $a2->is_error 0 11 11
396
397 11 ▶ return $self->ret('boolean', $a1->{value} || $a2->{value}) if $self->{type} eq 'OrExpr';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"type"} eq "OrExpr" 11 0 11
Condition100%3/3
$a1->{'value'} || $a2->{'value'}
l!l&&r!l&&!r
218
MC/DC100%2/2
$a1->{'value'} || $a2->{'value'}
$a1->{'value'} $a2->{'value'}
Truth table100%3/3
A || B
A= $a1->{'value'}B= $a2->{'value'}
ABresult
1X1
011
000
398 0 ▶ return $self->ret('boolean', $a1->{value} && $a2->{value}) if $self->{type} eq 'AndExpr';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"type"} eq "AndExpr" 0 0 0
Condition0%0/3
$a1->{'value'} && $a2->{'value'}
!ll&&!rl&&r
000
MC/DC0%0/2
$a1->{'value'} && $a2->{'value'}
$a1->{'value'} $a2->{'value'}
Truth table0%0/3
A && B
A= $a1->{'value'}B= $a2->{'value'}
ABresult
0X0
100
111
399
400 }elsif ($self->{type} eq 'AdditiveExpr'){
401
402 27 my $a1 = $self->get_child_arg(0, 'number');
403 27 my $a2 = $self->get_child_arg(1, 'number');
404
405 27 ▶ return $a1 if $a1->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $a1->is_error 0 27 27
406 27 ▶ return $a2 if $a2->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $a2->is_error 0 27 27
407
408 27 my $result = 0;
409 27 ▶ $result = $a1->{value} + $a2->{value} if $self->{content} eq '+';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"content"} eq "+" 26 1 27
410 27 ▶ $result = $a1->{value} - $a2->{value} if $self->{content} eq '-';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"content"} eq "-" 1 26 27
411
412 27 return $self->ret('number', $result);
413
414 }elsif ($self->{type} eq 'UnaryExpr'){
415
416 6 my $a1 = $self->get_child_arg(0, 'number');
417
418 6 ▶ return $a1 if $a1->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $a1->is_error 0 6 6
419
420 6 $a1->{value} = - $a1->{value};
421
422 6 return $a1;
423
424 }else{
425 1 return $self->ret('Error', "Don't know how to eval a '$self->{type}' node.");
426 }
427 }
428
429 196 ▶sub coerce {
Subroutine coerce: called CC=6 SCAR=17.9
Pod undocumented
430 196 my ($self, $arg, $type) = @_;
431
432 196 my $value = undef;
433
434 196 ▶ $value = $arg->get_string if $type eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "string" 110 86 196
435 196 ▶ $value = $arg->get_number if $type eq 'number';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "number" 22 174 196
436 196 ▶ $value = $arg->get_nodeset if $type eq 'nodeset';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "nodeset" 47 149 196
437 196 ▶ $value = $arg->get_boolean if $type eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "boolean" 4 192 196
438 196 ▶ $value = $arg if $type eq 'any';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "any" 13 183 196
439
440 196 return $value;
441 }
442
443 172 ▶sub get_child_arg {
Subroutine get_child_arg: called CC=3 SCAR=11.2
Pod undocumented
444 172 my ($self, $pos, $type) = @_;
445
446 172 my $token = $self->{tokens}->[$pos];
447 172 ▶ return $self->ret('Error', "Required child token {1+$pos} for $self->{type} token wasn't found.") unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 172 172
448
449 172 my $out = $token->eval($self->{context});
450 172 ▶ return $out if $out->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $out->is_error 0 172 172
451
452 172 return $out->get_type($type);
453 }
454
455
456 280 ▶sub get_function_handler {
Subroutine get_function_handler: called CC=2 SCAR=7.6
Pod undocumented
457 280 my ($self, $function) = @_;
458
459 280 my $function_map = {
460
461 # nodeset functions
462 'last' => [\&function_last, '' ],
463 'position' => [\&function_position, '' ],
464 'count' => [\&function_count, 'nodeset' ],
465 'id' => [\&function_id, 'any' ],
466 'local-name' => [\&function_local_name, 'nodeset?' ],
467 'namespace-uri' => [\&function_namespace_uri, 'nodeset?' ],
468 'name' => [\&function_name, 'nodeset?' ],
469
470 # string functions
471 'string' => [\&function_string, 'any?' ],
472 'concat' => [\&function_concat, 'string,string+' ],
473 'starts-with' => [\&function_starts_with, 'string,string' ],
474 'contains' => [\&function_contains, 'string,string' ],
475 'substring-before' => [\&function_substring_befor, 'string,string' ],
476 'substring-after' => [\&function_substring_after, 'string,string' ],
477 'substring' => [undef, 'string,number,number?' ],
478 'string-length' => [\&function_string_length, 'string?' ],
479 'normalize-space' => [\&function_normalize_space, 'string?' ],
480 'translate' => [undef, 'string,string,string' ],
481
482 # boolean functions
483 'boolean' => [undef, 'any' ],
484 'not' => [\&function_not, 'boolean' ],
485 'true' => [undef, '' ],
486 'false' => [undef, '' ],
487 'lang' => [undef, 'string' ],
488
489 # number functions
490 'number' => [undef, 'any?' ],
491 'sum' => [undef, 'nodeset' ],
492 'floor' => [\&function_floor, 'number' ],
493 'ceiling' => [\&function_ceiling, 'number' ],
494 'round' => [undef, 'number' ],
495
496 };
497
498 280 ▶ return $function_map->{$function} if defined $function_map->{$function};
Branch: 1 branch
BranchTrueFalseTotal
if defined $function_map->{$function} 280 0 280
499
500 0 return undef;
501 }
502
503 29 ▶sub function_last {
Subroutine function_last: called CC=1 SCAR=0.0
Pod undocumented
504 29 my ($self, $args) = @_;
505
506 29 return $self->ret('number', $self->{context}->{value}->{context_size});
507 }
508
509 4 ▶sub function_not {
Subroutine function_not: called CC=1 SCAR=0.0
Pod undocumented
510 4 my ($self, $args) = @_;
511
512 4 my $out = $args->[0];
513 4 $out->{value} = !$out->{value};
514
515 4 return $out
516 }
517
518 3 ▶sub function_normalize_space {
Subroutine function_normalize_space: called CC=3 SCAR=12.3
Pod undocumented
519 3 my ($self, $args) = @_;
520
521 3 my $value = $args->[0];
522
523 3 ▶ unless (defined $value){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 3 3
524 0 $value = $self->{context}->get_string;
525 0 ▶ return $value if $value->get_error;
Branch: 1 branch
BranchTrueFalseTotal
if $value->get_error 0 0 0
526 }
527
528 3 $value = $value->{value};
529 3 $value =~ s!^[\x20\x09\x0d\x0a]+!!;
530 3 $value =~ s![\x20\x09\x0d\x0a]+$!!;
531 3 $value =~ s![\x20\x09\x0d\x0a]+! !g;
532
533 3 return $self->ret('string', $value);
534 }
535
536 38 ▶sub function_count {
Subroutine function_count: called CC=2 SCAR=7.4
Pod undocumented
537 38 my ($self, $args) = @_;
538
539 38 my $subject = $args->[0];
540
541 38 ▶ return $self->ret('number', scalar(@{$subject->{value}})) if $subject->{type} eq 'nodeset';
Branch: 1 branch
BranchTrueFalseTotal
if $subject->{"type"} eq "nodeset" 38 0 38
542
543 0 die("can't perform count() on $subject->{type}");
544 }
545
546 14 ▶sub function_starts_with {
Subroutine function_starts_with: called CC=1 SCAR=0.0
Pod undocumented
547 14 my ($self, $args) = @_;
548
549 14 my $s1 = $args->[0]->{value};
550 14 my $s2 = $args->[1]->{value};
551
552 14 return $self->ret('boolean', (substr($s1, 0, length $s2) eq $s2));
553 }
554
555 18 ▶sub function_contains {
Subroutine function_contains: called CC=1 SCAR=0.0
Pod undocumented
556 18 my ($self, $args) = @_;
557
558 18 my $s1 = $args->[0]->{value};
559 18 my $s2 = quotemeta $args->[1]->{value};
560
561 18 return $self->ret('boolean', ($s1 =~ /$s2/));
562 }
563
564 21 ▶sub function_string_length {
Subroutine function_string_length: called CC=3 SCAR=14.2
Pod undocumented
565 21 my ($self, $args) = @_;
566
567 21 my $value = $args->[0];
568
569 21 ▶ unless (defined $value){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 21 21
570 0 $value = $self->{context}->get_string;
571 0 ▶ return $value if $value->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $value->is_error 0 0 0
572 }
573
574 21 return $self->ret('number', length $value->{value});
575 }
576
577 33 ▶sub function_position {
Subroutine function_position: called CC=3 SCAR=11.2
Pod undocumented
578 33 my ($self, $args) = @_;
579
580 33 my $node = $self->{context}->get_nodeset;
581 33 ▶ return $node if $node->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $node->is_error 0 33 33
582
583 33 $node = $node->{value}->[0];
584 33 ▶ return $self->ret('Error', "No node in context nodeset o_O") unless defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 33 33
585
586 33 return $self->ret('number', $node->{proximity_position});
587 }
588
589 11 ▶sub function_floor {
Subroutine function_floor: called CC=2 SCAR=7.0
Pod undocumented
590 11 my ($self, $args) = @_;
591
592 11 my $val = $args->[0]->{value};
593 11 my $ret = $self->simple_floor($val);
594
595 11 ▶ $ret = - $self->simple_ceiling(-$val) if $val < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $val < 0 0 11 11
596
597 11 return $self->ret('number', $ret);
598 }
599
600 11 ▶sub function_ceiling {
Subroutine function_ceiling: called CC=2 SCAR=7.0
Pod undocumented
601 11 my ($self, $args) = @_;
602
603 11 my $val = $args->[0]->{value};
604 11 my $ret = $self->simple_ceiling($val);
605
606 11 ▶ $ret = - $self->simple_floor(-$val) if $val < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $val < 0 0 11 11
607
608 11 return $self->ret('number', $ret);
609 }
610
611 4 ▶sub function_id {
Subroutine function_id: called CC=9 SCAR=23.3
Pod undocumented
612 4 my ($self, $args) = @_;
613
614 4 ▶ unless ($self->{context}->{type} eq 'node' || $self->{context}->{type} eq 'nodeset'){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"context"}{"type"} eq "node" or $self->{"context"}{"type"} eq "nodeset") 0 4 4
Condition33%1/3
$self->{"context"}{"type"} eq "node" or $self->{"context"}{"type"} eq "nodeset"
l!l&&r!l&&!r
040
MC/DC0%0/2
$self->{"context"}{"type"} eq "node" or $self->{"context"}{"type"} eq "nodeset"
$self->{"context"}{"type"} eq "node" $self->{"context"}{"type"} eq "nodeset"
Truth table33%1/3
A or B
A= $self->{"context"}{"type"} eq "node"B= $self->{"context"}{"type"} eq "nodeset"
ABresult
1X1
011
000
615
616 0 return $self->ret('Error', "Can only call id() in a node or nodeset context - not $self->{context}->{type}");
617 }
618
619 4 my $obj = $args->[0];
620 4 my $ids = '';
621
622 4 ▶ if ($obj->{type} eq 'nodeset'){
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{'type'} eq 'nodeset') { } 2 2 4
623
624 2 for my $node(@{$obj->{value}}){
625
626 8 $ids .= ' ' . $self->get_string_value($node);
627 }
628 }else{
629 2 $ids = $obj->get_string->{value};
630 }
631
632 4 $ids =~ s!^\s*(.*?)\s*$!$1!;
633
634 4 ▶ $self->ret('nodeset', []) unless length $ids;
Branch: 1 branch
BranchTrueFalseTotal
unless length $ids 0 4 4
635
636 4 my @ids = split /[ \t\r\n]+/, $ids;
637
638
639 #
640 # we have a list of IDs to search for - now traverse the whole document,
641 # checking every element node
642 #
643
644 4 my $root = {};
645
646 4 ▶ if ($self->{context}->{type} eq 'nodeset'){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"context"}{"type"} eq "nodeset") 4 0 4
647 4 $root = $self->{context}->{value}->[0];
648 }
649 4 ▶ if ($self->{context}->{type} eq 'node'){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"context"}{"type"} eq "node") 0 4 4
650 0 $root = $self->{context}->{value};
651 }
652
653 4 ▶ $root = $root->{parent} while defined $root->{parent};
Branch: 1 branch
BranchTrueFalseTotal
defined $root->{"parent"} and do { $root = $root->{"parent"} } 0 4 4
654
655 4 my $out = $self->_recurse_find_id($root, \@ids);
656
657 4 return $self->ret('nodeset', $out);
658 }
659
660 32 ▶sub _recurse_find_id {
Subroutine _recurse_find_id: called CC=9 SCAR=22.0
661 32 my ($self, $node, $ids) = @_;
662
663 32 my $out = [];
664
665 #
666 # is it a match?
667 #
668
669 32 ▶ if ($node->{type} eq 'element' && length $node->{uid}){
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"type"} eq "element" and length $node->{"uid"}) 12 20 32
Condition100%3/3
$node->{"type"} eq "element" and length $node->{"uid"}
!ll&&!rl&&r
12812
MC/DC100%2/2
$node->{"type"} eq "element" and length $node->{"uid"}
$node->{"type"} eq "element" length $node->{"uid"}
Truth table100%3/3
A and B
A= $node->{"type"} eq "element"B= length $node->{"uid"}
ABresult
0X0
100
111
670
671 12 for my $id (@{$ids}){
672 22 ▶ if ($id eq $node->{uid}){
Branch: 1 branch
BranchTrueFalseTotal
if ($id eq $node->{"uid"}) 6 16 22
673 6 push @{$out}, $node;
674 6 last;
675 }
676 }
677 }
678
679
680 #
681 # do we need to recurse?
682 #
683
684 32 ▶ if ($node->{type} eq 'element' || $node->{type} eq 'root'){
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"type"} eq "element" or $node->{"type"} eq "root") 24 8 32
Condition100%3/3
$node->{"type"} eq "element" or $node->{"type"} eq "root"
l!l&&r!l&&!r
2048
MC/DC100%2/2
$node->{"type"} eq "element" or $node->{"type"} eq "root"
$node->{"type"} eq "element" $node->{"type"} eq "root"
Truth table100%3/3
A or B
A= $node->{"type"} eq "element"B= $node->{"type"} eq "root"
ABresult
1X1
011
000
685
686 24 for my $child (@{$node->{children}}){
687
688 28 my $more = $self->_recurse_find_id($child, $ids);
689
690 28 for my $match (@{$more}){
691
692 12 push @{$out}, $match;
693 }
694 }
695 }
696
697 32 return $out;
698 }
699
700 9 ▶sub function_local_name {
Subroutine function_local_name: called CC=4 SCAR=14.0
Pod undocumented
701 9 my ($self, $args) = @_;
702
703 9 my $node = $self->_get_first_node_by_doc_order($args);
704
705 9 ▶ return $node if $node->{type} eq 'Error';
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"type"} eq "Error" 0 9 9
706 9 ▶ return $self->ret('string', '') unless defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 9 9
707
708 9 my $name = $self->get_expanded_name($node);
709
710 9 ▶ return return $self->ret('string', $name->{local}) if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 8 1 9
711 1 return $self->ret('string', '');
712 }
713
714 7 ▶sub function_namespace_uri {
Subroutine function_namespace_uri: called CC=4 SCAR=15.0
Pod undocumented
715 7 my ($self, $args) = @_;
716
717 7 my $node = $self->_get_first_node_by_doc_order($args);
718
719 7 ▶ return $node if $node->{type} eq 'Error';
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"type"} eq "Error" 0 7 7
720 7 ▶ return $self->ret('string', '') unless defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 7 7
721
722 7 my $name = $self->get_expanded_name($node);
723
724 7 ▶ return return $self->ret('string', $name->{ns}) if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 7 0 7
725 0 return $self->ret('string', '');
726 }
727
728 57 ▶sub function_name {
Subroutine function_name: called CC=4 SCAR=14.0
Pod undocumented
729 57 my ($self, $args) = @_;
730
731 57 my $node = $self->_get_first_node_by_doc_order($args);
732
733 57 ▶ return $node if $node->{type} eq 'Error';
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"type"} eq "Error" 0 57 57
734 57 ▶ return $self->ret('string', '') unless defined $node;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $node 0 57 57
735
736 57 my $name = $self->get_expanded_name($node);
737
738 57 ▶ return return $self->ret('string', $name->{qname}) if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 56 1 57
739 1 return $self->ret('string', '');
740 }
741
742 75 ▶sub _get_first_node_by_doc_order {
Subroutine _get_first_node_by_doc_order: called CC=8 SCAR=21.2
743 75 my ($self, $args) = @_;
744
745
746 #
747 # for no args, take the first node in the context nodeset
748 #
749
750 75 ▶ unless (defined $args->[0]){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->[0]) 64 11 75
751
752 64 ▶ return $self->{context}->{value} if $self->{context}->{type} eq 'node';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"context"}{"type"} eq "node" 62 2 64
753 2 ▶ return $self->{context}->{value}->[0] if $self->{context}->{type} eq 'nodeset';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"context"}{"type"} eq "nodeset" 2 0 2
754
755 0 return $self->ret('Error', "If argument is ommitted, context must be node or nodeset - not $self->{context}->{type}");
756 }
757
758
759 #
760 # we have a nodeset arg - return the node with the lowest doc order
761 #
762
763 11 ▶ return $args->[0]->{value} if $args->[0]->{type} eq 'node';
Branch: 1 branch
BranchTrueFalseTotal
if $args->[0]{"type"} eq "node" 0 11 11
764
765 11 ▶ if ($args->[0]->{type} eq 'nodeset'){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->[0]{"type"} eq "nodeset") 11 0 11
766
767 11 my $min = $self->{max_order} + 1;
768 11 my $low = undef;
769
770 11 for my $node (@{$args->[0]->{value}}){
771
772 15 ▶ if ($node->{order} < $min){
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"order"} < $min) 11 4 15
773
774 11 $min = $node->{order};
775 11 $low = $node;
776 }
777 }
778
779 11 return $low;
780 }
781
782 0 return $self->ret('Error', "Argument to fucntion isn't expected node/nodeset");
783 }
784
785 10 ▶sub function_string {
Subroutine function_string: called CC=12 SCAR=26.0
Pod undocumented
786 10 my ($self, $args) = @_;
787
788
789 #
790 # for no args, use the context node
791 #
792
793 10 ▶ unless (defined $args->[0]){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args->[0]) 1 9 10
794
795 1 ▶ return $self->ret('string', $self->get_string_value($self->{context}->{value})) if $self->{context}->{type} eq 'node';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"context"}{"type"} eq "node" 0 1 1
796 1 ▶ return $self->ret('string', $self->get_string_value($self->{context}->{value}->[0])) if $self->{context}->{type} eq 'nodeset';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"context"}{"type"} eq "nodeset" 1 0 1
797
798 0 return $self->ret('Error', "If argument to string() is ommitted, context must be node or nodeset - not $self->{context}->{type}");
799 }
800
801 9 ▶ if ($args->[0]->{type} eq 'number'){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->[0]{"type"} eq "number") 4 5 9
802
803 4 return $self->ret('string', $args->[0]->{value});
804 }
805
806 5 ▶ if ($args->[0]->{type} eq 'string'){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->[0]{"type"} eq "string") 1 4 5
807
808 1 return $self->ret('string', $args->[0]->{value});
809 }
810
811 4 ▶ if ($args->[0]->{type} eq 'node' || $args->[0]->{type} eq 'nodeset'){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->[0]{"type"} eq "node" or $args->[0]{"type"} eq "nodeset") 2 2 4
Condition66%2/3
$args->[0]{"type"} eq "node" or $args->[0]{"type"} eq "nodeset"
l!l&&r!l&&!r
022
MC/DC50%1/2
$args->[0]{"type"} eq "node" or $args->[0]{"type"} eq "nodeset"
$args->[0]{"type"} eq "node" $args->[0]{"type"} eq "nodeset"
Truth table66%2/3
A or B
A= $args->[0]{"type"} eq "node"B= $args->[0]{"type"} eq "nodeset"
ABresult
1X1
011
000
812
813 2 my $node = $self->_get_first_node_by_doc_order($args);
814 2 ▶ return $node if $node->{type} eq 'Error';
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"type"} eq "Error" 0 2 2
815
816 2 ▶ if ($node->{type} eq 'element'){
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{'type'} eq 'element') { } 2 0 2
817 2 return $self->ret('string', $self->get_string_value($node));
818 }else{
819 0 return $self->ret('string', '');
820 }
821 }
822
823 2 ▶ if ($args->[0]->{type} eq 'boolean'){
Branch: 1 branch
BranchTrueFalseTotal
if ($args->[0]{"type"} eq "boolean") 2 0 2
824
825 2 ▶ return $self->ret('string', $args->[0]->{value} ? 'true' : 'false');
Branch: 1 branch
BranchTrueFalseTotal
$args->[0]{'value'} ? : 1 1 2
826 }
827
828 0 return $self->ret('Error', "Don't know how to perform string() on a $args->[0]->{type}");
829 }
830
831 4 ▶sub function_concat {
Subroutine function_concat: called CC=2 SCAR=6.9
Pod undocumented
832 4 my ($self, $args) = @_;
833
834 4 my $out = '';
835 4 $out .= $_->{value} for @{$args};
836
837 4 return $self->ret('string', $out);
838 }
839
840 3 ▶sub function_substring_befor {
Subroutine function_substring_befor: called CC=2 SCAR=6.9
Pod undocumented
841 3 my ($self, $args) = @_;
842
843 3 my $idx = index $args->[0]->{value}, $args->[1]->{value};
844
845 3 ▶ if ($idx == -1){
Branch: 1 branch
BranchTrueFalseTotal
if ($idx == -1) 1 2 3
846 1 return $self->ret('string', '');
847 }
848
849 2 return $self->ret('string', substr $args->[0]->{value}, 0, $idx);
850 }
851
852 3 ▶sub function_substring_after {
Subroutine function_substring_after: called CC=2 SCAR=6.9
Pod undocumented
853 3 my ($self, $args) = @_;
854
855 3 my $idx = index $args->[0]->{value}, $args->[1]->{value};
856
857 3 ▶ if ($idx == -1){
Branch: 1 branch
BranchTrueFalseTotal
if ($idx == -1) 1 2 3
858 1 return $self->ret('string', '');
859 }
860
861 2 return $self->ret('string', substr $args->[0]->{value}, $idx + length $args->[1]->{value});
862 }
863
864 11 ▶sub simple_floor {
Subroutine simple_floor: called CC=1 SCAR=0.0
Pod undocumented
865 11 my ($self, $value) = @_;
866 11 return int $value;
867 }
868
869 11 ▶sub simple_ceiling {
Subroutine simple_ceiling: called CC=2 SCAR=6.9
Pod undocumented
870 11 my ($self, $value) = @_;
871 11 my $t = int $value;
872 11 ▶ return $t if $t == $value;
Branch: 1 branch
BranchTrueFalseTotal
if $t == $value 3 8 11
873 8 return $t+1;
874 }
875
876 119 ▶sub compare_op {
Subroutine compare_op: called CC=27 SCAR=49.4
Pod undocumented
877 119 my ($self, $op, $a1, $a2) = @_;
878
879 119 ▶ if ($a1->{type} eq 'string'){
Branch: 1 branch
BranchTrueFalseTotal
if ($a1->{"type"} eq "string") 27 92 119
880 27 ▶ if ($op eq '=' ){ return $self->ret('boolean', ($a1->{value} eq $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq "=") 27 0 27
$a1->{'value'} eq $a2->{'value'} ? : 13 14 27
881 0 ▶ if ($op eq '!='){ return $self->ret('boolean', ($a1->{value} ne $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq "!=") 0 0 0
$a1->{'value'} ne $a2->{'value'} ? : 0 0 0
882 0 ▶ if ($op eq '>='){ return $self->ret('boolean', ($a1->{value} ge $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq ">=") 0 0 0
$a1->{'value'} ge $a2->{'value'} ? : 0 0 0
883 0 ▶ if ($op eq '<='){ return $self->ret('boolean', ($a1->{value} le $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq "<=") 0 0 0
$a1->{'value'} le $a2->{'value'} ? : 0 0 0
884 0 ▶ if ($op eq '>' ){ return $self->ret('boolean', ($a1->{value} gt $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq ">") 0 0 0
$a1->{'value'} gt $a2->{'value'} ? : 0 0 0
885 0 ▶ if ($op eq '<' ){ return $self->ret('boolean', ($a1->{value} lt $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq "<") 0 0 0
$a1->{'value'} lt $a2->{'value'} ? : 0 0 0
886 }
887
888 92 ▶ if ($a1->{type} eq 'number'){
Branch: 1 branch
BranchTrueFalseTotal
if ($a1->{"type"} eq "number") 92 0 92
889 92 ▶ if ($op eq '=' ){ return $self->ret('boolean', ($a1->{value} == $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq "=") 77 15 92
$a1->{'value'} == $a2->{'value'} ? : 18 59 77
890 15 ▶ if ($op eq '!='){ return $self->ret('boolean', ($a1->{value} != $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq "!=") 1 14 15
$a1->{'value'} != $a2->{'value'} ? : 0 1 1
891 0 ▶ if ($op eq '>='){ return $self->ret('boolean', ($a1->{value} >= $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq ">=") 0 14 14
$a1->{'value'} >= $a2->{'value'} ? : 0 0 0
892 0 ▶ if ($op eq '<='){ return $self->ret('boolean', ($a1->{value} <= $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq "<=") 0 14 14
$a1->{'value'} <= $a2->{'value'} ? : 0 0 0
893 14 ▶ if ($op eq '>' ){ return $self->ret('boolean', ($a1->{value} > $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq ">") 7 7 14
$a1->{'value'} > $a2->{'value'} ? : 3 4 7
894 7 ▶ if ($op eq '<' ){ return $self->ret('boolean', ($a1->{value} < $a2->{value}) ? 1 : 0); }
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq "<") 7 0 7
$a1->{'value'} < $a2->{'value'} ? : 2 5 7
895 }
896
897 0 return $self->ret('Error', "Don't know how to compare $op on type $a1->{type}");
898 }
899
900 12 ▶sub op_mod {
Subroutine op_mod: called CC=1 SCAR=0.0
Pod undocumented
901 12 my ($self, $n1, $n2) = @_;
902
903 12 my $r = int ($n1 / $n2);
904 12 return $n1 - ($r * $n2);
905 }
906
907 23 ▶sub op_div {
Subroutine op_div: called CC=1 SCAR=0.0
Pod undocumented
908 23 my ($self, $n1, $n2) = @_;
909
910 23 return $n1 / $n2;
911 }
912
913 32 ▶sub get_string_value {
Subroutine get_string_value: called CC=9 SCAR=22.5
Pod undocumented
914 32 my ($self, $node) = @_;
915
916
917 32 ▶ if ($node->{type} eq 'element' || $node->{type} eq 'root'){
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"type"} eq "element" or $node->{"type"} eq "root") 20 12 32
Condition100%3/3
$node->{"type"} eq "element" or $node->{"type"} eq "root"
l!l&&r!l&&!r
19112
MC/DC100%2/2
$node->{"type"} eq "element" or $node->{"type"} eq "root"
$node->{"type"} eq "element" $node->{"type"} eq "root"
Truth table100%3/3
A or B
A= $node->{"type"} eq "element"B= $node->{"type"} eq "root"
ABresult
1X1
011
000
918
919 #
920 # The string-value of an element node is the concatenation of the string-values
921 # of all text node descendants of the element node in document order.
922 #
923
924 20 my $value = '';
925 20 for my $child (@{$node->{children}}){
926 21 ▶ if ($child->{type} eq 'element'){
Branch: 1 branch
BranchTrueFalseTotal
if ($child->{"type"} eq "element") 11 10 21
927 11 $value .= $self->get_string_value($child);
928 }
929 21 ▶ if ($child->{type} eq 'text'){
Branch: 1 branch
BranchTrueFalseTotal
if ($child->{"type"} eq "text") 10 11 21
930 10 $value .= $self->get_string_value($child);
931 }
932 }
933 20 return $value;
934 }
935
936 12 ▶ if ($node->{type} eq 'attribute'){
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"type"} eq "attribute") 0 12 12
937
938 #
939 # An attribute node has a string-value. The string-value is the normalized value
940 # as specified by the XML Recommendation [XML]. An attribute whose normalized value
941 # is a zero-length string is not treated specially: it results in an attribute node
942 # whose string-value is a zero-length string.
943 #
944 }
945
946 12 ▶ if ($node->{type} eq 'namespace'){
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"type"} eq "namespace") 0 12 12
947
948 #
949 # The string-value of a namespace node is the namespace URI that is being bound to
950 # the namespace prefix; if it is relative, it must be resolved just like a namespace
951 # URI in an expanded-name.
952 #
953 }
954
955 #
956 # The string-value of a processing instruction node is the part of the processing
957 # instruction following the target and any whitespace. It does not include the
958 # terminating ?>.
959 #
960
961 #
962 # The string-value of comment is the content of the comment not including the
963 # opening <!-- or the closing -->.
964 #
965
966 12 ▶ if ($node->{type} eq 'text'){
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"type"} eq "text") 12 0 12
967
968 #
969 # The string-value of a text node is the character data. A text node always has
970 # at least one character of data.
971 #
972
973 12 return $node->{content};
974 }
975
976 0 print "# we can't find a string-value for this node!\n";
977 0 print Dumper $node;
978
979 0 return '';
980 }
981
982 73 ▶sub get_expanded_name {
Subroutine get_expanded_name: called CC=4 SCAR=15.5
Pod undocumented
983 73 my ($self, $node) = @_;
984
985 73 ▶ if ($node->{type} eq 'element'){
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"type"} eq "element") 71 2 73
986
987 return {
988 'ns' => $node->{ns},
989 'qname' => $node->{name},
990 'local' => defined $node->{local_name} ? $node->{local_name} : $node->{name},
991 71 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
defined $node->{'local_name'} ? : 71 0 71
992 }
993
994 2 ▶ if ($node->{type} eq 'root'){
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"type"} eq "root") 2 0 2
995
996 2 return undef;
997 }
998
999 0 print "# we can't find an expanded name for this node!\n";
1000 0 print Dumper $node;
1001
1002 0 return undef;
1003 }
1004
1005 32 1;
↑ Summary XPath/Test.pm »