HTML::DOM::Text - A Perl class for representing text nodes in an HTML DOM tree


HTML-DOM documentation Contained in the HTML-DOM distribution.

Index


Code Index:

NAME

Top

HTML::DOM::Text - A Perl class for representing text nodes in an HTML DOM tree

SYNOPSIS

Top

  use HTML::DOM;
  $doc = HTML::DOM->new;
  $text_node = $doc->createTextNode('the text goes here, I think');

  $text_node->data;              # 'the text goes here, I think'
  $text_node->length;            #  27
  $text_node->substringData(22); # 'think' 
  # etc.

DESCRIPTION

Top

This class implements the Text interface for HTML::DOM. It inherits from HTML::DOM::CharacterData, which inherits from HTML::DOM::Node.

METHODS

Top

HTML::DOM::Text's Own Methods

$text->splitText($offset)

Splits the node into two separate sibling text nodes at the given offset.

$text->splitText16($offset)

This is just like splitText except that the offset is given in UTF-16, rather than Unicode.

$text->nodeName

This returns '#text'.

$text->nodeType

This returns the constant HTML::DOM::Node::TEXT_NODE.

Inherited Methods

These are inherited from HTML::DOM::CharacterData:

data
length
length16
substringData
substringData16
appendData
insertData
insertData16
deleteData
deleteData16
replaceData
replaceData16
nodeValue

These are inherited from HTML::DOM::Node:

nodeValue
parentNode
childNodes
firstChild
lastChild
previousSibling
nextSibling
attributes
ownerDocument
insertBefore
replaceChild
removeChild
appendChild
hasChildNodes
cloneNode

SEE ALSO

Top

HTML::DOM

HTML::DOM::CharacterData

HTML::DOM::Node


HTML-DOM documentation Contained in the HTML-DOM distribution.
package HTML::DOM::Text;

use warnings;
use strict;

use HTML::DOM::Node qw 'TEXT_NODE ATTRIBUTE_NODE';

require HTML::DOM::CharacterData;

our @ISA = 'HTML::DOM::CharacterData';
our $VERSION = '0.048';



sub new { # $_[1] contains the text
	$_[0]->SUPER::new('~text', text => "$_[1]");
}

sub splitText {
	my($self,$setoff) = @_;
	my $new_node = __PACKAGE__->new(
		# subtstringData takes care of throwing the right errors
		$self->substringData($setoff)
	);
	$self->deleteData($setoff);
	$self->postinsert($new_node);
	$new_node;
}

sub splitText16 { # UTF-16 version
	my($self,$setoff) = @_;
	my $new_node = __PACKAGE__->new(
		$self->substringData16($setoff)
	);
	$self->deleteData16(($setoff,));
	$self->postinsert($new_node);
	$new_node;
}

# ---------------- NODE METHODS ---------- #

sub nodeName { '#text' }
*nodeType = \&TEXT_NODE;


# --------- OVERRIDDEN EVENT TARGET METHOD -------- #

sub trigger_event {
	my ($n,$evnt) = (shift,shift);
	my $p = $n->parent;
	$n->SUPER::trigger_event(
		$evnt,
		$p && $p->nodeType == ATTRIBUTE_NODE
		  ?(
			DOMCharacterDataModified_default =>sub {
				$_[0]->target->parent->_text_node_modified(
					$_[0]
				)
			},
		  ):(),
		@_,
	);
}

1
__END__