line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Tree::Create::Callback; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-04-01'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
719
|
use 5.010001; |
|
2
|
|
|
|
|
5
|
|
7
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
40
|
|
8
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
49
|
|
9
|
2
|
|
|
2
|
|
537
|
use HTML::Entities; |
|
2
|
|
|
|
|
4822
|
|
|
2
|
|
|
|
|
156
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
13
|
use Exporter qw(import); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
611
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(create_html_tree_using_callback); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _render_elem { |
15
|
19
|
|
|
19
|
|
13
|
my ($callback, $level, $seniority) = @_; |
16
|
|
|
|
|
|
|
|
17
|
19
|
|
|
|
|
23
|
my $indent = " " x $level; |
18
|
19
|
|
|
|
|
23
|
my $indent2 = " " x ($level + 1); |
19
|
|
|
|
|
|
|
|
20
|
19
|
|
|
|
|
26
|
my ($elem, $attrs, $text_before, $text_after, $num_children) = |
21
|
|
|
|
|
|
|
$callback->($level, $seniority); |
22
|
|
|
|
|
|
|
|
23
|
19
|
|
|
|
|
65
|
my @res; |
24
|
|
|
|
|
|
|
|
25
|
19
|
|
50
|
|
|
46
|
$attrs //= {}; |
26
|
|
|
|
|
|
|
push @res, ( |
27
|
|
|
|
|
|
|
$indent, |
28
|
|
|
|
|
|
|
"<$elem", |
29
|
|
|
|
|
|
|
keys(%$attrs) ? " " : "", |
30
|
|
|
|
|
|
|
join(" ", |
31
|
19
|
100
|
|
|
|
60
|
map {$_ . '="' . encode_entities($attrs->{$_}) . '"'} |
|
28
|
|
|
|
|
114
|
|
32
|
|
|
|
|
|
|
sort keys %$attrs |
33
|
|
|
|
|
|
|
), |
34
|
|
|
|
|
|
|
">\n" |
35
|
|
|
|
|
|
|
); |
36
|
19
|
100
|
100
|
|
|
184
|
if (defined($text_before) && length($text_before)) { |
37
|
10
|
|
|
|
|
12
|
push @res, $indent2, $text_before, "\n"; |
38
|
|
|
|
|
|
|
} |
39
|
19
|
|
|
|
|
26
|
for (0..$num_children-1) { |
40
|
17
|
|
|
|
|
38
|
push @res, _render_elem($callback, $level+1, $_); |
41
|
|
|
|
|
|
|
} |
42
|
19
|
100
|
100
|
|
|
52
|
if (defined($text_after) && length($text_after)) { |
43
|
10
|
|
|
|
|
11
|
push @res, $indent2, $text_after, "\n"; |
44
|
|
|
|
|
|
|
} |
45
|
19
|
|
|
|
|
24
|
push @res, $indent, "$elem>\n"; |
46
|
19
|
|
|
|
|
113
|
@res; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub create_html_tree_using_callback { |
50
|
2
|
|
|
2
|
1
|
16
|
my $callback = shift; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# create the root node |
53
|
2
|
|
|
|
|
8
|
join("", _render_elem($callback, 0, 0)); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
# ABSTRACT: Create HTML document by using a callback |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |