| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Allow the definition of user tags in WebMake files, like so: |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# <{mkthumb name="${from}" delim=","}>...text...{mkthumb}> |
|
4
|
|
|
|
|
|
|
# <{alone name="${from}" }/> |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package HTML::WebMake::UserTags; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
########################################################################### |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
49
|
|
|
12
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
23
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use HTML::WebMake::Main; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
17
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
955
|
use vars qw{ |
|
17
|
|
|
|
|
|
|
@ISA |
|
18
|
1
|
|
|
1
|
|
5
|
}; |
|
|
1
|
|
|
|
|
2
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
########################################################################### |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new ($$$$$) { |
|
28
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
29
|
0
|
|
0
|
|
|
|
$class = ref($class) || $class; |
|
30
|
0
|
|
|
|
|
|
my ($main) = @_; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $self = { |
|
33
|
|
|
|
|
|
|
'main' => $main, |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
'tags' => { }, |
|
36
|
|
|
|
|
|
|
'tags_defined' => 0, |
|
37
|
|
|
|
|
|
|
'tag_names' => [ ], |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
'prefmt_tags' => { }, |
|
40
|
|
|
|
|
|
|
'prefmt_tags_defined' => 0, |
|
41
|
|
|
|
|
|
|
'prefmt_tag_names' => [ ], |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
'wmk_tags' => { }, |
|
44
|
|
|
|
|
|
|
'wmk_tags_defined' => 0, |
|
45
|
|
|
|
|
|
|
'wmk_tag_names' => [ ], |
|
46
|
|
|
|
|
|
|
}; |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
bless ($self, $class); |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$self; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
0
|
0
|
|
sub dbg { HTML::WebMake::Main::dbg (@_); } |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub def_tag { |
|
58
|
0
|
|
|
0
|
0
|
|
my ($self, $is_empty, $is_wmk, $is_prefmt, $name, $fn, @reqd_attrs) = @_; |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $tag = { }; |
|
61
|
0
|
0
|
|
|
|
|
if ($is_empty) { |
|
62
|
0
|
|
|
|
|
|
$tag->{is_empty} = 1; |
|
63
|
0
|
|
|
|
|
|
$tag->{pattern} = qr{\<\{?${name}(?:\s([^>]*?)|)\s*\/\}?\>}is; |
|
64
|
|
|
|
|
|
|
} else { |
|
65
|
0
|
|
|
|
|
|
$tag->{is_empty} = 0; |
|
66
|
0
|
|
|
|
|
|
$tag->{pattern} = |
|
67
|
|
|
|
|
|
|
qr{\<\{?${name}(?:\s([^>]*?)|)\s*\}?\>(.*?)\<\/\{?${name}\s*\}?\>}is; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
@{$tag->{reqd_attrs}} = @reqd_attrs; |
|
|
0
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$tag->{handler_fn} = $fn; |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ($is_wmk) { |
|
|
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
push (@{$self->{wmk_tag_names}}, $name); |
|
|
0
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$self->{wmk_tags_defined}++; |
|
76
|
0
|
|
|
|
|
|
$self->{wmk_tags}->{$name} = $tag; |
|
77
|
0
|
|
|
|
|
|
dbg ("Defined new WebMake tag: <$name>"); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} elsif ($is_prefmt) { |
|
80
|
0
|
|
|
|
|
|
push (@{$self->{prefmt_tag_names}}, $name); |
|
|
0
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->{prefmt_tags_defined}++; |
|
82
|
0
|
|
|
|
|
|
$self->{prefmt_tags}->{$name} = $tag; |
|
83
|
0
|
|
|
|
|
|
dbg ("Defined new preformat content tag: <$name>"); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} else { |
|
86
|
0
|
|
|
|
|
|
push (@{$self->{tag_names}}, $name); |
|
|
0
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$self->{tags_defined}++; |
|
88
|
0
|
|
|
|
|
|
$self->{tags}->{$name} = $tag; |
|
89
|
0
|
|
|
|
|
|
dbg ("Defined new content tag: <$name>"); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
''; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub subst_tags { |
|
98
|
0
|
|
|
0
|
0
|
|
my ($self, $from, $str) = @_; |
|
99
|
0
|
|
|
|
|
|
return $self->_subst_tags($from, $str, 0, 0); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub subst_wmk_tags { |
|
103
|
0
|
|
|
0
|
0
|
|
my ($self, $from, $str) = @_; |
|
104
|
0
|
|
|
|
|
|
return $self->_subst_tags($from, $str, 1, 0); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub subst_preformat_tags { |
|
108
|
0
|
|
|
0
|
0
|
|
my ($self, $from, $str) = @_; |
|
109
|
0
|
|
|
|
|
|
return $self->_subst_tags($from, $str, 0, 1); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _subst_tags { |
|
113
|
0
|
|
|
0
|
|
|
my ($self, $from, $str, $is_wmk, $is_prefmt) = @_; |
|
114
|
0
|
|
|
|
|
|
my @tags; |
|
115
|
|
|
|
|
|
|
my $tag; |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if ($is_wmk) { |
|
|
|
0
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
return unless ($self->{wmk_tags_defined}); |
|
119
|
0
|
|
|
|
|
|
@tags = @{$self->{wmk_tag_names}}; |
|
|
0
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
} elsif ($is_prefmt) { |
|
122
|
0
|
0
|
|
|
|
|
return unless ($self->{prefmt_tags_defined}); |
|
123
|
0
|
|
|
|
|
|
@tags = @{$self->{prefmt_tag_names}}; |
|
|
0
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} else { |
|
126
|
0
|
0
|
|
|
|
|
return unless ($self->{tags_defined}); |
|
127
|
0
|
|
|
|
|
|
@tags = @{$self->{tag_names}}; |
|
|
0
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my $foundatag = 0; |
|
131
|
0
|
|
|
|
|
|
foreach my $tagname (@tags) { |
|
132
|
0
|
0
|
|
|
|
|
next unless (defined $tagname); |
|
133
|
0
|
0
|
|
|
|
|
if ($is_wmk) { |
|
|
|
0
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
$tag = $self->{wmk_tags}->{$tagname}; |
|
135
|
|
|
|
|
|
|
} elsif ($is_prefmt) { |
|
136
|
0
|
|
|
|
|
|
$tag = $self->{prefmt_tags}->{$tagname}; |
|
137
|
|
|
|
|
|
|
} else { |
|
138
|
0
|
|
|
|
|
|
$tag = $self->{tags}->{$tagname}; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
next unless ($$str =~ /\<${tagname}\b/is); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# been deprecated for a while. take it out |
|
144
|
|
|
|
|
|
|
# next unless ($$str =~ /\<\{?${tagname}[\s>}]/is); |
|
145
|
|
|
|
|
|
|
# if ($$str =~ /\<\{${tagname}/is) { #} |
|
146
|
|
|
|
|
|
|
# warn "$from: <{${tagname}}> deprecated, use <${tagname}> instead\n"; |
|
147
|
|
|
|
|
|
|
# } |
|
148
|
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
$foundatag = 1; |
|
150
|
0
|
|
|
|
|
|
my $pat = $tag->{pattern}; |
|
151
|
0
|
0
|
|
|
|
|
if ($tag->{is_empty}) { |
|
152
|
0
|
|
|
|
|
|
$$str =~ s/${pat}/ $self->call_tag ($tag, $from, $tagname, $1, ''); /gies; |
|
|
0
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
} else { |
|
154
|
0
|
|
|
|
|
|
$$str =~ s/${pat}/ $self->call_tag ($tag, $from, $tagname, $1, $2); /gies; |
|
|
0
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return $foundatag; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub call_tag { |
|
164
|
0
|
|
|
0
|
0
|
|
my ($self, $tag, $from, $tagname, $argtext, $text) = @_; |
|
165
|
0
|
|
|
|
|
|
local ($_) = ''; |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my $util = $self->{main}->{util}; |
|
168
|
0
|
|
|
|
|
|
my $attrs = $util->parse_xml_tag_attributes ($tagname, |
|
169
|
|
|
|
|
|
|
defined ($argtext) ? $argtext : '', |
|
170
|
0
|
0
|
|
|
|
|
$from, @{$tag->{reqd_attrs}}); |
|
171
|
0
|
0
|
|
|
|
|
if (!defined $attrs) { return ''; } |
|
|
0
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
|
if ($self->{main}->{paranoid}) { |
|
174
|
0
|
|
|
|
|
|
return "\n(Paranoid mode on - perl code evaluation prohibited.)\n"; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
my $pl = $self->{main}->getperlinterp(); |
|
178
|
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
$pl->enter_perl_call(); |
|
180
|
0
|
|
|
|
|
|
my $ret = eval { |
|
181
|
|
|
|
|
|
|
package main; |
|
182
|
0
|
|
|
|
|
|
&{$tag->{handler_fn}} ($tagname, $attrs, $text, $pl); |
|
|
0
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
}; |
|
184
|
0
|
|
|
|
|
|
$pl->exit_perl_call(); |
|
185
|
|
|
|
|
|
|
|
|
186
|
0
|
0
|
|
|
|
|
if (!defined $ret) { |
|
187
|
0
|
|
|
|
|
|
warn "<$tagname> code failed: $@\n"; |
|
188
|
0
|
|
|
|
|
|
$ret = ''; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
0
|
|
|
|
|
|
$ret; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |