| 1 | package XML::Parser::Lite::Tree::XPath::Eval; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 29 | ▶ | use XML::Parser::Lite::Tree::XPath::Token; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 29 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 29 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 130 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 8 | 130 | my ($class) = @_; | |||||||||||||||||||||||||||
| 9 | 130 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 10 | 130 | $self->{error} = 0; | |||||||||||||||||||||||||||
| 11 | 130 | return $self; | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 130 | ▶ | sub query { | ||||||||||||||||||||||||||
|
Subroutine
query: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 130 | my ($self, $xpath, $tree) = @_; | |||||||||||||||||||||||||||
| 16 | 130 | $self->{error} = 0; | |||||||||||||||||||||||||||
| 17 | 130 | $self->{tree} = $tree; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 130 | $self->{root} = XML::Parser::Lite::Tree::XPath::Result->new('nodeset', [$self->{tree}]); | |||||||||||||||||||||||||||
| 20 | 130 | $self->{max_order} = $self->mark_orders($self->{tree}, 1, undef); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 130 | $self->{uids} = {}; | |||||||||||||||||||||||||||
| 23 | 130 | $self->mark_uids($self->{tree}); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 130 | my $token = $xpath->{tokens}->[0]; | |||||||||||||||||||||||||||
| 26 | 130 | ▶ | unless (defined $token){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | $self->{error} = "couldn't get root token to eval."; | |||||||||||||||||||||||||||
| 28 | 0 | return 0; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 130 | $self->mark_token($token); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 130 | my $out = $token->eval($self->{root}); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 130 | ▶ | if ($out->is_error){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 1 | $self->{error} = $out->{value}; | |||||||||||||||||||||||||||
| 37 | 1 | return 0; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 129 | return $out; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ($out->{type} ne 'nodeset'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | $self->{error} = "Result was not a nodeset (was a $out->{type})"; | |||||||||||||||||||||||||||
| 44 | 0 | return 0; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | return $out->{value}; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1185 | ▶ | sub mark_orders { | ||||||||||||||||||||||||||
|
Subroutine
mark_orders: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 1185 | my ($self, $tag, $i, $parent) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1185 | $tag->{order} = $i++; | |||||||||||||||||||||||||||
| 54 | 1185 | $tag->{parent} = $parent; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1185 | for my $child(@{$tag->{children}}){ | |||||||||||||||||||||||||||
| 57 | 1055 | $i = $self->mark_orders($child, $i, $tag); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1185 | return $i; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 926 | ▶ | sub mark_token { | ||||||||||||||||||||||||||
|
Subroutine
mark_token: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 926 | my ($self, $token) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 926 | $token->{root} = $self->{root}; | |||||||||||||||||||||||||||
| 67 | 926 | $token->{max_order} = $self->{max_order}; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 926 | for my $child(@{$token->{tokens}}){ | |||||||||||||||||||||||||||
| 70 | 796 | $self->mark_token($child); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1185 | ▶ | sub mark_uids { | ||||||||||||||||||||||||||
|
Subroutine
mark_uids: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 1185 | my ($self, $tag) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # | ||||||||||||||||||||||||||||
| 78 | # mark | ||||||||||||||||||||||||||||
| 79 | # | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 1185 | ▶ | if ($tag->{type} eq 'element'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 985 | $tag->{uid} = ''; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 985 | my $id = $tag->{attributes}->{id}; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 985 | ▶ | if (defined $id && length $id){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $id and length $id
MC/DC50%1/2
defined $id and length $id
defined $id
length $id
Truth table66%2/3
A and B
A= defined $idB= length $id
| |||||||||||||||||||||||||||||
| 88 | 710 | ▶ | unless (defined $self->{uids}->{$id}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 710 | $tag->{uid} = $id; | |||||||||||||||||||||||||||
| 91 | 710 | $self->{uids}->{$id} = 1; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # | ||||||||||||||||||||||||||||
| 98 | # descend | ||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1185 | ▶ | if ($tag->{type} eq 'root' || $tag->{type} eq 'element'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tag->{"type"} eq "root" or $tag->{"type"} eq "element"
MC/DC100%2/2
$tag->{"type"} eq "root" or $tag->{"type"} eq "element"
$tag->{"type"} eq "root"
$tag->{"type"} eq "element"
Truth table100%3/3
A or B
A= $tag->{"type"} eq "root"B= $tag->{"type"} eq "element"
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 1115 | for my $child (@{$tag->{children}}){ | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1055 | $self->mark_uids($child); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 29 | 1; | |||||||||||||||||||||||||||