line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Make::Page; |
2
|
2
|
|
|
2
|
|
126273
|
use warnings; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
63
|
|
3
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
33
|
|
4
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
139
|
|
5
|
2
|
|
|
2
|
|
12
|
use utf8; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
13
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw/make_page/; |
9
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
10
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
13
|
2
|
|
|
2
|
|
1075
|
use HTML::Make 0.16; |
|
2
|
|
|
|
|
49924
|
|
|
2
|
|
|
|
|
1500
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub add_meta |
16
|
|
|
|
|
|
|
{ |
17
|
1
|
|
|
1
|
0
|
3
|
my ($head, $meta) = @_; |
18
|
1
|
50
|
|
|
|
4
|
if (ref $meta ne 'ARRAY') { |
19
|
0
|
|
|
|
|
0
|
carp "meta is not an array reference"; |
20
|
0
|
|
|
|
|
0
|
return; |
21
|
|
|
|
|
|
|
} |
22
|
1
|
|
|
|
|
3
|
my $i = -1; |
23
|
1
|
|
|
|
|
2
|
for my $m (@$meta) { |
24
|
1
|
|
|
|
|
2
|
$i++; |
25
|
1
|
50
|
|
|
|
4
|
if (ref $m ne 'HASH') { |
26
|
0
|
|
|
|
|
0
|
carp "meta element $i is not a hash reference"; |
27
|
0
|
|
|
|
|
0
|
next; |
28
|
|
|
|
|
|
|
} |
29
|
1
|
|
|
|
|
14
|
$head->push ('meta', attr => $m); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub add_link |
34
|
|
|
|
|
|
|
{ |
35
|
1
|
|
|
1
|
0
|
3
|
my ($head, $link, $quiet) = @_; |
36
|
1
|
50
|
|
|
|
4
|
if (ref $link ne 'ARRAY') { |
37
|
0
|
|
|
|
|
0
|
carp "link is not an array reference"; |
38
|
0
|
|
|
|
|
0
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
1
|
|
|
|
|
2
|
my $i = -1; |
41
|
1
|
|
|
|
|
13
|
for my $l (@$link) { |
42
|
1
|
|
|
|
|
2
|
$i++; |
43
|
1
|
50
|
|
|
|
5
|
if (ref $l ne 'HASH') { |
44
|
0
|
|
|
|
|
0
|
carp "link element $i is not a hash reference"; |
45
|
0
|
|
|
|
|
0
|
next; |
46
|
|
|
|
|
|
|
} |
47
|
1
|
50
|
|
|
|
5
|
if (! $l->{rel}) { |
48
|
0
|
|
|
|
|
0
|
carp "link element $i has no value for 'rel', skipping"; |
49
|
0
|
|
|
|
|
0
|
next; |
50
|
|
|
|
|
|
|
} |
51
|
1
|
50
|
|
|
|
3
|
if (! $l->{href}) { |
52
|
0
|
0
|
|
|
|
0
|
if (! $quiet) { |
53
|
0
|
|
|
|
|
0
|
carp "link element $i ($l->{rel}) has no href"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
1
|
|
|
|
|
4
|
$head->push ('link', attr => $l); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub make_page |
61
|
|
|
|
|
|
|
{ |
62
|
9
|
|
|
9
|
1
|
6501
|
my (%options) = @_; |
63
|
9
|
|
|
|
|
15
|
my $quiet; |
64
|
9
|
100
|
|
|
|
28
|
if ($options{quiet}) { |
65
|
2
|
|
|
|
|
3
|
$quiet = $options{quiet}; |
66
|
2
|
|
|
|
|
6
|
delete $options{quiet}; |
67
|
|
|
|
|
|
|
} |
68
|
9
|
|
|
|
|
34
|
my $html = HTML::Make->new ('html'); |
69
|
9
|
100
|
|
|
|
285
|
if ($options{lang}) { |
70
|
2
|
|
|
|
|
9
|
$html->add_attr (lang => $options{lang}); |
71
|
2
|
|
|
|
|
628
|
delete $options{lang}; |
72
|
|
|
|
|
|
|
} |
73
|
9
|
|
|
|
|
30
|
my $head = $html->push ('head'); |
74
|
9
|
|
|
|
|
526
|
$head->push ( |
75
|
|
|
|
|
|
|
'meta', |
76
|
|
|
|
|
|
|
attr => { |
77
|
|
|
|
|
|
|
charset => 'UTF-8' |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
); |
80
|
9
|
|
|
|
|
1424
|
$head->push ( |
81
|
|
|
|
|
|
|
'meta', |
82
|
|
|
|
|
|
|
attr => { |
83
|
|
|
|
|
|
|
name => 'viewport', |
84
|
|
|
|
|
|
|
content => |
85
|
|
|
|
|
|
|
'width=device-width, initial-scale=1.0' |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
); |
88
|
9
|
100
|
|
|
|
993
|
if ($options{css}) { |
89
|
1
|
|
|
|
|
2
|
for my $css (@{$options{css}}) { |
|
1
|
|
|
|
|
4
|
|
90
|
2
|
|
|
|
|
440
|
$head->push ( |
91
|
|
|
|
|
|
|
'link', |
92
|
|
|
|
|
|
|
attr => { |
93
|
|
|
|
|
|
|
rel => 'stylesheet', |
94
|
|
|
|
|
|
|
type => 'text/css', |
95
|
|
|
|
|
|
|
href => $css, |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
} |
99
|
1
|
|
|
|
|
137
|
delete $options{css}; |
100
|
|
|
|
|
|
|
} |
101
|
9
|
100
|
|
|
|
23
|
if ($options{js}) { |
102
|
1
|
|
|
|
|
5
|
add_js ($head, $options{js}, $quiet); |
103
|
1
|
|
|
|
|
2
|
delete $options{js}; |
104
|
|
|
|
|
|
|
} |
105
|
9
|
100
|
|
|
|
21
|
if ($options{title}) { |
106
|
1
|
|
|
|
|
17
|
$head->push ('title', text => $options{title}); |
107
|
1
|
|
|
|
|
81
|
delete $options{title}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
8
|
100
|
|
|
|
18
|
if (! $quiet) { |
111
|
6
|
|
|
|
|
838
|
carp "No title"; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
9
|
100
|
|
|
|
161
|
if ($options{style}) { |
115
|
1
|
|
|
|
|
5
|
$head->push ('style', text => $options{style}); |
116
|
1
|
|
|
|
|
91
|
delete $options{style}; |
117
|
|
|
|
|
|
|
} |
118
|
9
|
100
|
|
|
|
23
|
if ($options{meta}) { |
119
|
1
|
|
|
|
|
5
|
add_meta ($head, $options{meta}); |
120
|
1
|
|
|
|
|
123
|
delete $options{meta}; |
121
|
|
|
|
|
|
|
} |
122
|
9
|
100
|
|
|
|
19
|
if ($options{link}) { |
123
|
1
|
|
|
|
|
5
|
add_link ($head, $options{link}, $quiet); |
124
|
1
|
|
|
|
|
185
|
delete $options{link}; |
125
|
|
|
|
|
|
|
} |
126
|
9
|
100
|
|
|
|
22
|
if (! $quiet) { |
127
|
7
|
|
|
|
|
17
|
for my $k (keys %options) { |
128
|
0
|
|
|
|
|
0
|
carp "Unknown option $k"; |
129
|
0
|
|
|
|
|
0
|
delete $options{$k}; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
9
|
|
|
|
|
23
|
my $body = $html->push ('body'); |
133
|
9
|
|
|
|
|
442
|
return ($html, $body); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub add_js |
137
|
|
|
|
|
|
|
{ |
138
|
1
|
|
|
1
|
0
|
12
|
my ($head, $jss, $quiet) = @_; |
139
|
1
|
|
|
|
|
4
|
my $i = -1; |
140
|
1
|
|
|
|
|
2
|
for my $js (@$jss) { |
141
|
3
|
|
|
|
|
474
|
$i++; |
142
|
3
|
100
|
|
|
|
10
|
if (ref $js eq 'HASH') { |
143
|
1
|
50
|
|
|
|
7
|
if ($js->{src}) { |
144
|
1
|
|
|
|
|
4
|
$head->push ('script', attr => $js); |
145
|
1
|
|
|
|
|
124
|
next; |
146
|
|
|
|
|
|
|
} |
147
|
0
|
0
|
|
|
|
0
|
if ($js->{text}) { |
148
|
0
|
|
|
|
|
0
|
$head->push ('script', text => $js->{text}); |
149
|
0
|
|
|
|
|
0
|
next; |
150
|
|
|
|
|
|
|
} |
151
|
0
|
0
|
|
|
|
0
|
if (! $quiet) { |
152
|
0
|
|
|
|
|
0
|
carp "No src or text specified for js element $i"; |
153
|
|
|
|
|
|
|
} |
154
|
0
|
|
|
|
|
0
|
next; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
$head->push ( |
157
|
2
|
|
|
|
|
9
|
'script', |
158
|
|
|
|
|
|
|
attr => { |
159
|
|
|
|
|
|
|
src => $js, |
160
|
|
|
|
|
|
|
}, |
161
|
|
|
|
|
|
|
); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |