Tree::...actory(3pm)
π Tree::Simple::VisitorFactory π
okay bestie, so this is a page from the User Contributed Perl Documentation β it's Tree::Simple::VisitorFactory(3pm), and it's literally the little vending machine that hands you Visitor objects so you don't have to type out their giant class names. slay. let's get into it π«Ά
β¨ NAME β¨
Tree::Simple::VisitorFactory β a factory object for dispensing Visitor objects π
πΈ SYNOPSIS πΈ
use Tree::Simple::VisitorFactory;
my $tf = Tree::Simple::VisitorFactory->new();
my $visitor = $tf->get("PathToRoot");
# or call it as a class method
my $visitor = Tree::Simple::VisitorFactory->getVisitor("PathToRoot");
π DESCRIPTION π
So, this object is literally just a factory for dispensing Tree::Simple::Visitor::* objects. that's the whole vibe. and ngl, you are not required to use this package to use all the Visitors β it's just a kinda convenient way to avoid typing out their long class names. it's giving "I'm doing this for your own good" energy π
The author considered making this a Singleton, but did not, because some people might not want that. and fr fr, the author knows they're very picky about using Singletons, especially in multiprocess environments like mod_perl. so instead they implemented the smallest instance they knew how to, and made sure all the other methods could be called as class methods too. iconic, honestly. π
π¦ METHODS π¦
newβ Returns a minimal instance of this object, basically just a reference back to the package (literally, see the source if you care π).get ($visitor_type)β Attempts to load the$visitor_typeand returns an instance of it if successful. If no$visitor_typeis specified, an exception is thrown; if$visitor_typefails to load, an exception is thrown. so like, you will be told, no silent suffering here πgetVisitor ($visitor_type)β This is an alias of"get". same thing, different name, both ate.
π AVAILABLE VISITORS π
This distribution provides a number of Visitor objects which can be loaded just by giving their name. Below is a description of the available Visitors and a sort description of what they do. The author attempted to classify the Visitors into groups which are related to their use. π
This factory will load any module contained inside the Tree::Simple::Visitor::* namespace. Given a name, it will attempt to "require" the module Tree::Simple::Visitor::<Name>.pm. This means other people can create Visitors which can be accessed with this factory without needing to include them in this distribution. bestie-friendly design, we love to see it π«Ά
π Search/Path Related Visitors π
PathToRootβ Given aTree::Simpleobject, this Visitor will find the path back to the tree's root node. like a lil "take me home" button πFindByPathβ Given a path andTree::Simplehierarchy, this Visitor will attempt to find the node specified by the path.FindByUIDβ Given a UID andTree::Simplehierarchy, this Visitor will attempt to find the node with the same UID.FindByNodeValueβ Given a node value andTree::Simplehierarchy, this Visitor will attempt to find the node with the same node value.
πΆ Traversal Visitors πΆ
BreadthFirstTraversalβ This implements a breadth-first traversal of aTree::Simplehierarchy.PostOrderTraversalβ Post-order traversal is a variation of the depth-first traversal in which the sub-tree's are processed before the parent.PreOrderTraversalβ Pre-order traversal is a depth-first traversal method in which the sub-tree's are processed after the parent.
ποΈ FileSystem Visitors ποΈ
LoadDirectoryTreeβ This visitor can be used to load a directory tree into aTree::Simplehierarchy.CreateDirectoryTreeβ This visitor can be used to create a set of directories and files from aTree::Simpleobject hierarchy.
π Conversion Visitors π
FromNestedArrayβ Given a tree constructed from nested arrays, this Visitor will create the equivalentTree::Simplehierarchy.ToNestedArrayβ Given aTree::Simplehierarchy, this Visitor will create the equivalent tree constructed from nested arrays.FromNestedHashβ Given a tree constructed from nested hashs, this Visitor will create the equivalentTree::Simplehierarchy.ToNestedHashβ Given aTree::Simplehierarchy, this Visitor will create the equivalent tree constructed from nested hashes.
πͺ Reflective Visitors πͺ
LoadClassHierarchyβ Given a class name or instance, this Visitor will create aTree::Simplehierarchy which models the classes inheritance hierarchy. it's giving mirror, mirror πͺβ¨
π² Misc. Visitors π²
GetAllDescendentsβ Given aTree::Simpleinstance this Visitor will return all the descendents recursively on down the hierarchy.Sortβ This implements a multi-level sort of aTree::Simplehierarchy.VariableDepthCloneβ A Visitor for cloning parts ofTree::Simplehierarchy.
π BUGS π
None that the author is aware of. Of course, if you find a bug, let them know, and they will be sure to fix it. so like, speak up bestie, they're listening π«Ά
π CODE COVERAGE π
The author uses Devel::Cover to test the code coverage of the tests, and below is the Devel::Cover report on this module test suite. look at those numbers, not a single 100.0-less total in sight for stmt/pod π₯
-------------------------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt branch cond sub pod time total
-------------------------------------------- ------ ------ ------ ------ ------ ------ ------
Tree/Simple/VisitorFactory.pm 100.0 100.0 n/a 100.0 100.0 0.4 100.0
Tree/Simple/Visitor/BreadthFirstTraversal.pm 100.0 100.0 66.7 100.0 100.0 2.5 96.3
Tree/Simple/Visitor/PostOrderTraversal.pm 100.0 100.0 77.8 100.0 100.0 1.7 96.3
Tree/Simple/Visitor/PreOrderTraversal.pm 100.0 n/a 33.3 100.0 100.0 0.7 90.5
Tree/Simple/Visitor/CreateDirectoryTree.pm 100.0 85.7 86.7 100.0 100.0 3.4 95.8
Tree/Simple/Visitor/LoadClassHierarchy.pm 100.0 73.1 33.3 100.0 100.0 4.9 89.2
Tree/Simple/Visitor/LoadDirectoryTree.pm 100.0 89.3 85.2 100.0 100.0 26.1 94.7
Tree/Simple/Visitor/FindByNodeValue.pm 100.0 100.0 86.7 100.0 100.0 3.1 98.3
Tree/Simple/Visitor/FindByPath.pm 100.0 100.0 66.7 100.0 100.0 1.2 97.9
Tree/Simple/Visitor/FindByUID.pm 100.0 100.0 86.7 100.0 100.0 2.9 98.3
Tree/Simple/Visitor/GetAllDescendents.pm 100.0 100.0 77.8 100.0 100.0 2.3 97.1
Tree/Simple/Visitor/PathToRoot.pm 100.0 87.5 75.0 100.0 100.0 0.8 95.1
Tree/Simple/Visitor/Sort.pm 100.0 100.0 77.8 100.0 100.0 8.8 98.1
Tree/Simple/Visitor/ToNestedArray.pm 100.0 100.0 66.7 100.0 100.0 1.5 96.5
Tree/Simple/Visitor/ToNestedHash.pm 100.0 100.0 66.7 100.0 100.0 1.4 96.5
Tree/Simple/Visitor/FromNestedArray.pm 100.0 94.4 81.8 100.0 100.0 8.1 96.6
Tree/Simple/Visitor/FromNestedHash.pm 100.0 91.7 77.8 100.0 100.0 4.8 95.9
Tree/Simple/Visitor/VariableDepthClone.pm 100.0 100.0 66.7 100.0 100.0 25.5 97.3
-------------------------------------------- ------ ------ ------ ------ ------ ------ ------
Total 100.0 93.8 76.3 100.0 100.0 100.0 96.1
-------------------------------------------- ------ ------ ------ ------ ------ ------ ------
π SEE ALSO π
These Visitor classes are meant to work with Tree::Simple hierarchies, so you should refer to that module for more information. go read it, it's the main character of this whole situation π
π 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>
π AUTHOR π
stevan little, <stevan@iinteractive.com>
Ron Savage <ron@savage.net.au> has taken over maintenance as of V 0.11.
π 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 the whole page bestie π this was documented for perl v5.36.0 and the date on it is 2022-11-19 β go forth and dispense some Visitors, you absolute icon πβ¨π
π¦πΈ
π¦ 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