| 1 | package HTML::DOM::Text; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 24 | ▶ | use HTML::DOM::Node qw 'TEXT_NODE ATTRIBUTE_NODE'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 24 | require HTML::DOM::CharacterData; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 24 | our @ISA = 'HTML::DOM::CharacterData'; | |||||||||||||||||||||||||||
| 11 | 24 | our $VERSION = '0.057'; | |||||||||||||||||||||||||||
| 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.057 | ||||||||||||||||||||||||||||
| 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<HTML::DOM>. It inherits from | ||||||||||||||||||||||||||||
| 36 | L<HTML::DOM::CharacterData>, which inherits from L<HTML::DOM::Node>. | ||||||||||||||||||||||||||||
| 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<splitText> 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 | 559 | ▶ | $_[0]->SUPER::new('~text', text => "$_[1]"); | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub splitText { | ||||||||||||||||||||||||||||
| 69 | 3 | ▶ | my($self,$setoff) = @_; | ||||||||||||||||||||||||||
|
Subroutine
splitText: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 3 | my $new_node = __PACKAGE__->new( | |||||||||||||||||||||||||||
| 71 | # subtstringData takes care of throwing the right errors | ||||||||||||||||||||||||||||
| 72 | $self->substringData($setoff) | ||||||||||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||||||||||
| 74 | 1 | $self->deleteData($setoff); | |||||||||||||||||||||||||||
| 75 | 1 | $self->postinsert($new_node); | |||||||||||||||||||||||||||
| 76 | 1 | $new_node; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub splitText16 { # UTF-16 version | ||||||||||||||||||||||||||||
| 80 | 3 | ▶ | my($self,$setoff) = @_; | ||||||||||||||||||||||||||
|
Subroutine
splitText16: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 81 | 3 | my $new_node = __PACKAGE__->new( | |||||||||||||||||||||||||||
| 82 | $self->substringData16($setoff) | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | 1 | $self->deleteData16(($setoff,)); | |||||||||||||||||||||||||||
| 85 | 1 | $self->postinsert($new_node); | |||||||||||||||||||||||||||
| 86 | 1 | $new_node; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # ---------------- NODE METHODS ---------- # | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 45 | ▶ | sub nodeName { '#text' } | ||||||||||||||||||||||||||
|
Subroutine
nodeName: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 24 | *nodeType = \&TEXT_NODE; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # --------- OVERRIDDEN EVENT TARGET METHOD -------- # | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | sub trigger_event { | ||||||||||||||||||||||||||||
| 98 | 230 | ▶ | my ($n,$evnt) = (shift,shift); | ||||||||||||||||||||||||||
|
Subroutine
trigger_event: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 230 | my $p = $n->parent; | |||||||||||||||||||||||||||
| 100 | $n->SUPER::trigger_event( | ||||||||||||||||||||||||||||
| 101 | $evnt, | ||||||||||||||||||||||||||||
| 102 | $p && $p->nodeType == ATTRIBUTE_NODE | ||||||||||||||||||||||||||||
| 103 | ?( | ||||||||||||||||||||||||||||
| 104 | DOMCharacterDataModified_default =>sub { | ||||||||||||||||||||||||||||
| 105 | 6 | ▶ | $_[0]->target->parent->_text_node_modified( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 106 | $_[0] | ||||||||||||||||||||||||||||
| 107 | ) | ||||||||||||||||||||||||||||
| 108 | }, | ||||||||||||||||||||||||||||
| 109 | 230 | ▶ | ):(), | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$p and $p->nodeType == 2
MC/DC50%1/2
$p and $p->nodeType == 2
$p
$p->nodeType == 2
Truth table66%2/3
A and B
A= $pB= $p->nodeType == 2
| |||||||||||||||||||||||||||||
| 110 | @_, | ||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 24 | 1 | |||||||||||||||||||||||||||
| 115 | __END__ | ||||||||||||||||||||||||||||