line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Builder; |
2
|
6
|
|
|
6
|
|
168583
|
use strict; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
242
|
|
3
|
6
|
|
|
6
|
|
33
|
use warnings; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
157
|
|
4
|
6
|
|
|
6
|
|
30
|
use Carp; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
2912
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
5
|
|
|
5
|
1
|
257
|
my ( $class, %args ) = @_; |
10
|
5
|
|
|
|
|
11
|
my $level = 0; |
11
|
|
|
|
|
|
|
bless { |
12
|
|
|
|
|
|
|
%args, |
13
|
|
|
|
|
|
|
blocks => [], |
14
|
|
|
|
|
|
|
stack => [], |
15
|
57
|
|
|
57
|
|
148
|
level => sub { $level }, |
16
|
34
|
|
|
34
|
|
72
|
inc => sub { $level++ }, |
17
|
34
|
|
|
34
|
|
76
|
dec => sub { $level-- }, |
18
|
5
|
|
|
|
|
95
|
}, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub block { |
22
|
9
|
|
|
9
|
1
|
60
|
my ( $self, $block, $args_ref ) = @_; |
23
|
|
|
|
|
|
|
# TODO: check args_ref is hashref and if anything left in @_ then croak |
24
|
9
|
|
|
|
|
609
|
eval "require $block"; |
25
|
|
|
|
|
|
|
# TODO: put $@ check here and add relevant test |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return $self->_new_block( $block->__new__( |
28
|
|
|
|
|
|
|
%$args_ref, |
29
|
|
|
|
|
|
|
_output => $self->{output}, |
30
|
|
|
|
|
|
|
_inc => $self->{inc}, |
31
|
|
|
|
|
|
|
_dec => $self->{dec}, |
32
|
|
|
|
|
|
|
_level => $self->{level}, |
33
|
|
|
|
|
|
|
_block_id => $self->_block_id, |
34
|
|
|
|
|
|
|
_stack => $self->{ stack } |
35
|
9
|
|
|
|
|
113
|
)); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub render { |
39
|
16
|
|
|
16
|
1
|
59
|
my ( $self ) = @_; |
40
|
16
|
|
|
|
|
20
|
my $render; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# loop thru return chain (DOM!) |
43
|
16
|
|
|
|
|
22
|
while ( my $block = shift @{ $self->{ stack } } ) { |
|
118
|
|
|
|
|
351
|
|
44
|
102
|
|
|
|
|
140
|
my ( $block_id, $code ) = @$block; |
45
|
102
|
|
|
|
|
225
|
$render.= $code->(); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
16
|
|
|
|
|
78
|
return $render; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub flush { |
52
|
0
|
|
|
0
|
1
|
0
|
my ( $self ) = @_; |
53
|
0
|
|
|
|
|
0
|
$self->{ stack } = []; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _block_id { |
57
|
9
|
|
|
9
|
|
106
|
my ( $self ) = shift; |
58
|
9
|
|
|
|
|
1100
|
return scalar @{ $self->{blocks} }; |
|
9
|
|
|
|
|
632
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _new_block { |
62
|
9
|
|
|
9
|
|
19
|
my ( $self, $block ) = @_; |
63
|
9
|
|
|
|
|
12
|
push @{ $self->{blocks} }, $block; |
|
9
|
|
|
|
|
22
|
|
64
|
9
|
|
|
|
|
31
|
return $block; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |