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