Tree::...ndents(3pm)

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

πŸ’– NAME πŸ’–

okay so bestie, this is Tree::Simple::Visitor::GetAllDescendents β€” a whole Visitor whose entire job is fetching all the descendents of a Tree::Simple object. yes, all of them. the whole family tree. periodt. 🌳✨

(this page lives in the Tree::...ndents(3pm) corner of your man pages, iykyk πŸ’…)


✨ SYNOPSIS ✨

use Tree::Simple::Visitor::GetAllDescendents;

# create an instance of our visitor
my $visitor = Tree::Simple::Visitor::GetAllDescendents->new();

# pass the visitor to a Tree::Simple object
$tree->accept($visitor);

# you can also get the descendents
# back as an array of node values
my @descendents = $visitor->getDescendents();

# for more complex node objects, you can specify
# a node filter which will be used to extract the
# information desired from each node
$visitor->setNodeFilter(sub {
              my ($t) = @_;
              return $t->getNodeValue()->description();
              });

look at her go πŸ¦‹ that's literally the whole vibe right there.


🌸 DESCRIPTION 🌸

so basically: you hand this Visitor a Tree::Simple instance, and it will return all the descendents, recursively, all the way down the hierarchy. no cap, it goes down down. every branch, every leaf, the whole situation. πŸ”₯


πŸ’… METHODS πŸ’…

  • new β€” there are no arguments to the constructor, so the object just spawns in its default state, fresh-faced and ready. if you wanna customize how it behaves, that's what the setNodeFilter method is for. she's customizable but not demanding. πŸ’–
  • setTraversalMethod ($visitor) β€” by default we use Tree::Simple's built-in depth-first (pre-order) traverse method, which is iconic of her honestly. but if you desire the descendents to come back in a different ordering, bestie you can absolutely do that β€” just hand this method a $visitor object that implements that traversal type. see Tree::Simple::Visitor::BreadthFirstTraversal, Tree::Simple::Visitor::PreOrderTraversal and Tree::Simple::Visitor::PostOrderTraversal. pick your fighter. πŸŽ€
  • setNodeFilter ($filter_function) β€” this one accepts a CODE reference as its $filter_function argument, and it will throw an exception if you hand it something that is not a code reference. (not me handing it a string πŸ’€) the code reference filters the tree nodes as they're being collected β€” use it to customize output, or to gather specific info out of 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, keep it tight. ✨
  • visit ($tree) β€” this is the method Tree::Simple's accept method calls, but you can also use it on its own. it requires the $tree argument to be a Tree::Simple object (or something derived from a Tree::Simple object) β€” otherwise it will throw an exception. so like, be normal about it. 🫢
  • getAllDescendents β€” this method gives back an array of descendents in depth-first order (pre-order), or in whatever order you specified with setTraversalMethod. called in scalar context it gives you an array reference; called in list context it returns a regular array. this method is the exact same as calling getResults. two names, one queen. πŸ‘‘

🌈 Repository 🌈

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


πŸ“ SUPPORT πŸ“

bugs should be reported via the CPAN bug tracker at

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


🧚 CODE COVERAGE 🧚

see the CODE COVERAGE section in Tree::Simple::VisitorFactory for more info. the details live over there, go peek. πŸ’œ


⭐ SEE ALSO ⭐

these Visitor classes are all subclasses of Tree::Simple::Visitor, which can be found in the Tree::Simple module β€” refer to that module for more information. it's giving the parent module knows 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 one's running on perl v5.36.0 and it was last touched on 2022-11-19 β€” go forth and fetch those descendents, you absolute main character. πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from