NAME
Text::Tree::Indented - render a tree data structure in the classic indented view
SYNOPSIS
use Text::Tree::Indented qw/ generate_tree /;
my $data = ['ABC', ['DEF', ... ];
binmode(STDOUT, "utf8");
print generate_tree($data);
which produces
ABC
├─DEF
│ ├─GHI
│ └─JKL
├─MNO
│ └─PQR
│ └─STU
└─VWX
DESCRIPTION
This module provides a single function, generate_tree
, which takes a perl data structure and renders it into an indented tree view.
Note: the design of this module is still very much in flux, so the data structure and other aspects made change from release to release.
The tree data is passed as an arrayref. A string in the arrayref represents a node in the tree; if it's followed by an arrayref, that's a subtree. So let's say the root of your tree is Fruit, and it has three children, Apples, Bananas, and Oranges, then the data would look like this:
my $tree = ['Fruit', ['Apples', 'Bananas', 'Oranges'] ];
This results in the following tree:
Fruit
├─Apples
├─Bananas
└─Oranges
Now you want to add in Red Bananas and Williams Bananas, so your data becomes:
my $tree = ['Fruit', ['Apples', 'Bananas', ['Red', 'Williams'], 'Oranges'] ];
And now the tree looks like this:
Fruit
├─Apples
├─Bananas
│ ├─Red
│ └─Williams
└─Oranges
generate_tree( $data, $options )
In addition to the tree data, this function takes an optional second argument, which should be a hashref.
At the moment there is just one option, style, which can be one of 'boxrule', 'classic', or 'norule'. The default is 'boxrule'.
If you are using the boxrule style, then you should make sure your output can handle wide characters, as in the SYNOPSIS.
REPOSITORY
https://github.com/neilb/Text-Tree-Indented
AUTHOR
Neil Bowers <neilb@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2021 by Neil Bowers.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.