| 1 | # $Id: /tree-xpathengine/trunk/lib/Tree/XPathEngine/NodeSet.pm 17 2006-02-12T08:00:01.814064Z mrodrigu $ | ||||||||||
| 2 | |||||||||||
| 3 | package Tree::XPathEngine::NodeSet; | ||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 6 | ▶ | use Tree::XPathEngine::Boolean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | use overload | ||||||||||
| 9 | 6 | ▶ | '""' => \&xpath_to_literal, | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 'bool' => \&xpath_to_boolean, | ||||||||||
| 11 | 6 | ; | |||||||||
| 12 | |||||||||||
| 13 | 5033 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 14 | 5033 | my $class = shift; | |||||||||
| 15 | 5033 | bless [], $class; | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | 799 | ▶ | sub sort { | ||||||||
|
Subroutine
sort: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 19 | 799 | my $self = CORE::shift; | |||||||||
| 20 | 799 | @$self = CORE::sort { $a->xpath_cmp( $b) } @$self; | |||||||||
| 21 | 799 | return $self; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 640 | ▶ | sub remove_duplicates { | ||||||||
|
Subroutine
remove_duplicates: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 25 | 640 | my $self = CORE::shift; | |||||||||
| 26 | 640 | my @unique; | |||||||||
| 27 | 640 | my $last_node=0; | |||||||||
| 28 | 640 | foreach my $node (@$self) { | |||||||||
| 29 | 973 | ▶ | push @unique, $node unless( $node == $last_node); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 973 | $last_node= $node; | |||||||||
| 31 | } | ||||||||||
| 32 | 640 | @$self= @unique; | |||||||||
| 33 | 640 | return $self; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub pop { | ||||||||
|
Subroutine
pop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 38 | 0 | my $self = CORE::shift; | |||||||||
| 39 | 0 | CORE::pop @$self; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 2524 | ▶ | sub push { | ||||||||
|
Subroutine
push: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 43 | 2524 | my $self = CORE::shift; | |||||||||
| 44 | 2524 | my (@nodes) = @_; | |||||||||
| 45 | 2524 | CORE::push @$self, @nodes; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 2106 | ▶ | sub append { | ||||||||
|
Subroutine
append: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 49 | 2106 | my $self = CORE::shift; | |||||||||
| 50 | 2106 | my ($nodeset) = @_; | |||||||||
| 51 | 2106 | CORE::push @$self, $nodeset->get_nodelist; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub shift { | ||||||||
|
Subroutine
shift: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 55 | 0 | my $self = CORE::shift; | |||||||||
| 56 | 0 | CORE::shift @$self; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 1375 | ▶ | sub unshift { | ||||||||
|
Subroutine
unshift: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 60 | 1375 | my $self = CORE::shift; | |||||||||
| 61 | 1375 | my (@nodes) = @_; | |||||||||
| 62 | 1375 | CORE::unshift @$self, @nodes; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub prepend { | ||||||||
|
Subroutine
prepend: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 66 | 0 | my $self = CORE::shift; | |||||||||
| 67 | 0 | my ($nodeset) = @_; | |||||||||
| 68 | 0 | CORE::unshift @$self, $nodeset->get_nodelist; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 5098 | ▶ | sub size { | ||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 72 | 5098 | my $self = CORE::shift; | |||||||||
| 73 | 5098 | scalar @$self; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 3124 | ▶ | sub get_node { # uses array index starting at 1, not 0 | ||||||||
|
Subroutine
get_node: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 77 | 3124 | my $self = CORE::shift; | |||||||||
| 78 | 3124 | my ($pos) = @_; | |||||||||
| 79 | 3124 | $self->[$pos - 1]; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 0 | ▶ | sub xpath_get_root_node { | ||||||||
|
Subroutine
xpath_get_root_node: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 83 | 0 | my $self = CORE::shift; | |||||||||
| 84 | 0 | return $self->[0]->xpath_get_root_node; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 2612 | ▶ | sub get_nodelist { | ||||||||
|
Subroutine
get_nodelist: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 88 | 2612 | my $self = CORE::shift; | |||||||||
| 89 | 2612 | @$self; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 99 | ▶ | sub xpath_to_boolean { | ||||||||
|
Subroutine
xpath_to_boolean: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 93 | 99 | my $self = CORE::shift; | |||||||||
| 94 | 99 | ▶ | return (@$self > 0) ? Tree::XPathEngine::Boolean->_true : Tree::XPathEngine::Boolean->_false; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | sub xpath_string_value { | ||||||||
|
Subroutine
xpath_string_value: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 98 | 0 | my $self = CORE::shift; | |||||||||
| 99 | 0 | ▶ | return '' unless @$self; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | return $self->[0]->xpath_string_value; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | 116 | ▶ | sub xpath_to_literal { | ||||||||
|
Subroutine
xpath_to_literal: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 104 | 116 | my $self = CORE::shift; | |||||||||
| 105 | return Tree::XPathEngine::Literal->new( | ||||||||||
| 106 | 116 | join('', map { $_->xpath_string_value } @$self) | |||||||||
| 107 | ); | ||||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 54 | ▶ | sub xpath_to_number { | ||||||||
|
Subroutine
xpath_to_number: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 111 | 54 | my $self = CORE::shift; | |||||||||
| 112 | 54 | return Tree::XPathEngine::Number->new( | |||||||||
| 113 | $self->xpath_to_literal | ||||||||||
| 114 | ); | ||||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | 6 | 1; | |||||||||
| 118 | __END__ | ||||||||||