| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#============================================================= -*-Perl-*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Template::Plugin::HTML |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# DESCRIPTION |
|
6
|
|
|
|
|
|
|
# Template Toolkit plugin providing useful functionality for generating |
|
7
|
|
|
|
|
|
|
# HTML. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# AUTHOR |
|
10
|
|
|
|
|
|
|
# Andy Wardley |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
# COPYRIGHT |
|
13
|
|
|
|
|
|
|
# Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved. |
|
14
|
|
|
|
|
|
|
# |
|
15
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
|
16
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
#============================================================================ |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Template::Plugin::HTML; |
|
21
|
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
517
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
32
|
|
|
23
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
26
|
|
|
24
|
1
|
|
|
1
|
|
4
|
use base 'Template::Plugin'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
403
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = 2.62; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
|
29
|
6
|
|
|
6
|
1
|
34
|
my ($class, $context, @args) = @_; |
|
30
|
6
|
100
|
|
|
|
27
|
my $hash = ref $args[-1] eq 'HASH' ? pop @args : { }; |
|
31
|
|
|
|
|
|
|
bless { |
|
32
|
|
|
|
|
|
|
_SORTED => $hash->{ sorted } || 0, |
|
33
|
|
|
|
|
|
|
attributes => $hash->{ attributes } || $hash->{ attrs } || { }, |
|
34
|
6
|
|
100
|
|
|
121
|
}, $class; |
|
|
|
|
50
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub element { |
|
38
|
1
|
|
|
1
|
1
|
3
|
my ($self, $name, $attr) = @_; |
|
39
|
1
|
50
|
|
|
|
8
|
($name, $attr) = %$name if ref $name eq 'HASH'; |
|
40
|
1
|
50
|
33
|
|
|
10
|
return '' unless defined $name and length $name; |
|
41
|
1
|
|
|
|
|
6
|
$attr = $self->attributes($attr); |
|
42
|
1
|
50
|
|
|
|
7
|
$attr = " $attr" if $attr; |
|
43
|
1
|
|
|
|
|
8
|
return "<$name$attr>"; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub closed_element { |
|
47
|
0
|
|
|
0
|
0
|
0
|
my ($self, $name, $attr) = @_; |
|
48
|
0
|
0
|
|
|
|
0
|
($name, $attr) = %$name if ref $name eq 'HASH'; |
|
49
|
0
|
0
|
0
|
|
|
0
|
return '' unless defined $name and length $name; |
|
50
|
0
|
|
|
|
|
0
|
$attr = $self->attributes( $attr ); |
|
51
|
0
|
0
|
|
|
|
0
|
$attr = " $attr" if $attr; |
|
52
|
0
|
|
|
|
|
0
|
return "<$name$attr />"; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub attributes { |
|
56
|
2
|
|
|
2
|
1
|
4
|
my ($self, $hash) = @_; |
|
57
|
2
|
|
33
|
|
|
6
|
$hash ||= $self->{ attributes }; |
|
58
|
2
|
50
|
|
|
|
9
|
return '' unless ref $hash eq 'HASH'; |
|
59
|
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
9
|
my @keys = keys %$hash; |
|
61
|
2
|
100
|
|
|
|
10
|
@keys = sort @keys if $self->{ _SORTED }; |
|
62
|
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
17
|
join(' ', map { |
|
64
|
2
|
|
|
|
|
6
|
"$_=\"" . $self->escape( $hash->{ $_ } ) . '"'; |
|
65
|
|
|
|
|
|
|
} @keys); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub add_attributes { |
|
69
|
0
|
|
|
0
|
0
|
0
|
my ($self, $attr) = @_; |
|
70
|
0
|
0
|
|
|
|
0
|
return unless ref $attr eq 'HASH'; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
my $cur = $self->{ attributes }; |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
for (keys %{$attr}) { |
|
|
0
|
|
|
|
|
0
|
|
|
75
|
0
|
0
|
|
|
|
0
|
$cur->{$_} = exists $cur->{$_} |
|
76
|
|
|
|
|
|
|
? $cur->{$_} . " $attr->{$_}" |
|
77
|
|
|
|
|
|
|
: $attr->{$_}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
return; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
*add_attribute = \&add_attributes; |
|
85
|
|
|
|
|
|
|
*add = \&add_attributes; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub replace_attributes { |
|
89
|
0
|
|
|
0
|
0
|
0
|
my ($self, $attr) = @_; |
|
90
|
0
|
0
|
|
|
|
0
|
return unless ref $attr eq 'HASH'; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
my $cur = $self->{ attributes }; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
for (keys %{$attr}) { |
|
|
0
|
|
|
|
|
0
|
|
|
95
|
0
|
|
|
|
|
0
|
$cur->{$_} = $attr->{$_}; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
return; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
*replace_attribute = \&replace_attributes; |
|
102
|
|
|
|
|
|
|
*replace = \&replace_attributes; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub clear_attributes { |
|
105
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
106
|
0
|
|
|
|
|
0
|
$self->{ attributes } = { }; |
|
107
|
0
|
|
|
|
|
0
|
return; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub escape { |
|
112
|
5
|
|
|
5
|
1
|
9
|
my ($self, $text) = @_; |
|
113
|
5
|
|
|
|
|
13
|
for ($text) { |
|
114
|
5
|
|
|
|
|
15
|
s/&/&/g; |
|
115
|
5
|
|
|
|
|
10
|
s/</g; |
|
116
|
5
|
|
|
|
|
14
|
s/>/>/g; |
|
117
|
5
|
|
|
|
|
15
|
s/"/"/g; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
5
|
|
|
|
|
46
|
$text; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub url { |
|
123
|
1
|
|
|
1
|
0
|
3
|
my ($self, $text) = @_; |
|
124
|
1
|
50
|
|
|
|
5
|
return undef unless defined $text; |
|
125
|
1
|
|
|
|
|
6
|
$text =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; |
|
|
1
|
|
|
|
|
10
|
|
|
126
|
1
|
|
|
|
|
6
|
return $text; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |