☺唐鳳☻
and 1 contributors

NAME

Tree - A basic n-ary tree

SYNOPSIS

  use Tree;
  
  my $root = Tree.new(:node<0>).add_children(
      Tree.new(:node<1>).add_children(
          Tree.new(:node<1.1>),
          Tree.new(:node<1.2>),
          Tree.new(:node<1.3>),                
      ),
      Tree.new(:node<2>).add_children(
          Tree.new(:node<2.1>).add_children(
              Tree.new(:node<2.1.1>).add_children(
                  Tree.new(:node<2.1.1.1)
              ),
              Tree.new(:node<2.1.2>),             
          )
      )        
  );
  
  $root.traverse(-> $t {
      say(('    ' x $t.depth()) ~ $t.node())
  });

DESCRIPTION

METHODS

new (Any ?$node) returns Tree
node ($self: Any ?$node) returns Any
depth returns Int
parent ($self: Tree ?$parent) returns Tree
is_root returns Bool
is_leaf returns Bool
child_count returns Int
add_child ($self: Tree $child) returns Tree
add_children ($self: *@children) returns Tree
get_child ($self: Int $index) returns Tree
get_all_children returns Array
traverse ($self: Code $func) returns Void

TODO

Write more docs
Convert more tests

A good amount of Tree::Simple's test will not be relevant though.

Create a Visitor class

This would also be a good use for Roles.

AUTHOR

stevan little, <stevan@iinteractive.com>

COPYRIGHT

Copyright (c) 2005. Stevan Little. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html