line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Forest::Tree::Builder; |
2
|
10
|
|
|
10
|
|
15166
|
use Moose::Role; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
101
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
5
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:STEVAN'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with qw(Forest::Tree::Constructor); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'tree' => ( |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
writer => "_tree", |
12
|
|
|
|
|
|
|
isa => 'Forest::Tree::Pure', |
13
|
|
|
|
|
|
|
lazy_build => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has tree_class => ( |
17
|
|
|
|
|
|
|
isa => "ClassName", |
18
|
|
|
|
|
|
|
is => "ro", |
19
|
|
|
|
|
|
|
reader => "_tree_class", |
20
|
|
|
|
|
|
|
default => "Forest::Tree", |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# horrible horrible kludge to satisfy 'requires' without forcing 'sub |
24
|
|
|
|
|
|
|
# tree_class {}' in every single class. God i hate roles and attributes |
25
|
0
|
|
|
0
|
0
|
|
sub tree_class { shift->_tree_class(@_) } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _build_tree { |
28
|
0
|
|
|
0
|
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$self->create_new_subtree( |
31
|
|
|
|
|
|
|
children => $self->subtrees, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has subtrees => ( |
36
|
|
|
|
|
|
|
isa => "ArrayRef[Forest::Tree::Pure]", |
37
|
|
|
|
|
|
|
is => "ro", |
38
|
|
|
|
|
|
|
lazy_build => 1, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
requires "_build_subtrees"; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# ex: set sw=4 et: |
44
|
|
|
|
|
|
|
|
45
|
10
|
|
|
10
|
|
74647
|
no Moose::Role; 1; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
64
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Forest::Tree::Builder - An abstract role for bottom up tree reader |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
package MyBuilder; |
56
|
|
|
|
|
|
|
use Moose; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
with qw(Forest::Tree::Builder); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# implement required builder: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _build_subtrees { |
63
|
|
|
|
|
|
|
return [ |
64
|
|
|
|
|
|
|
$self->create_new_subtree( ... ), # probably a recursive process |
65
|
|
|
|
|
|
|
]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $builder = MyBuilder->new( |
70
|
|
|
|
|
|
|
tree_class => ..., |
71
|
|
|
|
|
|
|
... |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $tree = $builder->tree; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 DESCRIPTION |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
L<Forest::Tree::Builder> replaces L<Forest::Tree::Loader> and |
79
|
|
|
|
|
|
|
L<Forest::Tree::Reader> with a bottom up construction approach, which is also |
80
|
|
|
|
|
|
|
suitable for constructing L<Forest::Tree::Pure> derived trees without excessive |
81
|
|
|
|
|
|
|
cloning. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
It provides a declarative API instead of an imperative one, where C<tree> is |
84
|
|
|
|
|
|
|
lazily constructed on the first use, instead of being constructed immediately |
85
|
|
|
|
|
|
|
and "filled in" by the C<load> method. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 METHODS |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=over 4 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item create_new_subtree |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Implemented by L<Forest::Tree::Constructor> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item _build_tree |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Constructs a root node by using the top level C<subtrees> list as the children. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item _build_subtrees |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Build the subtrees. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Abstract method that should return an array ref of L<Forest::Tree::Pure> derived objects. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=back |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SEE ALSO |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L<Forest::Tree::Builder::SimpleTextFile> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 BUGS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
All complex software has bugs lurking in it, and this module is no |
114
|
|
|
|
|
|
|
exception. If you find a bug please either email me, or add the bug |
115
|
|
|
|
|
|
|
to cpan-RT. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 AUTHOR |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Yuval Kogman |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Copyright 2008-2014 Infinity Interactive, Inc. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L<http://www.iinteractive.com> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
128
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |