| 1 | package XML::TinyXML::Selector::XPath::Axes; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use XML::TinyXML::NodeAttribute; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 4 | our $VERSION = "0.34"; | |||||||||
| 8 | |||||||||||
| 9 | 52 | ▶ | sub child { | ||||||||
|
Subroutine
child: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 10 | 52 | my ($class, $context) = @_; | |||||||||
| 11 | 52 | my @res = map { $_->children } grep { defined } @{$context->items}; | |||||||||
| 12 | 52 | ▶ | return wantarray?@res:\@res; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | 40 | ▶ | sub descendant { | ||||||||
|
Subroutine
descendant: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 16 | 40 | my ($class, $context) = @_; | |||||||||
| 17 | 40 | my @res = map { $_->children } @{$context->items}; | |||||||||
| 18 | 40 | ▶ | if (@res) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 26 | my $newctx = XML::TinyXML::Selector::XPath::Context->new($context->xml); | |||||||||
| 20 | 26 | $newctx->{items} = \@res; | |||||||||
| 21 | 26 | push (@res, descendant($class, $newctx)); | |||||||||
| 22 | } | ||||||||||
| 23 | 40 | ▶ | return wantarray?@res:\@res; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 3 | ▶ | sub parent { | ||||||||
|
Subroutine
parent: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 27 | 3 | my ($class, $context) = @_; | |||||||||
| 28 | 3 | my @res = map { $_->parent } grep { defined } @{$context->items}; | |||||||||
| 29 | 3 | ▶ | return wantarray?@res:\@res; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 3 | ▶ | sub ancestor { | ||||||||
|
Subroutine
ancestor: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||
| 33 | 3 | my ($class, $context) = @_; | |||||||||
| 34 | 3 | my @res; | |||||||||
| 35 | 3 | foreach my $node (@{$context->items}) { | |||||||||
| 36 | 3 | my $parent = $node->parent; | |||||||||
| 37 | 3 | ▶ | push(@res, $parent) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | if($parent); | ||||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 3 | ▶ | if (@res) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 2 | my $newctx = XML::TinyXML::Selector::XPath::Context->new($context->xml); | |||||||||
| 43 | 2 | $newctx->{items} = \@res; | |||||||||
| 44 | 2 | my @new = ancestor($class, $newctx); | |||||||||
| 45 | 2 | ▶ | push (@res, @new) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | if (@new); | ||||||||||
| 47 | } | ||||||||||
| 48 | 3 | ▶ | return wantarray?@res:\@res; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 2 | ▶ | sub following_sibling { | ||||||||
|
Subroutine
following_sibling: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 52 | 2 | my ($class, $context) = @_; | |||||||||
| 53 | 2 | my @res; | |||||||||
| 54 | 2 | foreach my $node (@{$context->items}) { | |||||||||
| 55 | 2 | ▶ | while ($node) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 5 | my $next = $node->nextSibling; | |||||||||
| 57 | 5 | ▶ | push (@res, $next) if $next; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 5 | $node = $next; | |||||||||
| 59 | } | ||||||||||
| 60 | } | ||||||||||
| 61 | 2 | ▶ | return wantarray?@res:\@res; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 1 | ▶ | sub preceding_sibling { | ||||||||
|
Subroutine
preceding_sibling: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 65 | 1 | my ($class, $context) = @_; | |||||||||
| 66 | 1 | my @res; | |||||||||
| 67 | 1 | foreach my $node (@{$context->items}) { | |||||||||
| 68 | 1 | ▶ | while ($node) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 4 | my $prev = $node->prevSibling; | |||||||||
| 70 | 4 | ▶ | push (@res, $prev) if $prev; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 4 | $node = $prev; | |||||||||
| 72 | } | ||||||||||
| 73 | } | ||||||||||
| 74 | 1 | ▶ | return wantarray?@res:\@res; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 10 | ▶ | sub attribute { | ||||||||
|
Subroutine
attribute: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 78 | 10 | my ($class, $context) = @_; | |||||||||
| 79 | 10 | my @res = map { $_->getAttributes } grep { defined } @{$context->items}; | |||||||||
| 80 | 10 | ▶ | return wantarray?@res:\@res; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 2 | ▶ | sub self { | ||||||||
|
Subroutine
self: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 84 | 2 | my ($class, $context) = @_; | |||||||||
| 85 | 2 | return @{$context->items}; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | 13 | ▶ | sub descendant_or_self { | ||||||||
|
Subroutine
descendant_or_self: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 89 | 13 | my ($class, $context) = @_; | |||||||||
| 90 | 13 | my @res = descendant($class, $context); | |||||||||
| 91 | 13 | foreach my $node (@{$context->items}) { | |||||||||
| 92 | 12 | push (@res, $node); | |||||||||
| 93 | } | ||||||||||
| 94 | 13 | ▶ | return wantarray?@res:\@res; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | sub ancestor_or_self { | ||||||||
|
Subroutine
ancestor_or_self: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 98 | 0 | my ($class, $context) = @_; | |||||||||
| 99 | 0 | my @res = ancestor($context); | |||||||||
| 100 | 0 | unshift(@res, $context->{node}); | |||||||||
| 101 | 0 | ▶ | return wantarray?@res:\@res; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | 4 | 1; | |||||||||