Tree::...hToRoot(3pm)

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

πŸ’– Tree::Simple::Visitor::PathToRoot β€” the manual, but make it make sense πŸ’–

okay bestie, so this is Tree::Simple::Visitor::PathToRoot, a lil Perl module from the User Contributed Perl Documentation collection. it's a Visitor β€” and its whole personality is walking back up a Tree::Simple object to find the path to the root. that's it. that's the job. and it slays at it πŸ’…


✨ NAME ✨

Tree::Simple::Visitor::PathToRoot β€” A Visitor for finding the path back a Tree::Simple object's root


πŸŽ€ SYNOPSIS πŸŽ€

use Tree::Simple::Visitor::PathToRoot;

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

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

# now get the accumulated path as a string
# with the '/' character as the delimiter
print $visitor->getPathAsString("/");

# include the tree's trunk in your
# output as well
$visitor->includeTrunk();

# 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();
              });

# you can also get the path back as an array
my @path = $visitor->getPath();

no cap, that's the whole vibe right there πŸ¦‹


🌸 DESCRIPTION 🌸

hand it a Tree::Simple object and this Visitor goes full detective mode πŸ” β€” it finds the path back to the tree's root node. it's giving ancestry.com but for your data structure. iconic, honestly.


πŸ’… METHODS πŸ’…

  • new β€” constructor moment ✨ there are no arguments to it, so the object just shows up in its default state. you can then use the includeTrunk and setNodeFilter methods to customize its behavior. main character setup, fr fr.
  • includeTrunk ($boolean) β€” based on the value of $boolean, this tells the visitor to collect the trunk of the tree as well. yes, the trunk. like, the whole tree, not just the branches. πŸ’œ
  • setNodeFilter ($filter_function) β€” this method accepts a CODE reference as its $filter_function argument, and throws an exception if it is not a code reference 🚨. this code reference is used to filter the tree nodes as they are collected. use it to customize output, or to gather specific information from a more complex tree node. the filter function should accept a single argument, which is the current Tree::Simple object.
  • visit ($tree) β€” this is the method that gets used by Tree::Simple's accept method. it can also be used on its own β€” it requires the $tree argument to be a Tree::Simple object (or derived from a Tree::Simple object), and will throw and exception otherwise. so like… give it a real tree or it's gonna be dramatic about it 😭
  • getPath β€” this will return the collected path as an array, or in scalar context, as an array reference. pick your fighter πŸ’–
  • getPathAsString ($delimiter) β€” this will return the collected path as a string with the path elements joined by a $delimiter. if no $delimiter is specified, the default (', ') will be used. yes, comma-space. the default ate and left no crumbs πŸ“

πŸ’€ BUGS πŸ’€

None that I am aware of. Of course, if you find a bug, let me know, and I will be sure to fix it. (ngl that's a flex, but ok πŸ‘‘)


πŸ”₯ CODE COVERAGE πŸ”₯

See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more information.


🌈 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. iykyk β€” go read the parent module, bestie 🫢


πŸ’œ 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 a wrap on the PathToRoot lore, bestie. this page came to you from perl v5.36.0, dated 2022-11-19, and it lives under the manual name Tree::...hToRoot(3pm) 🌸 go find some roots, you've got this πŸ’–βœ¨
πŸ“¦ where this page comes from