| 1 | package XML::XPath::Function; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | $VERSION = '1.26'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use XML::XPath::Number; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use XML::XPath::Literal; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use XML::XPath::Boolean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use XML::XPath::NodeSet; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use XML::XPath::Node::Attribute; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my ($pp, $name, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | bless { | |||||||||||||||||||||||||||||||||||||||||
| 16 | pp => $pp, | ||||||||||||||||||||||||||||||||||||||||||
| 17 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | params => $params | ||||||||||||||||||||||||||||||||||||||||||
| 19 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub as_string { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $string = $self->{name} . "("; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $second; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | foreach (@{$self->{params}}) { | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $string .= "," if $second++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $string .= $_->as_string; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $string .= ")"; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | sub as_xml { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_xml: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $string = "<Function name=\"$self->{name}\""; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $params = ""; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | foreach (@{$self->{params}}) { | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $params .= "<Param>" . $_->as_string . "</Param>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ($params) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $string .= ">\n$params</Function>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $string .= " />\n"; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($node->isa('XML::XPath::NodeSet')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $node = $node->get_node(1); | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my @params; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | foreach my $param (@{$self->{params}}) { | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $results = $param->evaluate($node); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | push @params, $results; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $self->_execute($self->{name}, $node, @params); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | sub _execute { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_execute: not called CC=1 SCAR=1.7
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my ($name, $node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $name =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $self->$name($node, @params); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # All functions should return one of: | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # XML::XPath::Number | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # XML::XPath::Literal (string) | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # XML::XPath::NodeSet | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # XML::XPath::Boolean | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | ### NODESET FUNCTIONS ### | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | sub last { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | die "last: function doesn't take parameters\n" if (@params); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return XML::XPath::Number->new($self->{pp}->get_context_size); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | sub position { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
position: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if (@params) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | die "position: function doesn't take parameters [ ", @params, " ]\n"; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # return pos relative to axis direction | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return XML::XPath::Number->new($self->{pp}->get_context_pos); | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | sub count { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
count: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | die "count: Parameter must be a NodeSet\n" unless $params[0]->isa('XML::XPath::NodeSet'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | return XML::XPath::Number->new($params[0]->size); | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | sub id { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | die "id: Function takes 1 parameter\n" unless @params == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $results = XML::XPath::NodeSet->new(); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ($params[0]->isa('XML::XPath::NodeSet')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | # result is the union of applying id() to the | ||||||||||||||||||||||||||||||||||||||||||
| 112 | # string value of each node in the nodeset. | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | foreach my $node ($params[0]->get_nodelist) { | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $string = $node->string_value; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $results->append($self->id($node, XML::XPath::Literal->new($string))); | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | else { # The actual id() function... | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $string = $self->string($node, $params[0]); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $_ = $string->value; # get perl scalar | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my @ids = split; # splits $_ | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | foreach my $id (@ids) { | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if (my $found = $node->getElementById($id)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $results->push($found); | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return $results; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | sub local_name { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
local_name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if (@params > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | die "name() function takes one or no parameters\n"; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | elsif (@params) { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $nodeset = shift(@params); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $node = $nodeset->get_node(1); | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return XML::XPath::Literal->new($node->getLocalName); | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | sub namespace_uri { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
namespace_uri: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if (@params > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | die "namespace_uri() function takes one or no parameters\n"; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | elsif (@params) { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $nodeset = shift(@params); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $node = $nodeset->get_node(1); | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | # Sets to xmlns:[name]="namespace" or xmlns="namespace" | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $namespace = $node->getNamespace->toString; | |||||||||||||||||||||||||||||||||||||||||
| 159 | # We only need data between the quotation marks | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $namespace =~ /\"(.*?)\"/; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | return XML::XPath::Literal->new($1); | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | sub name { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if (@params > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | die "name() function takes one or no parameters\n"; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | elsif (@params) { | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $nodeset = shift(@params); | |||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $node = $nodeset->get_node(1); | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | return XML::XPath::Literal->new($node->getName); | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | ### STRING FUNCTIONS ### | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | sub string { | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
string: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | die "string: Too many parameters\n" if @params > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if (@params) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return XML::XPath::Literal->new($params[0]->string_value); | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | # TODO - this MUST be wrong! - not sure now. -matt | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return XML::XPath::Literal->new($node->string_value); | |||||||||||||||||||||||||||||||||||||||||
| 191 | # default to nodeset with just $node in. | ||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | sub concat { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
concat: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | die "concat: Too few parameters\n" if @params < 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my $string = join('', map {$_->string_value} @params); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return XML::XPath::Literal->new($string); | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | sub starts_with { | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
starts_with: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | die "starts-with: incorrect number of params\n" unless @params == 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my ($string1, $string2) = ($params[0]->string_value, $params[1]->string_value); | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if (substr($string1, 0, length($string2)) eq $string2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | return XML::XPath::Boolean->True; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | return XML::XPath::Boolean->False; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | sub contains { | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | die "starts-with: incorrect number of params\n" unless @params == 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my $value = $params[1]->string_value; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if ($params[0]->string_value =~ /(.*?)\Q$value\E(.*)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | # Store the values of contains1, contains2 for use in the | ||||||||||||||||||||||||||||||||||||||||||
| 220 | # substring functions below | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->{contains1} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $self->{contains2} = $2; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | return XML::XPath::Boolean->True; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return XML::XPath::Boolean->False; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | sub substring_before { | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
substring_before: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | die "starts-with: incorrect number of params\n" unless @params == 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if ($self->contains($node, @params)->value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return XML::XPath::Literal->new($self->{contains1}); | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | return XML::XPath::Literal->new(''); | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | sub substring_after { | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
substring_after: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | die "starts-with: incorrect number of params\n" unless @params == 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | if ($self->contains($node, @params)->value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | return XML::XPath::Literal->new($self->{contains2}); | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return XML::XPath::Literal->new(''); | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | sub substring { | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
substring: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | die "substring: Wrong number of parameters\n" if (@params < 2 || @params > 3); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@params < 2 or @params > 3
MC/DC0%0/2
@params < 2 or @params > 3
@params < 2
@params > 3
Truth table0%0/3
A or B
A= @params < 2B= @params > 3
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my ($str, $offset, $len); | |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $str = $params[0]->string_value; | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $offset = $params[1]->value; | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if ($offset eq 'NaN') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | return XML::XPath::Literal->new(''); | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if (@params == 3) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $len = $params[2]->value; | |||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if (($len eq 'NaN') || (($offset =~ /Infinity/) && ($len eq 'Infinity'))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$len eq "NaN" or $offset =~ /Infinity/ and $len eq "Infinity"
$offset =~ /Infinity/ and $len eq "Infinity"
MC/DC0%0/3
$len eq "NaN" or $offset =~ /Infinity/ and $len eq "Infinity"
$len eq "NaN"
$offset =~ /Infinity/
$len eq "Infinity"
Truth table0%0/4
A or B and C
A= $len eq "NaN"B= $offset =~ /Infinity/C= $len eq "Infinity"
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | return XML::XPath::Literal->new(''); | |||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ($offset ne 'Infinity') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $offset--; # uses 1 based offsets | |||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $offset = POSIX::floor($offset + 0.5); # round. | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ($offset < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if ($len ne 'Infinity') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $len += $offset; | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $len = length($str); | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $offset = 0; | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | if ($len eq 'Infinity') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | return XML::XPath::Literal->new(''); | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | return XML::XPath::Literal->new(''); | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ($len eq 'Infinity') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $len = length($str); | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $len = POSIX::floor($len + 0.5); # round. | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | return XML::XPath::Literal->new(substr($str, $offset, $len)); | |||||||||||||||||||||||||||||||||||||||||
| 301 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $offset--; # uses 1 based offsets | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $offset = POSIX::floor($offset + 0.5); # round. | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ($offset < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $offset = 0; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | return XML::XPath::Literal->new(substr($str, $offset)); | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | sub string_length { | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
string_length: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | die "string-length: Wrong number of params\n" if @params > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if (@params) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | return XML::XPath::Number->new(length($params[0]->string_value)); | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | return XML::XPath::Number->new( | |||||||||||||||||||||||||||||||||||||||||
| 322 | length($node->string_value) | ||||||||||||||||||||||||||||||||||||||||||
| 323 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | sub normalize_space { | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_space: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | die "normalize-space: Wrong number of params\n" if @params > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my $str; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if (@params) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $str = $params[0]->string_value; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $str = $node->string_value; | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $str =~ s/^\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $str =~ s/\s*$//; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | $str =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | return XML::XPath::Literal->new($str); | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | sub translate { | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
translate: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ▶ | die "translate: Wrong number of params\n" if @params != 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | local $_ = $params[0]->string_value; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $find = $params[1]->string_value; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $repl = $params[2]->string_value; | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | eval "tr/\\Q$find\\E/\\Q$repl\\E/d, 1" or die $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return XML::XPath::Literal->new($_); | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | ### BOOLEAN FUNCTIONS ### | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | sub boolean { | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
boolean: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | die "boolean: Incorrect number of parameters\n" if @params != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return $params[0]->to_boolean; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | sub not { | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
not: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | $params[0] = $params[0]->to_boolean unless $params[0]->isa('XML::XPath::Boolean'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | $params[0]->value ? XML::XPath::Boolean->False : XML::XPath::Boolean->True; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | sub true { | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
true: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | die "true: function takes no parameters\n" if @params > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | XML::XPath::Boolean->True; | |||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | sub false { | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
false: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | die "true: function takes no parameters\n" if @params > 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | XML::XPath::Boolean->False; | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | sub lang { | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lang: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | die "lang: function takes 1 parameter\n" if @params != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my $lang = $node->findvalue('(ancestor-or-self::*[@xml:lang]/@xml:lang)[last()]'); | |||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $lclang = lc($params[0]->string_value); | |||||||||||||||||||||||||||||||||||||||||
| 391 | # warn("Looking for lang($lclang) in $lang\n"); | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | if (substr(lc($lang), 0, length($lclang)) eq $lclang) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | return XML::XPath::Boolean->True; | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | return XML::XPath::Boolean->False; | |||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | ### NUMBER FUNCTIONS ### | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | sub number { | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
number: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | die "number: Too many parameters\n" if @params > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | if (@params) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if ($params[0]->isa('XML::XPath::Node')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | return XML::XPath::Number->new( | |||||||||||||||||||||||||||||||||||||||||
| 409 | $params[0]->string_value | ||||||||||||||||||||||||||||||||||||||||||
| 410 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | return $params[0]->to_number; | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | return XML::XPath::Number->new( $node->string_value ); | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | sub sum { | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sum: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | die "sum: Parameter must be a NodeSet\n" unless $params[0]->isa('XML::XPath::NodeSet'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | my $sum = 0; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | foreach my $node ($params[0]->get_nodelist) { | |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $sum += $self->number($node)->value; | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | return XML::XPath::Number->new($sum); | |||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | sub floor { | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
floor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my $num = $self->number($node, @params); | |||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | return XML::XPath::Number->new( | |||||||||||||||||||||||||||||||||||||||||
| 435 | POSIX::floor($num->value)); | ||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | sub ceiling { | ||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ceiling: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my $num = $self->number($node, @params); | |||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | return XML::XPath::Number->new( | |||||||||||||||||||||||||||||||||||||||||
| 444 | POSIX::ceil($num->value)); | ||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | sub round { | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
round: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | my ($node, @params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | my $num = $self->number($node, @params); | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | return XML::XPath::Number->new( | |||||||||||||||||||||||||||||||||||||||||
| 453 | POSIX::floor($num->value + 0.5)); # Yes, I know the spec says don't do this... | ||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||