File Coverage

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


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