Tree::...tedHash(3pm)
πΈ 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 thesetNodeFilterandincludTrunkmethods to customize its behavior. (yes, that spelling. it'sincludTrunk. we keep it exactly, no touching π)includTrunk ($boolean)β setting the$booleanvalue 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_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 placed into the hash tree. the$filter_functionis passed aTree::Simpleobject, 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'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 if$treeis not aTree::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 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 so final thing bestie: this whole page came fromperl v5.36.0dated2022-11-19, and that's the tea. πβ¨ go make some nested hashes, you absolute main character. periodt. π π
π¦ 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