line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::DOM::Text; |
2
|
|
|
|
|
|
|
|
3
|
24
|
|
|
24
|
|
89
|
use warnings; |
|
24
|
|
|
|
|
24
|
|
|
24
|
|
|
|
|
570
|
|
4
|
24
|
|
|
24
|
|
72
|
use strict; |
|
24
|
|
|
|
|
23
|
|
|
24
|
|
|
|
|
418
|
|
5
|
|
|
|
|
|
|
|
6
|
24
|
|
|
24
|
|
66
|
use HTML::DOM::Node qw 'TEXT_NODE ATTRIBUTE_NODE'; |
|
24
|
|
|
|
|
24
|
|
|
24
|
|
|
|
|
5938
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require HTML::DOM::CharacterData; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = 'HTML::DOM::CharacterData'; |
11
|
|
|
|
|
|
|
our $VERSION = '0.056'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
HTML::DOM::Text - A Perl class for representing text nodes in an HTML DOM tree |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 VERSION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Version 0.056 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use HTML::DOM; |
25
|
|
|
|
|
|
|
$doc = HTML::DOM->new; |
26
|
|
|
|
|
|
|
$text_node = $doc->createTextNode('the text goes here, I think'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$text_node->data; # 'the text goes here, I think' |
29
|
|
|
|
|
|
|
$text_node->length; # 27 |
30
|
|
|
|
|
|
|
$text_node->substringData(22); # 'think' |
31
|
|
|
|
|
|
|
# etc. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
This class implements the Text interface for L. It inherits from |
36
|
|
|
|
|
|
|
L, which inherits from L. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 HTML::DOM::Text's Own Methods |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=over 4 |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item $text->splitText($offset) |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Splits the node into two separate sibling text nodes at the given offset. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item $text->splitText16($offset) |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This is just like C except that the offset is given in UTF-16, |
51
|
|
|
|
|
|
|
rather than Unicode. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item $text->nodeName |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This returns '#text'. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item $text->nodeType |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This returns the constant HTML::DOM::Node::TEXT_NODE. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { # $_[1] contains the text |
65
|
608
|
|
|
608
|
0
|
1614
|
$_[0]->SUPER::new('~text', text => "$_[1]"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub splitText { |
69
|
3
|
|
|
3
|
1
|
570
|
my($self,$setoff) = @_; |
70
|
3
|
|
|
|
|
10
|
my $new_node = __PACKAGE__->new( |
71
|
|
|
|
|
|
|
# subtstringData takes care of throwing the right errors |
72
|
|
|
|
|
|
|
$self->substringData($setoff) |
73
|
|
|
|
|
|
|
); |
74
|
1
|
|
|
|
|
6
|
$self->deleteData($setoff); |
75
|
1
|
|
|
|
|
7
|
$self->postinsert($new_node); |
76
|
1
|
|
|
|
|
2
|
$new_node; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub splitText16 { # UTF-16 version |
80
|
3
|
|
|
3
|
1
|
287
|
my($self,$setoff) = @_; |
81
|
3
|
|
|
|
|
9
|
my $new_node = __PACKAGE__->new( |
82
|
|
|
|
|
|
|
$self->substringData16($setoff) |
83
|
|
|
|
|
|
|
); |
84
|
1
|
|
|
|
|
6
|
$self->deleteData16(($setoff,)); |
85
|
1
|
|
|
|
|
3
|
$self->postinsert($new_node); |
86
|
1
|
|
|
|
|
2
|
$new_node; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# ---------------- NODE METHODS ---------- # |
90
|
|
|
|
|
|
|
|
91
|
54
|
|
|
54
|
1
|
130
|
sub nodeName { '#text' } |
92
|
|
|
|
|
|
|
*nodeType = \&TEXT_NODE; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# --------- OVERRIDDEN EVENT TARGET METHOD -------- # |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub trigger_event { |
98
|
234
|
|
|
234
|
1
|
297
|
my ($n,$evnt) = (shift,shift); |
99
|
234
|
|
|
|
|
392
|
my $p = $n->parent; |
100
|
|
|
|
|
|
|
$n->SUPER::trigger_event( |
101
|
|
|
|
|
|
|
$evnt, |
102
|
|
|
|
|
|
|
$p && $p->nodeType == ATTRIBUTE_NODE |
103
|
|
|
|
|
|
|
?( |
104
|
|
|
|
|
|
|
DOMCharacterDataModified_default =>sub { |
105
|
6
|
|
|
6
|
|
16
|
$_[0]->target->parent->_text_node_modified( |
106
|
|
|
|
|
|
|
$_[0] |
107
|
|
|
|
|
|
|
) |
108
|
|
|
|
|
|
|
}, |
109
|
234
|
100
|
66
|
|
|
1148
|
):(), |
110
|
|
|
|
|
|
|
@_, |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1 |
115
|
|
|
|
|
|
|
__END__ |