Tree::...dArray(3pm)
π¦ NAME π¦
Tree::Simple::Visitor::FromNestedArray β a Visitor that literally builds Tree::Simple objects out of nested array trees. bestie. it converts. that's the whole job. π
β¨ SYNOPSIS β¨
use Tree::Simple::Visitor::FromNestedArray;
my $visitor = Tree::Simple::Visitor::FromNestedArray->new();
# given this nested array tree
my $array_tree = [
'Root', [
'Child1', [
'GrandChild1',
'GrandChild2'
],
'Child2'
]
];
# set the array tree we
# are going to convert
$visitor->setArrayTree($array_tree);
$tree->accept($visitor);
# this then creates the equivalent Tree::Simple object:
# Tree::Simple->new("Root")
# ->addChildren(
# Tree::Simple->new("Child1")
# ->addChildren(
# Tree::Simple->new("GrandChild1"),
# Tree::Simple->new("GrandChild2")
# ),
# Tree::Simple->new("Child2"),
# );
okay so like. you hand it a nested array situation and it hands you back the exact same shape as a Tree::Simple hierarchy. slay. π«Ά
πΈ DESCRIPTION πΈ
Give this Visitor a tree that was built out of nested arrays and it will construct the equivalent Tree::Simple hierarchy for you. no cap, that's it, that's the vibe. β¨
π METHODS π
newβ so there are no arguments to the constructor, the object just starts out in its default state. if you wanna customize how it behaves, you've gotsetNodeFilter,includTrunkandsetArrayTreefor that. pick your fighter. πincludTrunk ($boolean)β set$booleanto true (1) and the node value of the$treeobject you pass intovisitgets set with the root value found in the$array_tree. set it to false (0), or just don't set it at all, and the first value in the$array_treewill create a new node level instead. your call bestie. πsetNodeFilter ($filter_function)β this one takes aCODEreference as its$filter_functionargument and throws an exception if it's not a code reference, so don't try it. π that code reference is what filters the tree nodes as they get created:$filter_functiongets handed the node value pulled out of the array before it gets inserted into the tree being built, and it's expected to return the value you actually want going into the tree. yes this is the glow-up phase. πsetArrayTree ($array_tree)β this is how you set the$array_treethat ourTree::Simplehierarchy is gonna be constructed from. it has to be in exactly this form:
[
'Root', [
'Child1', [
'GrandChild1',
'GrandChild2'
],
'Child2'
]
]
basically, every element in the array counts as a node β unless it's an array reference, in which case it's interpreted as holding the children of the node created from the previous element in the array. iykyk. π¦
the tree gets validated before it's accepted, and if it fails validation an exception will be thrown. the rules are as follows:
- the array tree must not be empty. it makes not sense to create a tree out of nothing, so it is assumed that this is a sign of something wrong. like girl. where's the tree. π
- all nodes of the array tree must not be array references. the root node is validated against this in this function, but all subsequent nodes are checked as the tree is built. any nodes found to be array references are rejected and an exception is thrown. if you desire your node values to be array references, you can use the node filtering mechanism to achieve this as the node is filtered after it is validated. loophole unlocked π₯
- the array tree must be a single rooted tree. if there is a second element in the array tree, it is assumed to be the children of the root, and therefore must be in the form of an array reference. one root, one queen, periodt π
visit ($tree)β this is the method that theTree::Simpleacceptmethod uses. it can also be used on its own, it just requires the$treeargument to be aTree::Simpleobject (or something derived from aTree::Simpleobject), and will throw and exception otherwise. so like, give it a real tree or get out. π
π 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. not me being confident about it π
π CODE COVERAGE π
see the CODE COVERAGE section in Tree::Simple::VisitorFactory for more information. go read it bestie. π
π 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. the mothership, fr fr. π
π 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.
okay that's the whole page, and that's a wrap, mwah π β this was perl v5.36.0, dated 2022-11-19, Tree::...dArray(3pm), and she ate, no crumbs. bye bestie! πβ¨π¦
π¦ 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