Tree::From::TextLines - Build a tree object from lines of text, each line indented to express structure
This document describes version 0.021 of Tree::From::TextLines (from Perl distribution Tree-From-Text), released on 2021-05-06.
use Tree::From::TextLines qw(build_tree_from_text_lines); use Tree::Object::Hash; my $tree = build_tree_from_text_lines(<<'_'); id:root _class:Tree::Object::Hash id:child1 attr1:foo id:child2 attr1:foo attr2:bar _class:My::Node id:grandchild1 id:child3 _
This function can be used to build a tree object from text lines. Each line represents a node and its indentation expresses structure: line that is more indented than its previous line signifies that the node is child of the previous node.
This is more convenient than Tree::From::Struct, but actually internally the the text will be converted to structure to feed to Tree::From::Struct to get the final tree object.
Each line of text by default must be in form of name-value pairs separated by whitespaces (it will be parsed simply using Perl code %attrs = /(\w+):(\S*)/g), e.g.:
%attrs = /(\w+):(\S*)/g
id:root attr1:foo attr2:bar
The names will become object attributes, except special names that begin with underscore (_), like _class, _constructor, etc. They mean the same as in Tree::From::Struct.
_
_class
_constructor
To use this function, you must have at least one tree node class. Any class will do as long as it responds to parent and children (see Role::TinyCommons::Tree::Node for more details on the requirement). Supply the class name in _class in the first line.
parent
children
Available options:
Please visit the project's homepage at https://metacpan.org/release/Tree-From-Text.
Source repository is at https://github.com/perlancar/perl-Tree-From-Text.
Please report any bugs or feature requests on the bugtracker website https://github.com/perlancar/perl-Tree-From-Text/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Tree::From::Struct, Tree::From::ObjArray
perlancar <perlancar@cpan.org>
This software is copyright (c) 2021 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Tree::From::Text, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tree::From::Text
CPAN shell
perl -MCPAN -e shell install Tree::From::Text
For more information on module installation, please visit the detailed CPAN module installation guide.