| 1 | # Internal use only | ||||||||||||||||||||||||||||
| 2 | package XML::TinyXML::Selector::XPath::Functions; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use POSIX qw(:sys_types_h); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | our $VERSION = "0.34"; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # NODE FUNCTIONS | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub last { | ||||||||||||||||||||||||||
|
Subroutine
last: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 2 | my ($class, $context) = @_; | |||||||||||||||||||||||||||
| 14 | 2 | ▶ | return scalar(@{$context->items}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | if ($context); | ||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | sub position { | ||||||||||||||||||||||||||
|
Subroutine
position: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 3 | my ($class, $context) = @_; | |||||||||||||||||||||||||||
| 20 | 3 | my $cnt = 0; | |||||||||||||||||||||||||||
| 21 | 3 | return map { ++$cnt => $_ } @{$context->items}; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub count { | ||||||||||||||||||||||||||
|
Subroutine
count: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 0 | my ($class, $context, $items) = @_; | |||||||||||||||||||||||||||
| 26 | 0 | return scalar(@{$items}); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub id { | ||||||||||||||||||||||||||
|
Subroutine
id: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 0 | my ($class, $context, $id, $cnode) = @_; | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | foreach my $child ($cnode?$cnode->children:$context->{xml}->rootNodes) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | my @selection; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($child->attributes->{id} and $child->attributes->{id} eq $id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$child->attributes->{"id"} and $child->attributes->{"id"} eq $id
MC/DC0%0/2
$child->attributes->{"id"} and $child->attributes->{"id"} eq $id
$child->attributes->{"id"}
$child->attributes->{"id"} eq $id
Truth table0%0/3
A and B
A= $child->attributes->{"id"}B= $child->attributes->{"id"} eq $id
| |||||||||||||||||||||||||||||
| 34 | 0 | return $child; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 0 | return id($class, $context, $child); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub local_name { | ||||||||||||||||||||||||||
|
Subroutine
local_name: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | 0 | my ($class, $context, $items) = @_; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | return map { $_->name } $items?@$items:@{$context->items}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | # XXX - out of spe | ||||||||||||||||||||||||||||
| 47 | 0 | return local_name(@_); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # STRING FUNCTIONS | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub string { | ||||||||||||||||||||||||||
|
Subroutine
string: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 0 | my ($class, $context, $items) = @_; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | return map { $_->value } $items?@$items:@{$context->items}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub concat { | ||||||||||||||||||||||||||
|
Subroutine
concat: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 0 | my ($class, $context, $str1, $str2) = @_; | |||||||||||||||||||||||||||
| 59 | 0 | return $str1.$str2; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | sub starts_with { | ||||||||||||||||||||||||||
|
Subroutine
starts_with: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 2 | my ($class, $context, $str1, $str2) = @_; | |||||||||||||||||||||||||||
| 64 | 2 | ▶ | return ($str1 =~ /^$str2/)?1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | ▶ | sub contains { | ||||||||||||||||||||||||||
|
Subroutine
contains: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 2 | my ($class, $context, $str1, $str2) = @_; | |||||||||||||||||||||||||||
| 69 | 2 | ▶ | return ($str1 =~ /$str2/)?1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | ▶ | sub substring_before { | ||||||||||||||||||||||||||
|
Subroutine
substring_before: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 73 | 1 | my ($class, $context, $str1, $str2) = @_; | |||||||||||||||||||||||||||
| 74 | 1 | my ($match) = $str1 =~ /(.*?)$str2/; | |||||||||||||||||||||||||||
| 75 | 1 | return $match; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | ▶ | sub substring_after { | ||||||||||||||||||||||||||
|
Subroutine
substring_after: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 2 | my ($class, $context, $str1, $str2) = @_; | |||||||||||||||||||||||||||
| 80 | 2 | my ($match) = $str1 =~ /$str2(.*)/; | |||||||||||||||||||||||||||
| 81 | 2 | return $match; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 10 | ▶ | sub substring { | ||||||||||||||||||||||||||
|
Subroutine
substring: called CC=15 SCAR=27.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 10 | my ($class, $context, $str, $offset, $length) = @_; | |||||||||||||||||||||||||||
| 86 | # handle edge cases as defined in XPath spec | ||||||||||||||||||||||||||||
| 87 | # [ http://www.w3.org/TR/xpath ] | ||||||||||||||||||||||||||||
| 88 | 10 | ▶ | if ($length and $length =~ /(\S+)\s+(\S+)\s+(\S+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$length and $length =~ /(\S+)\s+(\S+)\s+(\S+)/
MC/DC100%2/2
$length and $length =~ /(\S+)\s+(\S+)\s+(\S+)/
$length
$length =~ /(\S+)\s+(\S+)\s+(\S+)/
Truth table100%3/3
A and B
A= $lengthB= $length =~ /(\S+)\s+(\S+)\s+(\S+)/
| |||||||||||||||||||||||||||||
| 89 | 3 | $length = $context->operators->{$2}->($1, $3); | |||||||||||||||||||||||||||
| 90 | 3 | ▶ | return "" if(!defined($length) and $offset !~ /^-[0-9]+$/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $length or $offset =~ /^-[0-9]+$/
MC/DC50%1/2
defined $length or $offset =~ /^-[0-9]+$/
defined $length
$offset =~ /^-[0-9]+$/
Truth table66%2/3
A or B
A= defined $lengthB= $offset =~ /^-[0-9]+$/
| |||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||
| 92 | 7 | ▶ | $length = round($class, $context, $length) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$length and $length =~ /\./
MC/DC100%2/2
$length and $length =~ /\./
$length
$length =~ /\./
Truth table100%3/3
A and B
A= $lengthB= $length =~ /\./
| |||||||||||||||||||||||||||||
| 93 | if ($length and $length =~ /\./); | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 8 | ▶ | if ($offset and $offset =~ /(\S+)\s+(\S+)\s+(\S+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$offset and $offset =~ /(\S+)\s+(\S+)\s+(\S+)/
MC/DC100%2/2
$offset and $offset =~ /(\S+)\s+(\S+)\s+(\S+)/
$offset
$offset =~ /(\S+)\s+(\S+)\s+(\S+)/
Truth table100%3/3
A and B
A= $offsetB= $offset =~ /(\S+)\s+(\S+)\s+(\S+)/
| |||||||||||||||||||||||||||||
| 96 | 3 | $offset = $context->operators->{$2}->($1, $3); | |||||||||||||||||||||||||||
| 97 | 3 | ▶ | return "" unless(defined($offset)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } else { | ||||||||||||||||||||||||||||
| 99 | 5 | ▶ | $offset = round($class, $context, $offset) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | if ($offset =~ /\./); | ||||||||||||||||||||||||||||
| 101 | 5 | ▶ | $length-- if ($length and $offset == 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$length and $offset == 0
MC/DC100%2/2
$length and $offset == 0
$length
$offset == 0
Truth table100%3/3
A and B
A= $lengthB= $offset == 0
| |||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 7 | ▶ | $offset-- if ($offset > 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 7 | ▶ | return defined($length) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | ? substr($str, $offset, $length) | ||||||||||||||||||||||||||||
| 106 | : substr($str, $offset); | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub string_length { | ||||||||||||||||||||||||||
|
Subroutine
string_length: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 110 | 0 | my ($class, $context, $str) = @_; | |||||||||||||||||||||||||||
| 111 | 0 | return length($str); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub normalize_space { | ||||||||||||||||||||||||||
|
Subroutine
normalize_space: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 0 | my ($class, $context, $str) = @_; | |||||||||||||||||||||||||||
| 116 | 0 | $str =~ s/(^\s+|\s+$)//g; | |||||||||||||||||||||||||||
| 117 | 0 | return $str; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 2 | ▶ | sub translate { | ||||||||||||||||||||||||||
|
Subroutine
translate: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 121 | 2 | my ($class, $context, $str, $tfrom, $tto) = @_; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 2 | my @from = split(//, $tfrom); | |||||||||||||||||||||||||||
| 124 | 2 | my @to = split(//, $tto); | |||||||||||||||||||||||||||
| 125 | 2 | foreach my $i (0..$#from) { | |||||||||||||||||||||||||||
| 126 | 7 | ▶ | if ($to[$i]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 6 | $str =~ s/$from[$i]/$to[$i]/g; | |||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||
| 129 | 1 | $str =~ s/$from[$i]//g; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | 2 | return $str; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # BOOLEAN FUNCTIONS | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub boolean { | ||||||||||||||||||||||||||
|
Subroutine
boolean: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 138 | 0 | my ($class, $context, $item) = @_; | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | return $item?1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub not { | ||||||||||||||||||||||||||
|
Subroutine
not: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 143 | 0 | my ($class, $context, $item) = @_; | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | return !$item?1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub true { | ||||||||||||||||||||||||||
|
Subroutine
true: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 148 | 0 | return 1; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub falce { | ||||||||||||||||||||||||||
|
Subroutine
falce: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 152 | 0 | return 0; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub lang { | ||||||||||||||||||||||||||
|
Subroutine
lang: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 156 | 0 | my ($class, $context, $lang) = @_; | |||||||||||||||||||||||||||
| 157 | # TODO - implement; | ||||||||||||||||||||||||||||
| 158 | 0 | warn __PACKAGE__."::lang() unimplemented"; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | # NUMBER FUNCTIONS | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub number { | ||||||||||||||||||||||||||
|
Subroutine
number: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 164 | 0 | my ($class, $context, $item) = @_; | |||||||||||||||||||||||||||
| 165 | 0 | return 0+$item; # force numeric context | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub sum { | ||||||||||||||||||||||||||
|
Subroutine
sum: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 0 | my ($class, $context, $items) = @_; | |||||||||||||||||||||||||||
| 170 | 0 | my $res = 0; | |||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ($items) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | $res += $_->value for (@$items); | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | 0 | return $res; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub floor { | ||||||||||||||||||||||||||
|
Subroutine
floor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 178 | 0 | my ($class, $context, $number) = @_; | |||||||||||||||||||||||||||
| 179 | 0 | return POSIX::floor($number); | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | sub ceil { | ||||||||||||||||||||||||||
|
Subroutine
ceil: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 183 | 0 | my ($class, $context, $number) = @_; | |||||||||||||||||||||||||||
| 184 | 0 | return POSIX::ceil($number); | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 2 | ▶ | sub round { | ||||||||||||||||||||||||||
|
Subroutine
round: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 188 | 2 | my ($class, $context, $number) = @_; | |||||||||||||||||||||||||||
| 189 | 2 | return int($number + .5 * ($number <=> 0)); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 4 | 1; | |||||||||||||||||||||||||||