blib/lib/XML/LibXML/XPathContext.pm

filter: Statementstmt 97.5% 79 / 81 Branchbran 85.0% 17 / 20 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 94.4% 17 / 18 Podpod 100% 9 / 9 totaltotal 92.9% 132 / 142 CC 14 SCAR 13.6
CC
14
Cov
94%
_perl_dispatcher
9.1
_guarded_find_call
4.0
find
2.1
CRAP 3.9
« blib/lib/XML/LibXML/Error.pm ↑ Summary blib/lib/XML/LibXML/AttributeHash.pm »
1 # $Id: XPathContext.pm 422 2002-11-08 17:10:30Z phish $
2 #
3 # This is free software, you may use it and distribute it under the same terms as
4 # Perl itself.
5 #
6 # Copyright 2001-2003 AxKit.com Ltd., 2002-2006 Christian Glahn, 2006-2009 Petr Pajas
7 #
8 #
9  
10 package XML::LibXML::XPathContext;
11  
12 77 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 77 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 77 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 77 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 77 ▶use XML::LibXML::NodeList;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 77 our $VERSION = "2.0213"; # VERSION TEMPLATE: DO NOT CHANGE
20  
21 # should LibXML XPath data types be used for simple objects
22 # when passing parameters to extension functions (default: no)
23 77 our $USE_LIBXML_DATA_TYPES = 0;
24  
25 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
26  
27 61 ▶sub findnodes {
Subroutine findnodes: called CC=2 SCAR=6.9
Pod documented
28 61 my ($self, $xpath, $node) = @_;
29  
30 61 my @nodes = $self->_guarded_find_call('_findnodes', $node, $xpath);
31  
32 59 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 13 46 59
33 13 return @nodes;
34 }
35 else {
36 46 return XML::LibXML::NodeList->new(@nodes);
37 }
38 }
39  
40 66 ▶sub find {
Subroutine find: called CC=2 SCAR=7.4
Pod documented
41 66 my ($self, $xpath, $node) = @_;
42  
43 66 my ($type, @params) = $self->_guarded_find_call('_find', $node, $xpath,0);
44  
45 56 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 56 0 56
46 56 return $type->new(@params);
47 }
48 0 return undef;
49 }
50  
51 3 ▶sub exists {
Subroutine exists: called CC=1 SCAR=0.0
Pod documented
52 3 my ($self, $xpath, $node) = @_;
53 3 my (undef, $value) = $self->_guarded_find_call('_find', $node, $xpath,1);
54 3 return $value;
55 }
56  
57 44 ▶sub findvalue {
Subroutine findvalue: called CC=1 SCAR=0.0
Pod documented
58 44 my $self = shift;
59 44 return $self->find(@_)->to_literal->value;
60 }
61  
62 130 ▶sub _guarded_find_call {
Subroutine _guarded_find_call: called CC=4 SCAR=13.9
63 130 my ($self, $method, $node)=(shift,shift,shift);
64  
65 130 my $prev_node;
66 130 ▶ if (ref($node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node) 17 113 130
67 17 $prev_node = $self->getContextNode();
68 17 $self->setContextNode($node);
69 }
70 130 my @ret;
71 130 eval {
72 130 @ret = $self->$method(@_);
73 };
74 130 $self->_free_node_pool;
75 130 ▶ $self->setContextNode($prev_node) if ref($node);
Branch: 1 branch
BranchTrueFalseTotal
if ref $node 17 113 130
76  
77 130 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 12 118 130
78 12 my $err = $@;
79 12 chomp $err;
80 12 croak $err;
81 }
82  
83 118 return @ret;
84 }
85  
86 12 ▶sub registerFunction {
Subroutine registerFunction: called CC=1 SCAR=0.0
Pod documented
87 12 my ($self, $name, $sub) = @_;
88 12 $self->registerFunctionNS($name, undef, $sub);
89 12 return;
90 }
91  
92 3 ▶sub unregisterNs {
Subroutine unregisterNs: called CC=1 SCAR=0.0
Pod documented
93 3 my ($self, $prefix) = @_;
94 3 $self->registerNs($prefix, undef);
95 3 return;
96 }
97  
98 4 ▶sub unregisterFunction {
Subroutine unregisterFunction: called CC=1 SCAR=0.0
Pod documented
99 4 my ($self, $name) = @_;
100 4 $self->registerFunctionNS($name, undef, undef);
101 4 return;
102 }
103  
104 1 ▶sub unregisterFunctionNS {
Subroutine unregisterFunctionNS: called CC=1 SCAR=0.0
Pod documented
105 1 my ($self, $name, $ns) = @_;
106 1 $self->registerFunctionNS($name, $ns, undef);
107 1 return;
108 }
109  
110 1 ▶sub unregisterVarLookupFunc {
Subroutine unregisterVarLookupFunc: called CC=1 SCAR=0.0
Pod documented
111 1 my ($self) = @_;
112 1 $self->registerVarLookupFunc(undef, undef);
113 1 return;
114 }
115  
116 # extension function perl dispatcher
117 # borrowed from XML::LibXSLT
118  
119 32 ▶sub _perl_dispatcher {
Subroutine _perl_dispatcher: called CC=9 SCAR=22.1
120 32 my $func = shift;
121 32 my @params = @_;
122 32 my @perlParams;
123  
124 32 my $i = 0;
125 32 ▶ while (@params) {
Branch: 1 branch
BranchTrueFalseTotal
if (@params) 23 32 55
126 23 my $type = shift(@params);
127 23 ▶ if ($type eq 'XML::LibXML::Literal' or
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'XML::LibXML::Literal' or $type eq 'XML::LibXML::Number' or $type eq 'XML::LibXML::Boolean') { } 12 11 23
elsif ($type eq 'XML::LibXML::NodeList') { } 11 0 11
Condition83%5/6
$type eq "XML::LibXML::Literal" or $type eq "XML::LibXML::Number" or $type eq "XML::LibXML::Boolean"
l!l&&r!l&&!r
12011
$type eq "XML::LibXML::Literal" or $type eq "XML::LibXML::Number"
l!l&&r!l&&!r
8411
MC/DC66%2/3
$type eq "XML::LibXML::Literal" or $type eq "XML::LibXML::Number" or $type eq "XML::LibXML::Boolean"
$type eq "XML::LibXML::Literal" $type eq "XML::LibXML::Number" $type eq "XML::LibXML::Boolean"
Truth table75%3/4
A or B or C
A= $type eq "XML::LibXML::Literal"B= $type eq "XML::LibXML::Number"C= $type eq "XML::LibXML::Boolean"
ABCresult
1XX1
01X1
0011
0000
128 $type eq 'XML::LibXML::Number' or
129 $type eq 'XML::LibXML::Boolean')
130 {
131 12 my $val = shift(@params);
132 12 ▶ unshift(@perlParams, $USE_LIBXML_DATA_TYPES ? $type->new($val) : $val);
Branch: 1 branch
BranchTrueFalseTotal
$XML::LibXML::XPathContext::USE_LIBXML_DATA_TYPES ? : 0 12 12
133 }
134 elsif ($type eq 'XML::LibXML::NodeList') {
135 11 my $node_count = shift(@params);
136 11 unshift(@perlParams, $type->new(splice(@params, 0, $node_count)));
137 }
138 }
139  
140 32 ▶ $func = "main::$func" unless ref($func) || $func =~ /(.+)::/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $func or $func =~ /(.+)::/ 1 31 32
Condition66%2/3
ref $func or $func =~ /(.+)::/
l!l&&r!l&&!r
3101
MC/DC50%1/2
ref $func or $func =~ /(.+)::/
ref $func $func =~ /(.+)::/
Truth table66%2/3
A or B
A= ref $funcB= $func =~ /(.+)::/
ABresult
1X1
011
000
141 77 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
142 32 my $res = $func->(@perlParams);
143 31 return $res;
144 }
145  
146 77 1;
« blib/lib/XML/LibXML/Error.pm ↑ Summary blib/lib/XML/LibXML/AttributeHash.pm »