line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##---------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
## HTML Object - ~/lib/HTML/Object/XPath/Root.pm |
3
|
|
|
|
|
|
|
## Version v0.2.0 |
4
|
|
|
|
|
|
|
## Copyright(c) 2021 DEGUEST Pte. Ltd. |
5
|
|
|
|
|
|
|
## Author: Jacques Deguest <jack@deguest.jp> |
6
|
|
|
|
|
|
|
## Created 2021/12/04 |
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::Root; |
15
|
|
|
|
|
|
|
BEGIN |
16
|
|
|
|
|
|
|
{ |
17
|
8
|
|
|
8
|
|
57
|
use strict; |
|
8
|
|
|
|
|
39
|
|
|
8
|
|
|
|
|
243
|
|
18
|
8
|
|
|
8
|
|
47
|
use warnings; |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
237
|
|
19
|
8
|
|
|
8
|
|
43
|
use parent qw( Module::Generic ); |
|
8
|
|
|
|
|
26
|
|
|
8
|
|
|
|
|
47
|
|
20
|
8
|
|
|
8
|
|
585
|
use vars qw( $BASE_CLASS $DEBUG $VERSION ); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
655
|
|
21
|
8
|
|
|
8
|
|
39
|
our $BASE_CLASS = 'HTML::Object::XPath'; |
22
|
8
|
|
|
|
|
19
|
our $DEBUG = 0; |
23
|
8
|
|
|
|
|
137
|
our $VERSION = 'v0.2.0'; |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
|
26
|
8
|
|
|
8
|
|
53
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
220
|
|
27
|
8
|
|
|
8
|
|
43
|
use warnings; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
2845
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new |
30
|
|
|
|
|
|
|
{ |
31
|
48
|
|
|
48
|
1
|
161
|
my $this = shift( @_ ); |
32
|
48
|
|
|
|
|
124
|
my $str = shift( @_ ); |
33
|
48
|
|
33
|
|
|
462
|
return( bless( \$str => ( ref( $this ) || $this ) ) ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
0
|
1
|
0
|
sub as_string { return; } |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
0
|
1
|
0
|
sub as_xml { return( "<Root/>\n" ); } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub evaluate |
41
|
|
|
|
|
|
|
{ |
42
|
60
|
|
|
60
|
1
|
154
|
my $self = shift( @_ ); |
43
|
60
|
|
|
|
|
106
|
my $nodeset = shift( @_ ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# must only ever occur on 1 node |
46
|
60
|
50
|
|
|
|
225
|
die "Can't go to root on > 1 node!" unless $nodeset->size == 1; |
47
|
|
|
|
|
|
|
# return( $self->error( "Can't go to root on > 1 node!" ) ) unless( $nodeset->size == 1 ); |
48
|
|
|
|
|
|
|
|
49
|
60
|
|
|
|
|
179
|
my $newset = $self->new_nodeset; |
50
|
|
|
|
|
|
|
# $newset->push($nodeset->get_node(1)->getRootNode()); |
51
|
60
|
|
|
|
|
315
|
my $node = $nodeset->get_node(1); |
52
|
|
|
|
|
|
|
# $node->debug(4); |
53
|
60
|
|
|
|
|
376
|
my $rootNode = $node->getRootNode(); |
54
|
60
|
|
|
|
|
799
|
$newset->push( $rootNode ); |
55
|
60
|
|
|
|
|
302
|
return( $newset ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
60
|
|
|
60
|
1
|
228
|
sub new_nodeset { return( shift->_class_for( 'NodeSet' )->new( @_ ) ); } |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _class_for |
61
|
|
|
|
|
|
|
{ |
62
|
60
|
|
|
60
|
|
160
|
my( $self, $mod ) = @_; |
63
|
60
|
|
|
|
|
2619
|
eval( "require ${BASE_CLASS}\::${mod};" ); |
64
|
60
|
50
|
|
|
|
371
|
die( $@ ) if( $@ ); |
65
|
|
|
|
|
|
|
# ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG; |
66
|
60
|
|
50
|
|
|
2530
|
eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) ); |
67
|
60
|
|
|
|
|
523
|
return( "${BASE_CLASS}::${mod}" ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
# NOTE: POD |
72
|
|
|
|
|
|
|
__END__ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=encoding utf-8 |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NAME |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
HTML::Object::XPath::Root - HTML Object |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use HTML::Object::XPath::Root; |
83
|
|
|
|
|
|
|
my $root = HTML::Object::XPath::Root->new || |
84
|
|
|
|
|
|
|
die( HTML::Object::XPath::Root->error, "\n" ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 VERSION |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
v0.2.0 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This module represents a root element, which is the top element. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 new |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Provided with a string, and this returns a new L<HTML::Object::XPath::Root> object. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 METHODS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 as_string |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns C<undef> in scalar context and an empty list in list context. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 as_xml |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Returns C<<Root/>> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 evaluate |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Provided with a L<node set|HTML::Object::XPath::NodeSet> object and this the first element in the node set, get its root node and return a new L<set|HTML::Object::XPath::NodeSet> with the node as its sole element. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 new_nodeset |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Returns a new L<HTML::Object::XPath::NodeSet> passing it whatever argument was provided. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SEE ALSO |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
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> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Copyright(c) 2021 DEGUEST Pte. Ltd. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
All rights reserved |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |