XPath/Eval.pm

filter: Statementstmt 90.0% 54 / 60 Branchbran 71.4% 10 / 14 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 5 totaltotal 82.4% 80 / 97 CC 13 SCAR 15.5
CC
13
Cov
86%
mark_uids
8.0
query
4.6
mark_orders
2.0
CRAP 4.7
« XPath/Axis.pm ↑ Summary XPath.pm »
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
BranchTrueFalseTotal
unless (defined $token) 0 130 130
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
BranchTrueFalseTotal
if ($out->is_error) 1 129 130
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
BranchTrueFalseTotal
if ($out->{"type"} ne "nodeset") 0 0 0
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
BranchTrueFalseTotal
if ($tag->{"type"} eq "element") 985 200 1185
82  
83 985 $tag->{uid} = '';
84  
85 985 my $id = $tag->{attributes}->{id};
86  
87 985 ▶ if (defined $id && length $id){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and length $id) 710 275 985
Condition66%2/3
defined $id and length $id
!ll&&!rl&&r
2750710
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
ABresult
0X0
100
111
88 710 ▶ unless (defined $self->{uids}->{$id}){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"uids"}{$id}) 710 0 710
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
BranchTrueFalseTotal
if ($tag->{"type"} eq "root" or $tag->{"type"} eq "element") 1115 70 1185
Condition100%3/3
$tag->{"type"} eq "root" or $tag->{"type"} eq "element"
l!l&&r!l&&!r
13098570
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"
ABresult
1X1
011
000
102  
103 1115 for my $child (@{$tag->{children}}){
104  
105 1055 $self->mark_uids($child);
106 }
107 }
108 }
109  
110 29 1;
« XPath/Axis.pm ↑ Summary XPath.pm »