Tree::...dArray(3pm)
πΈ NAME πΈ
Tree::Simple::Visitor::ToNestedArray β a Visitor bestie that takes your Tree::Simple objects and turns them into nested array trees π
β¨ SYNOPSIS β¨
use Tree::Simple::Visitor::ToNestedArray;
my $visitor = Tree::Simple::Visitor::ToNestedArray->new();
# given this Tree::Simple tree
my $tree = Tree::Simple->new("Root")
->addChildren(
Tree::Simple->new("Child1")
->addChildren(
Tree::Simple->new("GrandChild1"),
Tree::Simple->new("GrandChild2")
),
Tree::Simple->new("Child2"),
);
# include the trunk (Root)
$visitor->includeTrunk(1);
# visit the tree
$tree->accept($visitor);
my $array_tree = $visitor->getResults();
# this then creates the equivalent nested array tree:
# [
# 'Root', [
# 'Child1', [
# 'GrandChild1',
# 'GrandChild2'
# ],
# 'Child2'
# ]
# ]
# if you don't include the trunk (Root) then ...
$tree->accept($visitor);
my $array_tree = $visitor->getResults();
# this then creates the following nested array tree:
# [
# 'Child1', [
# 'GrandChild1',
# 'GrandChild2'
# ],
# 'Child2'
# ]
π¦ DESCRIPTION π¦
okay so picture this: you already have a tree built out of a Tree::Simple hierarchy. this Visitor literally just makes you the equivalent tree of nested arrays. that's it, that's the whole vibe. same shape, array edition. slay π
π METHODS π
newβ there are no arguments to the constructor, so your object just chills in its default state. wanna customize its behavior? use thesetNodeFilterandincludTrunkmethods. (yes bestie,includTrunkβ that's how it's written here, no cap π)includTrunk ($boolean)β set that$booleanto true (1) and the node value of the tree's root gets included in the nested array output. set it to false and it does the exact opposite. root in or root out, your call πsetNodeFilter ($filter_function)β this one takes a CODE reference as its$filter_functionargument, and if you hand it literally anything that is not a code reference it throws an exception, periodt. that code reference filters the tree nodes as they get placed into the array tree. your$filter_functiongets passed a Tree::Simple object, and it's expected to return the value you want included in the array tree. πvisit ($tree)β the method Tree::Simple'sacceptmethod calls. you can also run it on its own, but it needs the$treeargument to be a Tree::Simple object (or derived from one) β otherwise it throws an exception, no exceptions π€getResultsβ hands you back the array tree that got constructed. that's the payoff, bestie β¨
π 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>
fr fr, if something's broken, tell them β don't just suffer in silence π
π§ CODE COVERAGE π§
see the CODE COVERAGE section in Tree::Simple::VisitorFactory for more info. go look, iykyk πΈ
β SEE ALSO β
these Visitor classes are all subclasses of Tree::Simple::Visitor, which lives in the Tree::Simple module β so you should refer to that module for more information. family tree of modules, iconic π
π 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 bestie π this page was served up by perl v5.36.0, dated 2022-11-19, and the manual name it was filed under is Tree::...dArray(3pm) (yes, the header truncates it like that, we don't make the rules π). go build some nested arrays, you absolute main character π¦β¨
π¦ 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