File Coverage

blib/lib/Tree/Object/Hash.pm
Criterion Covered Total %
statement 22 22 100.0
branch 4 4 100.0
condition 2 4 50.0
subroutine 7 7 100.0
pod 3 3 100.0
total 38 40 95.0


line stmt bran cond sub pod time code
1             package Tree::Object::Hash;
2              
3             our $DATE = '2016-04-14'; # DATE
4             our $VERSION = '0.07'; # VERSION
5              
6 1     1   64429 use 5.010001;
  1         11  
7 1     1   4 use strict;
  1         2  
  1         15  
8 1     1   4 use warnings;
  1         1  
  1         20  
9              
10 1     1   345 use Role::Tiny::With;
  1         4099  
  1         138  
11              
12             with 'Role::TinyCommons::Tree::NodeMethods';
13              
14             sub new {
15 13     13 1 3525 my $class = shift;
16 13         15 my %attrs = @_;
17 13   50     43 $attrs{_parent} //= undef;
18 13   50     36 $attrs{_children} //= [];
19 13         29 bless \%attrs, $class;
20             }
21              
22             sub parent {
23 123     123 1 36600 my $self = shift;
24 123 100       245 $self->{_parent} = $_[0] if @_;
25 123         208 $self->{_parent};
26             }
27              
28             sub children {
29 140     140 1 5151 my $self = shift;
30              
31 140 100       213 $self->{_children} = $_[0] if @_;
32 140         250 $self->{_children};
33             }
34              
35             1;
36             # ABSTRACT: A hash-based tree object
37              
38             __END__
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             Tree::Object::Hash - A hash-based tree object
47              
48             =head1 VERSION
49              
50             This document describes version 0.07 of Tree::Object::Hash (from Perl distribution Tree-Object), released on 2016-04-14.
51              
52             =head1 SYNOPSIS
53              
54             use Tree::Object::Hash;
55             my $tree = Tree::Object::Hash->new(attr1 => ..., attr2 => ...);
56              
57             =head1 DESCRIPTION
58              
59             This is a pretty generic hash-based tree object you can use directly or as a
60             base class.
61              
62             It gets its methods from L<Role::TinyCommons::Tree::Node> and
63             L<Role::TinyCommons::Tree::NodeMethods> roles.
64              
65             Parent node is stored internally in the C<_parent> key. Children nodes in the
66             C<_children> key (arrayref). You can store attributes in other keys.
67              
68             =head1 METHODS
69              
70             See L<Role::TinyCommons::Tree::Node>, L<Role::TinyCommons::Tree::NodeMethods>
71             for the complete list of methods.
72              
73             =head2 CLASS->new(%attrs) => obj
74              
75             Constructor.
76              
77             =head2 $obj->parent( [ $obj ] ) => obj
78              
79             Get or set parent.
80              
81             =head2 $obj->children( [ \@children ] ) => arrayref
82              
83             Get or set children.
84              
85             =head1 HOMEPAGE
86              
87             Please visit the project's homepage at L<https://metacpan.org/release/Tree-Object>.
88              
89             =head1 SOURCE
90              
91             Source repository is at L<https://github.com/perlancar/perl-Tree-Object>.
92              
93             =head1 BUGS
94              
95             Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Tree-Object>
96              
97             When submitting a bug or request, please include a test-file or a
98             patch to an existing test-file that illustrates the bug or desired
99             feature.
100              
101             =head1 SEE ALSO
102              
103             L<Role::TinyCommons::Tree::Node>
104              
105             L<Role::TinyCommons::Tree::NodeMethods>
106              
107             =head1 AUTHOR
108              
109             perlancar <perlancar@cpan.org>
110              
111             =head1 COPYRIGHT AND LICENSE
112              
113             This software is copyright (c) 2016 by perlancar@cpan.org.
114              
115             This is free software; you can redistribute it and/or modify it under
116             the same terms as the Perl 5 programming language system itself.
117              
118             =cut