| 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
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | $self->{filter} = delete $args->{filter} | ||||||||||||||||||||
| 33 | 6299 | ▶ | or panic "no filter specified"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | $self->{path} = delete $args->{path} | ||||||||||||||||||||
| 36 | 6299 | ▶ | or panic "no path specified"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
MC/DC100%2/2
$node ||= $self->currentChild
$node
$self->currentChild
Truth table100%3/3
A ||= B
A= $nodeB= $self->currentChild
| |||||||||||||||||||||
| 46 | 5123 | ▶ | defined $node or return undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 5122 | my $path = $self->path; | |||||||||||||||||||
| 49 | 5122 | ▶ | $path .= '/'.$p if defined $p; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | (ref $self)->new | ||||||||||||||||||||
| 52 | 5122 | ▶ | ($node, $path, ($filter || $self->{filter})); | ||||||||||||||||||
|
Condition33%1/3
$filter || $self->{'filter'}
MC/DC0%0/2
$filter || $self->{'filter'}
$filter
$self->{'filter'}
Truth table33%1/3
A || B
A= $filterB= $self->{'filter'}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 119 | 25 | ▶ | my $nil = $node->getAttributeNS(SCHEMA2001i, 'nil') || ''; | ||||||||||||||||||
|
Condition100%2/2
$node->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'nil') || ''
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')
| |||||||||||||||||||||
| 120 | 25 | ▶ | $nil eq 'true' || $nil eq '1'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 144 | 0 | $current->textContent; | |||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 50 | 1; | |||||||||||||||||||