line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fern; |
2
|
1
|
|
|
1
|
|
77552
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
6
|
use base qw(Exporter); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
1228
|
|
5
|
|
|
|
|
|
|
our @EXPORT = qw(tag empty_element_tag render_tag render_tag_and_metadata); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub _parse_attributes_and_content { |
8
|
110
|
|
|
110
|
|
108
|
my $attributes = shift; |
9
|
110
|
|
|
|
|
133
|
my @content = @_; |
10
|
|
|
|
|
|
|
|
11
|
110
|
100
|
100
|
|
|
335
|
if (!ref($attributes) || (ref($attributes) ne 'HASH' && ref($attributes) ne 'ARRAY')) { |
|
|
|
66
|
|
|
|
|
12
|
98
|
100
|
|
|
|
159
|
if (defined $attributes) { |
13
|
16
|
|
|
|
|
24
|
unshift @content, $attributes; |
14
|
|
|
|
|
|
|
} |
15
|
98
|
|
|
|
|
140
|
$attributes = {}; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
110
|
|
|
|
|
231
|
return ($attributes, @content); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub render_tag_and_metadata { |
22
|
142
|
|
|
142
|
1
|
164
|
my ($atom, @params) = @_; |
23
|
142
|
100
|
66
|
|
|
738
|
return ref($atom) && ref($atom) eq 'CODE' ? ($atom->(@params)) : ($atom); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub render_tag { |
27
|
105
|
|
|
105
|
1
|
131
|
my ($atom, @params) = @_; |
28
|
105
|
|
|
|
|
161
|
return (render_tag_and_metadata($atom, @params))[0]; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _stringify_key_value_pair { |
32
|
18
|
|
|
18
|
|
24
|
my ($key, $value, @params) = @_; |
33
|
18
|
|
|
|
|
34
|
return $key . '="' . render_tag($value, @params) . '"'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _stringify_attribute_hash { |
37
|
110
|
|
|
110
|
|
111
|
my ($attribute_hash, @params) = @_; |
38
|
110
|
100
|
|
|
|
866
|
return '' if (!keys %$attribute_hash); |
39
|
11
|
|
|
|
|
19
|
return ' ' . join(' ', map { _stringify_key_value_pair($_, $attribute_hash->{$_}, @params) } keys %$attribute_hash); |
|
16
|
|
|
|
|
26
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _stringify_attribute_array { |
43
|
1
|
|
|
1
|
|
3
|
my ($attribute_array, @params) = @_; |
44
|
1
|
50
|
|
|
|
5
|
return '' if !@$attribute_array; |
45
|
1
|
|
|
|
|
5
|
return ' ' . join(' ', map { _stringify_key_value_pair($attribute_array->[2 * $_], $attribute_array->[2 * $_ + 1], @params) } (0 .. @$attribute_array / 2 - 1)); |
|
2
|
|
|
|
|
7
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _stringify_attributes { |
49
|
111
|
|
|
111
|
|
135
|
my ($attributes, @params) = @_; |
50
|
111
|
100
|
|
|
|
196
|
if (ref($attributes) eq 'HASH') { |
51
|
110
|
|
|
|
|
166
|
return _stringify_attribute_hash($attributes, @params); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
1
|
|
|
|
|
4
|
return _stringify_attribute_array($attributes, @params); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _stringify_content { |
59
|
111
|
|
|
111
|
|
134
|
my ($content, @params) = @_; |
60
|
111
|
|
|
|
|
147
|
my @all_content = map { [render_tag_and_metadata($_, @params)] } @$content; |
|
37
|
|
|
|
|
60
|
|
61
|
|
|
|
|
|
|
return ( |
62
|
37
|
|
|
|
|
82
|
@all_content ? join('', map {$_->[0]} @all_content) : '', |
|
37
|
|
|
|
|
104
|
|
63
|
111
|
100
|
|
|
|
280
|
map {@$_[1..$#$_]} @all_content, |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub empty_element_tag { |
68
|
5
|
|
|
5
|
1
|
1038
|
my $tag_name = shift; |
69
|
5
|
|
|
|
|
11
|
my ($attributes, @content) = _parse_attributes_and_content(@_); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
return sub { |
72
|
5
|
|
|
5
|
|
16
|
my ($stringified_content, @metadata) = _stringify_content(\@content, @_); |
73
|
5
|
50
|
|
|
|
11
|
if ($stringified_content) { |
74
|
0
|
|
|
|
|
0
|
return +("<$tag_name" . _stringify_attributes($attributes, @_) . ">$stringified_content$tag_name>", @metadata); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
5
|
|
|
|
|
13
|
return +("<$tag_name" . _stringify_attributes($attributes, @_) . " />", @metadata); |
78
|
|
|
|
|
|
|
} |
79
|
5
|
|
|
|
|
28
|
}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub tag { |
83
|
105
|
|
|
105
|
1
|
27295
|
my $tag_name = shift; |
84
|
105
|
|
|
|
|
182
|
my ($attributes, @content) = _parse_attributes_and_content(@_); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return sub { |
87
|
106
|
|
|
106
|
|
199
|
my ($stringified_content, @metadata) = _stringify_content(\@content, @_); |
88
|
|
|
|
|
|
|
return +( |
89
|
106
|
|
|
|
|
246
|
"<$tag_name" . _stringify_attributes($attributes, @_) . ">" . |
90
|
|
|
|
|
|
|
$stringified_content . |
91
|
|
|
|
|
|
|
"$tag_name>", |
92
|
|
|
|
|
|
|
@metadata |
93
|
|
|
|
|
|
|
); |
94
|
105
|
|
|
|
|
536
|
}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |