File Coverage

blib/lib/Tree/Object/Array.pm
Criterion Covered Total %
statement 29 29 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 36 37 97.3


line stmt bran cond sub pod time code
1             package Tree::Object::Array;
2              
3             our $DATE = '2016-04-14'; # DATE
4             our $VERSION = '0.07'; # VERSION
5              
6 1     1   65001 use 5.010001;
  1         12  
7 1     1   5 use strict;
  1         2  
  1         18  
8 1     1   4 use warnings;
  1         1  
  1         166  
9              
10             sub import {
11 1     1   7 my ($class0, @attrs) = @_;
12              
13 1         4 my $caller = caller();
14              
15 1         15 my $code_str = "package $caller;\n";
16              
17 1         3 $code_str .= "use Class::Accessor::Array {\n";
18 1         1 $code_str .= " accessors => {\n";
19 1         1 my $idx = 0;
20 1         3 for (@attrs, "parent", "children") {
21 3         5 $code_str .= " '$_' => $idx,\n";
22 3         5 $idx++;
23             }
24 1         2 $code_str .= " },\n";
25 1         1 $code_str .= "};\n";
26              
27 1         1 $code_str .= "use Role::Tiny::With;\n";
28 1         2 $code_str .= "with 'Role::TinyCommons::Tree::NodeMethods';\n";
29              
30             #say $code_str;
31              
32 1     1   692 eval $code_str;
  1     1   31  
  1         7  
  1         867  
  1         4180  
  1         41  
  1         62  
33 1 50       3863 die if $@;
34             }
35              
36             1;
37             # ABSTRACT: An array-based tree object
38              
39             __END__
40              
41             =pod
42              
43             =encoding UTF-8
44              
45             =head1 NAME
46              
47             Tree::Object::Array - An array-based tree object
48              
49             =head1 VERSION
50              
51             This document describes version 0.07 of Tree::Object::Array (from Perl distribution Tree-Object), released on 2016-04-14.
52              
53             =head1 SYNOPSIS
54              
55             In F<lib/My/ArrayTree.pm>:
56              
57             package My::ArrayTree;
58             use Tree::Object::Array qw(attr1 attr2 attr3);
59             1;
60              
61             =head1 DESCRIPTION
62              
63             This module lets you create an array-backed (instead of hash-backed) tree
64             object. Instead of subclassing C<Tree::Object::Hash>, you C<use> it in your
65             class and listing all the attributes you will need. It uses
66             L<Class::Accessor::Array> to store data:
67              
68             [$attr1, $attr2, ..., $parent, \@children]
69              
70             =head1 HOMEPAGE
71              
72             Please visit the project's homepage at L<https://metacpan.org/release/Tree-Object>.
73              
74             =head1 SOURCE
75              
76             Source repository is at L<https://github.com/perlancar/perl-Tree-Object>.
77              
78             =head1 BUGS
79              
80             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Tree-Object>
81              
82             When submitting a bug or request, please include a test-file or a
83             patch to an existing test-file that illustrates the bug or desired
84             feature.
85              
86             =head1 SEE ALSO
87              
88             L<Tree::Object::Array::Glob>, a variant which stores the children nodes directly
89             as the last elements of the array to avoid creating an extra subarray.
90              
91             =head1 AUTHOR
92              
93             perlancar <perlancar@cpan.org>
94              
95             =head1 COPYRIGHT AND LICENSE
96              
97             This software is copyright (c) 2016 by perlancar@cpan.org.
98              
99             This is free software; you can redistribute it and/or modify it under
100             the same terms as the Perl 5 programming language system itself.
101              
102             =cut