Tree::...erarchy(3pm)

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

πŸ’– NAME πŸ’–

Tree::Simple::Visitor::LoadClassHierarchy β€” bestie, it's a Visitor that loads class hierarchies into a Tree::Simple hierarchy. That's the whole vibe. ✨

This page lives in the User Contributed Perl Documentation corner of the manual-verse, and yes we're calling it Tree::...erarchy(3pm) because that's what the header said and I'm not gonna lie to you. 🫢


✨ SYNOPSIS ✨

use Tree::Simple::Visitor::LoadClassHierarchy;

# create an visitor
my $visitor = Tree::Simple::Visitor::LoadClassHierarchy->new();

# set class as an instance, or
$visitor->setClass($class);

# as a package name
$visitor->setClass("My::Class");

# pass our visitor to the tree
$tree->accept($visitor);

# the $tree now mirrors the inheritance hierarchy of the $class
no cap, that last comment is literally the entire point of this module. the $tree is giving the class's whole family tree after this runs. πŸ‘‘

🌸 DESCRIPTION 🌸

So this visitor walks a class's inheritance hierarchy β€” it goes through the @ISA arrays, okay β€” and builds a Tree::Simple hierarchy that mirrors it. It's giving genealogy but for packages. 🧚


πŸ’… METHODS πŸ’…

  • new β€” there are no arguments to the constructor, so the object just chills in its default state. If you wanna customize how it behaves, you use the setNodeFilter method. That's it, that's the whole thing. πŸŽ€
  • includeTrunk ($boolean) β€” set that $boolean to true (1) and the node value of the $tree object you passed into visit gets set with the root value found in the class hierarchy. Set it to false (0), or just don't set it at all, and the first value in the class hierarchy creates a new node level instead. pick your fighter bestie πŸ’…
  • includeMethods ($boolean) β€” set $boolean to true (1) and methods get added as children of the class node. Set it to false (0), or don't set it, and that just... doesn't happen. simple as. ✨
NOTE: Methods are sorted ascii-betically before they're added to the tree. That's on purpose β€” it makes for a more predictable hierarchy. sorted = slay. πŸ“
  • setClass ($class) β€” the argument $class should be either a class name or an instance. Either one works. It's then used as the root from which to determine the class hierarchy. main character of the tree, honestly. πŸ‘‘
  • setNodeFilter ($filter_function) β€” this method takes a CODE reference as its $filter_function argument, and it throws an exception if it is not a code reference. (rude, but fair.) This code reference filters the tree nodes as they're created: the $filter_function gets passed the node value extracted from the hash <before> it gets inserted into the tree being built. The $filter_function is expected to return the value you actually want included in the tree. so like, you're the stylist and it's the fit check πŸŽ€
  • visit ($tree) β€” this is the method that Tree::Simple's accept method calls. You can also run it on its own, no problem. It requires the $tree argument to be a Tree::Simple object (or derived from one), and it'll throw an exception otherwise. πŸ’€

The $tree argument passed to visit must be a leaf node. Why? Because this Visitor is gonna create all the sub-nodes for this tree. If the tree is not a leaf, an exception gets thrown. We do not require the tree to be a root though β€” and this Visitor will not affect any nodes above the $tree argument. so it stays in its lane, respectfully. 🫢


πŸ¦‹ TO DO πŸ¦‹

  • Improve the includeMethods functionality β€” the author isn't sure the tree this creates is the optimal tree for this situation. It's sufficient for now, until there's more of an actual need for this functionality. it's giving we'll circle back. 😭
  • Add includeFullSymbolTable functionality β€” this would traverse the full symbol tables and produce a detailed tree of everything it finds. That takes a lot more work, and since there's no current need for it, it remains on the TO DO list. iconic behaviour honestly. πŸ’€

πŸ“¦ 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>


🌈 CODE COVERAGE 🌈

See the CODE COVERAGE section in Tree::Simple::VisitorFactory for more information. iykyk. ✨


πŸ’œ 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. bestie it's literally the parent. go say hi. πŸŽ€


πŸ‘‘ 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 that's the whole page, you ate it, periodt. πŸ’…βœ¨ this was perl v5.36.0, dated 2022-11-19, and yes the footer tried to call this thing Tree::...erarchy(3pm) again β€” we love a consistent brand. bye bestie, go build a tree πŸ¦‹πŸ’–

πŸ“¦ where this page comes from