lib/XML/Compile/Iterator.pm

filter: Statementstmt 86.5% 58 / 67 Branchbran 58.3% 21 / 36 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 84.0% 21 / 25 Podpod 95.0% 19 / 20 totaltotal 79.5% 128 / 161 CC 22 SCAR 11.7
CC
22
Cov
77%
lastChild
6.0
previousChild
6.0
nodeLocal
6.0
CRAP 3.2
« lib/XML/Compile/Schema/BuiltInTypes.pm ↑ Summary
1 # Copyrights 2006-2018 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.02.
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 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 50 $VERSION = '1.60';
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 5975 ▶{ my ($class, $node, $path, $filter) = splice @_, 0, 4;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
23 5975 (bless {}, $class)
24 ->init( { node => $node, filter => $filter, path => $path, @_} );
25 }
26  
27 sub init($)
28 5975 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=14.5
Pod undocumented
29 $self->{node} = delete $args->{node}
30 5975 ▶ or panic "no node specified";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"node"} = delete $args->{"node"} or &panic("no node specified") 0 5975 5975
31  
32 $self->{filter} = delete $args->{filter}
33 5975 ▶ or panic "no filter specified";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"filter"} = delete $args->{"filter"} or &panic("no filter specified") 0 5975 5975
34  
35 $self->{path} = delete $args->{path}
36 5975 ▶ or panic "no path specified";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"path"} = delete $args->{"path"} or &panic("no path specified") 0 5975 5975
37  
38 5975 $self->{current} = 0;
39 5975 $self;
40 }
41  
42  
43 sub descend(;$$$)
44 4864 ▶{ my ($self, $node, $p, $filter) = @_;
Subroutine descend: called CC=5 SCAR=16.2
Pod documented
45 4864 ▶ $node ||= $self->currentChild;
Condition100%3/3
$node ||= $self->currentChild
l!l&&r!l&&!r
355013131
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 4864 ▶ defined $node or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $node or return undef 1 4863 4864
47  
48 4863 my $path = $self->path;
49 4863 ▶ $path .= '/'.$p if defined $p;
Branch: 1 branch
BranchTrueFalseTotal
if defined $p 1092 3771 4863
50  
51 (ref $self)->new
52 4863 ▶ ($node, $path, ($filter || $self->{filter}));
Condition33%1/3
$filter || $self->{'filter'}
l!l&&r!l&&!r
048630
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 14139 ▶sub node() {shift->{node}}
Subroutine node: called CC=1 SCAR=0.0
Pod documented
58 4241 ▶sub filter() {shift->{filter}}
Subroutine filter: called CC=1 SCAR=0.0
Pod documented
59 10573 ▶sub path() {shift->{path}}
Subroutine path: called CC=1 SCAR=0.0
Pod documented
60  
61 #----------------
62  
63 sub childs()
64 11629 ▶{ my $self = shift;
Subroutine childs: called CC=3 SCAR=11.0
Pod documented
65 11629 my $ln = $self->{childs};
66 11629 ▶ unless(defined $ln)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ln) 4241 7388 11629
67 4241 { my $filter = $self->filter;
68 $ln = $self->{childs}
69 4241 = [ grep {$filter->($_)} $self->node->childNodes ];
70 }
71 11629 ▶ wantarray ? @$ln : $ln;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 618 11011 11629
72 }
73  
74  
75 5655 ▶sub currentChild() { $_[0]->childs->[$_[0]->{current}] }
Subroutine currentChild: called CC=1 SCAR=0.0
Pod documented
76  
77  
78 1362 ▶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 1458 ▶{ my $self = shift;
Subroutine nextChild: called CC=2 SCAR=7.1
Pod documented
89 1458 my $list = $self->childs;
90 1458 ▶ $self->{current} < @$list ? $list->[ ++$self->{current} ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'current'} < @$list ? : 1458 0 1458
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 2536 ▶{ my $list = shift->childs;
Subroutine nrChildren: called CC=1 SCAR=0.0
Pod documented
103 2536 scalar @$list;
104 }
105  
106 #---------
107  
108 822 ▶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 "" 0 822 822
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 0 25 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 11 14 25
121 }
122  
123  
124 sub textContent()
125 542 ▶{ 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 0 542 542
126 542 $node->textContent;
127 }
128  
129  
130 sub currentType()
131 515 ▶{ 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 "" 48 467 515
132 467 type_of_node $current;
133 }
134  
135  
136 sub currentLocal()
137 1224 ▶{ 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 "" 572 652 1224
138 652 $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;
« lib/XML/Compile/Schema/BuiltInTypes.pm ↑ Summary