| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
|
2
|
|
|
|
|
|
|
## HTML Object - ~/lib/HTML/Object/XPath/LocationPath.pm |
|
3
|
|
|
|
|
|
|
## Version v0.2.0 |
|
4
|
|
|
|
|
|
|
## Copyright(c) 2021 DEGUEST Pte. Ltd. |
|
5
|
|
|
|
|
|
|
## Author: Jacques Deguest <jack@deguest.jp> |
|
6
|
|
|
|
|
|
|
## Created 2021/12/05 |
|
7
|
|
|
|
|
|
|
## Modified 2022/09/18 |
|
8
|
|
|
|
|
|
|
## All rights reserved |
|
9
|
|
|
|
|
|
|
## |
|
10
|
|
|
|
|
|
|
## |
|
11
|
|
|
|
|
|
|
## This program is free software; you can redistribute it and/or modify it |
|
12
|
|
|
|
|
|
|
## under the same terms as Perl itself. |
|
13
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
|
14
|
|
|
|
|
|
|
package HTML::Object::XPath::LocationPath; |
|
15
|
|
|
|
|
|
|
BEGIN |
|
16
|
|
|
|
|
|
|
{ |
|
17
|
8
|
|
|
8
|
|
61
|
use strict; |
|
|
8
|
|
|
|
|
14
|
|
|
|
8
|
|
|
|
|
246
|
|
|
18
|
8
|
|
|
8
|
|
67
|
use warnings; |
|
|
8
|
|
|
|
|
17
|
|
|
|
8
|
|
|
|
|
225
|
|
|
19
|
8
|
|
|
8
|
|
44
|
use parent qw( Module::Generic ); |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
362
|
|
|
20
|
8
|
|
|
8
|
|
477
|
use vars qw( $BASE_CLASS $DEBUG $VERSION ); |
|
|
8
|
|
|
|
|
19
|
|
|
|
8
|
|
|
|
|
594
|
|
|
21
|
8
|
|
|
8
|
|
29
|
our $BASE_CLASS = 'HTML::Object::XPath'; |
|
22
|
8
|
|
|
|
|
202
|
our $DEBUG = 0; |
|
23
|
8
|
|
|
|
|
185
|
our $VERSION = 'v0.2.0'; |
|
24
|
|
|
|
|
|
|
}; |
|
25
|
|
|
|
|
|
|
|
|
26
|
8
|
|
|
8
|
|
53
|
use strict; |
|
|
8
|
|
|
|
|
20
|
|
|
|
8
|
|
|
|
|
155
|
|
|
27
|
8
|
|
|
8
|
|
43
|
use warnings; |
|
|
8
|
|
|
|
|
21
|
|
|
|
8
|
|
|
|
|
4544
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new |
|
30
|
|
|
|
|
|
|
{ |
|
31
|
89
|
|
|
89
|
1
|
278
|
my $this = shift( @_ ); |
|
32
|
89
|
|
33
|
|
|
595
|
return( bless( [] => ( ref( $this ) || $this ) ) ); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub as_string |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
0
|
|
|
0
|
1
|
0
|
my $self = shift( @_ ); |
|
38
|
0
|
|
|
|
|
0
|
my $string; |
|
39
|
0
|
|
|
|
|
0
|
for( my $i = 0; $i < @$self; $i++ ) |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
0
|
|
|
|
|
0
|
$string .= $self->[ $i ]->as_string; |
|
42
|
0
|
0
|
|
|
|
0
|
$string .= '/' if( $self->[ $i + 1 ] ); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
0
|
|
|
|
|
0
|
return( $string ); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub as_xml |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
0
|
|
|
0
|
1
|
0
|
my $self = shift( @_ ); |
|
50
|
0
|
|
|
|
|
0
|
my $string = "<LocationPath>\n"; |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
for (my $i = 0; $i < @$self; $i++ ) |
|
53
|
|
|
|
|
|
|
{ |
|
54
|
0
|
|
|
|
|
0
|
$string .= $self->[ $i ]->as_xml; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
0
|
|
|
|
|
0
|
$string .= "</LocationPath>\n"; |
|
57
|
0
|
|
|
|
|
0
|
return( $string ); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub evaluate |
|
61
|
|
|
|
|
|
|
{ |
|
62
|
248
|
|
|
248
|
1
|
468
|
my $self = shift( @_ ); |
|
63
|
|
|
|
|
|
|
# context _MUST_ be a single node |
|
64
|
248
|
|
|
|
|
422
|
my $context = shift( @_ ); |
|
65
|
248
|
50
|
|
|
|
3014
|
die( "No context" ) unless( $context ); |
|
66
|
248
|
50
|
|
|
|
861
|
if( $self->debug ) |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
0
|
|
|
|
|
0
|
my( $p, $f, $l ) = caller; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# I _think_ this is how it should work :) |
|
72
|
248
|
|
|
|
|
5996
|
my $nodeset = $self->new_nodeset(); |
|
73
|
248
|
|
|
|
|
955
|
$nodeset->push( $context ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
248
|
|
|
|
|
684
|
foreach my $step ( @$self ) |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
|
|
|
|
|
|
# For each step |
|
78
|
|
|
|
|
|
|
# evaluate the step with the nodeset |
|
79
|
441
|
|
|
|
|
2226
|
my $pos = 1; |
|
80
|
|
|
|
|
|
|
# die( "Looping !\n" ) if( ref( $step ) eq ref( $self ) ); |
|
81
|
441
|
50
|
|
|
|
1887
|
die( "Looping !\n" ) if( $step eq $self ); |
|
82
|
441
|
|
|
|
|
1533
|
$nodeset = $step->evaluate( $nodeset ); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
245
|
|
|
|
|
2896
|
return( $nodeset ); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
248
|
|
|
248
|
1
|
859
|
sub new_nodeset { return( shift->_class_for( 'NodeSet' )->new( @_ ) ); } |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
1
|
0
|
sub new_root { return( shift->_class_for( 'Root' )->new( @_ ) ); } |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# sub push { return( CORE::push( @{$_[0]}, @_ ) ); } |
|
92
|
|
|
|
|
|
|
sub push |
|
93
|
|
|
|
|
|
|
{ |
|
94
|
169
|
|
|
169
|
1
|
311
|
my $self = shift( @_ ); |
|
95
|
169
|
50
|
|
|
|
531
|
if( $self->debug ) |
|
96
|
|
|
|
|
|
|
{ |
|
97
|
0
|
|
|
|
|
0
|
my( $p, $f, $l ) = caller; |
|
98
|
0
|
|
|
|
|
0
|
for( @_ ) |
|
99
|
|
|
|
|
|
|
{ |
|
100
|
0
|
0
|
|
|
|
0
|
if( ref( $_ ) eq ref( $self ) ) |
|
101
|
|
|
|
|
|
|
{ |
|
102
|
0
|
|
|
|
|
0
|
die( "A LocationPath object was added to its own stack!\n" ); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
169
|
|
|
|
|
4030
|
return( CORE::push( @$self, @_ ) ); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub set_root |
|
110
|
|
|
|
|
|
|
{ |
|
111
|
0
|
|
|
0
|
1
|
0
|
my $self = shift( @_ ); |
|
112
|
0
|
|
|
|
|
0
|
return( unshift( @$self, $self->new_root ) ); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub _class_for |
|
116
|
|
|
|
|
|
|
{ |
|
117
|
248
|
|
|
248
|
|
621
|
my( $self, $mod ) = @_; |
|
118
|
248
|
|
|
|
|
12861
|
eval( "require ${BASE_CLASS}\::${mod};" ); |
|
119
|
248
|
50
|
|
|
|
1178
|
die( $@ ) if( $@ ); |
|
120
|
|
|
|
|
|
|
# ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG; |
|
121
|
248
|
|
50
|
|
|
10548
|
eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) ); |
|
122
|
248
|
|
|
|
|
1918
|
return( "${BASE_CLASS}::${mod}" ); |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
|
126
|
|
|
|
|
|
|
# NOTE: POD |
|
127
|
|
|
|
|
|
|
__END__ |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=encoding utf-8 |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 NAME |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
HTML::Object::XPath::LocationPath - HTML Object XPath Location Path |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
use HTML::Object::XPath::LocationPath; |
|
138
|
|
|
|
|
|
|
my $this = HTML::Object::XPath::LocationPath->new || |
|
139
|
|
|
|
|
|
|
die( HTML::Object::XPath::LocationPath->error, "\n" ); |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 VERSION |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
v0.2.0 |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This module represents a XML LocationPath. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Takes no argument and returns a new array-based object. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 METHODS |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 as_string |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
For each element in it the current object array, this will call C<as_string> and concatenate those strings separated by C</>. It returns the result as a regular perl string. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 as_xml |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Calls C<as_xml> on each elements in the current object array and returns the concatenated string enclosed in <LocationPath> and </LocationPath> |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 evaluate |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Provided with a L<context|HTML::Object::Element>, and this will call C<evaluate> for each object in the stack. It returns a new L<HTML::Object::XPath::NodeSet> object containing the result with the C<context> initially provided as the first in the node set. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 new_nodeset |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Returns a new L<HTML::Object::XPath::NodeSet> passing it whatever argument was provided. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 new_root |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns a new L<HTML::Object::XPath::Root> passing it whatever argument was provided. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 push |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Add the elements provided to the object array. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 set_root |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Add a new L<root object|HTML::Object::XPath::Root> as the first element of our internal array. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 AUTHOR |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
L<HTML::Object::XPath>, L<HTML::Object::XPath::Boolean>, L<HTML::Object::XPath::Expr>, L<HTML::Object::XPath::Function>, L<HTML::Object::XPath::Literal>, L<HTML::Object::XPath::LocationPath>, L<HTML::Object::XPath::NodeSet>, L<HTML::Object::XPath::Number>, L<HTML::Object::XPath::Root>, L<HTML::Object::XPath::Step>, L<HTML::Object::XPath::Variable> |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Copyright(c) 2021 DEGUEST Pte. Ltd. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
All rights reserved |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |