blib/lib/XML/LibXML/XPathContext.pm

filter: Statementstmt 97.6% 82 / 84 Branchbran 85.0% 17 / 20 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 94.7% 18 / 19 Podpod 100% 9 / 9 totaltotal 93.1% 136 / 146 CC 14 SCAR 13.4
CC
14
Cov
94%
_perl_dispatcher
9.1
_guarded_find_call
4.0
find
2.1
CRAP 3.8
« 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 69 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 69 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 69 ▶use vars qw($VERSION @ISA $USE_LIBXML_DATA_TYPES);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 69 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 69 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 69 ▶use XML::LibXML::NodeList;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 69 $VERSION = "2.0210"; # VERSION TEMPLATE: DO NOT CHANGE
21  
22 # should LibXML XPath data types be used for simple objects
23 # when passing parameters to extension functions (default: no)
24 69 $USE_LIBXML_DATA_TYPES = 0;
25  
26 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
27  
28 sub findnodes {
29 61 ▶ my ($self, $xpath, $node) = @_;
Subroutine findnodes: called CC=2 SCAR=6.9
Pod documented
30  
31 61 my @nodes = $self->_guarded_find_call('_findnodes', $node, $xpath);
32  
33 59 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 13 46 59
34 13 return @nodes;
35 }
36 else {
37 46 return XML::LibXML::NodeList->new(@nodes);
38 }
39 }
40  
41 sub find {
42 66 ▶ my ($self, $xpath, $node) = @_;
Subroutine find: called CC=2 SCAR=7.4
Pod documented
43  
44 66 my ($type, @params) = $self->_guarded_find_call('_find', $node, $xpath,0);
45  
46 56 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 56 0 56
47 56 return $type->new(@params);
48 }
49 0 return undef;
50 }
51  
52 sub exists {
53 3 ▶ my ($self, $xpath, $node) = @_;
Subroutine exists: called CC=1 SCAR=0.0
Pod documented
54 3 my (undef, $value) = $self->_guarded_find_call('_find', $node, $xpath,1);
55 3 return $value;
56 }
57  
58 sub findvalue {
59 44 ▶ my $self = shift;
Subroutine findvalue: called CC=1 SCAR=0.0
Pod documented
60 44 return $self->find(@_)->to_literal->value;
61 }
62  
63 sub _guarded_find_call {
64 130 ▶ my ($self, $method, $node)=(shift,shift,shift);
Subroutine _guarded_find_call: called CC=4 SCAR=13.9
65  
66 130 my $prev_node;
67 130 ▶ if (ref($node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $node) 17 113 130
68 17 $prev_node = $self->getContextNode();
69 17 $self->setContextNode($node);
70 }
71 130 my @ret;
72 130 eval {
73 130 @ret = $self->$method(@_);
74 };
75 130 $self->_free_node_pool;
76 130 ▶ $self->setContextNode($prev_node) if ref($node);
Branch: 1 branch
BranchTrueFalseTotal
if ref $node 17 113 130
77  
78 130 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 12 118 130
79 12 my $err = $@;
80 12 chomp $err;
81 12 croak $err;
82 }
83  
84 118 return @ret;
85 }
86  
87 sub registerFunction {
88 12 ▶ my ($self, $name, $sub) = @_;
Subroutine registerFunction: called CC=1 SCAR=0.0
Pod documented
89 12 $self->registerFunctionNS($name, undef, $sub);
90 12 return;
91 }
92  
93 sub unregisterNs {
94 3 ▶ my ($self, $prefix) = @_;
Subroutine unregisterNs: called CC=1 SCAR=0.0
Pod documented
95 3 $self->registerNs($prefix, undef);
96 3 return;
97 }
98  
99 sub unregisterFunction {
100 4 ▶ my ($self, $name) = @_;
Subroutine unregisterFunction: called CC=1 SCAR=0.0
Pod documented
101 4 $self->registerFunctionNS($name, undef, undef);
102 4 return;
103 }
104  
105 sub unregisterFunctionNS {
106 1 ▶ my ($self, $name, $ns) = @_;
Subroutine unregisterFunctionNS: called CC=1 SCAR=0.0
Pod documented
107 1 $self->registerFunctionNS($name, $ns, undef);
108 1 return;
109 }
110  
111 sub unregisterVarLookupFunc {
112 1 ▶ my ($self) = @_;
Subroutine unregisterVarLookupFunc: called CC=1 SCAR=0.0
Pod documented
113 1 $self->registerVarLookupFunc(undef, undef);
114 1 return;
115 }
116  
117 # extension function perl dispatcher
118 # borrowed from XML::LibXSLT
119  
120 sub _perl_dispatcher {
121 32 ▶ my $func = shift;
Subroutine _perl_dispatcher: called CC=9 SCAR=22.1
122 32 my @params = @_;
123 32 my @perlParams;
124  
125 32 my $i = 0;
126 32 ▶ while (@params) {
Branch: 1 branch
BranchTrueFalseTotal
if (@params) 23 32 55
127 23 my $type = shift(@params);
128 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
129 $type eq 'XML::LibXML::Number' or
130 $type eq 'XML::LibXML::Boolean')
131 {
132 12 my $val = shift(@params);
133 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
134 }
135 elsif ($type eq 'XML::LibXML::NodeList') {
136 11 my $node_count = shift(@params);
137 11 unshift(@perlParams, $type->new(splice(@params, 0, $node_count)));
138 }
139 }
140  
141 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
142 69 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
143 32 my $res = $func->(@perlParams);
144 31 return $res;
145 }
146  
147 69 1;
« blib/lib/XML/LibXML/Error.pm ↑ Summary blib/lib/XML/LibXML/AttributeHash.pm »