.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Forest::Tree 3pm" .TH Forest::Tree 3pm "2022-06-14" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Forest::Tree \- An n\-ary tree .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Forest::Tree; \& \& my $t = Forest::Tree\->new( \& node => 1, \& children => [ \& Forest::Tree\->new( \& node => 1.1, \& children => [ \& Forest::Tree\->new(node => 1.1.1), \& Forest::Tree\->new(node => 1.1.2), \& Forest::Tree\->new(node => 1.1.3), \& ] \& ), \& Forest::Tree\->new(node => 1.2), \& Forest::Tree\->new( \& node => 1.3, \& children => [ \& Forest::Tree\->new(node => 1.3.1), \& Forest::Tree\->new(node => 1.3.2), \& ] \& ), \& ] \& ); \& \& $t\->traverse(sub { \& my $t = shift; \& print((\*(Aq \*(Aq x $t\->depth) . ($t\->node || \*(Aq\eundef\*(Aq) . "\en"); \& }); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module is a basic n\-ary tree, it provides most of the functionality of Tree::Simple, whatever is missing will be added eventually. .PP This class inherits from Forest::Tree::Pure>, but all shared methods and attributes are documented in both classes. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" .IP "\fInode\fR" 4 .IX Item "node" .PD 0 .IP "\fIuid\fR" 4 .IX Item "uid" .IP "\fIparent\fR" 4 .IX Item "parent" .RS 4 .IP "\fBparent\fR" 4 .IX Item "parent" .IP "\fB_set_parent\fR" 4 .IX Item "_set_parent" .IP "\fBhas_parent\fR" 4 .IX Item "has_parent" .IP "\fBclear_parent\fR" 4 .IX Item "clear_parent" .RE .RS 4 .RE .IP "\fIchildren\fR" 4 .IX Item "children" .RS 4 .IP "\fBget_child_at ($index)\fR" 4 .IX Item "get_child_at ($index)" .PD Return the child at this position. (zero-base index) .IP "\fBchild_count\fR" 4 .IX Item "child_count" Returns the number of children this tree has .RE .RS 4 .RE .IP "\fIsize\fR" 4 .IX Item "size" .RS 4 .PD 0 .IP "\fBsize\fR" 4 .IX Item "size" .IP "\fBhas_size\fR" 4 .IX Item "has_size" .IP "\fBclear_size\fR" 4 .IX Item "clear_size" .RE .RS 4 .RE .IP "\fIheight\fR" 4 .IX Item "height" .RS 4 .IP "\fBheight\fR" 4 .IX Item "height" .IP "\fBhas_height\fR" 4 .IX Item "has_height" .IP "\fBclear_height\fR" 4 .IX Item "clear_height" .RE .RS 4 .RE .PD .SH "METHODS" .IX Header "METHODS" .IP "\fBis_root\fR" 4 .IX Item "is_root" True if the current tree has no parent .IP "\fBis_leaf\fR" 4 .IX Item "is_leaf" True if the current tree has no children .IP "\fBdepth\fR" 4 .IX Item "depth" Return the depth of this tree. Root has a depth of \-1 .IP "\fBadd_child ($child)\fR" 4 .IX Item "add_child ($child)" .PD 0 .IP "\fBadd_children (@children)\fR" 4 .IX Item "add_children (@children)" .PD Add a new child. The \f(CW$child\fR must be a \f(CW\*(C`Forest::Tree\*(C'\fR .IP "\fBinsert_child_at ($index, \f(CB$child\fB)\fR" 4 .IX Item "insert_child_at ($index, $child)" Insert a child at this position. (zero-base index) .IP "\fBremove_child_at ($index)\fR" 4 .IX Item "remove_child_at ($index)" Remove the child at this position. (zero-base index) .IP "\fBtraverse (\e&func)\fR" 4 .IX Item "traverse (&func)" Takes a reference to a subroutine and traverses the tree applying this subroutine to every descendant. .IP "\fBsiblings\fR" 4 .IX Item "siblings" Returns an array reference of all siblings (not including us) .IP "\fBto_pure_tree\fR" 4 .IX Item "to_pure_tree" Invokes \f(CW\*(C`reconstruct_with_class\*(C'\fR with Forest::Tree::Pure. .IP "\fBto_mutable_tree\fR" 4 .IX Item "to_mutable_tree" Returns the invocant (without cloning). .IP "\fBclone\fR" 4 .IX Item "clone" See \*(L"clone\*(R" in Forest::Tree::Pure. .Sp This variant will \fBnot\fR clone the parent, but return a clone of the subtree that is detached. .IP "\fBget_index_in_siblings\fR" 4 .IX Item "get_index_in_siblings" Returns the index of the tree in the list of children. .Sp Equivalent to calling \f(CW\*(C`$tree\-\*(C'\fRparent\->get_child_index($tree)>. .Sp Returns \-1 if the node has no parent (the root node). .SH "BUGS" .IX Header "BUGS" All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. .SH "AUTHOR" .IX Header "AUTHOR" Stevan Little .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 2008\-2014 Infinity Interactive, Inc. .PP .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.