Tree::...versal(3pm)

πŸ“¦
version 0.16 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

🌸 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 $boolean says, 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_function argument, 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 current Tree::Simple object. πŸŽ€
  • visit ($tree) β€” this is the method the Tree::Simple "accept" method uses. You can also run it on its own, but it requires the $tree argument to be a Tree::Simple object (or something derived from a Tree::Simple object), 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 2004, 2005 by Infinity Interactive, Inc.

<http://www.iinteractive.com>

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