line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
5
|
|
|
5
|
|
30
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
211
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
31
|
use Tree::XPathEngine::Boolean; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
208
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use overload |
9
|
5
|
|
|
|
|
49
|
'""' => \&xpath_to_literal, |
10
|
|
|
|
|
|
|
'bool' => \&xpath_to_boolean, |
11
|
5
|
|
|
5
|
|
111
|
; |
|
5
|
|
|
|
|
11
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
5033
|
|
|
5033
|
1
|
7085
|
my $class = shift; |
15
|
5033
|
|
|
|
|
19959
|
bless [], $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub sort { |
19
|
799
|
|
|
799
|
1
|
886
|
my $self = CORE::shift; |
20
|
799
|
|
|
|
|
2200
|
@$self = CORE::sort { $a->xpath_cmp( $b) } @$self; |
|
4391
|
|
|
|
|
59542
|
|
21
|
799
|
|
|
|
|
4528
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub remove_duplicates { |
25
|
640
|
|
|
640
|
1
|
786
|
my $self = CORE::shift; |
26
|
640
|
|
|
|
|
670
|
my @unique; |
27
|
640
|
|
|
|
|
747
|
my $last_node=0; |
28
|
640
|
|
|
|
|
1162
|
foreach my $node (@$self) { |
29
|
973
|
100
|
|
|
|
2349
|
push @unique, $node unless( $node == $last_node); |
30
|
973
|
|
|
|
|
1688
|
$last_node= $node; |
31
|
|
|
|
|
|
|
} |
32
|
640
|
|
|
|
|
2634
|
@$self= @unique; |
33
|
640
|
|
|
|
|
2424
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub pop { |
38
|
0
|
|
|
0
|
1
|
0
|
my $self = CORE::shift; |
39
|
0
|
|
|
|
|
0
|
CORE::pop @$self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub push { |
43
|
2524
|
|
|
2524
|
1
|
5326
|
my $self = CORE::shift; |
44
|
2524
|
|
|
|
|
4236
|
my (@nodes) = @_; |
45
|
2524
|
|
|
|
|
11309
|
CORE::push @$self, @nodes; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub append { |
49
|
2106
|
|
|
2106
|
1
|
2515
|
my $self = CORE::shift; |
50
|
2106
|
|
|
|
|
2611
|
my ($nodeset) = @_; |
51
|
2106
|
|
|
|
|
4575
|
CORE::push @$self, $nodeset->get_nodelist; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub shift { |
55
|
0
|
|
|
0
|
1
|
0
|
my $self = CORE::shift; |
56
|
0
|
|
|
|
|
0
|
CORE::shift @$self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub unshift { |
60
|
1375
|
|
|
1375
|
1
|
1855
|
my $self = CORE::shift; |
61
|
1375
|
|
|
|
|
2373
|
my (@nodes) = @_; |
62
|
1375
|
|
|
|
|
13480
|
CORE::unshift @$self, @nodes; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub prepend { |
66
|
0
|
|
|
0
|
1
|
0
|
my $self = CORE::shift; |
67
|
0
|
|
|
|
|
0
|
my ($nodeset) = @_; |
68
|
0
|
|
|
|
|
0
|
CORE::unshift @$self, $nodeset->get_nodelist; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub size { |
72
|
5098
|
|
|
5098
|
1
|
6091
|
my $self = CORE::shift; |
73
|
5098
|
|
|
|
|
41112
|
scalar @$self; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub get_node { # uses array index starting at 1, not 0 |
77
|
3124
|
|
|
3124
|
1
|
3959
|
my $self = CORE::shift; |
78
|
3124
|
|
|
|
|
3865
|
my ($pos) = @_; |
79
|
3124
|
|
|
|
|
12066
|
$self->[$pos - 1]; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub xpath_get_root_node { |
83
|
0
|
|
|
0
|
1
|
0
|
my $self = CORE::shift; |
84
|
0
|
|
|
|
|
0
|
return $self->[0]->xpath_get_root_node; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub get_nodelist { |
88
|
2612
|
|
|
2612
|
1
|
2677
|
my $self = CORE::shift; |
89
|
2612
|
|
|
|
|
9972
|
@$self; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub xpath_to_boolean { |
93
|
167
|
|
|
167
|
1
|
244
|
my $self = CORE::shift; |
94
|
167
|
100
|
|
|
|
785
|
return (@$self > 0) ? Tree::XPathEngine::Boolean->_true : Tree::XPathEngine::Boolean->_false; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub xpath_string_value { |
98
|
0
|
|
|
0
|
1
|
0
|
my $self = CORE::shift; |
99
|
0
|
0
|
|
|
|
0
|
return '' unless @$self; |
100
|
0
|
|
|
|
|
0
|
return $self->[0]->xpath_string_value; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub xpath_to_literal { |
104
|
116
|
|
|
116
|
1
|
178
|
my $self = CORE::shift; |
105
|
187
|
|
|
|
|
1157
|
return Tree::XPathEngine::Literal->new( |
106
|
116
|
|
|
|
|
424
|
join('', map { $_->xpath_string_value } @$self) |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub xpath_to_number { |
111
|
54
|
|
|
54
|
1
|
78
|
my $self = CORE::shift; |
112
|
54
|
|
|
|
|
149
|
return Tree::XPathEngine::Number->new( |
113
|
|
|
|
|
|
|
$self->xpath_to_literal |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
__END__ |