HTML::O...deFilter(3)
πΈ NAME πΈ
Okay so this is HTML::Object::DOM::NodeFilter β HTML Object DOM Node Filter. It's from the User Contributed Perl Documentation, and it's giving iconic reference-page energy. π
β¨ SYNOPSIS β¨
use HTML::Object::DOM::NodeFilter;
my $filter = HTML::Object::DOM::NodeFilter->new ||
die( HTML::Object::DOM::NodeFilter->error, "\n" );
π VERSION π
v0.2.0 β literally the version, bestie. π«Ά
π DESCRIPTION π
A NodeFilter interface represents an object used to filter the nodes in a HTML::Object::DOM::NodeIterator or a HTML::Object::DOM::::TreeWalker. (Yep, that's four colons in the original β I'm keeping it character-for-character, no cap. π) A NodeFilter knows nothing about the document or traversing nodes; it only knows how to evaluate a single node against the provided filter. It's giving single-responsibility icon. Periodt. β¨
π¦ PROPERTIES π¦
There are no properties. That's it. Zero. Nada. The vibe check is empty, and honestly? Obsessed with the simplicity. π¦
π₯ METHODS π₯
π acceptNode π
Returns an unsigned short that will be used to tell if a given Node must be accepted or not by the HTML::Object::DOM::NodeIterator or HTML::Object::DOM::TreeWalker iteration algorithm.
This method is expected to be written by the user of a NodeFilter. (You're the main character here, bestie. π) Possible return values are:
FILTER_ACCEPTβ value returned by theacceptNodemethod when a node should be accepted. Slay.FILTER_REJECTβ value to be returned by theacceptNodemethod when a node should be rejected. ForHTML::Object::DOM::TreeWalker, child nodes are also rejected. ForNodeIterator, this flag is synonymous withFILTER_SKIP.FILTER_SKIPβ value to be returned byacceptNodefor nodes to be skipped by theHTML::Object::DOM::NodeIteratororHTML::Object::DOM::TreeWalkerobject. The children of skipped nodes are still considered. This is treated as "skip this node but not its children".
Example:
use HTML::Object::DOM::NodeFilter qw( :all );
my $nodeIterator = $doc->createNodeIterator(
# Node to use as root
$doc->getElementById('someId'),
# Only consider nodes that are text nodes (nodeType 3)
SHOW_TEXT,
# Object containing the sub to use for the acceptNode method
# of the NodeFilter
{ acceptNode => sub
{
my $node = shift( @_ ); # also available as $_
# Logic to determine whether to accept, reject or skip node
# In this case, only accept nodes that have content other than whitespace
if( $node->data !~ /^\s*$/ )
{
return( FILTER_ACCEPT );
}
}
},
0 # false
);
# Show the content of every non-empty text node that is a child of root
my $node;
while( ( $node = $nodeIterator->nextNode() ) )
{
say( $node->data );
}
See also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/NodeFilter/acceptNode.
π CONSTANTS π
SHOW_ALL(4294967295) β shows all nodes. All of them. Ate.SHOW_ELEMENT(1) β shows Element nodes.SHOW_ATTRIBUTE(2) β shows attributeAttributenodes. This is meaningful only when creating aNodeIteratorwith anAttributenode as its root; in this case, it means that the attribute node will appear in the first position of the iteration or traversal. Since attributes are never children of other nodes, they do not appear when traversing over the document tree.SHOW_TEXT(4) β shows Text nodes.
Example:
use HTML::Object::DOM::NodeFilter qw( :all );
my $nodeIterator = $doc->createNodeIterator(
$doc->body,
SHOW_ELEMENT | SHOW_COMMENT | SHOW_TEXT,
{ acceptNode => sub{ return( FILTER_ACCEPT ); } },
0 # false
);
if( ( $nodeIterator->whatToShow & SHOW_ALL ) ||
( $nodeIterator->whatToShow & SHOW_COMMENT ) )
{
# $nodeIterator will show comments
}
SHOW_CDATA_SECTION(8) β will always return nothing, because there is no support for xml documents.SHOW_ENTITY_REFERENCE(16) β legacy, no more used. It's giving retired icon. πSHOW_ENTITY(32) β legacy, no more used.SHOW_PROCESSING_INSTRUCTION(64) β shows ProcessingInstruction nodes.SHOW_COMMENT(128) β shows Comment nodes.SHOW_DOCUMENT(256) β shows Document nodes.SHOW_DOCUMENT_TYPE(512) β showsDocumentTypenodes.SHOW_DOCUMENT_FRAGMENT(1024) β showsHTML::Object::DOM::DocumentFragmentnodes.SHOW_NOTATION(2048) β legacy, no more used.SHOW_SPACE(4096) β show Space nodes. This is a non-standard extension under this perl framework.
And for the callback control:
FILTER_ACCEPT(1)FILTER_REJECT(2)FILTER_SKIP(3)
π AUTHOR π
Jacques Deguest <jack@deguest.jp> β author icon. π
β SEE ALSO β
- Mozilla documentation:
https://developer.mozilla.org/en-US/docs/Web/API/NodeFilter - W3C specifications:
https://dom.spec.whatwg.org/#interface-nodefilter
π COPYRIGHT & LICENSE π
Copyright(c) 2022 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.
π That's the whole page, bestie. Source/version and date on deck: perl v5.42.2, 2026-02-15, and the manual is HTML::O...deFilter(3). Periodt. π
π¦ 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