1Text::Tree(3)         User Contributed Perl Documentation        Text::Tree(3)
2
3
4

NAME

6       Text::Tree - format a simple tree of strings into a textual tree graph
7

SYNOPSIS

9           use Text::Tree;
10
11           my $tree = new Text::Tree( "root",
12                                      [ "left\nnode" ],
13                                      [ "right", [ "1" ], [ "2" ] ] );
14           print $tree->layout("boxed");
15
16           __OUTPUT__
17
18               +----+
19               ⎪root⎪
20               +----+
21             .---^---.
22           +----+ +-----+
23           ⎪left⎪ ⎪right⎪
24           ⎪node⎪ +-----+
25           +----+  .-^-.
26                  +-+ +-+
27                  ⎪1⎪ ⎪2⎪
28                  +-+ +-+
29

METHODS

31       new()
32
33           my $tree = new Text::Tree( "label",
34                                      [ "left child label", [ ... ] ],
35                                      [ "right child label", [ ... ] );
36
37       Create a new tree object from a nested set of array references.  The
38       first element of each array must be a string used as a node label.  The
39       remaining elements must each be an array reference for a child of the
40       node.  Labels may contain newlines to support multiple lines of text.
41
42       layout()
43
44           my @lines = $tree->layout( "centered in boxes" );
45           print @lines;
46
47       Lays out the tree into an array of newline-terminated strings, ready
48       for printing or displaying.  The optional style argument may contain
49       various keywords such as 'center', 'box', 'line', 'oval' and/or
50       'space'.  These style keywords affect how the tree nodes are formatted.
51

DESCRIPTION

53       Allows the caller to develop a tree structure, using nested arrays of
54       strings and references.  Once developed, the whole tree can be printed
55       as a diagram, with the root of the tree at the top, and child nodes
56       formatted horizontally below them.
57
58       The string labels are printed as-is, or optionally surrounded with a
59       simple outlining style using printable ASCII characters.
60
61       This module may be used with object-oriented or simple function calls.
62

HISTORY

64       Mark Jason Dominus (aka MJD) asked for this functionality on his
65       Expert-level "Perl Quiz of the Week" Number 5.  You can find out more
66       about the QOTW discussion forum at http://perl.plover.com/qotw/
67
68       The central formatting routine was submitted by Ron Isaacson to the
69       Quiz forum as one possible solution to the general problem.
70
71       Ed Halley adapted the Ron Isaacson entry (with permission), to correct
72       some tree structures not originally handled, and to allow more format‐
73       ting options for the box styles.
74
76       Copyright 2003-2004 by Ron Isaacson
77
78       Portions Copyright 2003 by Mark Jason Dominus
79
80       Portions Copyright 2004 by Ed Halley
81
82       This library is free software; you can redistribute it and/or modify it
83       under the same terms as Perl itself.
84
85
86
87perl v5.8.8                       2004-05-28                     Text::Tree(3)
Impressum