line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::View::ByCode::Renderer; |
2
|
|
|
|
|
|
|
$Catalyst::View::ByCode::Renderer::VERSION = '0.25'; |
3
|
3
|
|
|
3
|
|
202153
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
101
|
|
4
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
91
|
|
5
|
3
|
|
|
3
|
|
17
|
use base qw(Exporter); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
243
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
3564
|
use Devel::Declare(); |
|
3
|
|
|
|
|
29819
|
|
|
3
|
|
|
|
|
95
|
|
8
|
3
|
|
|
3
|
|
2644
|
use Catalyst::View::ByCode::Declare; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
112
|
|
9
|
3
|
|
|
3
|
|
19
|
use Scalar::Util 'blessed'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
190
|
|
10
|
3
|
|
|
3
|
|
3177
|
use HTML::Tagset; |
|
3
|
|
|
|
|
5073
|
|
|
3
|
|
|
|
|
1561
|
|
11
|
|
|
|
|
|
|
# use HTML::Entities; ### TODO: think about -- but pollutes our namespaces |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw(clear_markup init_markup get_markup); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw(template block block_content |
16
|
|
|
|
|
|
|
load |
17
|
|
|
|
|
|
|
yield |
18
|
|
|
|
|
|
|
params |
19
|
|
|
|
|
|
|
attr |
20
|
|
|
|
|
|
|
class id on |
21
|
|
|
|
|
|
|
stash c _ |
22
|
|
|
|
|
|
|
doctype boilerplate |
23
|
|
|
|
|
|
|
nbsp |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
26
|
|
|
|
|
|
|
markup => [ qw(clear_markup init_markup get_markup) ], |
27
|
|
|
|
|
|
|
default => [ @EXPORT ], |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our @IS_KNOWN = ( |
31
|
|
|
|
|
|
|
# HTML5 tags not defined in HTML::Tagset |
32
|
|
|
|
|
|
|
qw( article aside audio |
33
|
|
|
|
|
|
|
bdi bdo |
34
|
|
|
|
|
|
|
canvas |
35
|
|
|
|
|
|
|
data datalist details dialog |
36
|
|
|
|
|
|
|
figcaption figure footer |
37
|
|
|
|
|
|
|
header |
38
|
|
|
|
|
|
|
keygen |
39
|
|
|
|
|
|
|
main mark markup menu menuitem meter |
40
|
|
|
|
|
|
|
nav |
41
|
|
|
|
|
|
|
output |
42
|
|
|
|
|
|
|
progress |
43
|
|
|
|
|
|
|
rd rp rt ruby |
44
|
|
|
|
|
|
|
section source summary |
45
|
|
|
|
|
|
|
time track |
46
|
|
|
|
|
|
|
video ), |
47
|
|
|
|
|
|
|
grep { m{\A \w}xms } |
48
|
|
|
|
|
|
|
keys(%HTML::Tagset::isKnown) |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
our %EMPTY_ELEMENT = ( |
52
|
|
|
|
|
|
|
( |
53
|
|
|
|
|
|
|
map { ($_=>1) } |
54
|
|
|
|
|
|
|
qw(source) ### FIXME: more needed!!! |
55
|
|
|
|
|
|
|
), |
56
|
|
|
|
|
|
|
%HTML::Tagset::emptyElement |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# |
60
|
|
|
|
|
|
|
# define variables -- get local() ized at certain positions |
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
our @m; # whole content: initialized with &init_markup() |
63
|
|
|
|
|
|
|
our @top = ( \@m ); # contains open tags |
64
|
|
|
|
|
|
|
our $stash; # current stash |
65
|
|
|
|
|
|
|
our $c; # current context |
66
|
|
|
|
|
|
|
our $view; # ByCode View instance |
67
|
|
|
|
|
|
|
our $block_content; # code for executing &content() |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# |
70
|
|
|
|
|
|
|
# some constants |
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
our $NEED_ESCAPE = qr{[\"<>&\x{0000}-\x{001f}\x{007f}-\x{ffff}]}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# |
75
|
|
|
|
|
|
|
# some tags get changed by simply renaming them |
76
|
|
|
|
|
|
|
# |
77
|
|
|
|
|
|
|
# 'html tag' 'sub name' |
78
|
|
|
|
|
|
|
our %change_tags = ('select' => 'choice', |
79
|
|
|
|
|
|
|
'link' => 'link_tag', |
80
|
|
|
|
|
|
|
'tr' => 'trow', |
81
|
|
|
|
|
|
|
'td' => 'tcol', |
82
|
|
|
|
|
|
|
'sub' => 'subscript', |
83
|
|
|
|
|
|
|
'sup' => 'superscript', |
84
|
|
|
|
|
|
|
'meta' => 'meta_tag', # Moose needs &meta()... |
85
|
|
|
|
|
|
|
'q' => 'quote', |
86
|
|
|
|
|
|
|
's' => 'strike', |
87
|
|
|
|
|
|
|
'map' => 'map_tag', |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
######################################## IMPORT |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
# just importing this module... |
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
sub import { |
95
|
3
|
|
|
3
|
|
52
|
my $module = shift; # eat off 'Catalyst::View::ByCode::Renderer'; |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
21
|
my $calling_package = caller; |
98
|
|
|
|
|
|
|
|
99
|
3
|
|
|
|
|
67
|
my $default_export = grep {$_ eq ':default'} @_; |
|
3
|
|
|
|
|
11
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
# do Exporter's Job on Catalyst::View::ByCode::Renderer's @EXPORT |
103
|
|
|
|
|
|
|
# |
104
|
3
|
|
|
|
|
7
|
$module->export_to_level(1, $module, grep {!ref $_} @_); |
|
3
|
|
|
|
|
687
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# |
107
|
|
|
|
|
|
|
# overwrite (or create) &import in calling_package which |
108
|
|
|
|
|
|
|
# - auto-imports all block() directives |
109
|
|
|
|
|
|
|
# - adds a Devel::Declare-setup for every block() directive |
110
|
|
|
|
|
|
|
# |
111
|
3
|
100
|
66
|
|
|
47
|
if ($default_export && !UNIVERSAL::can($calling_package, '_import')) { |
112
|
3
|
|
|
3
|
|
20
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
616
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# save original -- in doubt use Exporter::import |
115
|
2
|
|
|
|
|
15
|
local *_old_import = (*{"$calling_package\::import"}{CODE}) |
|
0
|
|
|
|
|
0
|
|
116
|
2
|
|
|
|
|
18
|
? *{"$calling_package\::import"} |
117
|
2
|
50
|
|
|
|
5
|
: *{"Exporter::import"}; |
118
|
|
|
|
|
|
|
|
119
|
2
|
|
|
|
|
5
|
*{"$calling_package\::_import"} = *_old_import; |
|
2
|
|
|
|
|
8
|
|
120
|
2
|
|
|
|
|
5
|
*{"$calling_package\::import"} = \&overloaded_import; |
|
2
|
|
|
|
|
6
|
|
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# |
124
|
|
|
|
|
|
|
# build HTML Tag-subs into caller's namespace |
125
|
|
|
|
|
|
|
# |
126
|
3
|
100
|
|
|
|
15
|
_construct_functions($calling_package) |
127
|
|
|
|
|
|
|
if ($default_export); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# |
130
|
|
|
|
|
|
|
# create *OUT and *RAW in calling package to allow 'print' to work |
131
|
|
|
|
|
|
|
# 'print OUT' works, Components use a 'select OUT' to allow 'print' alone |
132
|
|
|
|
|
|
|
# |
133
|
3
|
|
|
3
|
|
16
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
624
|
|
134
|
3
|
100
|
66
|
|
|
2180
|
if ($default_export || !scalar(@_)) { |
135
|
2
|
|
|
|
|
5
|
tie *{"$calling_package\::OUT"}, $module, 1; # escaped: OUT |
|
2
|
|
|
|
|
107
|
|
136
|
2
|
|
|
|
|
5
|
tie *{"$calling_package\::RAW"}, $module, 0; # unescaped: RAW |
|
2
|
|
|
|
|
15
|
|
137
|
2
|
|
|
|
|
4
|
tie *{"$calling_package\::STDOUT"}, $module, 1; # escaped: STDOUT |
|
2
|
|
|
|
|
11
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# stupid hack to make -w happy ;-) |
140
|
2
|
|
|
|
|
3
|
my $dummy0 = *{"$calling_package\::OUT"}; |
|
2
|
|
|
|
|
8
|
|
141
|
2
|
|
|
|
|
3
|
my $dummy1 = *{"$calling_package\::RAW"}; |
|
2
|
|
|
|
|
6
|
|
142
|
2
|
|
|
|
|
6
|
my $dummy2 = *{"$calling_package\::STDOUT"}; |
|
2
|
|
|
|
|
47
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# |
147
|
|
|
|
|
|
|
# our importing packages' import() routine... |
148
|
|
|
|
|
|
|
# |
149
|
|
|
|
|
|
|
sub overloaded_import { |
150
|
0
|
|
|
0
|
0
|
0
|
my $imported_package = $_[0]; |
151
|
0
|
|
|
|
|
0
|
my $calling_package = caller; |
152
|
|
|
|
|
|
|
|
153
|
3
|
|
|
3
|
|
17
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2501
|
|
154
|
|
|
|
|
|
|
|
155
|
0
|
0
|
|
|
|
0
|
if (scalar(@{"$imported_package\::EXPORT_BLOCK"})) { |
|
0
|
|
|
|
|
0
|
|
156
|
|
|
|
|
|
|
# |
157
|
|
|
|
|
|
|
# process every recorded block() directive |
158
|
|
|
|
|
|
|
# |
159
|
0
|
|
|
|
|
0
|
my %declare; |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
0
|
foreach my $symbol (@{"$imported_package\::EXPORT_BLOCK"}) { |
|
0
|
|
|
|
|
0
|
|
162
|
|
|
|
|
|
|
### FIXME: aliasing makes trouble in case of overwriting !!!!! |
163
|
0
|
|
|
|
|
0
|
*{"$calling_package\::$symbol"} = *{"$imported_package\::$symbol"}; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
164
|
|
|
|
|
|
|
# *{"$calling_package\::$symbol"} = eval qq{ sub { goto $imported_package\::$symbol } }; |
165
|
|
|
|
|
|
|
# *{"$calling_package\::$symbol"} = eval qq{ sub { $imported_package\::$symbol(\@_) } }; |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
0
|
$declare{$symbol} = { |
168
|
|
|
|
|
|
|
const => Catalyst::View::ByCode::Declare::tag_parser |
169
|
|
|
|
|
|
|
}; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
0
|
0
|
|
|
|
0
|
if (scalar(keys(%declare))) { |
173
|
0
|
|
|
|
|
0
|
Devel::Declare->setup_for($calling_package, \%declare); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# |
178
|
|
|
|
|
|
|
# proceed with the original import |
179
|
|
|
|
|
|
|
# |
180
|
0
|
|
|
|
|
0
|
goto &{"$imported_package\::_import"}; |
|
0
|
|
|
|
|
0
|
|
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
######################################## FILE HANDLE MANAGEMENT |
184
|
|
|
|
|
|
|
# |
185
|
|
|
|
|
|
|
# IN/OUT stuff using a tied thing |
186
|
|
|
|
|
|
|
# |
187
|
|
|
|
|
|
|
sub TIEHANDLE { |
188
|
6
|
|
|
6
|
|
13
|
my $class = shift; # my class (Catalyst::View::ByCode::Renderer) |
189
|
6
|
|
|
|
|
10
|
my $handle = shift; # escaping on or off -- use this scalar as a handle |
190
|
|
|
|
|
|
|
# and its value to decide escaping |
191
|
|
|
|
|
|
|
# -- see PRINT below |
192
|
|
|
|
|
|
|
|
193
|
6
|
|
|
|
|
24
|
return bless \$handle, $class; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub PRINT { |
197
|
7
|
|
|
7
|
|
155
|
my $handle = shift; |
198
|
|
|
|
|
|
|
|
199
|
7
|
|
|
|
|
16
|
push @{$top[-1]}, |
200
|
|
|
|
|
|
|
map { |
201
|
7
|
|
|
|
|
10
|
blessed($_) && $_->can('render') |
202
|
|
|
|
|
|
|
? $_->render() |
203
|
|
|
|
|
|
|
: $$handle |
204
|
7
|
100
|
66
|
|
|
77
|
? do { my $text = "$_"; |
|
2
|
100
|
|
|
|
6
|
|
205
|
2
|
|
|
|
|
88
|
$text =~ s{($NEED_ESCAPE)}{'&#' . ord($1) . ';'}oexmsg; |
|
3
|
|
|
|
|
15
|
|
206
|
2
|
|
|
|
|
11
|
$text; } |
207
|
|
|
|
|
|
|
: "$_" |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
@_; |
210
|
7
|
|
|
|
|
34
|
return; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
0
|
|
0
|
sub PRINTF { $_[0]->PRINT(sprintf(@_[1..$#_])) } |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
######################################## MARKUP |
216
|
|
|
|
|
|
|
# |
217
|
|
|
|
|
|
|
# |
218
|
|
|
|
|
|
|
# |
219
|
|
|
|
|
|
|
sub clear_markup { |
220
|
24
|
|
|
24
|
0
|
92
|
@m = (); |
221
|
24
|
|
|
|
|
54
|
@top = ( \@m ); |
222
|
24
|
|
|
|
|
34
|
undef $c; |
223
|
24
|
|
|
|
|
33
|
undef $stash; |
224
|
24
|
|
|
|
|
44
|
undef $view; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub init_markup { |
228
|
19
|
|
|
19
|
0
|
5122
|
clear_markup(); |
229
|
|
|
|
|
|
|
|
230
|
19
|
|
|
|
|
24
|
$view = shift; |
231
|
19
|
|
|
|
|
24
|
$c = shift; |
232
|
19
|
50
|
33
|
|
|
119
|
$stash = $c && $c->can('stash') |
233
|
|
|
|
|
|
|
? $c->stash |
234
|
|
|
|
|
|
|
: {}; # primitive fallback |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
53
|
|
|
53
|
0
|
1206
|
sub get_markup { _render(@m) } |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub _render { |
240
|
3
|
|
|
3
|
|
18
|
no warnings 'uninitialized'; # we might have undef sometimes |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2468
|
|
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
join ('', |
243
|
|
|
|
|
|
|
map { |
244
|
84
|
|
|
84
|
|
180
|
ref($_) eq 'ARRAY' |
245
|
|
|
|
|
|
|
# a Tag is [ 'tag', {attrs}, content, ... ] |
246
|
128
|
100
|
|
|
|
6579
|
? do { |
247
|
31
|
|
|
|
|
54
|
my $attr = $_->[1]; |
248
|
|
|
|
|
|
|
|
249
|
31
|
|
|
|
|
37
|
$_->[0] |
250
|
|
|
|
|
|
|
# tag structure is named => <tag ...> |
251
|
|
|
|
|
|
|
? "<$_->[0]" . |
252
|
|
|
|
|
|
|
# render attribute(s) |
253
|
|
|
|
|
|
|
join('', |
254
|
|
|
|
|
|
|
map { |
255
|
28
|
|
|
|
|
106
|
my $k = $_; |
256
|
31
|
|
|
|
|
52
|
my $v = $attr->{$k}; |
257
|
|
|
|
|
|
|
|
258
|
31
|
100
|
33
|
|
|
717
|
if (!defined $v) { |
|
|
50
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
259
|
2
|
|
|
|
|
12
|
" $k"; |
260
|
|
|
|
|
|
|
} elsif ($k eq 'autofocus' || |
261
|
|
|
|
|
|
|
$k eq 'checked' || |
262
|
|
|
|
|
|
|
$k eq 'disabled' || |
263
|
|
|
|
|
|
|
$k eq 'formnovalidate' || |
264
|
|
|
|
|
|
|
$k eq 'hidden' || |
265
|
|
|
|
|
|
|
$k eq 'inert' || |
266
|
|
|
|
|
|
|
$k eq 'multiple' || |
267
|
|
|
|
|
|
|
$k eq 'novalidate' || |
268
|
|
|
|
|
|
|
$k eq 'readonly' || |
269
|
|
|
|
|
|
|
$k eq 'selected' || |
270
|
|
|
|
|
|
|
$k eq 'required') { |
271
|
|
|
|
|
|
|
# special handling for magic names that require magic values |
272
|
0
|
0
|
|
|
|
0
|
$v ? qq{ $k="$k"} : ''; |
273
|
|
|
|
|
|
|
} else { |
274
|
|
|
|
|
|
|
# not a special attribute name |
275
|
29
|
100
|
|
|
|
189
|
if (ref $v eq 'SCALAR') { |
|
|
100
|
|
|
|
|
|
276
|
1
|
|
|
|
|
3
|
$v = $$v; |
277
|
|
|
|
|
|
|
} elsif (ref $v) { |
278
|
|
|
|
|
|
|
# handle ref values differently |
279
|
2
|
|
|
|
|
8
|
$v = ref $v eq 'ARRAY' |
280
|
1
|
|
|
|
|
1
|
? join(' ', @{$v}) |
281
|
|
|
|
|
|
|
: ref $v eq 'HASH' |
282
|
|
|
|
|
|
|
? join(';', |
283
|
1
|
|
|
|
|
3
|
map { my $k = $_; |
284
|
1
|
|
|
|
|
5
|
$k =~ s{([A-Z])|_}{-\l$1}oxmsg; |
285
|
1
|
|
|
|
|
5
|
"$k:$v->{$_}" } |
286
|
4
|
50
|
|
|
|
25
|
keys %{$v}) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
287
|
|
|
|
|
|
|
: ref $v eq 'CODE' |
288
|
|
|
|
|
|
|
? $v->() |
289
|
|
|
|
|
|
|
: "$v"; |
290
|
4
|
|
|
|
|
82
|
$v =~ s{($NEED_ESCAPE)}{'&#' . ord($1) . ';'}oexmsg; |
|
2
|
|
|
|
|
9
|
|
291
|
|
|
|
|
|
|
} else { |
292
|
24
|
|
|
|
|
200
|
$v =~ s{($NEED_ESCAPE)}{'&#' . ord($1) . ';'}oexmsg; |
|
2
|
|
|
|
|
11
|
|
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
# convert key into dash-separaed version, |
296
|
|
|
|
|
|
|
# dataId -> data-id, data_id => data-id |
297
|
29
|
|
|
|
|
130
|
$k =~ s{([A-Z])|_}{-\l$1}oxmsg; |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
# compose attr="value" |
300
|
29
|
|
|
|
|
171
|
qq{ $k="$v"}; |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
sort # not needed but nice for testing/guessing |
304
|
28
|
|
|
|
|
67
|
keys %{$attr} |
305
|
|
|
|
|
|
|
) . |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
# closing tag or content? |
308
|
|
|
|
|
|
|
(exists($EMPTY_ELEMENT{$_->[0]}) |
309
|
|
|
|
|
|
|
? ' />' |
310
|
|
|
|
|
|
|
: '>' . |
311
|
3
|
|
|
|
|
36
|
_render(@{$_}[2 .. $#$_]) . |
312
|
|
|
|
|
|
|
"</$_->[0]>") |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
# tag is unnamed -- just render content |
315
|
31
|
50
|
|
|
|
101
|
: _render(@{$_}[2 .. $#$_]) |
|
|
100
|
|
|
|
|
|
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# everything else is stringified |
319
|
|
|
|
|
|
|
: "$_" |
320
|
|
|
|
|
|
|
} @_); |
321
|
|
|
|
|
|
|
} |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
######################################## EXPORTED FUNCTIONS |
324
|
|
|
|
|
|
|
# |
325
|
|
|
|
|
|
|
# a template definition instead of sub RUN {} |
326
|
|
|
|
|
|
|
# |
327
|
|
|
|
|
|
|
sub template(&) { |
328
|
1
|
|
|
1
|
0
|
34
|
my $package = caller; |
329
|
|
|
|
|
|
|
|
330
|
1
|
|
|
|
|
42
|
my $code = shift; |
331
|
3
|
|
|
3
|
|
22
|
no strict 'refs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
841
|
|
332
|
1
|
|
|
|
|
4
|
*{"$package\::RUN"} = sub { |
333
|
1
|
|
|
1
|
|
21
|
push @{$top[-1]}, [ '', {} ]; |
|
1
|
|
|
|
|
6
|
|
334
|
|
|
|
|
|
|
|
335
|
1
|
|
|
|
|
2
|
push @top, $top[-1]->[-1]; |
336
|
|
|
|
|
|
|
|
337
|
1
|
|
|
|
|
5
|
my $text = $code->(); |
338
|
1
|
50
|
33
|
|
|
10
|
if (ref($text) && UNIVERSAL::can($text, 'render')) { |
339
|
0
|
|
|
|
|
0
|
push @{$top[-1]}, $text->render; |
|
0
|
|
|
|
|
0
|
|
340
|
|
|
|
|
|
|
} else { |
341
|
3
|
|
|
3
|
|
19
|
no warnings 'uninitialized'; # we might see undef values |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
599
|
|
342
|
1
|
|
|
|
|
27
|
$text =~ s{($NEED_ESCAPE)}{'&#' . ord($1) . ';'}oexmsg; |
|
0
|
|
|
|
|
0
|
|
343
|
1
|
|
|
|
|
2
|
push @{$top[-1]}, $text; |
|
1
|
|
|
|
|
18
|
|
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
|
346
|
1
|
|
|
|
|
2
|
pop @top; |
347
|
1
|
|
|
|
|
5
|
return; |
348
|
1
|
|
|
|
|
7
|
}; |
349
|
|
|
|
|
|
|
|
350
|
1
|
|
|
|
|
5
|
return; |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
# |
354
|
|
|
|
|
|
|
# a block definition |
355
|
|
|
|
|
|
|
# |
356
|
|
|
|
|
|
|
sub block($&;@) { |
357
|
1
|
|
|
1
|
0
|
123
|
my $name = shift; |
358
|
1
|
|
|
|
|
3
|
my $code = shift; |
359
|
|
|
|
|
|
|
|
360
|
1
|
|
|
|
|
4
|
my $package = caller; |
361
|
|
|
|
|
|
|
|
362
|
3
|
|
|
3
|
|
18
|
no strict 'refs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
91
|
|
363
|
3
|
|
|
3
|
|
14
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
3332
|
|
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
# |
366
|
|
|
|
|
|
|
# generate a sub in our namespace |
367
|
|
|
|
|
|
|
# |
368
|
1
|
|
|
|
|
9
|
*{"$package\::$name"} = sub(;&@) { |
369
|
1
|
|
|
1
|
|
4
|
local $block_content = $_[0]; |
370
|
|
|
|
|
|
|
|
371
|
1
|
|
|
|
|
2
|
push @{$top[-1]}, [ '', { @_[1 .. $#_] } ]; |
|
1
|
|
|
|
|
5
|
|
372
|
|
|
|
|
|
|
|
373
|
1
|
50
|
|
|
|
4
|
if ($code) { |
374
|
1
|
|
|
|
|
2
|
push @top, $top[-1]->[-1]; |
375
|
1
|
|
|
|
|
2
|
push @{$top[-1]}, $code->(); |
|
1
|
|
|
|
|
25
|
|
376
|
1
|
|
|
|
|
5
|
pop @top; |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
1
|
|
|
|
|
3
|
return; |
380
|
1
|
|
|
|
|
39
|
}; |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
# |
383
|
|
|
|
|
|
|
# mark this sub as a special exportable |
384
|
|
|
|
|
|
|
# |
385
|
1
|
|
|
|
|
3
|
${"$package\::EXPORT_BLOCK"}{$name} = 1; |
|
1
|
|
|
|
|
19
|
|
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
# |
389
|
|
|
|
|
|
|
# execute a block's content |
390
|
|
|
|
|
|
|
# |
391
|
|
|
|
|
|
|
sub block_content { |
392
|
0
|
0
|
|
0
|
0
|
0
|
push @{$top[-1]}, $block_content->(@_) if ($block_content); |
|
0
|
|
|
|
|
0
|
|
393
|
0
|
|
|
|
|
0
|
return; |
394
|
|
|
|
|
|
|
} |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
# |
397
|
|
|
|
|
|
|
# a simple shortcut for multiple param(name => ..., value => ...) sequences |
398
|
|
|
|
|
|
|
# |
399
|
|
|
|
|
|
|
sub params { |
400
|
0
|
|
|
0
|
0
|
0
|
my %params = @_; |
401
|
|
|
|
|
|
|
|
402
|
0
|
|
|
|
|
0
|
while (my ($name, $value) = each %params) { |
403
|
0
|
|
|
|
|
0
|
push @{$top[-1]}, [ 'param', { name => $name, value => $value } ]; |
|
0
|
|
|
|
|
0
|
|
404
|
|
|
|
|
|
|
} |
405
|
|
|
|
|
|
|
|
406
|
0
|
|
|
|
|
0
|
return; |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
# |
410
|
|
|
|
|
|
|
# a simple shortcut for css/js handling |
411
|
|
|
|
|
|
|
# usage: |
412
|
|
|
|
|
|
|
# load js => '/url/to/file.js'; |
413
|
|
|
|
|
|
|
# load css => '/url/to/file.js'; |
414
|
|
|
|
|
|
|
# |
415
|
|
|
|
|
|
|
# load <<Controller_name>> => file_name [.js] |
416
|
|
|
|
|
|
|
# |
417
|
|
|
|
|
|
|
### FIXME: build more logic into load() -- accumulate calls |
418
|
|
|
|
|
|
|
### and resolve as late as possible |
419
|
|
|
|
|
|
|
# |
420
|
|
|
|
|
|
|
sub load { |
421
|
0
|
|
|
0
|
0
|
0
|
my $kind = shift; |
422
|
|
|
|
|
|
|
|
423
|
0
|
0
|
0
|
|
|
0
|
return if (!$kind || ref($kind)); |
424
|
|
|
|
|
|
|
|
425
|
0
|
0
|
0
|
|
|
0
|
if ($kind eq 'css') { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
426
|
|
|
|
|
|
|
# |
427
|
|
|
|
|
|
|
# simple static CSS inserted just here and now |
428
|
|
|
|
|
|
|
# |
429
|
0
|
|
|
|
|
0
|
push @{$top[-1]}, |
|
0
|
|
|
|
|
0
|
|
430
|
0
|
|
|
|
|
0
|
map { [ 'link', |
431
|
|
|
|
|
|
|
{ |
432
|
|
|
|
|
|
|
rel => 'stylesheet', |
433
|
|
|
|
|
|
|
type => 'text/css', |
434
|
|
|
|
|
|
|
href => $_ |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
] } @_; |
437
|
|
|
|
|
|
|
} elsif ($kind eq 'js') { |
438
|
|
|
|
|
|
|
# |
439
|
|
|
|
|
|
|
# simple static JS inserted just here and now |
440
|
|
|
|
|
|
|
# |
441
|
0
|
|
|
|
|
0
|
push @{$top[-1]}, |
|
0
|
|
|
|
|
0
|
|
442
|
0
|
|
|
|
|
0
|
map { [ 'script', |
443
|
|
|
|
|
|
|
{ |
444
|
|
|
|
|
|
|
type => 'text/javascript', |
445
|
|
|
|
|
|
|
src => $_ |
446
|
|
|
|
|
|
|
} |
447
|
|
|
|
|
|
|
] } @_; |
448
|
|
|
|
|
|
|
} elsif ((my $controller = $c->controller($kind)) && |
449
|
|
|
|
|
|
|
($kind eq 'Js' || $kind eq 'Css')) { |
450
|
|
|
|
|
|
|
### FIXME: are Hardcoded controller names wise??? |
451
|
|
|
|
|
|
|
# |
452
|
|
|
|
|
|
|
# some other kind of load operation we have a controller for |
453
|
|
|
|
|
|
|
# |
454
|
|
|
|
|
|
|
# $c->log->debug("LOAD: kind=$kind, ref(controller)=" . ref($controller)); |
455
|
|
|
|
|
|
|
|
456
|
0
|
0
|
|
|
|
0
|
if ($kind eq 'Css') { |
457
|
0
|
|
|
|
|
0
|
push @{$top[-1]}, |
|
0
|
|
|
|
|
0
|
|
458
|
|
|
|
|
|
|
[ 'link', |
459
|
|
|
|
|
|
|
{ |
460
|
|
|
|
|
|
|
rel => 'stylesheet', |
461
|
|
|
|
|
|
|
type => 'text/css', |
462
|
|
|
|
|
|
|
href =>$c->uri_for($controller->action_for('default'), @_) |
463
|
|
|
|
|
|
|
} |
464
|
|
|
|
|
|
|
]; |
465
|
|
|
|
|
|
|
} else { |
466
|
0
|
|
|
|
|
0
|
push @{$top[-1]}, |
|
0
|
|
|
|
|
0
|
|
467
|
|
|
|
|
|
|
[ 'script', |
468
|
|
|
|
|
|
|
{ |
469
|
|
|
|
|
|
|
type => 'text/javascript', |
470
|
|
|
|
|
|
|
src => $c->uri_for($controller->action_for('default'), @_) |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
]; |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
|
476
|
0
|
|
|
|
|
0
|
return; |
477
|
|
|
|
|
|
|
} |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
# |
480
|
|
|
|
|
|
|
# a special sub-rendering command like Rails ;-) |
481
|
|
|
|
|
|
|
# |
482
|
|
|
|
|
|
|
# yield \&name_of_a_sub; |
483
|
|
|
|
|
|
|
# yield a_named_yield; |
484
|
|
|
|
|
|
|
# yield 'content'; |
485
|
|
|
|
|
|
|
# yield; # same as 'content' |
486
|
|
|
|
|
|
|
# yield 'path/to/template.pl' |
487
|
|
|
|
|
|
|
# ### TODO: yield package::subname |
488
|
|
|
|
|
|
|
# ### TODO: yield +package::package::package::subname |
489
|
|
|
|
|
|
|
# |
490
|
|
|
|
|
|
|
sub yield(;*@) { |
491
|
0
|
|
0
|
0
|
0
|
0
|
my $yield_name = shift || 'content'; |
492
|
|
|
|
|
|
|
|
493
|
0
|
0
|
|
|
|
0
|
$c->log->debug("yield '$yield_name' executing...") if $c->debug; |
494
|
|
|
|
|
|
|
|
495
|
0
|
0
|
|
|
|
0
|
_yield(exists($c->stash->{yield}->{$yield_name}) |
|
|
0
|
|
|
|
|
|
496
|
|
|
|
|
|
|
? $c->stash->{yield}->{$yield_name} |
497
|
|
|
|
|
|
|
: $yield_name) |
498
|
|
|
|
|
|
|
or $c->log->info("could not yield '$yield_name'"); |
499
|
|
|
|
|
|
|
|
500
|
0
|
|
|
|
|
0
|
return; |
501
|
|
|
|
|
|
|
} |
502
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
# helper for recursive resolution |
504
|
|
|
|
|
|
|
sub _yield { |
505
|
0
|
|
|
0
|
|
0
|
my $thing = shift; |
506
|
|
|
|
|
|
|
|
507
|
0
|
0
|
|
|
|
0
|
if (!$thing) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
508
|
0
|
|
|
|
|
0
|
return; |
509
|
|
|
|
|
|
|
} elsif (ref($thing) eq 'ARRAY') { |
510
|
0
|
|
|
|
|
0
|
my $result; |
511
|
0
|
|
|
|
|
0
|
while (my $x = shift(@{$thing})) { |
|
0
|
|
|
|
|
0
|
|
512
|
0
|
0
|
|
|
|
0
|
_yield($x) and $result = 1; |
513
|
|
|
|
|
|
|
} |
514
|
0
|
|
|
|
|
0
|
return $result; |
515
|
|
|
|
|
|
|
} elsif (ref($thing) eq 'CODE') { |
516
|
0
|
|
|
|
|
0
|
$thing->(); |
517
|
0
|
|
|
|
|
0
|
return 1; |
518
|
|
|
|
|
|
|
} elsif (!ref($thing)) { |
519
|
0
|
|
|
|
|
0
|
return _yield($view->_compile_template($c, $thing)); |
520
|
|
|
|
|
|
|
} |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
# |
524
|
|
|
|
|
|
|
# get/set attribute(s) of latest open tag |
525
|
|
|
|
|
|
|
# |
526
|
|
|
|
|
|
|
sub attr { |
527
|
|
|
|
|
|
|
# FIXME: better discovery of set/get !defined wantarray (?) |
528
|
|
|
|
|
|
|
|
529
|
2
|
50
|
66
|
2
|
0
|
16
|
return $top[-1]->[1]->{$_[0]} if scalar @_ == 1 && defined wantarray; |
530
|
|
|
|
|
|
|
|
531
|
3
|
|
|
3
|
|
51
|
no warnings; # avoid odd no of elements in hash |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
3536
|
|
532
|
2
|
|
|
|
|
4
|
%{ $top[-1]->[1] } = ( %{ $top[-1]->[1] }, @_ ); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
7
|
|
533
|
2
|
|
|
|
|
4
|
return; |
534
|
|
|
|
|
|
|
} |
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
# |
537
|
|
|
|
|
|
|
# set a class inside a tag |
538
|
|
|
|
|
|
|
# |
539
|
|
|
|
|
|
|
sub class { |
540
|
11
|
50
|
|
11
|
0
|
55
|
my @args = @_ |
541
|
|
|
|
|
|
|
or return; |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
# |
544
|
|
|
|
|
|
|
# class 'huhu'; - set 'huhu' (replacing previous name) |
545
|
|
|
|
|
|
|
# class 'huhu zzz'; - set 'huhu' and 'zzz' (replacing previous name/s) |
546
|
|
|
|
|
|
|
# class '-bar'; - remove 'bar' |
547
|
|
|
|
|
|
|
# class '-bar baz'; - remove 'bar' and 'baz' |
548
|
|
|
|
|
|
|
# class '+foo'; - add 'foo' |
549
|
|
|
|
|
|
|
# class '+foo moo' - add 'foo' and 'moo' |
550
|
|
|
|
|
|
|
# class '+foo -bar baz' - add 'foo', remove 'bar' and 'baz' |
551
|
|
|
|
|
|
|
# class '+foo','-bar','baz' - add 'foo', remove 'bar' and 'baz' |
552
|
|
|
|
|
|
|
# class qw(+foo -bar baz) - same thing. |
553
|
|
|
|
|
|
|
# |
554
|
11
|
|
100
|
|
|
41
|
my $class_name = $top[-1]->[1]->{class} || ''; |
555
|
8
|
|
|
|
|
25
|
my %class = map {($_ => 1)} |
|
8
|
|
|
|
|
15
|
|
556
|
11
|
|
|
|
|
56
|
grep {$_} |
557
|
|
|
|
|
|
|
split(qr{\s+}xms, $class_name); |
558
|
|
|
|
|
|
|
|
559
|
11
|
|
|
|
|
25
|
my $operation = 0; # -1 = sub, 0 = set, +1 = add |
560
|
11
|
50
|
33
|
|
|
19
|
foreach my $name (grep {length} map {split qr{\s+}xms} grep {!ref && defined && length} @args) { |
|
16
|
|
|
|
|
29
|
|
|
12
|
|
|
|
|
61
|
|
|
12
|
|
|
|
|
79
|
|
561
|
16
|
100
|
|
|
|
54
|
if ($name =~ s{\A([-+])}{}xms) { |
562
|
6
|
100
|
|
|
|
17
|
$operation = $1 eq '-' ? -1 : +1; |
563
|
|
|
|
|
|
|
} |
564
|
16
|
100
|
|
|
|
37
|
if ($operation < 0) { |
|
|
100
|
|
|
|
|
|
565
|
3
|
|
|
|
|
8
|
delete $class{$name}; |
566
|
|
|
|
|
|
|
} elsif ($operation > 0) { |
567
|
6
|
|
|
|
|
19
|
$class{$name} = 1; |
568
|
|
|
|
|
|
|
} else { |
569
|
7
|
|
|
|
|
17
|
%class = ($name => 1); |
570
|
7
|
|
|
|
|
14
|
$operation = +1; |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
} |
573
|
|
|
|
|
|
|
|
574
|
11
|
|
|
|
|
49
|
$top[-1]->[1]->{class} = join(' ', sort keys(%class)); |
575
|
11
|
|
|
|
|
36
|
return; |
576
|
|
|
|
|
|
|
} |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
# |
579
|
|
|
|
|
|
|
# set an ID |
580
|
|
|
|
|
|
|
# |
581
|
1
|
|
|
1
|
0
|
8
|
sub id { $top[-1]->[1]->{id} = $_[0]; return; } |
|
1
|
|
|
|
|
3
|
|
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
# |
584
|
|
|
|
|
|
|
# define a javascript-handler |
585
|
|
|
|
|
|
|
# |
586
|
0
|
|
|
0
|
0
|
0
|
sub on { $top[-1]->[1]->{"on$_[0]"} = join('', @_[1..$#_]); return; } |
|
0
|
|
|
|
|
0
|
|
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
# |
589
|
|
|
|
|
|
|
# simple getters |
590
|
|
|
|
|
|
|
# |
591
|
0
|
|
|
0
|
0
|
0
|
sub stash { $stash } |
592
|
0
|
|
|
0
|
0
|
0
|
sub c { $c } |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
# |
595
|
|
|
|
|
|
|
# generate a proper doctype line |
596
|
|
|
|
|
|
|
# |
597
|
|
|
|
|
|
|
sub doctype { |
598
|
0
|
|
|
0
|
0
|
0
|
my $kind = join(' ', @_); |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
# see http://hsivonen.iki.fi/doctype/ for details on these... |
601
|
0
|
|
|
|
|
0
|
my @doctype_finder = ( |
602
|
|
|
|
|
|
|
[qr(html(?:\W*5)) => 'html5'], |
603
|
|
|
|
|
|
|
[qr(html) => 'html5'], |
604
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
[qr(html(?:\W*4[0-9.]*)?\W*s) => 'html4_strict'], |
606
|
|
|
|
|
|
|
[qr(html(?:\W*4[0-9.]*)?\W*[tl]) => 'html4_loose'], |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
[qr(xhtml\W*1\W*1) => 'xhtml1_1'], |
609
|
|
|
|
|
|
|
[qr(xhtml(?:\W*1[0-9.]*)?\W*s) => 'xhtml1_strict'], |
610
|
|
|
|
|
|
|
[qr(xhtml(?:\W*1[0-9.]*)?\W*[tl]) => 'xhtml1_trans'], |
611
|
|
|
|
|
|
|
[qr(xhtml) => 'xhtml1'], |
612
|
|
|
|
|
|
|
); |
613
|
|
|
|
|
|
|
|
614
|
0
|
|
|
|
|
0
|
my %doctype_for = ( |
615
|
|
|
|
|
|
|
default => q{<!DOCTYPE html>}, |
616
|
|
|
|
|
|
|
html5 => q{<!DOCTYPE html>}, |
617
|
|
|
|
|
|
|
html4 => q{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">}, |
618
|
|
|
|
|
|
|
html4_strict => q{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" } . |
619
|
|
|
|
|
|
|
q{"http://www.w3.org/TR/html4/strict.dtd">}, |
620
|
|
|
|
|
|
|
html4_loose => q{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" } . |
621
|
|
|
|
|
|
|
q{"http://www.w3.org/TR/html4/loose.dtd">}, |
622
|
|
|
|
|
|
|
xhtml1_1 => q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" } . |
623
|
|
|
|
|
|
|
q{"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">}, |
624
|
|
|
|
|
|
|
xhtml1 => q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" } . |
625
|
|
|
|
|
|
|
q{"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">}, |
626
|
|
|
|
|
|
|
xhtml1_strict=> q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" } . |
627
|
|
|
|
|
|
|
q{"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">}, |
628
|
|
|
|
|
|
|
xhtml1_trans => q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" } . |
629
|
|
|
|
|
|
|
q{"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">}, |
630
|
|
|
|
|
|
|
); |
631
|
|
|
|
|
|
|
|
632
|
0
|
|
|
|
|
0
|
my $doctype = 'default'; |
633
|
0
|
|
|
|
|
0
|
foreach my $d (@doctype_finder) { |
634
|
0
|
0
|
|
|
|
0
|
if ($kind =~ m{\A $d->[0]}xmsi) { |
635
|
0
|
|
|
|
|
0
|
$doctype = $d->[1]; |
636
|
0
|
|
|
|
|
0
|
last; |
637
|
|
|
|
|
|
|
} |
638
|
|
|
|
|
|
|
} |
639
|
|
|
|
|
|
|
|
640
|
0
|
|
|
|
|
0
|
push @{$top[-1]}, $doctype_for{$doctype}; |
|
0
|
|
|
|
|
0
|
|
641
|
|
|
|
|
|
|
} |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
sub boilerplate(;&) { |
644
|
2
|
|
|
2
|
0
|
4
|
my $code = shift; |
645
|
|
|
|
|
|
|
|
646
|
2
|
|
|
|
|
3
|
push @{$top[-1]}, <<HTML; |
|
2
|
|
|
|
|
6
|
|
647
|
|
|
|
|
|
|
<!--[if lt IE 7 ]> <html class="no-js ie6" lang="en"> <![endif]--> |
648
|
|
|
|
|
|
|
<!--[if IE 7 ]> <html class="no-js ie7" lang="en"> <![endif]--> |
649
|
|
|
|
|
|
|
<!--[if IE 8 ]> <html class="no-js ie8" lang="en"> <![endif]--> |
650
|
|
|
|
|
|
|
<!--[if (gte IE 9)|!(IE)]><!--> <html class="no-js" lang="en"> <!--<![endif]--> |
651
|
|
|
|
|
|
|
HTML |
652
|
|
|
|
|
|
|
|
653
|
2
|
100
|
|
|
|
6
|
if ($code) { |
654
|
1
|
|
|
|
|
4
|
$code->(); |
655
|
|
|
|
|
|
|
} |
656
|
|
|
|
|
|
|
|
657
|
2
|
|
|
|
|
4
|
push @{$top[-1]}, '</html>'; |
|
2
|
|
|
|
|
6
|
|
658
|
|
|
|
|
|
|
} |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
######################################## Locale stuff |
661
|
|
|
|
|
|
|
# |
662
|
|
|
|
|
|
|
# get a localized version of something |
663
|
|
|
|
|
|
|
# |
664
|
|
|
|
|
|
|
{ |
665
|
3
|
|
|
3
|
|
21
|
no warnings 'redefine'; |
|
3
|
|
|
|
|
23
|
|
|
3
|
|
|
|
|
423
|
|
666
|
0
|
|
|
0
|
|
0
|
sub _ { return $c->localize(@_) } |
667
|
|
|
|
|
|
|
} |
668
|
|
|
|
|
|
|
|
669
|
0
|
|
|
0
|
0
|
0
|
sub nbsp { "\x{00a0}" } # bad hack in the moment... |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
# |
672
|
|
|
|
|
|
|
# define a function for every tag into a given namespace |
673
|
|
|
|
|
|
|
# |
674
|
|
|
|
|
|
|
sub _construct_functions { |
675
|
2
|
|
|
2
|
|
4
|
my $namespace = shift; |
676
|
|
|
|
|
|
|
|
677
|
3
|
|
|
3
|
|
16
|
no warnings 'redefine'; # in case of a re-compile. |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
214
|
|
678
|
|
|
|
|
|
|
|
679
|
2
|
|
|
|
|
5
|
my %declare; |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
# tags with content are treated the same as tags without content |
682
|
2
|
|
|
|
|
4
|
foreach my $tag_name (@IS_KNOWN) { |
683
|
276
|
|
66
|
|
|
987
|
my $sub_name = $change_tags{$tag_name} |
684
|
|
|
|
|
|
|
|| $tag_name; |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
# install a tag-named sub in caller's namespace |
687
|
3
|
|
|
3
|
|
21
|
no strict 'refs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
577
|
|
688
|
276
|
|
|
|
|
1770
|
*{"$namespace\::$sub_name"} = sub (;&@) { |
689
|
17
|
|
|
17
|
|
293
|
push @{$top[-1]}, [ $tag_name, { @_[1 .. $#_] } ]; |
|
17
|
|
|
|
|
83
|
|
690
|
|
|
|
|
|
|
|
691
|
17
|
50
|
|
|
|
48
|
if ($_[0]) { |
692
|
17
|
|
|
|
|
25
|
push @top, $top[-1]->[-1]; |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
#### TODO: find out why ->render does not work for HTML::FormFu !!! |
695
|
|
|
|
|
|
|
|
696
|
17
|
|
|
|
|
44
|
my $text = $_[0]->(@_); |
697
|
17
|
100
|
100
|
|
|
107
|
if (ref $text && UNIVERSAL::can($text, 'render')) { |
|
|
100
|
|
|
|
|
|
698
|
1
|
|
|
|
|
3
|
push @{$top[-1]}, $text->render; |
|
1
|
|
|
|
|
5
|
|
699
|
|
|
|
|
|
|
} elsif (ref $text eq 'SCALAR') { |
700
|
1
|
|
|
|
|
2
|
push @{$top[-1]}, $$text; |
|
1
|
|
|
|
|
4
|
|
701
|
|
|
|
|
|
|
} else { |
702
|
3
|
|
|
3
|
|
15
|
no warnings 'uninitialized'; # we might see undef values |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
491
|
|
703
|
15
|
|
|
|
|
45
|
$text =~ s{($NEED_ESCAPE)}{'&#' . ord($1) . ';'}oexmsg; |
|
0
|
|
|
|
|
0
|
|
704
|
15
|
|
|
|
|
19
|
push @{$top[-1]}, $text; |
|
15
|
|
|
|
|
34
|
|
705
|
|
|
|
|
|
|
} |
706
|
|
|
|
|
|
|
|
707
|
17
|
|
|
|
|
27
|
pop @top; |
708
|
|
|
|
|
|
|
} |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
### TODO: can we call _render() here and save text instead of a structure? |
711
|
|
|
|
|
|
|
### would convert [ tag => {attr}, content ] to <tag attr>content</tag> |
712
|
|
|
|
|
|
|
# $top[-1] = _render($top[-1]); |
713
|
|
|
|
|
|
|
|
714
|
17
|
|
|
|
|
50
|
return; |
715
|
276
|
|
|
|
|
1533
|
}; |
716
|
3
|
|
|
3
|
|
15
|
use strict 'refs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
424
|
|
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
# remember me to generate a magic tag-parser that applies extra magic |
719
|
276
|
|
|
|
|
683
|
$declare{$sub_name} = { |
720
|
|
|
|
|
|
|
const => Catalyst::View::ByCode::Declare::tag_parser |
721
|
|
|
|
|
|
|
}; |
722
|
|
|
|
|
|
|
} |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
# add logic for block definitions |
725
|
|
|
|
|
|
|
$declare{block} = { |
726
|
2
|
|
|
|
|
12
|
const => Catalyst::View::ByCode::Declare::block_parser |
727
|
|
|
|
|
|
|
}; |
728
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
# install all tag-parsers collected above |
730
|
2
|
|
|
|
|
26
|
Devel::Declare->setup_for($namespace, \%declare); |
731
|
|
|
|
|
|
|
} |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
1; |