| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package YATT::Lite::Core; sub MY () {__PACKAGE__} |
|
2
|
11
|
|
|
11
|
|
55
|
use strict; |
|
|
11
|
|
|
|
|
20
|
|
|
|
11
|
|
|
|
|
352
|
|
|
3
|
11
|
|
|
11
|
|
54
|
use warnings qw(FATAL all NONFATAL misc); |
|
|
11
|
|
|
|
|
21
|
|
|
|
11
|
|
|
|
|
405
|
|
|
4
|
11
|
|
|
11
|
|
53
|
use Carp; |
|
|
11
|
|
|
|
|
28
|
|
|
|
11
|
|
|
|
|
836
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
11
|
|
|
11
|
|
64
|
use constant DEBUG_REBUILD => $ENV{DEBUG_YATT_REBUILD}; |
|
|
11
|
|
|
|
|
16
|
|
|
|
11
|
|
|
|
|
807
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
268
|
use parent qw(YATT::Lite::VFS); |
|
|
11
|
|
|
|
|
5113
|
|
|
|
11
|
|
|
|
|
82
|
|
|
9
|
11
|
|
|
|
|
104
|
use YATT::Lite::MFields qw/cf_namespace cf_debug_cgen cf_no_lineinfo cf_check_lineno |
|
10
|
|
|
|
|
|
|
cf_index_name |
|
11
|
|
|
|
|
|
|
cf_tmpl_encoding |
|
12
|
|
|
|
|
|
|
cf_debug_parser |
|
13
|
|
|
|
|
|
|
cf_parse_while_loading cf_only_parse |
|
14
|
|
|
|
|
|
|
cf_die_in_error cf_error_handler |
|
15
|
|
|
|
|
|
|
cf_special_entities |
|
16
|
|
|
|
|
|
|
cf_lcmsg_sink |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
n_compiles |
|
19
|
|
|
|
|
|
|
cgen_class |
|
20
|
11
|
|
|
11
|
|
734
|
/; |
|
|
11
|
|
|
|
|
23
|
|
|
21
|
11
|
|
|
11
|
|
106
|
use YATT::Lite::Util; |
|
|
11
|
|
|
|
|
19
|
|
|
|
11
|
|
|
|
|
1460
|
|
|
22
|
11
|
|
|
11
|
|
6610
|
use YATT::Lite::Constants; |
|
|
11
|
|
|
|
|
27
|
|
|
|
11
|
|
|
|
|
2504
|
|
|
23
|
11
|
|
|
11
|
|
3013
|
use YATT::Lite::Entities; |
|
|
11
|
|
|
|
|
24
|
|
|
|
11
|
|
|
|
|
125
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# XXX: YATT::Lite に? |
|
26
|
11
|
|
|
11
|
|
62
|
use YATT::Lite::Breakpoint (); |
|
|
11
|
|
|
|
|
25
|
|
|
|
11
|
|
|
|
|
287
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#======================================== |
|
29
|
|
|
|
|
|
|
# 以下、 package YATT::Lite のための、内部クラス |
|
30
|
|
|
|
|
|
|
#======================================== |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
11
|
|
|
11
|
|
54
|
use YATT::Lite::VFS qw(Folder Item); |
|
|
11
|
|
|
|
|
20
|
|
|
|
11
|
|
|
|
|
1837
|
|
|
33
|
|
|
|
|
|
|
use YATT::Lite::Types |
|
34
|
11
|
|
|
|
|
374
|
([Part => -base => MY->Item |
|
35
|
|
|
|
|
|
|
, -fields => [qw(toks arg_dict arg_order |
|
36
|
|
|
|
|
|
|
cf_namespace cf_kind cf_folder cf_data |
|
37
|
|
|
|
|
|
|
cf_implicit cf_suppressed |
|
38
|
|
|
|
|
|
|
cf_startln cf_bodyln cf_endln |
|
39
|
|
|
|
|
|
|
cf_startpos cf_bodypos cf_bodylen |
|
40
|
|
|
|
|
|
|
cf_subpattern |
|
41
|
|
|
|
|
|
|
)] |
|
42
|
|
|
|
|
|
|
, -constants => [[public => 0]] |
|
43
|
|
|
|
|
|
|
, [Widget => -fields => [qw(tree var_dict has_required_arg)] |
|
44
|
|
|
|
|
|
|
, [Page => (), -constants => [[public => 1]]]] |
|
45
|
|
|
|
|
|
|
, [Action => (), -constants => [[public => 1]]] |
|
46
|
|
|
|
|
|
|
, [Data => ()]] |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
, [Template => -base => MY->File |
|
49
|
|
|
|
|
|
|
, -alias => 'vfs_file' |
|
50
|
|
|
|
|
|
|
, -fields => [qw(product parse_ok cf_mtime cf_utf8 cf_age |
|
51
|
|
|
|
|
|
|
cf_usage cf_constants |
|
52
|
|
|
|
|
|
|
cf_ignore_trailing_newlines |
|
53
|
|
|
|
|
|
|
cf_subroutes |
|
54
|
|
|
|
|
|
|
)]] |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
, [ParsingState => -fields => [qw(startln endln |
|
57
|
|
|
|
|
|
|
startpos curpos |
|
58
|
|
|
|
|
|
|
cf_path |
|
59
|
|
|
|
|
|
|
)]] |
|
60
|
11
|
|
|
11
|
|
58
|
); |
|
|
11
|
|
|
|
|
21
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# folder の weaken は parser がしてる。 |
|
63
|
|
|
|
|
|
|
# sub YATT::Lite::Core::Part::source { |
|
64
|
|
|
|
|
|
|
# (my Part $part) = @_; |
|
65
|
|
|
|
|
|
|
# join "", map {ref $_ ? "\n" x $$_[0] : $_} @{$part->{source}}; |
|
66
|
|
|
|
|
|
|
# } |
|
67
|
|
|
|
|
|
|
sub YATT::Lite::Core::Template::source_length { |
|
68
|
0
|
|
|
0
|
0
|
0
|
(my Template $self) = @_; |
|
69
|
0
|
|
|
|
|
0
|
length $self->{cf_string}; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
sub YATT::Lite::Core::Template::list_parts { |
|
72
|
170
|
|
|
170
|
0
|
265
|
(my Template $self, my $type) = @_; |
|
73
|
170
|
50
|
|
|
|
399
|
return @{$self->{partlist}} unless defined $type; |
|
|
0
|
|
|
|
|
0
|
|
|
74
|
170
|
|
|
|
|
222
|
grep { UNIVERSAL::isa($_, $type) } @{$self->{partlist}} |
|
|
264
|
|
|
|
|
1680
|
|
|
|
170
|
|
|
|
|
408
|
|
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
sub YATT::Lite::Core::Template::node_source { |
|
77
|
9
|
|
|
9
|
0
|
1475
|
(my Template $tmpl, my $node) = @_; |
|
78
|
9
|
50
|
|
|
|
29
|
unless (ref $node eq 'ARRAY') { |
|
79
|
0
|
|
|
|
|
0
|
confess "Node is not an ARRAY"; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
9
|
|
|
|
|
22
|
$tmpl->source_region($node->[NODE_BEGIN], $node->[NODE_END]); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
sub YATT::Lite::Core::Template::node_body_source { |
|
84
|
69
|
|
|
69
|
0
|
120
|
(my Template $tmpl, my $node) = @_; |
|
85
|
69
|
50
|
|
|
|
236
|
unless (ref $node eq 'ARRAY') { |
|
86
|
0
|
|
|
|
|
0
|
confess "Node is not an ARRAY"; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
69
|
|
|
|
|
212
|
$tmpl->source_region($node->[NODE_BODY_BEGIN], $node->[NODE_BODY_END]); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
sub YATT::Lite::Core::Template::source_region { |
|
91
|
82
|
|
|
82
|
0
|
8495
|
(my Template $tmpl, my ($begin, $end)) = @_; |
|
92
|
82
|
|
|
|
|
247
|
$tmpl->source_substr($begin, $end - $begin); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
sub YATT::Lite::Core::Template::source_substr { |
|
95
|
2078
|
|
|
2078
|
0
|
3666
|
(my Template $tmpl, my ($offset, $len)) = @_; |
|
96
|
2078
|
50
|
|
|
|
4720
|
unless (defined $len) { |
|
97
|
0
|
|
|
|
|
0
|
substr $tmpl->{cf_string}, $offset; |
|
98
|
|
|
|
|
|
|
} else { |
|
99
|
2078
|
50
|
|
|
|
4261
|
return undef if $len < 0; |
|
100
|
2078
|
|
|
|
|
8129
|
substr $tmpl->{cf_string}, $offset, $len; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub YATT::Lite::Core::Part::reorder_hash_params { |
|
105
|
0
|
|
|
0
|
0
|
0
|
(my Widget $widget, my ($params)) = @_; |
|
106
|
0
|
|
|
|
|
0
|
my @params; |
|
107
|
0
|
0
|
|
|
|
0
|
foreach my $name (map($_ ? @$_ : (), $widget->{arg_order})) { |
|
108
|
0
|
|
|
|
|
0
|
push @params, delete $params->{$name}; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
0
|
0
|
|
|
|
0
|
if (keys %$params) { |
|
111
|
0
|
|
|
|
|
0
|
die "Unknown args for $widget->{cf_name}: " . join(", ", keys %$params); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
0
|
0
|
|
|
|
0
|
wantarray ? @params : \@params; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub YATT::Lite::Core::Part::reorder_cgi_params { |
|
117
|
24
|
|
|
24
|
0
|
61
|
(my Widget $widget, my ($cgi, $list)) = @_; |
|
118
|
24
|
|
100
|
|
|
136
|
$list ||= []; |
|
119
|
24
|
|
|
|
|
95
|
foreach my $name ($cgi->param) { |
|
120
|
2
|
100
|
|
|
|
29
|
next unless $name =~ /^[a-z]\w*$/i; |
|
121
|
1
|
50
|
|
|
|
7
|
my $argdecl = $widget->{arg_dict}{$name} |
|
122
|
|
|
|
|
|
|
or die "Unknown args for widget '$widget->{cf_name}': $name"; |
|
123
|
1
|
|
|
|
|
6
|
my @value = $cgi->multi_param($name); |
|
124
|
1
|
50
|
|
|
|
14
|
$list->[$argdecl->argno] = $argdecl->type->[0] eq 'list' |
|
125
|
|
|
|
|
|
|
? \@value : $value[0]; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
24
|
|
|
|
|
98
|
@$list; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
#======================================== |
|
131
|
|
|
|
|
|
|
sub configure_rc_script { |
|
132
|
1
|
|
|
1
|
0
|
3
|
(my MY $vfs, my $script) = @_; |
|
133
|
1
|
|
|
|
|
3
|
my Folder $f = $vfs->{root}; |
|
134
|
|
|
|
|
|
|
my $pkg = $f->{cf_entns} |
|
135
|
1
|
50
|
|
|
|
5
|
or die $vfs->error("package name is not specified for configure rc_script"); |
|
136
|
|
|
|
|
|
|
# print STDERR "#### $pkg \n"; |
|
137
|
|
|
|
|
|
|
# XXX: base は設定済みだったはずだけど... |
|
138
|
1
|
|
|
|
|
7
|
ckeval(qq{package $pkg; use strict; use YATT::Lite; $script}); |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
#======================================== |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Template alias さえ拡張すれば済むように。 |
|
143
|
|
|
|
|
|
|
# 逆に言うと、 vfs_file だけを定義して Template を定義しなかった場合, 継承が働かなくなった。 |
|
144
|
|
|
|
|
|
|
sub create_file { |
|
145
|
16
|
|
|
16
|
0
|
40
|
(my MY $vfs, my $spec) = splice @_, 0, 2; |
|
146
|
16
|
|
|
|
|
162
|
$vfs->Template->new(path => $spec, @_); |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# |
|
150
|
|
|
|
|
|
|
# called from |
|
151
|
|
|
|
|
|
|
# |
|
152
|
|
|
|
|
|
|
sub declare_base { |
|
153
|
2
|
|
|
2
|
0
|
8
|
(my MY $vfs, my ParsingState $state, my Template $tmpl, my ($ns, @args)) = @_; |
|
154
|
|
|
|
|
|
|
|
|
155
|
2
|
50
|
|
|
|
7
|
unless (@args) { |
|
156
|
0
|
|
|
|
|
0
|
$vfs->synerror($state, q{No base arg}); |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
2
|
|
50
|
|
|
14
|
my $base = $tmpl->{cf_base} //= []; |
|
160
|
2
|
50
|
|
|
|
7
|
if (@$base) { |
|
161
|
0
|
|
|
|
|
0
|
$vfs->synerror($state, "Duplicate base decl! was=%s, new=%s" |
|
162
|
|
|
|
|
|
|
, terse_dump($base), terse_dump(\@args)); |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
2
|
|
|
|
|
4
|
foreach my $att (@args) { |
|
166
|
2
|
|
|
|
|
10
|
my $type = $vfs->node_type($att); |
|
167
|
|
|
|
|
|
|
|
|
168
|
2
|
50
|
|
|
|
7
|
$type == TYPE_ATT_TEXT |
|
169
|
|
|
|
|
|
|
or $vfs->synerror($state, q{Not implemented base decl type: %s}, $att); |
|
170
|
|
|
|
|
|
|
|
|
171
|
2
|
50
|
|
|
|
11
|
nonempty(my $fn = $vfs->node_value($att)) |
|
172
|
|
|
|
|
|
|
or $vfs->synerror($state, q{base spec is empty!}); |
|
173
|
|
|
|
|
|
|
|
|
174
|
2
|
|
|
|
|
13
|
my Folder $dirobj = $tmpl->dirobj; |
|
175
|
|
|
|
|
|
|
|
|
176
|
2
|
50
|
|
|
|
6
|
if ($vfs->{on_memory}) { |
|
177
|
2
|
50
|
|
|
|
9
|
my $o = $vfs->find_file($fn) |
|
178
|
|
|
|
|
|
|
or $vfs->synerror($state, q{No such base path: %s}, $fn); |
|
179
|
2
|
|
|
|
|
10
|
push @$base, $o; |
|
180
|
|
|
|
|
|
|
} else { |
|
181
|
0
|
0
|
|
|
|
0
|
defined(my $realfn = $vfs->resolve_path_from($dirobj, $fn)) |
|
182
|
|
|
|
|
|
|
or $vfs->synerror($state, q{Can't find object path for: %s}, $fn); |
|
183
|
|
|
|
|
|
|
|
|
184
|
0
|
0
|
|
|
|
0
|
-e $realfn |
|
185
|
|
|
|
|
|
|
or $vfs->synerror($state, q{No such base path: %s}, $realfn); |
|
186
|
0
|
0
|
|
|
|
0
|
my $kind = -d $realfn ? 'dir' : 'file'; |
|
187
|
0
|
|
|
|
|
0
|
push @$base, $vfs->create($kind => $realfn, parent => $dirobj); |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub synerror { |
|
193
|
0
|
|
|
0
|
0
|
0
|
(my MY $vfs, my ParsingState $state, my ($fmt, @opts)) = @_; |
|
194
|
0
|
|
|
|
|
0
|
my $opts = {depth => 2}; |
|
195
|
0
|
0
|
|
|
|
0
|
$opts->{tmpl_file} = $state->{cf_path} if $state->{cf_path}; |
|
196
|
0
|
0
|
|
|
|
0
|
$opts->{tmpl_line} = $state->{startln} if $state->{startln}; |
|
197
|
0
|
|
|
|
|
0
|
die $vfs->error($opts, $fmt, @opts); |
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
#======================================== |
|
201
|
|
|
|
|
|
|
{ |
|
202
|
|
|
|
|
|
|
sub Parser { |
|
203
|
|
|
|
|
|
|
# local $@; |
|
204
|
|
|
|
|
|
|
# my $err = catch { |
|
205
|
331
|
|
|
331
|
0
|
5089
|
require YATT::Lite::LRXML; |
|
206
|
|
|
|
|
|
|
# }; |
|
207
|
|
|
|
|
|
|
# unless ($err =~ /^Can't locate loadable object for module main::Tie::Hash::NamedCapture/) { |
|
208
|
|
|
|
|
|
|
# die $err || $@ || "(unknown reason)"; |
|
209
|
|
|
|
|
|
|
# } |
|
210
|
331
|
|
|
|
|
1855
|
'YATT::Lite::LRXML' |
|
211
|
|
|
|
|
|
|
} |
|
212
|
25
|
|
|
25
|
0
|
51
|
sub cgen_perl { 'YATT::Lite::CGen::Perl' } |
|
213
|
|
|
|
|
|
|
sub stat_mtime { |
|
214
|
41
|
|
|
41
|
0
|
74
|
my ($fn) = @_; |
|
215
|
41
|
50
|
|
|
|
923
|
-e $fn or return; |
|
216
|
41
|
|
|
|
|
810
|
(stat($fn))[9]; |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
sub get_parser { |
|
219
|
331
|
|
|
331
|
0
|
473
|
my MY $self = shift; |
|
220
|
|
|
|
|
|
|
# $self->{parser} ||= |
|
221
|
|
|
|
|
|
|
$self->Parser->new |
|
222
|
|
|
|
|
|
|
(vfs => $self, $self->cf_delegate |
|
223
|
|
|
|
|
|
|
(qw(namespace special_entities) |
|
224
|
|
|
|
|
|
|
, [debug_parser => 'debug'] |
|
225
|
|
|
|
|
|
|
, [tmpl_encoding => 'encoding'] |
|
226
|
|
|
|
|
|
|
) |
|
227
|
331
|
50
|
|
|
|
744
|
, $self->{cf_parse_while_loading} ? (all => 1) : () |
|
228
|
|
|
|
|
|
|
, @_); |
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
sub ensure_parsed { |
|
231
|
2
|
|
|
2
|
0
|
5
|
(my MY $self, my Widget $widget) = @_; |
|
232
|
2
|
|
|
|
|
6
|
$self->get_parser->parse_body($widget->{cf_folder}); |
|
233
|
|
|
|
|
|
|
# $self->get_parser->parse_widget($widget) |
|
234
|
2
|
|
|
|
|
22
|
@{$widget->{tree}}; |
|
|
2
|
|
|
|
|
6
|
|
|
235
|
|
|
|
|
|
|
} |
|
236
|
|
|
|
|
|
|
sub render { |
|
237
|
0
|
|
|
0
|
0
|
0
|
my MY $self = shift; |
|
238
|
0
|
0
|
|
|
|
0
|
open my $fh, '>', \ (my $str = "") or die "Can't open capture buffer!: $!"; |
|
239
|
0
|
|
|
|
|
0
|
$self->render_into($fh, @_); |
|
240
|
0
|
|
|
|
|
0
|
close $fh; |
|
241
|
0
|
|
|
|
|
0
|
$str; |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
sub render_into { |
|
244
|
7
|
|
|
7
|
0
|
22
|
(my MY $self, my ($fh, $namerec, $args, @opts)) = @_; |
|
245
|
7
|
|
|
|
|
27
|
my ($part, $sub, $pkg) = $self->find_part_handler($namerec); |
|
246
|
7
|
50
|
|
|
|
36
|
unless ($part->public) { |
|
247
|
|
|
|
|
|
|
# XXX: refresh する手もあるだろう。 |
|
248
|
0
|
|
|
|
|
0
|
croak $self->error(q|Forbidden request '%s'|, terse_dump($namerec)); |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
|
|
251
|
7
|
|
|
|
|
12
|
my @args = do { |
|
252
|
7
|
100
|
66
|
|
|
92
|
unless (defined $args and $part->isa(MY->Widget)) { |
|
|
|
50
|
|
|
|
|
|
|
253
|
1
|
|
|
|
|
2
|
(); |
|
254
|
|
|
|
|
|
|
} elsif (ref $args eq 'ARRAY') { |
|
255
|
6
|
|
|
|
|
18
|
@$args |
|
256
|
|
|
|
|
|
|
} else { |
|
257
|
|
|
|
|
|
|
# $args can be a Hash::MultiValue and other HASH compatible obj. |
|
258
|
0
|
|
|
|
|
0
|
$part->reorder_hash_params($args); |
|
259
|
|
|
|
|
|
|
} |
|
260
|
|
|
|
|
|
|
}; |
|
261
|
|
|
|
|
|
|
|
|
262
|
7
|
50
|
|
|
|
28
|
if (@opts) { |
|
263
|
0
|
|
|
|
|
0
|
$self->cf_let(\@opts, $sub, $pkg, $fh, @args); |
|
264
|
|
|
|
|
|
|
} else { |
|
265
|
7
|
|
|
|
|
55
|
$sub->($pkg, $fh, @args); |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# root から見える part (と、その template)を取り出す。 |
|
270
|
|
|
|
|
|
|
sub get_part { |
|
271
|
0
|
|
|
0
|
0
|
0
|
(my MY $self, my $name, my %opts) = @_; |
|
272
|
0
|
|
|
|
|
0
|
my $ignore_error = delete $opts{ignore_error}; |
|
273
|
0
|
|
|
|
|
0
|
my Template $tmpl; |
|
274
|
|
|
|
|
|
|
my Part $part; |
|
275
|
0
|
0
|
|
|
|
0
|
if (UNIVERSAL::isa($self->{root}, Template)) { |
|
276
|
0
|
|
|
|
|
0
|
$tmpl = $self->{root}; |
|
277
|
0
|
|
|
|
|
0
|
$part = $self->find_part($name); |
|
278
|
|
|
|
|
|
|
} else { |
|
279
|
0
|
0
|
0
|
|
|
0
|
$tmpl = $self->find_file($name) |
|
|
|
|
0
|
|
|
|
|
|
280
|
|
|
|
|
|
|
or ($ignore_error and return) |
|
281
|
|
|
|
|
|
|
or croak "No such template file: $name"; |
|
282
|
0
|
|
|
|
|
0
|
$part = $tmpl->{Item}{''}; |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
# XXX: それとも、 $part から $tmpl が引けるようにするか? weaken して... |
|
285
|
0
|
0
|
|
|
|
0
|
wantarray ? ($part, $tmpl) : $part; |
|
286
|
|
|
|
|
|
|
} |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
sub find_part_handler { |
|
289
|
28
|
|
|
28
|
0
|
65
|
(my MY $self, my $nameSpec, my %opts) = @_; |
|
290
|
28
|
|
|
|
|
62
|
my $ignore_error = delete $opts{ignore_error}; |
|
291
|
28
|
100
|
|
|
|
103
|
my ($partName, $kind, $pureName, @rest) |
|
292
|
|
|
|
|
|
|
= ref $nameSpec ? @$nameSpec : $nameSpec; |
|
293
|
|
|
|
|
|
|
|
|
294
|
28
|
|
66
|
|
|
75
|
$partName ||= $self->{cf_index_name}; |
|
295
|
28
|
|
100
|
|
|
143
|
$kind //= 'page'; |
|
296
|
28
|
|
100
|
|
|
111
|
$pureName //= ''; |
|
297
|
|
|
|
|
|
|
|
|
298
|
28
|
|
|
|
|
169
|
my ($itemKey, $method) = $self->can("_itemKey_$kind")->($self, $pureName); |
|
299
|
|
|
|
|
|
|
|
|
300
|
28
|
|
|
|
|
52
|
(my Template $tmpl, my Part $part); |
|
301
|
|
|
|
|
|
|
|
|
302
|
28
|
100
|
|
|
|
347
|
if (UNIVERSAL::isa($self->{root}, Template)) { |
|
303
|
|
|
|
|
|
|
# Special case. |
|
304
|
1
|
|
|
|
|
3
|
$tmpl = $self->{root}; |
|
305
|
|
|
|
|
|
|
|
|
306
|
1
|
0
|
0
|
|
|
6
|
$part = $tmpl->{Item}{$partName} |
|
|
|
|
33
|
|
|
|
|
|
307
|
|
|
|
|
|
|
or ($ignore_error and return) |
|
308
|
|
|
|
|
|
|
or croak "No such item in template: $partName"; |
|
309
|
|
|
|
|
|
|
|
|
310
|
1
|
|
|
|
|
2
|
$method = "render_$partName"; |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
} else { |
|
313
|
|
|
|
|
|
|
# General container case. |
|
314
|
27
|
0
|
0
|
|
|
128
|
$tmpl = $self->find_file($partName) |
|
|
|
|
33
|
|
|
|
|
|
315
|
|
|
|
|
|
|
or ($ignore_error and return) |
|
316
|
|
|
|
|
|
|
or croak "No such template file: $partName"; |
|
317
|
27
|
50
|
50
|
|
|
600
|
$part = $tmpl->{Item}{$itemKey} |
|
|
|
|
66
|
|
|
|
|
|
318
|
|
|
|
|
|
|
or ($ignore_error and return) |
|
319
|
|
|
|
|
|
|
or croak "No such $kind in file $partName: $pureName"; |
|
320
|
|
|
|
|
|
|
} |
|
321
|
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
|
|
323
|
26
|
0
|
0
|
|
|
101
|
my $pkg = $self->find_product(perl => $tmpl) |
|
|
|
|
33
|
|
|
|
|
|
324
|
|
|
|
|
|
|
or ($ignore_error and return) |
|
325
|
|
|
|
|
|
|
or croak "Can't compile template file: $partName"; |
|
326
|
|
|
|
|
|
|
|
|
327
|
26
|
0
|
0
|
|
|
453
|
my $sub = $pkg->can($method) |
|
|
|
|
33
|
|
|
|
|
|
328
|
|
|
|
|
|
|
or ($ignore_error and return) |
|
329
|
|
|
|
|
|
|
or croak "Can't extract $method from file: $partName"; |
|
330
|
|
|
|
|
|
|
|
|
331
|
26
|
|
|
|
|
145
|
($part, $sub, $pkg, @rest); |
|
332
|
|
|
|
|
|
|
} |
|
333
|
|
|
|
|
|
|
|
|
334
|
25
|
|
|
25
|
|
41
|
sub _itemKey_page { shift; ($_[0], "render_$_[0]") } |
|
|
25
|
|
|
|
|
80
|
|
|
335
|
3
|
|
|
3
|
|
8
|
sub _itemKey_action { shift; ("do_$_[0]") x 2; } |
|
|
3
|
|
|
|
|
11
|
|
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
sub find_renderer { |
|
338
|
1
|
|
|
1
|
0
|
3
|
my MY $self = shift; |
|
339
|
1
|
50
|
|
|
|
4
|
my ($part, $sub, $pkg) = $self->find_part_handler(@_) |
|
340
|
|
|
|
|
|
|
or return; |
|
341
|
1
|
50
|
|
|
|
5
|
wantarray ? ($sub, $pkg) : $sub; |
|
342
|
|
|
|
|
|
|
} |
|
343
|
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
# DirHandler INST 固有 CGEN_perl の生成 |
|
345
|
|
|
|
|
|
|
sub get_cgen_class { |
|
346
|
156
|
|
|
156
|
0
|
260
|
(my MY $self, my $type) = @_; |
|
347
|
156
|
|
33
|
|
|
905
|
my $sub = $self->can("cgen_$type") |
|
348
|
|
|
|
|
|
|
|| carp "Unknown product type: $type"; |
|
349
|
156
|
|
66
|
|
|
742
|
$self->{cgen_class}{$type} ||= do { |
|
350
|
25
|
|
|
|
|
71
|
my $cg_base = $sub->(); |
|
351
|
|
|
|
|
|
|
# XXX: ref($facade) が INST 固有に成ってなかったら? |
|
352
|
25
|
|
|
|
|
89
|
my $instpkg = ref($self->{cf_facade})."::CGEN_$type"; |
|
353
|
25
|
|
|
|
|
123
|
ckeval(qq|package $instpkg; use base qw($cg_base)|); |
|
354
|
25
|
|
|
|
|
133
|
$instpkg; |
|
355
|
|
|
|
|
|
|
}; |
|
356
|
|
|
|
|
|
|
} |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
# XXX: Action only コンパイルは? |
|
359
|
|
|
|
|
|
|
sub find_product { |
|
360
|
207
|
|
|
207
|
0
|
505
|
(my MY $self, my $spec, my Template $tmpl, my %opts) = @_; |
|
361
|
207
|
50
|
|
|
|
557
|
my ($type, $kind) = ref $spec ? @$spec : $spec; |
|
362
|
|
|
|
|
|
|
# local $YATT = $self; |
|
363
|
207
|
100
|
|
|
|
672
|
unless ($tmpl->{product}{$type}) { |
|
364
|
156
|
|
|
|
|
477
|
my $cg_class = $self->get_cgen_class($type); |
|
365
|
|
|
|
|
|
|
my $cgen = $cg_class->new |
|
366
|
|
|
|
|
|
|
(vfs => $self |
|
367
|
|
|
|
|
|
|
, $self->cf_delegate(qw(no_lineinfo check_lineno only_parse |
|
368
|
|
|
|
|
|
|
lcmsg_sink)) |
|
369
|
|
|
|
|
|
|
, parser => $self->get_parser |
|
370
|
|
|
|
|
|
|
, sink => $opts{sink} || sub { |
|
371
|
137
|
|
|
137
|
|
588
|
my ($info, @script) = @_; |
|
372
|
137
|
50
|
|
|
|
463
|
if (not $self->{cf_debug_cgen}) { |
|
373
|
|
|
|
|
|
|
} else { |
|
374
|
0
|
|
|
|
|
0
|
my Template $real = $info->{folder}; |
|
375
|
0
|
|
|
|
|
0
|
print STDERR "# compiling $type code of $real->{cf_path}\n"; |
|
376
|
0
|
|
|
|
|
0
|
if ($self->{cf_debug_cgen} >= 2) { |
|
377
|
0
|
|
|
|
|
0
|
print STDERR "#--BEGIN--\n"; |
|
378
|
0
|
|
|
|
|
0
|
print STDERR @script, "\n"; |
|
379
|
0
|
|
|
|
|
0
|
print STDERR "#--END--\n\n" |
|
380
|
|
|
|
|
|
|
} |
|
381
|
|
|
|
|
|
|
} |
|
382
|
|
|
|
|
|
|
# |
|
383
|
137
|
|
|
|
|
254
|
$self->{n_compiles}++; |
|
384
|
|
|
|
|
|
|
|
|
385
|
137
|
|
|
|
|
513
|
ckeval(@script); |
|
386
|
156
|
|
50
|
|
|
640
|
}); |
|
387
|
|
|
|
|
|
|
# 二重生成防止のため、代入自体は ensure_generated の中で行う。 |
|
388
|
156
|
|
|
|
|
979
|
$cgen->ensure_generated($spec => $tmpl); |
|
389
|
|
|
|
|
|
|
}; |
|
390
|
180
|
|
|
|
|
1512
|
$tmpl->{product}{$type}; |
|
391
|
|
|
|
|
|
|
} |
|
392
|
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
# |
|
394
|
|
|
|
|
|
|
# extract_lcmsg |
|
395
|
|
|
|
|
|
|
# - filelist is a list(or scalar) of filename or item name(no ext). |
|
396
|
|
|
|
|
|
|
# - msgdict is used to share same msgid. |
|
397
|
|
|
|
|
|
|
# - msglist is used to keep msg order. |
|
398
|
|
|
|
|
|
|
# |
|
399
|
|
|
|
|
|
|
# XXX: find_product and extract_lcmsg is exclusive. |
|
400
|
|
|
|
|
|
|
sub extract_lcmsg { |
|
401
|
2
|
|
|
2
|
0
|
6
|
(my MY $self, my ($filelist, $msglist, $msgdict)) = @_; |
|
402
|
2
|
|
|
|
|
10
|
require Locale::PO; |
|
403
|
2
|
|
50
|
|
|
8
|
$msglist //= []; |
|
404
|
2
|
|
50
|
|
|
11
|
$msgdict //= {}; |
|
405
|
|
|
|
|
|
|
local $self->{cf_lcmsg_sink} = sub { |
|
406
|
3
|
|
|
3
|
|
11
|
$self->define_lcmsg_in($msglist, $msgdict, @_); |
|
407
|
2
|
|
|
|
|
11
|
}; |
|
408
|
2
|
|
|
|
|
5
|
my $type = 'perl'; |
|
409
|
2
|
|
|
|
|
7
|
foreach my $name (lexpand($filelist)) { |
|
410
|
2
|
50
|
|
|
|
8
|
my Template $tmpl = $self->find_file($name) |
|
411
|
|
|
|
|
|
|
or croak "No such template: $name"; |
|
412
|
2
|
|
|
|
|
8
|
$self->find_product($type => $tmpl); |
|
413
|
|
|
|
|
|
|
} |
|
414
|
|
|
|
|
|
|
# XXX: not wantarray |
|
415
|
2
|
|
|
|
|
17
|
@$msglist; |
|
416
|
|
|
|
|
|
|
} |
|
417
|
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
sub define_lcmsg_in { |
|
420
|
3
|
|
|
3
|
0
|
8
|
(my MY $self, my ($list, $dict, $place, $msgid, $other_msgs, $args)) = @_; |
|
421
|
3
|
50
|
|
|
|
10
|
if (my $obj = $dict->{$msgid}) { |
|
422
|
0
|
|
|
|
|
0
|
$obj->reference(join " ", grep {defined $_} $obj->reference, $place); |
|
|
0
|
|
|
|
|
0
|
|
|
423
|
|
|
|
|
|
|
} else { |
|
424
|
3
|
|
|
|
|
14
|
my @o = (-msgid => $msgid); |
|
425
|
3
|
100
|
66
|
|
|
11
|
if ($other_msgs and $other_msgs->[0]) { |
|
426
|
1
|
|
|
|
|
6
|
push @o, -msgid_plural => $other_msgs->[0] |
|
427
|
|
|
|
|
|
|
, -msgstr_n => {0 => '', 1 => ''}; |
|
428
|
|
|
|
|
|
|
} else { |
|
429
|
2
|
|
|
|
|
5
|
push @o, -msgstr => ''; |
|
430
|
|
|
|
|
|
|
} |
|
431
|
3
|
|
|
|
|
18
|
push @$list, my $po = $dict->{$msgid} = Locale::PO->new(@o); |
|
432
|
3
|
|
|
|
|
269
|
$po->add_flag('perl-format'); |
|
433
|
3
|
|
|
|
|
56
|
$po->reference($place); |
|
434
|
|
|
|
|
|
|
} |
|
435
|
|
|
|
|
|
|
} |
|
436
|
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
sub YATT::Lite::Core::Template::after_create { |
|
438
|
170
|
|
|
170
|
0
|
297
|
(my Template $tmpl, my MY $self) = @_; |
|
439
|
|
|
|
|
|
|
# XXX: ここでは SUPER が使えない。 |
|
440
|
170
|
|
|
|
|
779
|
$tmpl->YATT::Lite::VFS::File::after_create($self); |
|
441
|
|
|
|
|
|
|
($tmpl->{cf_name}) = $tmpl->{cf_path} =~ m{(\w+)\.\w+$} |
|
442
|
|
|
|
|
|
|
or $self->error("Can't extract part name from '%s'", [$tmpl->{cf_path}]) |
|
443
|
167
|
50
|
0
|
|
|
819
|
if not defined $tmpl->{cf_name} and defined $tmpl->{cf_path}; |
|
|
|
|
66
|
|
|
|
|
|
444
|
|
|
|
|
|
|
} |
|
445
|
|
|
|
|
|
|
sub YATT::Lite::Core::Template::reset { |
|
446
|
3
|
|
|
3
|
0
|
10
|
(my Template $tmpl) = @_; |
|
447
|
3
|
|
|
|
|
40
|
$tmpl->YATT::Lite::VFS::File::reset; |
|
448
|
3
|
|
|
|
|
13
|
undef $tmpl->{product}; |
|
449
|
3
|
|
|
|
|
9
|
undef $tmpl->{parse_ok}; |
|
450
|
3
|
|
|
|
|
12
|
undef $tmpl->{cf_subroutes}; |
|
451
|
|
|
|
|
|
|
# delpkg($tmpl->{cf_package}); # No way to avoid redef error. |
|
452
|
|
|
|
|
|
|
} |
|
453
|
|
|
|
|
|
|
sub YATT::Lite::Core::Template::refresh { |
|
454
|
199
|
|
|
199
|
0
|
325
|
(my Template $tmpl, my MY $self) = @_; |
|
455
|
|
|
|
|
|
|
|
|
456
|
199
|
|
|
|
|
363
|
my $old_product = $tmpl->{product}; |
|
457
|
|
|
|
|
|
|
|
|
458
|
199
|
100
|
66
|
|
|
1060
|
if ($tmpl->{cf_path}) { |
|
|
|
100
|
|
|
|
|
|
|
459
|
41
|
|
|
|
|
56
|
printf STDERR "template_refresh(%s)\n", $tmpl->{cf_path} if DEBUG_REBUILD; |
|
460
|
41
|
|
|
|
|
128
|
my $mtime = stat_mtime($tmpl->{cf_path}); |
|
461
|
41
|
50
|
100
|
|
|
299
|
unless (defined $mtime) { |
|
|
|
100
|
|
|
|
|
|
|
462
|
0
|
|
|
|
|
0
|
printf STDERR " => deleted\n" if DEBUG_REBUILD; |
|
463
|
0
|
|
|
|
|
0
|
return; # XXX: ファイルが消された |
|
464
|
|
|
|
|
|
|
} elsif (defined $tmpl->{cf_mtime} and $tmpl->{cf_mtime} >= $mtime) { |
|
465
|
22
|
|
|
|
|
32
|
printf STDERR " => not updated.\n" if DEBUG_REBUILD; |
|
466
|
22
|
50
|
|
|
|
67
|
$self->refresh_deps_for($tmpl) if $self->{cf_always_refresh_deps}; |
|
467
|
22
|
|
|
|
|
62
|
return; # timestamp は、キャッシュと同じかむしろ古い |
|
468
|
|
|
|
|
|
|
} |
|
469
|
19
|
|
|
|
|
31
|
printf STDERR " => found update\n" if DEBUG_REBUILD; |
|
470
|
19
|
|
|
|
|
41
|
$tmpl->{cf_mtime} = $mtime; |
|
471
|
19
|
|
|
|
|
67
|
my $parser = $self->get_parser; |
|
472
|
|
|
|
|
|
|
# decl のみ parse. |
|
473
|
|
|
|
|
|
|
# XXX: $tmpl->{cf_package} の指すパッケージをこの段階で map {undef $_} |
|
474
|
|
|
|
|
|
|
# すべきではないか? |
|
475
|
19
|
|
|
|
|
130
|
$parser->load_file_into($tmpl, $tmpl->{cf_path}); |
|
476
|
|
|
|
|
|
|
} elsif ($tmpl->{cf_string} and not $tmpl->{cf_mtime}) { |
|
477
|
|
|
|
|
|
|
# To avoid recompilation, use mtime to express generated time. |
|
478
|
|
|
|
|
|
|
# Not so good. |
|
479
|
154
|
|
|
|
|
394
|
$tmpl->{cf_mtime} = time; |
|
480
|
|
|
|
|
|
|
|
|
481
|
154
|
|
|
|
|
378
|
my $parser = $self->get_parser; |
|
482
|
|
|
|
|
|
|
$parser->load_string_into($tmpl, $tmpl->{cf_string} |
|
483
|
154
|
|
|
|
|
979
|
, scheme => "data", path => $tmpl->{cf_name}); |
|
484
|
|
|
|
|
|
|
} else { |
|
485
|
4
|
|
|
|
|
13
|
return; |
|
486
|
|
|
|
|
|
|
} |
|
487
|
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
# $tmpl->YATT::Lite::VFS::Folder::vivify_base_descs($self); |
|
489
|
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
# If there was products, rebuild it too. |
|
491
|
170
|
100
|
|
|
|
492
|
foreach my $type ($old_product ? keys %$old_product : ()) { |
|
492
|
3
|
|
|
|
|
20
|
$self->find_product($type => $tmpl); |
|
493
|
|
|
|
|
|
|
} |
|
494
|
|
|
|
|
|
|
|
|
495
|
170
|
|
|
|
|
362
|
$tmpl; |
|
496
|
|
|
|
|
|
|
} |
|
497
|
|
|
|
|
|
|
sub YATT::Lite::Core::Widget::fixup { |
|
498
|
269
|
|
|
269
|
0
|
449
|
(my Widget $widget, my Template $tmpl, my $parser) = @_; |
|
499
|
269
|
|
|
|
|
307
|
foreach my $argName (@{$widget->{arg_order}}) { |
|
|
269
|
|
|
|
|
720
|
|
|
500
|
|
|
|
|
|
|
$widget->{has_required_arg} = 1 |
|
501
|
257
|
100
|
|
|
|
946
|
if $widget->{arg_dict}{$argName}->is_required; |
|
502
|
|
|
|
|
|
|
} |
|
503
|
269
|
|
66
|
|
|
968
|
$widget->{arg_dict}{body} ||= do { |
|
504
|
|
|
|
|
|
|
# lineno も入れるべきかも。 $widget->{cf_bodyln} あたり. |
|
505
|
|
|
|
|
|
|
my $var = $parser->mkvar_at(undef, code => 'body' |
|
506
|
256
|
|
50
|
|
|
390
|
, scalar @{$widget->{arg_order} ||= []}); |
|
|
256
|
|
|
|
|
1243
|
|
|
507
|
256
|
|
|
|
|
384
|
push @{$widget->{arg_order}}, 'body'; |
|
|
256
|
|
|
|
|
573
|
|
|
508
|
256
|
|
|
|
|
1164
|
$var; |
|
509
|
|
|
|
|
|
|
}; |
|
510
|
|
|
|
|
|
|
} |
|
511
|
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
sub YATT::Lite::Core::Template::match_subroutes { |
|
513
|
9
|
|
|
9
|
0
|
16
|
my Template $tmpl = shift; |
|
514
|
9
|
100
|
|
|
|
32
|
return unless $tmpl->{cf_subroutes}; |
|
515
|
8
|
|
|
|
|
36
|
$tmpl->{cf_subroutes}->match($_[0]); |
|
516
|
|
|
|
|
|
|
} |
|
517
|
|
|
|
|
|
|
} |
|
518
|
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
sub find_template_from_package { |
|
520
|
3
|
|
|
3
|
0
|
8
|
(my MY $self, my $pkg) = @_; |
|
521
|
3
|
|
|
|
|
18
|
$self->{pkg2folder}{$pkg}; |
|
522
|
|
|
|
|
|
|
} |
|
523
|
|
|
|
|
|
|
|
|
524
|
11
|
|
|
11
|
|
88
|
use YATT::Lite::Breakpoint (); |
|
|
11
|
|
|
|
|
20
|
|
|
|
11
|
|
|
|
|
701
|
|
|
525
|
|
|
|
|
|
|
YATT::Lite::Breakpoint::break_load_core(); |
|
526
|
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
1; |