Compile/Iterator.pm

filter: Statementstmt 86.1% 56 / 65 Branchbran 58.3% 21 / 36 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 83.3% 20 / 24 Podpod 95.0% 19 / 20 totaltotal 79.1% 125 / 158 CC 22 SCAR 11.8
CC
22
Cov
76%
lastChild
6.0
previousChild
6.0
nodeLocal
6.0
CRAP 3.3
« Compile/Schema/BuiltInTypes.pm ↑ Summary
1 # Copyrights 2006-2024 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of distribution XML-Compile. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package XML::Compile::Iterator;{
10 50 our $VERSION = '1.64';
11 }
12  
13  
14 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 50 ▶use XML::Compile::Util qw/pack_type type_of_node SCHEMA2001i/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 50 ▶use Log::Report 'xml-compile', syntax => 'SHORT';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 sub new($@)
22 6299 ▶{ my ($class, $node, $path, $filter) = splice @_, 0, 4;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
23 6299 (bless {}, $class)
24 ->init( { node => $node, filter => $filter, path => $path, @_} );
25 }
26  
27 sub init($)
28 6299 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=14.5
Pod undocumented
29 $self->{node} = delete $args->{node}
30 6299 ▶ or panic "no node specified";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"node"} = delete $args->{"node"} or &panic("no node specified") 6299 0 6299
31  
32 $self->{filter} = delete $args->{filter}
33 6299 ▶ or panic "no filter specified";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"filter"} = delete $args->{"filter"} or &panic("no filter specified") 6299 0 6299
34  
35 $self->{path} = delete $args->{path}
36 6299 ▶ or panic "no path specified";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"path"} = delete $args->{"path"} or &panic("no path specified") 6299 0 6299
37  
38 6299 $self->{current} = 0;
39 6299 $self;
40 }
41  
42  
43 sub descend(;$$$)
44 5123 ▶{ my ($self, $node, $p, $filter) = @_;
Subroutine descend: called CC=5 SCAR=16.2
Pod documented
45 5123 ▶ $node ||= $self->currentChild;
Condition100%3/3
$node ||= $self->currentChild
l!l&&r!l&&!r
377013521
MC/DC100%2/2
$node ||= $self->currentChild
$node $self->currentChild
Truth table100%3/3
A ||= B
A= $nodeB= $self->currentChild
ABresult
1X1
011
000
46 5123 ▶ defined $node or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $node or return undef 5122 1 5123
47  
48 5122 my $path = $self->path;
49 5122 ▶ $path .= '/'.$p if defined $p;
Branch: 1 branch
BranchTrueFalseTotal
if defined $p 1118 4004 5122
50  
51 (ref $self)->new
52 5122 ▶ ($node, $path, ($filter || $self->{filter}));
Condition33%1/3
$filter || $self->{'filter'}
l!l&&r!l&&!r
051220
MC/DC0%0/2
$filter || $self->{'filter'}
$filter $self->{'filter'}
Truth table33%1/3
A || B
A= $filterB= $self->{'filter'}
ABresult
1X1
011
000
53 }
54  
55 #----------------
56  
57 14855 ▶sub node() {shift->{node}}
Subroutine node: called CC=1 SCAR=0.0
Pod documented
58 4510 ▶sub filter() {shift->{filter}}
Subroutine filter: called CC=1 SCAR=0.0
Pod documented
59 11091 ▶sub path() {shift->{path}}
Subroutine path: called CC=1 SCAR=0.0
Pod documented
60  
61 #----------------
62  
63 sub childs()
64 12735 ▶{ my $self = shift;
Subroutine childs: called CC=3 SCAR=11.0
Pod documented
65 12735 my $ln = $self->{childs};
66 12735 ▶ unless(defined $ln)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ln) 4510 8225 12735
67 4510 { my $filter = $self->filter;
68 $ln = $self->{childs}
69 4510 = [ grep {$filter->($_)} $self->node->childNodes ];
70 }
71 12735 ▶ wantarray ? @$ln : $ln;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 649 12086 12735
72 }
73  
74  
75 5865 ▶sub currentChild() { $_[0]->childs->[$_[0]->{current}] }
Subroutine currentChild: called CC=1 SCAR=0.0
Pod documented
76  
77  
78 1982 ▶sub firstChild() {shift->childs->[0]}
Subroutine firstChild: called CC=1 SCAR=0.0
Pod documented
79  
80  
81 sub lastChild()
82 0 ▶{ my $list = shift->childs;
Subroutine lastChild: not called CC=2 SCAR=17.9
Pod documented
83 0 ▶ @$list ? $list->[-1] : undef; # avoid error on empty list
Branch: 1 branch
BranchTrueFalseTotal
@$list ? : 0 0 0
84 }
85  
86  
87 sub nextChild()
88 1516 ▶{ my $self = shift;
Subroutine nextChild: called CC=2 SCAR=7.1
Pod documented
89 1516 my $list = $self->childs;
90 1516 ▶ $self->{current} < @$list ? $list->[ ++$self->{current} ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'current'} < @$list ? : 1516 0 1516
91 }
92  
93  
94 sub previousChild()
95 0 ▶{ my $self = shift;
Subroutine previousChild: not called CC=2 SCAR=17.9
Pod documented
96 0 my $list = $self->childs;
97 0 ▶ $self->{current} > 0 ? $list->[ --$self->{current} ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'current'} > 0 ? : 0 0 0
98 }
99  
100  
101 sub nrChildren()
102 2723 ▶{ my $list = shift->childs;
Subroutine nrChildren: called CC=1 SCAR=0.0
Pod documented
103 2723 scalar @$list;
104 }
105  
106 #---------
107  
108 859 ▶sub nodeType() { type_of_node(shift->node) || '' }
Subroutine nodeType: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
&type_of_node(scalar((shift())->node)) or "" 859 0 859
109  
110  
111 sub nodeLocal()
112 0 ▶{ my $node = shift->node or return '';
Subroutine nodeLocal: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $node = (shift())->node or return "" 0 0 0
113 0 $node->localName;
114 }
115  
116  
117 sub nodeNil()
118 25 ▶{ my $node = shift->node or return 0;
Subroutine nodeNil: called CC=4 SCAR=13.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $node = (shift())->node or return 0 25 0 25
119 25 ▶ my $nil = $node->getAttributeNS(SCHEMA2001i, 'nil') || '';
Condition100%2/2
$node->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'nil') || ''
l!l
1510
MC/DC100%1/1
$node->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'nil') || ''
$node->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'nil')
Truth table100%2/2
A
A= $node->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'nil')
Aresult
11
00
120 25 ▶ $nil eq 'true' || $nil eq '1';
Branch: 1 branch
BranchTrueFalseTotal
$nil eq "true" or $nil eq 1 14 11 25
121 }
122  
123  
124 sub textContent()
125 574 ▶{ my $node = shift->node or return undef;
Subroutine textContent: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $node = (shift())->node or return undef 574 0 574
126 574 $node->textContent;
127 }
128  
129  
130 sub currentType()
131 530 ▶{ my $current = shift->currentChild or return '';
Subroutine currentType: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $current = (shift())->currentChild or return "" 482 48 530
132 482 type_of_node $current;
133 }
134  
135  
136 sub currentLocal()
137 1260 ▶{ my $current = shift->currentChild or return '';
Subroutine currentLocal: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $current = (shift())->currentChild or return "" 674 586 1260
138 674 $current->localName;
139 }
140  
141  
142 sub currentContent()
143 0 ▶{ my $current = shift->currentChild or return undef;
Subroutine currentContent: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $current = (shift())->currentChild or return undef 0 0 0
144 0 $current->textContent;
145 }
146  
147 50 1;
« Compile/Schema/BuiltInTypes.pm ↑ Summary