HTML::O...OM::Text(3)
π NAME
HTML::Object::DOM::Text β the HTML Object DOM Text Class, aka the literal text-node girlies of the DOM β¨
(that's HTML::O...OM::Text(3) in the shell, iykyk π«Ά)
β¨ SYNOPSIS
use HTML::Object::DOM::Text;
my $text = HTML::Object::DOM::Text->new( value => $some_text ) ||
die( HTML::Object::DOM::Text->error, "\n" );
π VERSION
v0.2.1
πΈ DESCRIPTION
okay so bestie, this one inherits from HTML::Object::Text and HTML::Object::DOM::CharacterData. that's it, that's the whole vibe π
π¦ INHERITANCE
the family tree, and it's giving royal lineage fr fr π:
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------------+ +-------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::CharacterData | --> | HTML::Object::DOM::Text |
+-----------------------+ +---------------------------+ +-------------------------+ +----------------------------------+ +-------------------------+
| ^
| |
v |
+-----------------------+ |
| HTML::Object::Text | -----------------------------------------------------------------------------------------------------------------+
+-----------------------+
π PROPERTIES
π assignedSlot
so normally this is a read-only property, but bestie, under perl you can set or get a HTML::Object::DOM::Element::Slot object associated with the element. iconic behavior honestly π
also see the Mozilla documentation at <https://developer.mozilla.org/en-US/docs/Web/API/Text/assignedSlot> π«Ά
π nodeValue
sets or gets the text value for this element. that's it. that's the whole job β¨
π wholeText
the read-only wholeText property of the HTML::Object::DOM::Text interface returns the full text of all Text nodes logically adjacent to the node. the text is concatenated in document order. this is the moment where you can point at literally any text node and get all the adjacent text back as one single string π§
it returns a string with the concanated text.
example time, look at her go:
<p id="favy">I like <span class="maybe-not">Shochu</span>, Dorayaki and Natto-gohan.</p>
$doc->getElementsByTagName('span')->[0]->remove;
# Now paragraph contains 2 text nodes:
# 'I like '
# ', Dorayaki and Natto-gohan.'
say $doc->getElementById('favy')->getFirstChild->wholeText;
# I like , Dorayaki and Natto-gohan.
also see the Mozilla documentation at <https://developer.mozilla.org/en-US/docs/Web/API/Text/wholeText> π
π₯ METHODS
π« getAttributes
returns an empty list in list context, or an empty array reference in scalar context. nothing to see here, she's empty on purpose, no cap π«Ά
π« getChildNodes
returns an empty list in list context, or an empty array reference in scalar context. same energy as above, okurrr β¨
π« getElementById
returns an empty list in list context, or undef in scalar context. she is not finding that element for you, bestie, it's a text node π
π« getFirstChild
returns an empty list in list context, or undef in scalar context.
π« getLastChild
returns an empty list in list context, or undef in scalar context. matching set with getFirstChild, we love consistency π
π« getParentNode
returns the parent node, if any. and honestly? sometimes there just isn't one, and that's valid π
π« getRootNode
returns the root node π
π« getValue
returns the text value of this comment, i.e. the text between <!-- and --> π
π« is_inside
provided with a node, this will return true if it is inside this text's parent or false otherwise. vibe check, but for node ancestry β¨
π« isAttributeNode
returns false. not her π
π« isCommentNode
returns true. wait, yes, true. that's what it says and we're not questioning the icon π
π« isElementNode
returns false. nope, she's a text girlie not an element girlie πΈ
π« isEqualNode
provided with another element object, and this returns true if both text element are the same, or false otherwise. twin check π
π« isNamespaceNode
returns false.
π« isPINode
returns false.
π« isProcessingInstructionNode
returns false.
π« isTextNode
returns true. FINALLY, her main character moment ππ
π« parent
set or get this text's parent node π«Ά
π« replaceWholeText
this method of the Text interface replaces the text of the node and all of its logically adjacent text nodes with the specified text. the replaced nodes are removed, except the current node. so she stays, everyone else gets evicted, periodt π
it returns the current node with the newly text set.
example, because the example ate:
<p id="favy">I like apple,<span class="and"> and</span> orange,<span class="and"> and</span> kaki</p>
$doc->getElementsByTagName('span')->foreach(sub
{
$_->remove;
});
# Now text is: I like apple, orange, kaki
# which are 3 text nodes
# Take the 2nd one (for example) and set a new text for it and its adjacent siblings
$doc->getElementById('favy')->getChildNodes->[1]->replaceWholeText( 'I like fruits' );
# Now the whole chunk has become:
# <p id="favy">I like fruits</p>
also see the Mozilla documentation at <https://developer.mozilla.org/en-US/docs/Web/API/Text/replaceWholeText> π¦
π« splitText
provided with an offset position and this method breaks the Text node into two nodes at the specified offset, keeping both nodes in the tree as siblings. it's giving scissors, but make it DOM βοΈβ¨
after the split, the current node contains all the content up to the specified offset point, and a newly created node of the same type contains the remaining text. the newly created node is returned to the caller. if the original node had a parent, the new node is inserted as the next sibling of the original node. if the offset is equal to the length of the original node, the newly created node has no data. (empty queen behavior, honestly π«Ά)
it returns the newly created Text node that contains the text after the specified offset point.
β οΈ heads up bestie: it returns anHTML::Object::IndexSizeErrorif the specifiedoffsetis greater than the size of the node's text. so like, don't do that π
example, this one is so good:
<p>foobar</p>
my $p = $doc->getElementsByTagName('p')->first;
# Get contents of <p> as a text node
my $foobar = $p->firstChild;
# Split 'foobar' into two text nodes, 'foo' and 'bar',
# and save 'bar' as a const
my $bar = $foobar->splitText(3);
# Create a <u> element containing ' new content '
my $u = $doc->createElement('u');
$u->appendChild( $doc->createTextNode( ' new content ' ) );
# Add <u> before 'bar'
$p->insertBefore( $u, $bar );
# The result is: <p>foo<u> new content </u>bar</p>
also see the Mozilla documentation at <https://developer.mozilla.org/en-US/docs/Web/API/Text/splitText> π
π« string_value
returns the content of the comment as a string. π
π« toString
returns the content of the comment as a string. (yes, same as string_value, they're matching, we love a coordinated fit π
)
πΈ AUTHOR
Jacques Deguest <jack@deguest.jp> β thank you icon π«Άβ¨
β SEE ALSO
- Mozilla documentation at <https://developer.mozilla.org/en-US/docs/Web/API/Text> π¦
π COPYRIGHT & LICENSE
Copyright(c) 2021 DEGUEST Pte. Ltd.
All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
okay that's the whole page bestie, you understood it perfectly, I'm so proud π₯Ήπ
β this was perl v5.42.2, dated 2026-02-15, and the manual name is HTML::O...OM::Text(3). mwah, go write some text nodes πΈππ
π¦ where this page comes from
- alpine 3.24: perl-html-object-doc 0.6.0-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms