Tree::...dArray(3pm)

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

🌸 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 the setNodeFilter and includTrunk methods. (yes bestie, includTrunk β€” that's how it's written here, no cap 😭)
  • includTrunk ($boolean) β€” set that $boolean to 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_function argument, 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_function gets 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's accept method calls. you can also run it on its own, but it needs the $tree argument 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 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 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