---
name: "Tree::Simple::Visitor::LoadClassHierarchy"
section: "3pm"
platform: "linux"
package: "libtree-simple-visitorfactory-perl"
version: "0.16-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Tree::Simple::Visitor::LoadClassHierarchy"
---

# Tree::Simple::Visitor::LoadClassHierarchy(3pm)

A Visitor for loading class hierarchies into a Tree::Simple hierarchy

## NAME

Tree::Simple::Visitor::LoadClassHierarchy - A Visitor for loading class hierarchies into a Tree::Simple hierarchy

## 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
```

## DESCRIPTION

This visitor will traverse a class's inheritance hierarchy (through the `@ISA` arrays) and create a Tree::Simple hierarchy which mirrors it.

## METHODS

- **new**

  There are no arguments to the constructor the object will be in its default state. You can use the `"setNodeFilter"` method to customize its behavior.

- **includeTrunk ($boolean)**

  Setting the `$boolean` value to true (`1`) will cause the node value of the `$tree` object passed into `"visit"` to be set with the root value found in the class hierarchy. Setting it to false (`0`), or not setting it, will result in the first value in the class hierarchy creating a new node level.

- **includeMethods ($boolean)**

  Setting the `$boolean` value to true (`1`) will cause methods to be added as a children of the class node. Setting it to false (`0`), or not setting it, will result in this not happening.

  **NOTE:** Methods are sorted ascii-betically before they are added to the tree. This allows a more predictable hierarchy.

- **setClass ($class)**

  The argument `$class` should be either a class name or an instance, it is then used as the root from which to determine the class hierarchy.

- **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 created, the `$filter_function` is passed the node value extracted from the hash prior to it being inserted into the tree being built. The `$filter_function` is expected to return the value desired for inclusion into the tree.

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

  The `$tree` argument which is passed to `"visit"` must be a leaf node. This is because this Visitor will create all the sub-nodes for this tree. If the tree is not a leaf, an exception is thrown. We do not require the tree to be a root though, and this Visitor will not affect any nodes above the `$tree` argument.

## TO DO

- Improve the "includeMethods" functionality

  I am not sure the tree this creates is the optimal tree for this situation. It is sufficient for now, until I have more of an *actual* need for this functionality.

- Add "includeFullSymbolTable" functionality

  This would traverse the full symbol tables and produce a detailed tree of everything it finds. This takes a lot more work, and as I have no current need for it, it remains in the TO DO list.

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

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

## AUTHOR

stevan little, \<stevan@iinteractive.com\>

## COPYRIGHT AND LICENSE

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.
