Tree::...versal(3pm)

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

πŸ’– Tree::Simple::Visitor::PreOrderTraversal πŸ’–

okay bestie, so this is the manual page for Tree::Simple::Visitor::PreOrderTraversal, which lives in the Tree::...versal(3pm) slot of your perl docs. yes the name got squished, it's giving "my username got truncated in the group chat" energy, we move. πŸŽ€


✨ NAME ✨

Tree::Simple::Visitor::PreOrderTraversal β€” it's a Visitor that does a pre-order traversal of a Tree::Simple hierarchy. that's the whole job. she's focused. she's booked. πŸ’…


🌸 SYNOPSIS 🌸

use Tree::Simple::Visitor::PreOrderTraversal;

# create an visitor
my $visitor = Tree::Simple::Visitor::PreOrderTraversal->new();

# pass our visitor to the tree
$tree->accept($visitor);

# print our results
print join ", " => $visitor->getResults();

# this will print this:
#   1 1.1 1.1.1 1.2 2 2.1 3 3.1
# assuming your tree is like this:
#   1
#     1.1
#       1.1.1
#     1.2
#   2
#     2.1
#   3
#     3.1

look at that little tree grow πŸ¦‹ lowkey beautiful. (yes, the comment in the original says "create an visitor", we're keeping it exactly, that's a heritage artifact, no cap.)


🌈 DESCRIPTION 🌈

okay so pre-order traversal is a depth-first traversal method where the sub-tree's are processed after the parent. literally the parent goes first, always, main character energy, the kids follow. πŸ’…

ngl it's essentially just a wrapper around the base Tree::Simple::Visitor class β€” this module exists separately here purely for completeness. and honestly? iconic reasoning. if you've got a post-order, you should have a pre-order too. periodt. 🫢


πŸŽ€ METHODS πŸŽ€

  • new β€” there are no arguments to the constructor, so the object just vibes in its default state. you can use the setNodeFilter method later to customize its behavior. she's chill like that. 😌
  • includeTrunk ($boolean) β€” based on the value of $boolean, this tells the visitor whether to include the trunk</> of the tree in the traversal as well. yes, the trunk. the whole root situation. sometimes you want the whole thing, sometimes you don't, and that's between you and your $boolean. πŸ“
  • setNodeFilter ($filter_function) β€” this one takes a CODE reference as its $filter_function argument, and it will throw an exception if it's not a code reference. like, she will not be playing with you. 😀 the code ref gets used to filter the tree nodes as they're collected, so you can customize output, or gather specific info from a more complex tree node. the filter function should accept a single argument, which is the current Tree::Simple object. one arg. that's it. she doesn't want more. πŸ™ˆ
  • visit ($tree) β€” this is the method that Tree::Simple's accept method calls behind the scenes. you can also just use it on its own if you're feeling independent ✨. it requires the $tree argument to be a Tree::Simple object (or something derived from a Tree::Simple object), and it will throw and exception otherwise β€” that's right, an exception, and yes the original page says "and exception", we're not fixing it, we're preserving it, that's the vibe. πŸ’€
  • getResults β€” returns the accumulated results of the node filter being applied to the tree. the receipts. the haul. the final answer. πŸ‘‘

πŸ”₯ Repository πŸ”₯

<https://github.com/ronsavage/Tree-Simple-VisitorFactory>

go look. star it. it's free. 🌟


πŸ’œ SUPPORT πŸ’œ

bugs should be reported via the CPAN bug tracker at

<https://github.com/ronsavage/Tree-Simple-VisitorFactory/issues>

found a bug? report it, bestie. don't just suffer in silence, that's not the vibe. 🫢


⭐ CODE COVERAGE ⭐

see the CODE COVERAGE section in Tree::Simple::VisitorFactory for more information. iykyk. πŸ‘€


🧚 SEE ALSO 🧚

these Visitor classes are all subclasses of Tree::Simple::Visitor, which can be found in the Tree::Simple module. you should refer to that module for more information. go read the parent class, she raised them all. πŸ‘‘


🌸 AUTHOR 🌸

stevan little, <stevan@iinteractive.com>


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 doc came from perl v5.36.0, dated 2022-11-19 β€” vintage but still serving looks. mwah πŸ’‹ go traverse some trees. 🌳✨

πŸ“¦ where this page comes from