line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::GenerateUtil; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
153404
|
use strict; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
219
|
|
4
|
6
|
|
|
6
|
|
33
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
1440
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# This allows declaration use HTML::GenerateUtil ':all'; |
11
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
12
|
|
|
|
|
|
|
# will save memory. |
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
14
|
|
|
|
|
|
|
'all' => [ qw( |
15
|
|
|
|
|
|
|
escape_html generate_attributes generate_tag escape_uri escape_path set_paranoia |
16
|
|
|
|
|
|
|
EH_INPLACE EH_LFTOBR EH_SPTONBSP EH_LEAVEKNOWN |
17
|
|
|
|
|
|
|
GT_ESCAPEVAL GT_ADDNEWLINE GT_CLOSETAG |
18
|
|
|
|
|
|
|
EU_INPLACE |
19
|
|
|
|
|
|
|
$H $E a div span label ul ol li h1 h2 h3 h4 |
20
|
|
|
|
|
|
|
) ], |
21
|
|
|
|
|
|
|
'consts' => [ qw( |
22
|
|
|
|
|
|
|
EH_INPLACE EH_LFTOBR EH_SPTONBSP EH_LEAVEKNOWN |
23
|
|
|
|
|
|
|
GT_ESCAPEVAL GT_ADDNEWLINE GT_CLOSETAG |
24
|
|
|
|
|
|
|
EU_INPLACE |
25
|
|
|
|
|
|
|
) ] |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our @EXPORT = qw(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '1.20'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our $H = 'HTML::GenerateUtil'; |
35
|
|
|
|
|
|
|
our $E = 'HTML::GenerateUtil::Escape'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Not comprehensive, just for nicer output html with newlines on end |
38
|
|
|
|
|
|
|
my %BlockishTags = map { $_ => 1 } qw(h1 h2 h3 h4 h5 h6 li ol ul div p blockquote dd dl form hr pre table tr td th tbody tfoot thead); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
require XSLoader; |
41
|
|
|
|
|
|
|
XSLoader::load('HTML::GenerateUtil', $VERSION); |
42
|
|
|
|
|
|
|
|
43
|
6
|
|
|
6
|
|
179
|
use constant EH_INPLACE => 1; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
652
|
|
44
|
6
|
|
|
6
|
|
29
|
use constant EH_LFTOBR => 2; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
293
|
|
45
|
6
|
|
|
6
|
|
26
|
use constant EH_SPTONBSP => 4; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
307
|
|
46
|
6
|
|
|
6
|
|
26
|
use constant EH_LEAVEKNOWN => 8; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
278
|
|
47
|
|
|
|
|
|
|
|
48
|
6
|
|
|
6
|
|
28
|
use constant GT_ESCAPEVAL => 1; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
250
|
|
49
|
6
|
|
|
6
|
|
24
|
use constant GT_ADDNEWLINE => 2; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
271
|
|
50
|
6
|
|
|
6
|
|
31
|
use constant GT_CLOSETAG => 4; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
237
|
|
51
|
|
|
|
|
|
|
|
52
|
6
|
|
|
6
|
|
70
|
use constant EU_INPLACE => 1; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
2375
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Preloaded methods go here. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $escape_all = '"#$%&+,/:;<=>?@[]^`{}|\\' . "\x7f"; |
57
|
|
|
|
|
|
|
my $escape_lite = '"$+,/:;<=>@[]^`{}|\\' . "\x7f"; |
58
|
|
|
|
|
|
|
my $escape_path = q{'"` <>;}; |
59
|
|
|
|
|
|
|
|
60
|
1284
|
|
33
|
1284
|
1
|
692162
|
sub escape_uri { return escape_uri_internal($_[0], $_[2] || $escape_all, $_[1] || 0) } |
|
|
|
100
|
|
|
|
|
61
|
0
|
|
0
|
0
|
0
|
|
sub escape_uri_lite { return escape_uri_internal($_[0], $_[2] || $escape_lite, $_[1] || 0) } |
|
|
|
0
|
|
|
|
|
62
|
0
|
|
0
|
0
|
0
|
|
sub escape_path { return escape_uri_internal($_[0], $_[2] || $escape_path, $_[1] || 0) } |
|
|
|
0
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# If an unknown function is called, fill in some parameters and |
65
|
|
|
|
|
|
|
# call generate_tag |
66
|
|
|
|
|
|
|
# e.g. |
67
|
|
|
|
|
|
|
# font( $html ) |
68
|
|
|
|
|
|
|
# maps to generate_tag('font',undef,$html, 0 ) |
69
|
|
|
|
|
|
|
# font( { size => 1 }, $html ) |
70
|
|
|
|
|
|
|
# maps to generate_tag('font',{ size => 1},$html, 0 ) |
71
|
|
|
|
|
|
|
# font( $html, GT_ADDNEWLINE ) |
72
|
|
|
|
|
|
|
# maps to generate_tag('font',{ size => 1},$html, GT_ADDNEWLINE ) |
73
|
|
|
|
|
|
|
sub AUTOLOAD { |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# assume the function name is the tag name |
76
|
0
|
|
|
0
|
|
|
my $Tag = our $AUTOLOAD; |
77
|
0
|
|
|
|
|
|
$Tag =~ s{.*::}{}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# if the function was called on the class name, strip out the class name |
80
|
0
|
0
|
|
|
|
|
if ($_[0] eq $H) { shift; } |
|
0
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# if the first parameter was not a ref, assume no attributes passed, |
83
|
|
|
|
|
|
|
# so we use an empty attr list |
84
|
0
|
0
|
0
|
|
|
|
unshift @_, undef unless ($_[0] && ref($_[0])); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Use the tag as the first parameter |
87
|
0
|
|
|
|
|
|
unshift @_, lc $Tag; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Set default flags |
90
|
0
|
|
0
|
|
|
|
$_[3] ||= 0; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
goto &generate_tag; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
package HTML::GenerateUtil::Escape; |
98
|
|
|
|
|
|
|
|
99
|
6
|
|
|
6
|
|
30
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
189
|
|
100
|
6
|
|
|
6
|
|
30
|
use warnings; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
246
|
|
101
|
|
|
|
|
|
|
|
102
|
6
|
|
|
6
|
|
29
|
use constant GT_ADDNEWLINE => HTML::GenerateUtil::GT_ADDNEWLINE; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
2331
|
|
103
|
|
|
|
|
|
|
*escape_html = \&HTML::GenerateUtil::escape_html; |
104
|
|
|
|
|
|
|
*generate_tag = \&HTML::GenerateUtil::generate_tag; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub AUTOLOAD { |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# assume the function name is the tag name |
109
|
0
|
|
|
0
|
|
|
(my $Tag = our $AUTOLOAD) =~ s{.*::}{}; |
110
|
0
|
|
|
|
|
|
my $lcTag = lc $Tag; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Assume always called as $E-> |
113
|
0
|
|
|
|
|
|
shift; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# If the first parameter was not a hash ref, assume no |
116
|
|
|
|
|
|
|
# attributes passed, so we use an empty attr list |
117
|
0
|
0
|
0
|
|
|
|
my $Attr = $_[0] && ref $_[0] eq 'HASH' ? shift : undef; |
118
|
0
|
|
0
|
|
|
|
my $EHFlags = $Attr && delete $Attr->{_ehflags} || 0; |
119
|
0
|
|
0
|
|
|
|
my $GTFlags = $Attr && delete $Attr->{_gtflags} || 0; |
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
0
|
|
|
|
return join "", map { |
122
|
0
|
0
|
|
|
|
|
generate_tag($lcTag, $Attr, $_, $GTFlags | ($BlockishTags{$lcTag} && defined $_ ? GT_ADDNEWLINE : 0)); |
123
|
|
|
|
|
|
|
} map { |
124
|
0
|
0
|
|
|
|
|
ref $_ eq 'ARRAY' ? |
125
|
0
|
0
|
|
|
|
|
join "", map { ref $_ eq 'SCALAR' ? $$_ : escape_html($_, $EHFlags) } @$_ : |
|
|
0
|
|
|
|
|
|
126
|
|
|
|
|
|
|
ref $_ eq 'SCALAR' ? $$_ : escape_html($_, $EHFlags) |
127
|
|
|
|
|
|
|
} (@_ ? @_ : \undef); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |