The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tree::From::TextLines - Build a tree object from lines of text, each line indented to express structure

VERSION

This document describes version 0.021 of Tree::From::TextLines (from Perl distribution Tree-From-Text), released on 2021-05-06.

SYNOPSIS

 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
 _

DESCRIPTION

FUNCTIONS

build_tree_from_text_lines([ \%opts, ] $text) => obj

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.:

 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.

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.

Available options:

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Tree-From-Text.

SOURCE

Source repository is at https://github.com/perlancar/perl-Tree-From-Text.

BUGS

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.

SEE ALSO

Tree::From::Struct, Tree::From::ObjArray

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

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.