Tree::...tedHash(3pm)

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

🌸 Tree::Simple::Visitor::ToNestedHash πŸ’–

okay so bestie, this page is from the Tree::...tedHash(3pm) manual, and it's literally all about turning your Tree::Simple object into a nested hash tree. no cap, it's giving "glow up for your data structure". let's go πŸ’…


✨ NAME ✨

Tree::Simple::Visitor::ToNestedHash β€” A Visitor for creating nested hash trees from Tree::Simple objects.

like. that's the whole job. a visitor that makes nested hashes out of Tree::Simple objects. iconic behavior fr fr πŸ¦‹


✨ SYNOPSIS ✨

use Tree::Simple::Visitor::ToNestedHash;

my $visitor = Tree::Simple::Visitor::ToNestedHash->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"),
              );

$tree->accept($visitor);

my $array_tree = $visitor->getResults();

# this then creates the equivalent nested array tree:
# {
# Root => {
#         Child1 => {
#                 GrandChild1 => {},
#                 GrandChild2 => {}
#                 },
#         Child2 => {}
#         }
# }

so you build a $visitor, you build a tree, you let the tree accept the visitor, and then getResults hands you back the nested hash situation. and yes bestie, the comment literally says my $array_tree even though it's a hash tree β€” we do not fix what the original wrote, we simply respect it πŸ™ˆ


✨ DESCRIPTION ✨

Given a tree constructed from a Tree::Simple hierarchy, this Visitor will create the equivalent tree of nested hashes.

that's it. that's the vibe. tree goes in, nested hash tree comes out. πŸŽ€


✨ METHODS ✨

  • new β€” there are no arguments to the constructor, the object will be in its default state. you can use the setNodeFilter and includTrunk methods to customize its behavior. (yes, that spelling. it's includTrunk. we keep it exactly, no touching πŸ‘‘)
  • includTrunk ($boolean) β€” setting the $boolean value to true (1) will cause the node value of the tree's root to be included in the nested hash output, setting it to false will do the opposite. so like, do you want the trunk or not. that's the whole question 🌳
  • 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 placed into the hash tree. the $filter_function is passed a Tree::Simple object, and is expected to return the value desired for inclusion into the hash tree.
bestie listen. if you hand it something that is NOT a code ref, it throws an exception. do not test it. or do, but expect drama. πŸ’€
  • visit ($tree) β€” this is the method that is 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 if $tree is not a Tree::Simple (or something derived from one), it throws an exception. fr fr. it's very strict and honestly? same energy. 🫢
  • getResults β€” this method will return the hash tree constructed. boom. that's your output. that's the whole finale. ✨

🌈 Repository 🌈

<https://github.com/ronsavage/Tree-Simple-VisitorFactory>

go look at it. it's right there. ⭐


πŸ’œ SUPPORT πŸ’œ

Bugs should be reported via the CPAN bug tracker at

<https://github.com/ronsavage/Tree-Simple-VisitorFactory/issues>

if something's broken, tell the tracker, not me. i'm just the messenger πŸ’Œ


🧚 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.

like, if you want the lore, that's where the lore lives πŸ“š


πŸ‘‘ 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.


okay so final thing bestie: this whole page came from perl v5.36.0 dated 2022-11-19, and that's the tea. πŸ“βœ¨ go make some nested hashes, you absolute main character. periodt. πŸ’…πŸ’–
πŸ“¦ where this page comes from