Tree::...versal(3pm)
πΈ Tree::Simple::Visitor::BreadthFirstTraversal π
okay bestie, welcome to the <pink>Tree::...versal(3pm)</pink> page β yes that's the real abbreviated title, it's giving mysterious, it's giving main character. This is part of the User Contributed Perl Documentation, and it's about a visitor that walks your tree sideways-first. Let's get into it. π¦
β¨ NAME β¨
Tree::Simple::Visitor::BreadthFirstTraversal β a Visitor for breadth-first traversal of a Tree::Simple hierarchy. π
β¨ SYNOPSIS β¨
no cap, here's the whole vibe:
use Tree::Simple::Visitor::BreadthFirstTraversal;
# create an visitor
my $visitor = Tree::Simple::Visitor::BreadthFirstTraversal->new();
# pass our visitor to the tree
$tree->accept($visitor);
# print our results
print join ", " => $visitor->getResults();
# this will print this:
# 1, 2, 3, 1.1, 1.2, 2.1, 3.1, 1.1.1
# assuming your tree is like this:
# 1
# 1.1
# 1.1.1
# 1.2
# 2
# 2.1
# 3
# 3.1
see how it goes 1, then 2, then 3, then dips into the babies? that's the breadth-first moment. level by level, no skipping ahead, very organized of it. π
β¨ DESCRIPTION β¨
So this module implements a breadth-first traversal of a Tree::Simple hierarchy. If you're out here doing the built-in depth-first traversal from the Tree::Simple "traverse" method and you want a glow-up, this is the alternative. π
β¨ METHODS β¨
newβ there are no arguments to the constructor, so your object shows up in its default state. Want to customize how it behaves? That's what the"setNodeFilter"method is for, bestie. β¨includeTrunk ($boolean)β depending on what$booleansays, this tells the visitor whether to include the trunk of the tree in the traversal too. π«ΆsetNodeFilter ($filter_function)β this one takes a CODE reference as its$filter_functionargument, and it throws an exception if what you handed it isn't a code reference. That code reference filters the tree nodes as they get collected β perfect for customizing output, or for pulling specific info out of a more complicated tree node. The filter function should accept a single argument, which is the currentTree::Simpleobject. πvisit ($tree)β this is the method theTree::Simple"accept"method uses. You can also run it on its own, but it requires the$treeargument to be aTree::Simpleobject (or something derived from aTree::Simpleobject), and it will throw an exception otherwise. no exceptions... except the exception. πgetResultsβ returns the accumulated results of applying the node filter to the tree. the receipts, basically. π§Ύπ
β¨ Repository β¨
<https://github.com/ronsavage/Tree-Simple-VisitorFactory>
β¨ SUPPORT β¨
Got bugs? (not the cute kind π) Report them via the CPAN bug tracker at:
<https://github.com/ronsavage/Tree-Simple-VisitorFactory/issues>
β¨ CODE COVERAGE β¨
Peep the CODE COVERAGE section over in Tree::Simple::VisitorFactory for more info. π
β¨ SEE ALSO β¨
These Visitor classes are all subclasses of Tree::Simple::Visitor, which lives in the Tree::Simple module β so go refer to that module for more info. πΈ
β¨ AUTHOR β¨
stevan little, <stevan@iinteractive.com> β icon, legend, the moment. π«Ά
β¨ COPYRIGHT AND LICENSE β¨
Copyright 2004, 2005 by Infinity Interactive, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. π
and that's the whole page, bestie! this little doc is brought to you by perl v5.36.0, dated 2022-11-19 β so it's vintage but still slaying. now go traverse something, breadth-first, and text me when you're done. π¦πβ¨
π¦ where this page comes from
- debian bookworm: libtree-simple-visitorfactory-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtree-simple-visitorfactory-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtree-simple-visitorfactory-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtree-simple-visitorfactory-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtree-simple-visitorfactory-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms