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

DESCRIPTION

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

HISTORY

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