line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2006-2019 by [Mark Overmeer ]. |
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
|
|
|
50
|
|
5306
|
use vars '$VERSION'; |
|
50
|
|
|
|
|
89
|
|
|
50
|
|
|
|
|
2335
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.63'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
50
|
|
|
50
|
|
260
|
use warnings; |
|
50
|
|
|
|
|
66
|
|
|
50
|
|
|
|
|
1213
|
|
15
|
50
|
|
|
50
|
|
244
|
use strict; |
|
50
|
|
|
|
|
75
|
|
|
50
|
|
|
|
|
1891
|
|
16
|
|
|
|
|
|
|
|
17
|
50
|
|
|
50
|
|
251
|
use XML::Compile::Util qw/pack_type type_of_node SCHEMA2001i/; |
|
50
|
|
|
|
|
67
|
|
|
50
|
|
|
|
|
2485
|
|
18
|
50
|
|
|
50
|
|
246
|
use Log::Report 'xml-compile', syntax => 'SHORT'; |
|
50
|
|
|
|
|
80
|
|
|
50
|
|
|
|
|
287
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new($@) |
22
|
6182
|
|
|
6182
|
1
|
11822
|
{ my ($class, $node, $path, $filter) = splice @_, 0, 4; |
23
|
6182
|
|
|
|
|
19409
|
(bless {}, $class) |
24
|
|
|
|
|
|
|
->init( { node => $node, filter => $filter, path => $path, @_} ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub init($) |
28
|
6182
|
|
|
6182
|
0
|
7429
|
{ my ($self, $args) = @_; |
29
|
|
|
|
|
|
|
$self->{node} = delete $args->{node} |
30
|
6182
|
50
|
|
|
|
14808
|
or panic "no node specified"; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$self->{filter} = delete $args->{filter} |
33
|
6182
|
50
|
|
|
|
28573
|
or panic "no filter specified"; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->{path} = delete $args->{path} |
36
|
6182
|
50
|
|
|
|
10422
|
or panic "no path specified"; |
37
|
|
|
|
|
|
|
|
38
|
6182
|
|
|
|
|
7244
|
$self->{current} = 0; |
39
|
6182
|
|
|
|
|
18997
|
$self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub descend(;$$$) |
44
|
5018
|
|
|
5018
|
1
|
8313
|
{ my ($self, $node, $p, $filter) = @_; |
45
|
5018
|
|
100
|
|
|
9813
|
$node ||= $self->currentChild; |
46
|
5018
|
100
|
|
|
|
20203
|
defined $node or return undef; |
47
|
|
|
|
|
|
|
|
48
|
5017
|
|
|
|
|
6613
|
my $path = $self->path; |
49
|
5017
|
100
|
|
|
|
8390
|
$path .= '/'.$p if defined $p; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
(ref $self)->new |
52
|
5017
|
|
33
|
|
|
16456
|
($node, $path, ($filter || $self->{filter})); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#---------------- |
56
|
|
|
|
|
|
|
|
57
|
14585
|
|
|
14585
|
1
|
23676
|
sub node() {shift->{node}} |
58
|
4430
|
|
|
4430
|
1
|
5113
|
sub filter() {shift->{filter}} |
59
|
10872
|
|
|
10872
|
1
|
17402
|
sub path() {shift->{path}} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#---------------- |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub childs() |
64
|
11977
|
|
|
11977
|
1
|
11284
|
{ my $self = shift; |
65
|
11977
|
|
|
|
|
11841
|
my $ln = $self->{childs}; |
66
|
11977
|
100
|
|
|
|
15703
|
unless(defined $ln) |
67
|
4430
|
|
|
|
|
5902
|
{ my $filter = $self->filter; |
68
|
|
|
|
|
|
|
$ln = $self->{childs} |
69
|
4430
|
|
|
|
|
6180
|
= [ grep {$filter->($_)} $self->node->childNodes ]; |
|
9829
|
|
|
|
|
33381
|
|
70
|
|
|
|
|
|
|
} |
71
|
11977
|
100
|
|
|
|
43253
|
wantarray ? @$ln : $ln; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
5728
|
|
|
5728
|
1
|
7077
|
sub currentChild() { $_[0]->childs->[$_[0]->{current}] } |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
1454
|
|
|
1454
|
1
|
2116
|
sub firstChild() {shift->childs->[0]} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub lastChild() |
82
|
0
|
|
|
0
|
1
|
0
|
{ my $list = shift->childs; |
83
|
0
|
0
|
|
|
|
0
|
@$list ? $list->[-1] : undef; # avoid error on empty list |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub nextChild() |
88
|
1485
|
|
|
1485
|
1
|
13295
|
{ my $self = shift; |
89
|
1485
|
|
|
|
|
2243
|
my $list = $self->childs; |
90
|
1485
|
50
|
|
|
|
4408
|
$self->{current} < @$list ? $list->[ ++$self->{current} ] : undef; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub previousChild() |
95
|
0
|
|
|
0
|
1
|
0
|
{ my $self = shift; |
96
|
0
|
|
|
|
|
0
|
my $list = $self->childs; |
97
|
0
|
0
|
|
|
|
0
|
$self->{current} > 0 ? $list->[ --$self->{current} ] : undef; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub nrChildren() |
102
|
2679
|
|
|
2679
|
1
|
4466
|
{ my $list = shift->childs; |
103
|
2679
|
|
|
|
|
4978
|
scalar @$list; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#--------- |
107
|
|
|
|
|
|
|
|
108
|
840
|
50
|
|
840
|
1
|
1369
|
sub nodeType() { type_of_node(shift->node) || '' } |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub nodeLocal() |
112
|
0
|
0
|
|
0
|
1
|
0
|
{ my $node = shift->node or return ''; |
113
|
0
|
|
|
|
|
0
|
$node->localName; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub nodeNil() |
118
|
25
|
50
|
|
25
|
1
|
42
|
{ my $node = shift->node or return 0; |
119
|
25
|
|
100
|
|
|
154
|
my $nil = $node->getAttributeNS(SCHEMA2001i, 'nil') || ''; |
120
|
25
|
100
|
|
|
|
468
|
$nil eq 'true' || $nil eq '1'; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub textContent() |
125
|
563
|
50
|
|
563
|
1
|
877
|
{ my $node = shift->node or return undef; |
126
|
563
|
|
|
|
|
4553
|
$node->textContent; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub currentType() |
131
|
514
|
100
|
|
514
|
1
|
890
|
{ my $current = shift->currentChild or return ''; |
132
|
466
|
|
|
|
|
2338
|
type_of_node $current; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub currentLocal() |
137
|
1228
|
100
|
|
1228
|
1
|
1827
|
{ my $current = shift->currentChild or return ''; |
138
|
656
|
|
|
|
|
5944
|
$current->localName; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub currentContent() |
143
|
0
|
0
|
|
0
|
1
|
|
{ my $current = shift->currentChild or return undef; |
144
|
0
|
|
|
|
|
|
$current->textContent; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |