Tree::...hToRoot(3pm)
π 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 theincludeTrunkandsetNodeFiltermethods 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 aCODEreference as its$filter_functionargument, 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 currentTree::Simpleobject.visit ($tree)β this is the method that gets used byTree::Simple'sacceptmethod. it can also be used on its own β it requires the$treeargument to be aTree::Simpleobject (or derived from aTree::Simpleobject), 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$delimiteris 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 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 a wrap on thePathToRootlore, bestie. this page came to you fromperl v5.36.0, dated2022-11-19, and it lives under the manual nameTree::...hToRoot(3pm)πΈ go find some roots, you've got this πβ¨
π¦ 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