blib/lib/YATT/Lite/Core.pm

filter: Statementstmt 88.8% 437 / 492 Branchbran 67.8% 156 / 230 Conditioncond 43.7% 67 / 153 MC/DCmcdc 13.9% 11 / 79 Subroutinesub 92.2% 83 / 90 Podpod 0.0% 0 / 68 totaltotal 67.8% 754 / 1112 CC 190 SCAR 23.5
CC
190
Cov
75%
get_part
42.0
find_part_handler
32.7
find_part_renderer
25.8
CRAP 10.5
« blib/lib/YATT/Lite/LRXML.pm ↑ Summary blib/lib/YATT/Lite/CGen/Perl.pm »
1 package YATT::Lite::Core; sub MY () {__PACKAGE__}
2 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 49 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 49 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 49 ▶use constant DEBUG_REBUILD => $ENV{DEBUG_YATT_REBUILD};
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 49 ▶use parent qw(YATT::Lite::VFS);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 49 ▶use YATT::Lite::MFields qw/namespace debug_cgen no_lineinfo check_lineno
Subroutine BEGIN: called CC=1 SCAR=0.0
10 index_name
11 tmpl_encoding
12 debug_parser
13 parse_while_loading only_parse
14 die_in_error error_handler
15 special_entities
16 lcmsg_sink
17 match_argsroute_first
18 body_argument
19 body_argument_type
20 allow_bare_entity_in_decl
21  
22 stash_unknown_params_to
23 prefer_call_for_entity
24 no_conditional_call
25  
26 _n_compiles
27 49 /;
28 49 ▶use YATT::Lite::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 49 ▶use YATT::Lite::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 49 ▶use YATT::Lite::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 # XXX: YATT::Lite に?
33 49 ▶use YATT::Lite::Breakpoint ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 #========================================
36 # 以下、 package YATT::Lite のための、内部クラス
37 #========================================
38 {
39 49 ▶ use YATT::Lite::VFS qw(Folder Item);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 use YATT::Lite::Types
41 49 ▶ ([Part => -base => MY->Item
Subroutine BEGIN: called CC=1 SCAR=0.0
42 , -fields => [qw(_toks _arg_dict _arg_order
43 _argmacro_instance_dict
44 _argmacro_instance_list
45 _argmacro_trigger_dict
46 _decllist
47 namespace kind folder data
48 decl
49 implicit suppressed
50 startln bodyln endln
51 startpos bodypos bodylen
52 subpattern
53 )]
54 , -constants => [[public => 0]]
55 , [Widget => -fields => [qw(_tree _var_dict _has_required_arg)]
56 , [Page => (), -constants => [[public => 1]]]]
57 , [Action => (), -constants => [[public => 1],
58 [item_category => 'do'],
59 ]]
60 , [Data => ()]
61 , [Entity => ()
62 , -constants => [[item_category => 'entity']]
63 ]
64 , [ArgMacro => ()
65 , -fields => [qw(
66 output_args
67 _on_declare
68 _on_expand
69 to_name
70 from_name
71 rename_map
72 resolve_map
73 )]
74 ]
75 # <!yatt:import> が作る alias Part。実体は持たず、lookup 時に
76 # ソース側 Part へ解決される (resolve_alias)。GH-256
77 , [Import => ()
78 , -fields => [qw(
79 imported_kind
80 src_name
81 src_folder
82 )]
83 ]
84 ]
85  
86 , [Template => -base => MY->File
87 , -alias => 'vfs_file'
88 , -constants => [[can_generate_code => 1]]
89 , -fields => [qw(_product _parse_ok
90 mtime utf8 age
91 usage constants
92 ignore_trailing_newlines
93 subroutes
94 _decl_parsing
95 )]]
96  
97 , [ParsingState => -fields => [qw(_startln _endln
98 _startpos _curpos
99 path
100 )]]
101  
102 , [AbstParser => -fields => [qw(body_argument
103 body_argument_type
104 )]]
105 49 );
106  
107 0 ▶ sub YATT::Lite::Core::Part::public_name {
Subroutine public_name: not called CC=1 SCAR=6.9
Pod undocumented
108 0 (my Part $part) = @_;
109 0 $part->{name};
110 }
111 4 ▶ sub YATT::Lite::Core::Part::decl_kind {
Subroutine decl_kind: called CC=1 SCAR=0.0
Pod undocumented
112 4 (my Part $part) = @_;
113 4 join(":", $part->{namespace}, $part->{decl});
114 }
115 4 ▶ sub YATT::Lite::Core::Part::syntax_keyword {
Subroutine syntax_keyword: called CC=1 SCAR=0.0
Pod undocumented
116 4 (my Part $part) = @_;
117 4 join(" ", $part->decl_kind, $part->syntax_name);
118 }
119 49 *YATT::Lite::Core::Part::syntax_name = *YATT::Lite::Core::Part::public_name;
120 49 *YATT::Lite::Core::Part::syntax_name = *YATT::Lite::Core::Part::public_name;
121 3 ▶ sub YATT::Lite::Core::Widget::syntax_name {
Subroutine syntax_name: called CC=2 SCAR=7.2
Pod undocumented
122 3 (my Widget $widget) = @_;
123 3 ▶ $widget->{decl} eq 'args' ? () : $widget->{name};
Branch: 1 branch
BranchTrueFalseTotal
$widget->{'decl'} eq 'args' ? : 3 0 3
124 }
125 1 ▶ sub YATT::Lite::Core::Action::syntax_name {
Subroutine syntax_name: called CC=2 SCAR=7.2
Pod undocumented
126 1 (my Action $action) = @_;
127 1 ▶ $action->{name} eq '' ? q{''} : $action->{name};
Branch: 1 branch
BranchTrueFalseTotal
$action->{'name'} eq '' ? : 1 0 1
128 }
129  
130 2 ▶ sub YATT::Lite::Core::Widget::callsite_name {
Subroutine callsite_name: called CC=2 SCAR=8.4
Pod undocumented
131 2 (my Widget $widget) = @_;
132 2 ▶ if ($widget->{decl} eq 'args') {
Branch: 1 branch
BranchTrueFalseTotal
if ($widget->{'decl'} eq 'args') { } 0 2 2
133 0 my Template $tmpl = $widget->{folder};
134 0 join(":", $widget->{namespace}, $tmpl->{name});
135 } else {
136 2 join(":", $widget->{namespace}, $widget->{name});
137 }
138 }
139  
140 # item_key / method_name の符号化 (do\0 / entity\0, render_ / do_ / entity_)
141 # は各 part class の class メソッド *_for($name) に集約する。
142 # instance メソッドはそこへ委譲するだけ。GH-256
143 0 ▶ sub YATT::Lite::Core::Part::method_name {...}
Subroutine method_name: not called CC=1 SCAR=6.9
Pod undocumented
144 295 ▶ sub YATT::Lite::Core::Widget::method_name_for {"render_$_[1]"}
Subroutine method_name_for: called CC=1 SCAR=0.0
Pod undocumented
145 97 ▶ sub YATT::Lite::Core::Widget::method_name {
Subroutine method_name: called CC=1 SCAR=0.0
Pod undocumented
146 97 (my Widget $widget) = @_;
147 97 $widget->method_name_for($widget->{name});
148 }
149 19 ▶ sub YATT::Lite::Core::Action::method_name_for {"do_$_[1]"}
Subroutine method_name_for: called CC=1 SCAR=0.0
Pod undocumented
150 5 ▶ sub YATT::Lite::Core::Action::method_name {
Subroutine method_name: called CC=1 SCAR=0.0
Pod undocumented
151 5 (my Action $action) = @_;
152 5 $action->method_name_for($action->{name});
153 }
154 66 ▶ sub YATT::Lite::Core::Action::item_key_for {"do\0$_[1]"}
Subroutine item_key_for: called CC=1 SCAR=0.0
Pod undocumented
155 15 ▶ sub YATT::Lite::Core::Action::item_key {
Subroutine item_key: called CC=1 SCAR=0.0
Pod undocumented
156 15 (my Action $action) = @_;
157 15 $action->item_key_for($action->{name});
158 }
159  
160 280 ▶ sub YATT::Lite::Core::Entity::method_name_for {"entity_$_[1]"}
Subroutine method_name_for: called CC=1 SCAR=0.0
Pod undocumented
161 4 ▶ sub YATT::Lite::Core::Entity::method_name {
Subroutine method_name: called CC=1 SCAR=0.0
Pod undocumented
162 4 (my Entity $entity) = @_;
163 4 $entity->method_name_for($entity->{name});
164 }
165 345 ▶ sub YATT::Lite::Core::Entity::item_key_for {"entity\0$_[1]"}
Subroutine item_key_for: called CC=1 SCAR=0.0
Pod undocumented
166 16 ▶ sub YATT::Lite::Core::Entity::item_key {
Subroutine item_key: called CC=1 SCAR=0.0
Pod undocumented
167 16 (my Entity $entity) = @_;
168 16 $entity->item_key_for($entity->{name});
169 }
170  
171 #========================================
172 # <!yatt:import> の alias Part (GH-256)
173 #========================================
174  
175 # kind 名 → part class の登録簿。_Item 系の名前空間を持つ kind のみ。
176 # (argmacro は _argmacro_dict 系なので含めない)
177 49 our %PART_KIND_CLASS
178 = (widget => Widget, page => Page, action => Action, entity => Entity);
179  
180 91 ▶ sub YATT::Lite::Core::Import::part_class_of_imported_kind {
Subroutine part_class_of_imported_kind: called CC=3 SCAR=13.1
Pod undocumented
181 91 (my Import $import) = @_;
182 91 ▶ $PART_KIND_CLASS{$import->{imported_kind} // ''} // YATT::Lite::Core->Item;
Condition40%2/5
$YATT::Lite::Core::PART_KIND_CLASS{$import->{"imported_kind"} // ""} // "YATT::Lite::Core"->Item
l!l&&r!l&&!r
9100
$import->{"imported_kind"} // ""
l!l
910
MC/DC0%0/2
$YATT::Lite::Core::PART_KIND_CLASS{$import->{"imported_kind"} // ""} // "YATT::Lite::Core"->Item
$YATT::Lite::Core::PART_KIND_CLASS{$import->{"imported_kind"} // ""} "YATT::Lite::Core"->Item
MC/DC0%0/1
$import->{"imported_kind"} // ""
$import->{"imported_kind"}
Truth table33%1/3
A // B
A= $YATT::Lite::Core::PART_KIND_CLASS{$import->{"imported_kind"} // ""}B= "YATT::Lite::Core"->Item
ABresult
1X1
011
000
Truth table50%1/2
A
A= $import->{"imported_kind"}
Aresult
11
00
183 }
184 19 ▶ sub YATT::Lite::Core::Import::method_name {
Subroutine method_name: called CC=1 SCAR=0.0
Pod undocumented
185 19 (my Import $import) = @_;
186 19 $import->part_class_of_imported_kind->method_name_for($import->{name});
187 }
188 20 ▶ sub YATT::Lite::Core::Import::item_key {
Subroutine item_key: called CC=1 SCAR=0.0
Pod undocumented
189 20 (my Import $import) = @_;
190 20 $import->part_class_of_imported_kind->item_key_for($import->{name});
191 }
192 52 ▶ sub YATT::Lite::Core::Import::src_item_key {
Subroutine src_item_key: called CC=1 SCAR=0.0
Pod undocumented
193 52 (my Import $import) = @_;
194 52 $import->part_class_of_imported_kind->item_key_for($import->{src_name});
195 }
196 18 ▶ sub YATT::Lite::Core::Import::public {
Subroutine public: called CC=2 SCAR=7.0
Pod undocumented
197 18 (my Import $import) = @_;
198 18 my Part $part = eval { $import->resolve_alias };
199 18 ▶ $part ? $part->public : 0;
Branch: 1 branch
BranchTrueFalseTotal
$part ? : 18 0 18
200 }
201 # alias をソース側 Part へ解決する。$vfs が渡されたときは
202 # ソース template の refresh も行う (常に最新のメタ情報を返すため)。
203 52 ▶ sub YATT::Lite::Core::Import::resolve_alias {
Subroutine resolve_alias: called CC=8 SCAR=25.8
Pod undocumented
204 52 (my Import $import, my $vfs) = @_;
205 my Template $src = $import->{src_folder}
206 52 ▶ or croak "import source template is gone (for part '$import->{name}')";
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::Core::Template $src = $import->{"src_folder"} or croak(qq[import source template is gone (for part '$import->{"name"}')]) 52 0 52
207 52 ▶ if ($vfs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vfs) 34 18 52
208 $src->refresh($vfs)
209 34 ▶ unless $vfs->{mark}{Scalar::Util::refaddr($src)}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $vfs->{"mark"}{builtin::refaddr($src)}++ 0 34 34
210 }
211 52 my $key = $import->src_item_key;
212 my $item = $src->{_Item}{$key}
213 // ($vfs ? $vfs->find_part_from($src, $key) : undef)
214 or croak "No such part '$import->{src_name}' in "
215 . ($src->{path} // $src->{name})
216 52 ▶ . " (imported as '$import->{name}')";
Branch: 2 branches
BranchTrueFalseTotal
my $item = $src->{"_Item"}{$key} // ($vfs ? $vfs->find_part_from($src, $key) : undef) or croak(qq[No such part '$import->{"src_name"}' in ] . ($src->{"path"} // $src->{"name"}) . qq[ (imported as '$import->{"name"}')]) 52 0 52
$vfs ? : 0 0 0
Condition16%1/6
$src->{"_Item"}{$key} // ($vfs ? $vfs->find_part_from($src, $key) : undef)
l!l&&r!l&&!r
5200
$src->{"path"} // $src->{"name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$src->{"_Item"}{$key} // ($vfs ? $vfs->find_part_from($src, $key) : undef)
$src->{"_Item"}{$key} ($vfs ? $vfs->find_part_from($src, $key) : undef)
MC/DC0%0/2
$src->{"path"} // $src->{"name"}
$src->{"path"} $src->{"name"}
Truth table33%1/3
A // B
A= $src->{"_Item"}{$key}B= ($vfs ? $vfs->find_part_from($src, $key) : undef)
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $src->{"path"}B= $src->{"name"}
ABresult
1X1
011
000
217 # import の import (再輸出) も解決する。循環は宣言時に禁止済み。
218 52 $item->resolve_alias($vfs);
219 }
220  
221 433 ▶ sub YATT::Lite::Core::Template::list_import_sources {
Subroutine list_import_sources: called CC=6 SCAR=18.0
Pod undocumented
222 433 (my Template $tmpl) = @_;
223 433 my (%seen, @result);
224 433 ▶ foreach my Part $part (@{$tmpl->{_partlist} || []}) {
Condition50%1/2
$tmpl->{'_partlist'} || []
l!l
4330
MC/DC0%0/1
$tmpl->{'_partlist'} || []
$tmpl->{'_partlist'}
Truth table50%1/2
A
A= $tmpl->{'_partlist'}
Aresult
11
00
225 662 ▶ next unless UNIVERSAL::isa($part, Import);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($part, "YATT::Lite::Core::Import") 643 19 662
226 19 my Import $import = $part;
227 19 ▶ my Folder $src = $import->{src_folder} or next;
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::VFS::Folder $src = $import->{"src_folder"} or next 19 0 19
228 19 ▶ next if $seen{Scalar::Util::refaddr($src)}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{builtin::refaddr($src)}++ 2 17 19
229 17 push @result, $src;
230 }
231 433 @result;
232 }
233  
234 733 ▶ sub YATT::Lite::Core::Part::configure_folder {
Subroutine configure_folder: called CC=1 SCAR=0.0
Pod undocumented
235 733 (my Part $part, my Folder $folder) = @_;
236 733 Scalar::Util::weaken($part->{folder} = $folder);
237 # die "Can't weaken!" unless Scalar::Util::isweak($part->{folder});
238 }
239  
240 12 ▶ sub YATT::Lite::Core::ArgMacro::clone_with_renamespec {
Subroutine clone_with_renamespec: called CC=1 SCAR=0.0
Pod undocumented
241 12 (my ArgMacro $orig, my ($toName, $fromName)) = @_;
242 12 my ArgMacro $new = fields::new(ArgMacro);
243 12 %$new = %$orig;
244 12 Scalar::Util::weaken($new->{folder});
245 12 $new->{output_args} = YATT::Lite::Util::deep_copy_array($orig->{output_args});
246 12 $new->{to_name} = $toName;
247 12 $new->{from_name} = $fromName;
248 12 $new;
249 }
250  
251 # sub YATT::Lite::Core::Part::source {
252 # (my Part $part) = @_;
253 # join "", map {ref $_ ? "\n" x $$_[0] : $_} @{$part->{source}};
254 # }
255 0 ▶ sub YATT::Lite::Core::Template::source_length {
Subroutine source_length: not called CC=1 SCAR=6.9
Pod undocumented
256 0 (my Template $self) = @_;
257 0 length $self->{string};
258 }
259 499 ▶ sub YATT::Lite::Core::Template::list_parts {
Subroutine list_parts: called CC=3 SCAR=11.0
Pod undocumented
260 499 (my Template $self, my $type) = @_;
261 499 ▶ return unless $self->{_partlist};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_partlist"} 0 499 499
262 499 ▶ return @{$self->{_partlist}} unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 43 456 499
263 456 grep { UNIVERSAL::isa($_, $type) } @{$self->{_partlist}}
264 }
265 0 ▶ sub YATT::Lite::Core::Template::widget_list {
Subroutine widget_list: not called CC=1 SCAR=6.9
Pod undocumented
266 0 (my Template $self) = @_;
267 0 $self->list_parts(Widget);
268 }
269 10 ▶ sub YATT::Lite::Core::Template::node_source {
Subroutine node_source: called CC=2 SCAR=7.6
Pod undocumented
270 10 (my Template $tmpl, my $node) = @_;
271 10 ▶ unless (ref $node eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node eq "ARRAY") 0 10 10
272 0 confess "Node is not an ARRAY";
273 }
274 10 $tmpl->source_region($node->[NODE_BEGIN], $node->[NODE_END]);
275 }
276 102 ▶ sub YATT::Lite::Core::Template::node_body_source {
Subroutine node_body_source: called CC=2 SCAR=7.6
Pod undocumented
277 102 (my Template $tmpl, my $node) = @_;
278 102 ▶ unless (ref $node eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node eq "ARRAY") 0 102 102
279 0 confess "Node is not an ARRAY";
280 }
281 102 $tmpl->source_region($node->[NODE_BODY_BEGIN], $node->[NODE_BODY_END]);
282 }
283 1 ▶ sub YATT::Lite::Core::Template::node_outer_source {
Subroutine node_outer_source: called CC=2 SCAR=7.6
Pod undocumented
284 1 (my Template $tmpl, my $node) = @_;
285 1 ▶ unless (ref $node eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $node eq "ARRAY") 0 1 1
286 0 confess "Node is not an ARRAY";
287 }
288 1 $tmpl->source_region($node->[NODE_BEGIN], $node->[NODE_BODY_END]);
289 }
290 118 ▶ sub YATT::Lite::Core::Template::source_region {
Subroutine source_region: called CC=1 SCAR=0.0
Pod undocumented
291 118 (my Template $tmpl, my ($begin, $end)) = @_;
292 118 $tmpl->source_substr($begin, $end - $begin);
293 }
294 151 ▶ sub YATT::Lite::Core::Template::source_substr {
Subroutine source_substr: called CC=3 SCAR=12.0
Pod undocumented
295 151 (my Template $tmpl, my ($offset, $len)) = @_;
296 151 ▶ unless (defined $len) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $len) { } 151 0 151
297 0 substr $tmpl->{string}, $offset;
298 } else {
299 151 ▶ return undef if $len < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len < 0 0 151 151
300 151 substr $tmpl->{string}, $offset, $len;
301 }
302 }
303  
304 # source_substr ベースの part (action/entity) の本体抽出。GH-258
305 # (bodypos, bodylen) 区間内の yatt コメント span は「同じ改行数の \n 列」に
306 # 置換して返す (行番号保存)。yatt コメントは宣言より強い構文要素なので、
307 # raw 本体の中でも widget 同様「取り除かれる」意味論を成立させる。
308 # コメントが無ければ source_substr と同一 (バイト単位)。
309 29 ▶ sub YATT::Lite::Core::Template::part_body_source {
Subroutine part_body_source: called CC=7 SCAR=20.2
Pod undocumented
310 29 (my Template $tmpl, my Part $part) = @_;
311 29 my ($bodypos, $bodylen) = ($part->{bodypos}, $part->{bodylen});
312 29 my $src = $tmpl->source_substr($bodypos, $bodylen);
313 29 ▶ return $src unless defined $src;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $src 0 29 29
314 29 my $end = $bodypos + $bodylen;
315 # 後ろから置換すれば手前の offset がずれない
316 29 ▶ foreach my $entry (reverse @{$tmpl->{_boundarylist} // []}) {
Condition50%1/2
$tmpl->{"_boundarylist"} // []
l!l
290
MC/DC0%0/1
$tmpl->{"_boundarylist"} // []
$tmpl->{"_boundarylist"}
Truth table50%1/2
A
A= $tmpl->{"_boundarylist"}
Aresult
11
00
317 85 ▶ next unless $entry->{kind} eq 'comment';
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->{"kind"} eq "comment" 81 4 85
318 4 ▶ next unless $entry->{startpos} >= $bodypos and $entry->{endpos} <= $end;
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->{"startpos"} >= $bodypos and $entry->{"endpos"} <= $end 0 4 4
Condition33%1/3
$entry->{"startpos"} >= $bodypos and $entry->{"endpos"} <= $end
!ll&&!rl&&r
004
MC/DC0%0/2
$entry->{"startpos"} >= $bodypos and $entry->{"endpos"} <= $end
$entry->{"startpos"} >= $bodypos $entry->{"endpos"} <= $end
Truth table33%1/3
A and B
A= $entry->{"startpos"} >= $bodyposB= $entry->{"endpos"} <= $end
ABresult
0X0
100
111
319 substr($src, $entry->{startpos} - $bodypos
320 , $entry->{endpos} - $entry->{startpos})
321 4 = "\n" x $entry->{nlines};
322 }
323 29 $src;
324 }
325  
326 3 ▶ sub YATT::Lite::Core::Template::get_type_item {
Subroutine get_type_item: called CC=2 SCAR=7.1
Pod undocumented
327 3 (my Template $tmpl, my ($type, $name)) = @_;
328 3 ▶ my $class = $PART_KIND_CLASS{$type}
Branch: 1 branch
BranchTrueFalseTotal
my $class = $YATT::Lite::Core::PART_KIND_CLASS{$type} or Carp::croak("Unknown type: $type") 3 0 3
329 or Carp::croak "Unknown type: $type";
330 3 $tmpl->{_Item}{$class->item_key_for($name)};
331 }
332  
333 87 ▶ sub YATT::Lite::Core::Part::reorder_hash_params {
Subroutine reorder_hash_params: called CC=7 SCAR=20.4
Pod undocumented
334 87 (my Widget $widget, my ($orig_params)) = @_;
335 87 ▶ return unless $orig_params;
Branch: 1 branch
BranchTrueFalseTotal
unless $orig_params 70 17 87
336 17 ▶ return @$orig_params if ref $orig_params eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $orig_params eq "ARRAY" 14 3 17
337 3 my $params = +{%$orig_params};
338 3 my @params;
339 3 ▶ foreach my $name (map($_ ? @$_ : (), $widget->{_arg_order})) {
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 3 0 3
340 4 push @params, delete $params->{$name};
341 }
342 3 ▶ if (my @unknown = grep {/^[a-z]\w*$/i} keys %$params) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@unknown) = grep({/^[a-z]\w*$/i;} keys %$params)) 0 3 3
343 0 die "Unknown args for $widget->{name}: " . join(", ", @unknown)
344 . "\n";
345 }
346 3 ▶ wantarray ? @params : \@params;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
347 }
348 }
349 {
350 49 ▶ sub reorder_cgi_params {
Subroutine reorder_cgi_params: called CC=12 SCAR=24.9
Pod undocumented
351 274 (my MY $self, my Widget $widget, my ($cgi, $list)) = @_;
352 274 ▶ $list ||= [];
Condition100%2/2
$list ||= []
l!l
87187
MC/DC100%1/1
$list ||= []
$list
Truth table100%2/2
A
A= $list
Aresult
11
00
353 274 my $stash;
354 274 ▶ if ($self->{stash_unknown_params_to}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"stash_unknown_params_to"}) 270 4 274
355 270 ▶ $stash = $cgi->stash->{$self->{stash_unknown_params_to}} //= +{};
Condition50%1/2
$cgi->stash->{$self->{"stash_unknown_params_to"}} //= {}
l!l
0270
MC/DC0%0/1
$cgi->stash->{$self->{"stash_unknown_params_to"}} //= {}
$cgi->stash->{$self->{"stash_unknown_params_to"}}
Truth table50%1/2
A
A= $cgi->stash->{$self->{"stash_unknown_params_to"}}
Aresult
11
00
356 }
357 274 foreach my $name ($cgi->param) {
358 69 ▶ next unless $name =~ /^[a-z]\w*$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^[a-z]\w*$/i 15 54 69
359 54 ▶ my $argdecl = $widget->{_arg_dict}{$name} or do {
Branch: 1 branch
BranchTrueFalseTotal
my $argdecl = $widget->{"_arg_dict"}{$name} or do { if ($stash) { push @{$$stash{$name};}, $cgi->multi_param($name); next; } else { my $wname = $widget->{"name"} ? qq[ for widget '$widget->{"name"}'] : ""; die "Unknown args${wname}: $name\n"; } } 49 5 54
360 5 ▶ if ($stash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stash) { } 4 1 5
361 4 push @{$stash->{$name}}, $cgi->multi_param($name);
362 4 next;
363 } else {
364 my $wname = $widget->{name}
365 1 ▶ ? " for widget '$widget->{name}'" : "";
Branch: 1 branch
BranchTrueFalseTotal
$widget->{'name'} ? : 0 1 1
366 1 die "Unknown args$wname: $name\n";
367 }
368 };
369 49 ▶ if ($argdecl->is_unsafe_param) {
Branch: 1 branch
BranchTrueFalseTotal
if ($argdecl->is_unsafe_param) 2 47 49
370 2 ▶ if ($stash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stash) 2 0 2
371 2 push @{$stash->{$name}}, $cgi->multi_param($name);
372 }
373 2 next;
374 }
375 47 my @value = $cgi->multi_param($name);
376 47 ▶ $list->[$argdecl->argno] = $argdecl->type->[0] eq 'list'
Branch: 1 branch
BranchTrueFalseTotal
$argdecl->type->[0] eq 'list' ? : 0 47 47
377 ? \@value : $value[0];
378 }
379 273 @$list;
380 }
381 }
382 #========================================
383 49 ▶sub configure_rc_script {
Subroutine configure_rc_script: called CC=2 SCAR=7.0
Pod undocumented
384 1 (my MY $vfs, my $script) = @_;
385 1 my Folder $f = $vfs->{_root};
386 my $pkg = $f->{entns}
387 1 ▶ or die $vfs->error("package name is not specified for configure rc_script");
Branch: 1 branch
BranchTrueFalseTotal
my $pkg = $f->{"entns"} or die $vfs->error("package name is not specified for configure rc_script") 1 0 1
388 # print STDERR "#### $pkg \n";
389 # XXX: base は設定済みだったはずだけど...
390 1 ckeval(qq{package $pkg; use strict; use YATT::Lite; $script});
391 }
392 #========================================
393  
394 # Template alias さえ拡張すれば済むように。
395 # 逆に言うと、 vfs_file だけを定義して Template を定義しなかった場合, 継承が働かなくなった。
396 218 ▶sub create_file {
Subroutine create_file: called CC=1 SCAR=0.0
Pod undocumented
397 218 (my MY $vfs, my $spec) = splice @_, 0, 2;
398 218 $vfs->Template->new(path => $spec, @_);
399 }
400  
401 #
402 # called from <!yatt:base>
403 #
404 49 my %BASE_ATTS = ('' => 1, qw(file 1 dir 1));
405 18 ▶sub declare_base {
Subroutine declare_base: called CC=14 SCAR=28.9
Pod undocumented
406 18 (my MY $vfs, my ParsingState $state, my Template $tmpl, my ($ns, @args)) = @_;
407  
408 18 ▶ unless (@args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 0 18 18
409 0 $vfs->synerror($state, q{No base arg});
410 }
411  
412 18 ▶ my $base = $tmpl->{base} //= [];
Condition50%1/2
$tmpl->{"base"} //= []
l!l
018
MC/DC0%0/1
$tmpl->{"base"} //= []
$tmpl->{"base"}
Truth table50%1/2
A
A= $tmpl->{"base"}
Aresult
11
00
413 18 ▶ if (@$base) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$base) 0 18 18
414 0 $vfs->synerror($state, "Duplicate base decl! was=%s, new=%s"
415 , terse_dump($base), terse_dump(\@args));
416 }
417  
418 18 foreach my $att (@args) {
419 18 my $type = $vfs->node_type($att);
420  
421 18 ▶ $type == TYPE_ATT_TEXT
Branch: 1 branch
BranchTrueFalseTotal
$type == 8 or $vfs->synerror($state, "Not implemented base decl type: %s", $att) 18 0 18
422 or $vfs->synerror($state, q{Not implemented base decl type: %s}, $att);
423  
424 18 my $key = $vfs->node_path($att);
425 18 ▶ unless ($BASE_ATTS{$key // ''}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($BASE_ATTS{$key // ""}) 1 17 18
Condition50%1/2
$key // ""
l!l
180
MC/DC0%0/1
$key // ""
$key
Truth table50%1/2
A
A= $key
Aresult
11
00
426 1 ▶ $vfs->synerror($state, q{Unknown base option: %s}, $key // '')
Condition50%1/2
$key // ""
l!l
10
MC/DC0%0/1
$key // ""
$key
Truth table50%1/2
A
A= $key
Aresult
11
00
427 }
428  
429 17 ▶ nonempty(my $fn = $vfs->node_value($att))
Branch: 1 branch
BranchTrueFalseTotal
nonempty(my $fn = $vfs->node_value($att)) or $vfs->synerror($state, "base spec is empty!") 17 0 17
430 or $vfs->synerror($state, q{base spec is empty!});
431  
432 17 ▶ if ($vfs->{_on_memory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vfs->{'_on_memory'}) { } 3 14 17
433 3 ▶ my $o = $vfs->find_file($fn)
Branch: 1 branch
BranchTrueFalseTotal
my $o = $vfs->find_file($fn) or $vfs->synerror($state, "No such base path: %s", $fn) 3 0 3
434 or $vfs->synerror($state, q{No such base path: %s}, $fn);
435 3 push @$base, $o;
436 } else {
437 14 ▶ defined(my $realfn = $vfs->resolve_path_from($tmpl, $fn))
Branch: 1 branch
BranchTrueFalseTotal
defined(my $realfn = $vfs->resolve_path_from($tmpl, $fn)) or $vfs->synerror($state, "Can\\'t find object path for: %s", $fn) 14 0 14
438 or $vfs->synerror($state, q{Can\'t find object path for: %s}, $fn);
439  
440 14 ▶ -e $realfn
Branch: 1 branch
BranchTrueFalseTotal
-e $realfn or $vfs->synerror($state, "No such base path: %s", $realfn) 14 0 14
441 or $vfs->synerror($state, q{No such base path: %s}, $realfn);
442  
443 14 push @$base, my $o = $vfs->find_neighbor_type(undef, $realfn);
444  
445 14 $tmpl->add_dependency($realfn, $o);
446  
447 # GH-262: ここで find_product(perl => $o) してはいけない。
448 # declare 段階は記述子を置くだけにする(base の decl parse は
449 # find_neighbor_type 経由の create 時に済んでいる)。product の生成は
450 # cgen 時の setup_inheritance_for → ensure_generated_for_folders と
451 # dispatch 時の find_part_handler の事前コンパイルが遅延実行する。
452 # eager に生成すると、この宣言自身を parse 中のテンプレートが
453 # cached_in の dict 登録前(Util.pm:210)のため再 lookup で二重 create
454 # され、EntNS confliction になる(base+widget-use の循環参照が壊れる)。
455 }
456 }
457 }
458  
459 8 ▶sub synerror {
Subroutine synerror: called CC=3 SCAR=11.3
Pod undocumented
460 8 (my MY $vfs, my ParsingState $state, my ($fmt, @opts)) = @_;
461 8 my $opts = {depth => 2};
462 8 ▶ $opts->{tmpl_file} = $state->{path} if $state->{path};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"path"} 8 0 8
463 8 ▶ $opts->{tmpl_line} = $state->{_startln} if $state->{_startln};
Branch: 1 branch
BranchTrueFalseTotal
if $state->{"_startln"} 8 0 8
464 8 die $vfs->error($opts, $fmt, @opts);
465 }
466  
467 #
468 # called from <!yatt:import> (LRXML::declare_import). GH-256
469 #
470 29 ▶sub import_resolve_source {
Subroutine import_resolve_source: called CC=8 SCAR=21.9
Pod undocumented
471 29 (my MY $vfs, my ParsingState $state, my Template $tmpl, my $fn) = @_;
472  
473 29 my $o = do {
474 29 ▶ if ($vfs->{_on_memory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vfs->{'_on_memory'}) { } 11 18 29
475 11 ▶ $vfs->find_file($fn)
Condition33%1/3
$vfs->find_file($fn) || $vfs->synerror($state, 'No such import path: %s', $fn)
l!l&&r!l&&!r
1100
MC/DC0%0/2
$vfs->find_file($fn) || $vfs->synerror($state, 'No such import path: %s', $fn)
$vfs->find_file($fn) $vfs->synerror($state, 'No such import path: %s', $fn)
Truth table33%1/3
A || B
A= $vfs->find_file($fn)B= $vfs->synerror($state, 'No such import path: %s', $fn)
ABresult
1X1
011
000
476 or $vfs->synerror($state, q{No such import path: %s}, $fn);
477 } else {
478 18 ▶ defined(my $realfn = $vfs->resolve_path_from($tmpl, $fn))
Branch: 1 branch
BranchTrueFalseTotal
defined(my $realfn = $vfs->resolve_path_from($tmpl, $fn)) or $vfs->synerror($state, "Can't find object path for import: %s", $fn) 18 0 18
479 or $vfs->synerror($state, q{Can't find object path for import: %s}, $fn);
480  
481 18 ▶ -e $realfn
Branch: 1 branch
BranchTrueFalseTotal
-e $realfn or $vfs->synerror($state, "No such import path: %s", $realfn) 18 0 18
482 or $vfs->synerror($state, q{No such import path: %s}, $realfn);
483  
484 # find_neighbor_type より前に path で検査する。相手が cached_in の
485 # dict 代入前 (load 途中) だと、find_file が同じファイルの Template を
486 # 二重生成して EntNS confliction になってしまうため。
487 18 ▶ if ($YATT::Lite::LRXML::DECL_PARSING{$realfn}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YATT::Lite::LRXML::DECL_PARSING{$realfn}) 1 17 18
488 1 $vfs->synerror($state, q{Circular import detected: %s}, $fn);
489 }
490  
491 17 my $found = $vfs->find_neighbor_type(undef, $realfn);
492  
493 16 $tmpl->add_dependency($realfn, $found);
494  
495 16 $found;
496 }
497 };
498  
499 27 ▶ unless (UNIVERSAL::isa($o, MY->Template)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::isa($o, "YATT::Lite::Core"->Template)) 0 27 27
500 0 $vfs->synerror($state, q{import from non-template is not supported: %s}, $fn);
501 }
502  
503 27 my Template $src = $o;
504 27 ▶ if ($src->{_decl_parsing}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src->{"_decl_parsing"}) 0 27 27
505 0 $vfs->synerror($state, q{Circular import detected: %s}, $fn);
506 }
507  
508 # import 対象は宣言時点でコンパイルしておく (cf. <!yatt:base> declare_base)。
509 # これにより名前検証と @ISA/entns 確立が済んだ状態で以後の処理ができる。
510 27 $vfs->find_product(perl => $src);
511  
512 27 $src;
513 }
514  
515 #
516 # ソース template から import 対象を探す。$kind が undef なら自動判定。
517 # 戻り値: ($kind, $part_or_argmacro)
518 #
519 #
520 # find_kind_part_from (VFS.pm) の kind 別実装。
521 # item-key の符号化は各 part class の item_key_for に集約されている。GH-256
522 #
523 32 ▶sub _find_kind_part__widget {
Subroutine _find_kind_part__widget: called CC=4 SCAR=13.9
524 32 (my MY $vfs, my ($from, $name)) = @_;
525 32 ▶ my Part $part = $vfs->find_part_from($from, MY->Widget->item_key_for($name))
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::Core::Part $part = $vfs->find_part_from($from, "YATT::Lite::Core"->Widget->item_key_for($name)) or return undef 21 11 32
526 or return undef;
527 # widget と page は同じ名前空間なので kind で照合する
528 21 ▶ ($part->{kind} // '') eq 'widget' ? $part : undef;
Branch: 1 branch
BranchTrueFalseTotal
($part->{'kind'} // '') eq 'widget' ? : 18 3 21
Condition50%1/2
$part->{"kind"} // ""
l!l
210
MC/DC0%0/1
$part->{"kind"} // ""
$part->{"kind"}
Truth table50%1/2
A
A= $part->{"kind"}
Aresult
11
00
529 }
530 31 ▶sub _find_kind_part__page {
Subroutine _find_kind_part__page: called CC=4 SCAR=13.9
531 31 (my MY $vfs, my ($from, $name)) = @_;
532 31 ▶ my Part $part = $vfs->find_part_from($from, MY->Page->item_key_for($name))
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::Core::Part $part = $vfs->find_part_from($from, "YATT::Lite::Core"->Page->item_key_for($name)) or return undef 20 11 31
533 or return undef;
534 20 ▶ ($part->{kind} // '') eq 'page' ? $part : undef;
Branch: 1 branch
BranchTrueFalseTotal
($part->{'kind'} // '') eq 'page' ? : 3 17 20
Condition50%1/2
$part->{"kind"} // ""
l!l
200
MC/DC0%0/1
$part->{"kind"} // ""
$part->{"kind"}
Truth table50%1/2
A
A= $part->{"kind"}
Aresult
11
00
535 }
536 30 ▶sub _find_kind_part__action {
Subroutine _find_kind_part__action: called CC=1 SCAR=0.0
537 30 (my MY $vfs, my ($from, $name)) = @_;
538 30 $vfs->find_part_from($from, MY->Action->item_key_for($name));
539 }
540 30 ▶sub _find_kind_part__entity {
Subroutine _find_kind_part__entity: called CC=1 SCAR=0.0
541 30 (my MY $vfs, my ($from, $name)) = @_;
542 30 $vfs->find_part_from($from, MY->Entity->item_key_for($name));
543 }
544 30 ▶sub _find_kind_part__argmacro {
Subroutine _find_kind_part__argmacro: called CC=7 SCAR=22.7
545 30 (my MY $vfs, my ($from, $name)) = @_;
546 30 my Folder $folder = $from;
547 30 ▶ my $macro = $folder->{_argmacro_dict} && $folder->{_argmacro_dict}{$name};
Condition100%3/3
$folder->{'_argmacro_dict'} && $folder->{'_argmacro_dict'}{$name}
!ll&&!rl&&r
1794
MC/DC100%2/2
$folder->{'_argmacro_dict'} && $folder->{'_argmacro_dict'}{$name}
$folder->{'_argmacro_dict'} $folder->{'_argmacro_dict'}{$name}
Truth table100%3/3
A && B
A= $folder->{'_argmacro_dict'}B= $folder->{'_argmacro_dict'}{$name}
ABresult
0X0
100
111
548 30 ▶ return $macro if $macro;
Branch: 1 branch
BranchTrueFalseTotal
if $macro 4 26 30
549 # find_argmacro (LRXML.pm) と同じく base 1 段のみ探索
550 26 foreach my Folder $base ($folder->list_base) {
551 26 ▶ next unless UNIVERSAL::isa($base, MY->Template);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($base, "YATT::Lite::Core"->Template) 26 0 26
552 0 my Template $baseTmpl = $base;
553 return $baseTmpl->{_argmacro_dict}{$name}
554 0 ▶ if $baseTmpl->{_argmacro_dict} && $baseTmpl->{_argmacro_dict}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $baseTmpl->{"_argmacro_dict"} and $baseTmpl->{"_argmacro_dict"}{$name} 0 0 0
Condition0%0/3
$baseTmpl->{"_argmacro_dict"} and $baseTmpl->{"_argmacro_dict"}{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$baseTmpl->{"_argmacro_dict"} and $baseTmpl->{"_argmacro_dict"}{$name}
$baseTmpl->{"_argmacro_dict"} $baseTmpl->{"_argmacro_dict"}{$name}
Truth table0%0/3
A and B
A= $baseTmpl->{"_argmacro_dict"}B= $baseTmpl->{"_argmacro_dict"}{$name}
ABresult
0X0
100
111
555 }
556 26 undef;
557 }
558  
559 29 ▶sub import_find_source_part {
Subroutine import_find_source_part: called CC=10 SCAR=23.1
Pod undocumented
560 29 (my MY $vfs, my ParsingState $state, my Template $src, my ($srcName, $kind)) = @_;
561  
562 29 ▶ my $srcDesc = $src->{path} // $src->{name};
Condition66%2/3
$src->{"path"} // $src->{"name"}
l!l&&r!l&&!r
17120
MC/DC0%0/2
$src->{"path"} // $src->{"name"}
$src->{"path"} $src->{"name"}
Truth table66%2/3
A // B
A= $src->{"path"}B= $src->{"name"}
ABresult
1X1
011
000
563  
564 # 全 kind を probe する (widget/page は同じ名前空間だが kind 照合で区別される)
565 29 my @hits;
566 29 foreach my $k (qw(widget page action entity argmacro)) {
567 145 ▶ if (defined (my $found = $vfs->find_kind_part_from($src, $k, $srcName))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $found = $vfs->find_kind_part_from($src, $k, $srcName))) 29 116 145
568 29 push @hits, [$k => $found];
569 }
570 }
571  
572 29 ▶ if (defined $kind) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kind) { } 10 19 29
573 10 foreach my $hit (@hits) {
574 10 ▶ return @$hit if $hit->[0] eq $kind;
Branch: 1 branch
BranchTrueFalseTotal
if $hit->[0] eq $kind 8 2 10
575 }
576 2 ▶ if (@hits) {
Branch: 1 branch
BranchTrueFalseTotal
if (@hits) 2 0 2
577 $vfs->synerror($state
578 , q{Import kind mismatch for '%s': expected %s, but %s has %s}
579 , $srcName, $kind, $srcDesc
580 2 , join(", ", map {$_->[0]} @hits));
581 }
582 0 $vfs->synerror($state, q{No such part to import: %s:%s (in %s)}
583 , $srcName, $kind, $srcDesc);
584 } else {
585 19 ▶ unless (@hits) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@hits) 2 17 19
586 2 $vfs->synerror($state, q{No such part to import: %s (in %s)}
587 , $srcName, $srcDesc);
588 }
589 17 ▶ if (@hits > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@hits > 1) 2 15 17
590 $vfs->synerror($state
591 , q{Ambiguous import '%s' in %s (found as: %s); add kind annotation like [%s:%s]}
592 2 , $srcName, $srcDesc, join(", ", map {$_->[0]} @hits)
593 , $srcName, $hits[0][0]);
594 }
595 15 return @{$hits[0]};
596 }
597 }
598  
599 #========================================
600 {
601 919 ▶ sub Parser {
Subroutine Parser: called CC=1 SCAR=0.0
Pod undocumented
602 # local $@;
603 # my $err = catch {
604 919 require YATT::Lite::LRXML;
605 # };
606 # unless ($err =~ /^Can't locate loadable object for module main::Tie::Hash::NamedCapture/) {
607 # die $err || $@ || "(unknown reason)";
608 # }
609 919 'YATT::Lite::LRXML'
610 }
611 0 ▶ sub cgen_perl { 'YATT::Lite::CGen::Perl' }
Subroutine cgen_perl: not called CC=1 SCAR=6.9
Pod undocumented
612 589 ▶ sub stat_mtime {
Subroutine stat_mtime: called CC=2 SCAR=7.1
Pod undocumented
613 589 my ($fn) = @_;
614 589 ▶ -e $fn or return;
Branch: 1 branch
BranchTrueFalseTotal
-e $fn or return 589 0 589
615 589 (stat($fn))[9];
616 }
617 919 ▶ sub get_parser {
Subroutine get_parser: called CC=2 SCAR=7.2
Pod undocumented
618 919 my MY $self = shift;
619 # $self->{parser} ||=
620 $self->Parser->new
621 (vfs => $self, $self->cf_delegate
622 (qw(namespace special_entities
623 match_argsroute_first
624 body_argument
625 body_argument_type
626 allow_bare_entity_in_decl
627 )
628 , [debug_parser => 'debug']
629 , [tmpl_encoding => 'encoding']
630 )
631 919 ▶ , $self->{parse_while_loading} ? (all => 1) : ()
Branch: 1 branch
BranchTrueFalseTotal
$self->{'parse_while_loading'} ? : 0 919 919
632 , @_);
633 }
634 30 ▶ sub ensure_parsed {
Subroutine ensure_parsed: called CC=2 SCAR=6.9
Pod undocumented
635 30 (my MY $self, my Part $part) = @_;
636 30 my $parser = $self->get_parser;
637 30 my Template $tmpl = $part->{folder};
638 30 ▶ return if $tmpl->{_parse_ok};
Branch: 1 branch
BranchTrueFalseTotal
if $tmpl->{"_parse_ok"} 26 4 30
639 4 $parser->parse_decllist_entities($tmpl);
640 4 $parser->parse_body($tmpl);
641 }
642 0 ▶ sub render {
Subroutine render: not called CC=2 SCAR=17.9
Pod undocumented
643 0 my MY $self = shift;
644 0 ▶ open my $fh, '>', \ (my $str = "") or die "Can't open capture buffer!: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", \(my $str = "") or die "Can't open capture buffer!: $!" 0 0 0
645 0 $self->render_into($fh, @_);
646 0 close $fh;
647 0 $str;
648 }
649 1 ▶ sub render_into {
Subroutine render_into: called CC=5 SCAR=18.9
Pod undocumented
650 1 (my MY $self, my ($fh, $namerec, $args, @opts)) = @_;
651 1 my ($part, $sub, $pkg) = $self->find_part_handler($namerec);
652 1 ▶ unless ($part->public) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($part->public) 0 1 1
653 # XXX: refresh する手もあるだろう。
654 0 croak $self->error(q|Forbidden request '%s'|, terse_dump($namerec));
655 }
656  
657 1 my @args = do {
658 1 ▶ if (not defined $args) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $args) { } 0 1 1
elsif (ref $args eq 'ARRAY') { } 0 1 1
659 0 ();
660 } elsif (ref $args eq 'ARRAY') {
661 0 @$args
662 } else {
663 # $args can be a Hash::MultiValue and other HASH compatible obj.
664 1 $part->reorder_hash_params($args);
665 }
666 };
667  
668 1 ▶ if (@opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@opts) { } 0 1 1
669 0 $self->cf_let(\@opts, $sub, $pkg, $fh, @args);
670 } else {
671 1 $sub->($pkg, $fh, @args);
672 }
673 }
674  
675 # root から見える part (と、その template)を取り出す。
676 0 ▶ sub get_part {
Subroutine get_part: not called CC=6 SCAR=37.4
Pod undocumented
677 0 (my MY $self, my $name, my %opts) = @_;
678 0 my $ignore_error = delete $opts{ignore_error};
679 0 my Template $tmpl;
680 my Part $part;
681 0 ▶ if (UNIVERSAL::isa($self->{_root}, Template)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($self->{'_root'}, 'YATT::Lite::Core::Template')) { } 0 0 0
682 0 $tmpl = $self->{_root};
683 0 $part = $self->find_part($name);
684 } else {
685 0 ▶ $tmpl = $self->find_file($name)
Branch: 1 branch
BranchTrueFalseTotal
$tmpl = $self->find_file($name) or $ignore_error and return or croak("No such template file: $name") 0 0 0
Condition0%0/5
$tmpl = $self->find_file($name) or $ignore_error and return
l!l&&r!l&&!r
000
$ignore_error and return
!ll
00
MC/DC0%0/2
$tmpl = $self->find_file($name) or $ignore_error and return
$tmpl = $self->find_file($name) $ignore_error
Truth table0%0/3
A or B
A= $tmpl = $self->find_file($name)B= $ignore_error
ABresult
1X1
011
000
686 or ($ignore_error and return)
687 or croak "No such template file: $name";
688 0 $part = $tmpl->{_Item}{''};
689 }
690 # XXX: それとも、 $part から $tmpl が引けるようにするか? weaken して...
691 0 ▶ wantarray ? ($part, $tmpl) : $part;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
692 }
693  
694 86 ▶ sub find_part_renderer {
Subroutine find_part_renderer: called CC=12 SCAR=32.5
Pod undocumented
695 86 (my MY $self, my ($widgetPath, %opts)) = @_;
696 86 my $ignore_error = delete $opts{ignore_error};
697  
698 86 ▶ my @wpath = ref $widgetPath ? @$widgetPath : split ":", $widgetPath;
Branch: 1 branch
BranchTrueFalseTotal
ref $widgetPath ? : 0 86 86
699  
700 86 ▶ my $part = $self->find_part_from($self->{_root}, @wpath ? @wpath : '')
Branch: 2 branches
BranchTrueFalseTotal
my $part = $self->find_part_from($self->{"_root"}, @wpath ? @wpath : "") or $ignore_error and return or croak('No such widget: ' . join(":", @wpath)) 86 0 86
@wpath ? : 83 3 86
Condition20%1/5
my $part = $self->find_part_from($self->{"_root"}, @wpath ? @wpath : "") or $ignore_error and return
l!l&&r!l&&!r
8600
$ignore_error and return
!ll
00
MC/DC0%0/2
my $part = $self->find_part_from($self->{"_root"}, @wpath ? @wpath : "") or $ignore_error and return
my $part = $self->find_part_from($self->{"_root"}, @wpath ? @wpath : "") $ignore_error
Truth table33%1/3
A or B
A= my $part = $self->find_part_from($self->{"_root"}, @wpath ? @wpath : "")B= $ignore_error
ABresult
1X1
011
000
701 or ($ignore_error and return)
702 or croak "No such widget: ".join(":", @wpath);
703  
704 86 my $tmpl = $part->cget('folder');
705  
706 86 my $path = $tmpl->cget('path');
707  
708 86 my $method = "render_".$part->cget('name');
709  
710 86 ▶ my $pkg = $self->find_product(perl => $tmpl)
Branch: 1 branch
BranchTrueFalseTotal
my $pkg = $self->find_product("perl", $tmpl) or $ignore_error and return or croak("Can't compile template file: $path") 86 0 86
Condition20%1/5
my $pkg = $self->find_product("perl", $tmpl) or $ignore_error and return
l!l&&r!l&&!r
8600
$ignore_error and return
!ll
00
MC/DC0%0/2
my $pkg = $self->find_product("perl", $tmpl) or $ignore_error and return
my $pkg = $self->find_product("perl", $tmpl) $ignore_error
Truth table33%1/3
A or B
A= my $pkg = $self->find_product("perl", $tmpl)B= $ignore_error
ABresult
1X1
011
000
711 or ($ignore_error and return)
712 or croak "Can't compile template file: $path";
713  
714 86 ▶ my $sub = $pkg->can($method)
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $pkg->can($method) or $ignore_error and return or croak("Can't extract $method from file: $path") 86 0 86
Condition20%1/5
my $sub = $pkg->can($method) or $ignore_error and return
l!l&&r!l&&!r
8600
$ignore_error and return
!ll
00
MC/DC0%0/2
my $sub = $pkg->can($method) or $ignore_error and return
my $sub = $pkg->can($method) $ignore_error
Truth table33%1/3
A or B
A= my $sub = $pkg->can($method)B= $ignore_error
ABresult
1X1
011
000
715 or ($ignore_error and return)
716 or croak "Can't extract $method from file: $path";
717  
718 86 ($part, $sub, $pkg);
719 }
720  
721 232 ▶ sub find_part_handler {
Subroutine find_part_handler: called CC=24 SCAR=34.9
Pod undocumented
722 232 (my MY $self, my $nameSpec, my %opts) = @_;
723 232 my $ignore_error = delete $opts{ignore_error};
724 232 ▶ my ($partName, $kind, $pureName, @rest)
Branch: 1 branch
BranchTrueFalseTotal
ref $nameSpec ? : 195 37 232
725 = ref $nameSpec ? @$nameSpec : $nameSpec;
726  
727 232 ▶ $partName ||= $self->{index_name};
Condition66%2/3
$partName ||= $self->{"index_name"}
l!l&&r!l&&!r
23101
MC/DC50%1/2
$partName ||= $self->{"index_name"}
$partName $self->{"index_name"}
Truth table66%2/3
A ||= B
A= $partNameB= $self->{"index_name"}
ABresult
1X1
011
000
728  
729 232 my Template $tmpl = do {
730 232 ▶ if (UNIVERSAL::isa($self->{_root}, Template)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($self->{'_root'}, 'YATT::Lite::Core::Template')) { } 1 231 232
731 # Special case.
732 # XXX: Should add action tests for this case.
733 1 $self->{_root};
734  
735 } else {
736 # General container case.
737 231 ▶ $self->find_file($partName)
Condition62%5/8
$self->find_file($partName) || $ignore_error && (return) || croak("No such template file: $partName")
l!l&&r!l&&!r
19200
$self->find_file($partName) or $ignore_error and return
l!l&&r!l&&!r
192133
$ignore_error and return
!ll
034
MC/DC0%0/3
$self->find_file($partName) || $ignore_error && (return) || croak("No such template file: $partName")
$self->find_file($partName) $ignore_error croak("No such template file: $partName")
Truth table25%1/4
A or B || C
A= $self->find_file($partName)B= $ignore_errorC= croak("No such template file: $partName")
ABCresult
1XX1
01X1
0011
0000
738 or ($ignore_error and return)
739 or croak "No such template file: $partName";
740 }
741 };
742  
743 # part 探索より先にコンパイルする。継承 part の探索 (lookup_base) は
744 # @ISA に依存し、@ISA は setup_inheritance_for (コード生成時) が張るため。
745 # GH-255
746 193 ▶ my $pkg = $self->find_product(perl => $tmpl)
Branch: 1 branch
BranchTrueFalseTotal
my $pkg = $self->find_product("perl", $tmpl) or $ignore_error and return or croak("Can't compile template file: $partName") 193 0 193
Condition20%1/5
my $pkg = $self->find_product("perl", $tmpl) or $ignore_error and return
l!l&&r!l&&!r
19300
$ignore_error and return
!ll
00
MC/DC0%0/2
my $pkg = $self->find_product("perl", $tmpl) or $ignore_error and return
my $pkg = $self->find_product("perl", $tmpl) $ignore_error
Truth table33%1/3
A or B
A= my $pkg = $self->find_product("perl", $tmpl)B= $ignore_error
ABresult
1X1
011
000
747 or ($ignore_error and return)
748 or croak "Can't compile template file: $partName";
749  
750 193 (my Part $part, my $method) = do {
751 193 (my Part $p, my $meth);
752 193 ▶ if (not defined $kind and not defined $pureName) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $kind or defined $pureName) 173 20 193
Condition66%2/3
defined $kind or defined $pureName
l!l&&r!l&&!r
200173
MC/DC50%1/2
defined $kind or defined $pureName
defined $kind defined $pureName
Truth table66%2/3
A or B
A= defined $kindB= defined $pureName
ABresult
1X1
011
000
753 173 foreach my $k (qw(page action)) {
754 177 (my $itemKey, $meth) = $self->can("_itemKey_$k")->($self, '');
755 177 ▶ $p = $tmpl->{_Item}{$itemKey}
Branch: 1 branch
BranchTrueFalseTotal
$p = $tmpl->{"_Item"}{$itemKey} and last 173 4 177
756 and last;
757 }
758 }
759  
760 193 ▶ if ($p) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p) { } 173 20 193
761 173 ($p, $meth);
762 } else {
763  
764 20 ▶ $kind //= 'page';
Condition50%1/2
$kind //= "page"
l!l
200
MC/DC0%0/1
$kind //= "page"
$kind
Truth table50%1/2
A
A= $kind
Aresult
11
00
765 20 ▶ $pureName //= '';
Condition50%1/2
$pureName //= ""
l!l
200
MC/DC0%0/1
$pureName //= ""
$pureName
Truth table50%1/2
A
A= $pureName
Aresult
11
00
766  
767 20 my ($itemKey, $meth) = $self->can("_itemKey_$kind")->($self, $pureName);
768  
769 20 ▶ $p = $tmpl->{_Item}{$itemKey} || $self->find_part_from($tmpl, $itemKey)
Branch: 1 branch
BranchTrueFalseTotal
$p = $tmpl->{"_Item"}{$itemKey} || $self->find_part_from($tmpl, $itemKey) or $ignore_error and return or croak("No such $kind in file ${partName}: $pureName") 18 2 20
Condition75%6/8
$p = $tmpl->{"_Item"}{$itemKey} || $self->find_part_from($tmpl, $itemKey) or $ignore_error and return
l!l&&r!l&&!r
1802
$tmpl->{'_Item'}{$itemKey} || $self->find_part_from($tmpl, $itemKey)
l!l&&r!l&&!r
1352
$ignore_error and return
!ll
20
MC/DC66%2/3
$p = $tmpl->{"_Item"}{$itemKey} || $self->find_part_from($tmpl, $itemKey) or $ignore_error and return
$tmpl->{'_Item'}{$itemKey} $self->find_part_from($tmpl, $itemKey) $ignore_error
Truth table75%3/4
A || B or C
A= $tmpl->{'_Item'}{$itemKey}B= $self->find_part_from($tmpl, $itemKey)C= $ignore_error
ABCresult
1XX1
01X1
0011
0000
770 or ($ignore_error and return)
771 or croak "No such $kind in file $partName: $pureName";
772  
773 18 ($p, $meth);
774 };
775 };
776  
777 # import alias はソース Part へ解決してから返す
778 # (public 判定や引数 reorder が常に最新のソース側メタで動くように)。GH-256
779 191 $part = $part->resolve_alias($self);
780  
781 191 ▶ my $sub = $pkg->can($method)
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $pkg->can($method) or $ignore_error and return or croak("Can't extract $method from file: $partName") 191 0 191
Condition20%1/5
my $sub = $pkg->can($method) or $ignore_error and return
l!l&&r!l&&!r
19100
$ignore_error and return
!ll
00
MC/DC0%0/2
my $sub = $pkg->can($method) or $ignore_error and return
my $sub = $pkg->can($method) $ignore_error
Truth table33%1/3
A or B
A= my $sub = $pkg->can($method)B= $ignore_error
ABresult
1X1
011
000
782 or ($ignore_error and return)
783 or croak "Can't extract $method from file: $partName";
784  
785 191 ($part, $sub, $pkg, @rest);
786 }
787  
788 185 ▶ sub _itemKey_page {
Subroutine _itemKey_page: called CC=1 SCAR=0.0
789 185 shift;
790 185 (MY->Page->item_key_for($_[0]), MY->Page->method_name_for($_[0]));
791 }
792 12 ▶ sub _itemKey_action {
Subroutine _itemKey_action: called CC=1 SCAR=0.0
793 12 shift;
794 12 (MY->Action->item_key_for($_[0]), MY->Action->method_name_for($_[0]));
795 }
796  
797 #
798 # Action name => sub {}
799 #
800 1 ▶ sub add_root_action_handler {
Subroutine add_root_action_handler: called CC=1 SCAR=0.0
Pod undocumented
801 1 (my MY $self, my ($name, $sub, $callinfo)) = @_;
802 1 my Folder $root = $self->{_root};
803  
804 1 my ($callpack, $filename, $lineno) = @$callinfo;
805  
806 # XXX: This means do_$A.yatt will conflict with "Action $A" in .htyattrc.pl
807 1 my $action_name = "do_$name";
808  
809 1 *{globref($root->{entns}, $action_name)} = $sub;
810  
811 1 $root->{_Item}{MY->Action->item_key_for($name)}
812 = $self->Action->new(name => $action_name, kind => 'action'
813 , folder => $root
814 , startln => $lineno
815 );
816  
817 }
818  
819 37 ▶ sub find_renderer {
Subroutine find_renderer: called CC=3 SCAR=11.1
Pod undocumented
820 37 my MY $self = shift;
821 37 ▶ my ($part, $sub, $pkg) = $self->find_part_handler(@_)
Branch: 1 branch
BranchTrueFalseTotal
() = $self->find_part_handler(@_) or return 3 34 37
822 or return;
823 3 ▶ wantarray ? ($sub, $pkg) : $sub;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
824 }
825  
826 # DirHandler INST 固有 CGEN_perl の生成
827 422 ▶ sub get_cgen_class {
Subroutine get_cgen_class: called CC=1 SCAR=0.0
Pod undocumented
828 422 (my MY $self, my $type) = @_;
829 422 $self->{facade}->get_cgen_class($type);
830 }
831  
832 # XXX: Action only コンパイルは?
833 711 ▶ sub find_product {
Subroutine find_product: called CC=3 SCAR=11.0
Pod undocumented
834 711 (my MY $self, my $spec, my Template $tmpl, my %opts) = @_;
835 711 ▶ my ($type, $kind) = ref $spec ? @$spec : $spec;
Branch: 1 branch
BranchTrueFalseTotal
ref $spec ? : 0 711 711
836 # local $YATT = $self;
837 711 ▶ unless ($tmpl->{_product}{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tmpl->{"_product"}{$type}) 412 299 711
838 412 my $cgen = $self->build_cgen_of($type, \%opts);
839 # 二重生成防止のため、代入自体は ensure_generated の中で行う。
840 412 $cgen->ensure_generated($spec => $tmpl);
841 };
842 666 $tmpl->{_product}{$type};
843 }
844  
845 422 ▶ sub build_cgen_of {
Subroutine build_cgen_of: called CC=3 SCAR=16.0
Pod undocumented
846 422 (my MY $self, my $cgenSpec, my $opts) = @_;
847 422 my ($type, $cg_class) = lexpand($cgenSpec);
848 422 ▶ $cg_class //= $self->get_cgen_class($type);
Condition33%1/3
$cg_class //= $self->get_cgen_class($type)
l!l&&r!l&&!r
04220
MC/DC0%0/2
$cg_class //= $self->get_cgen_class($type)
$cg_class $self->get_cgen_class($type)
Truth table33%1/3
A //= B
A= $cg_classB= $self->get_cgen_class($type)
ABresult
1X1
011
000
849 $cg_class->new
850 (vfs => $self
851 , $self->cf_delegate(qw(no_lineinfo check_lineno only_parse
852 prefer_call_for_entity
853 no_conditional_call
854 lcmsg_sink))
855 , parser => $self->get_parser
856 392 ▶ , sink => $opts->{sink} || sub {
Subroutine __ANON__: called CC=5 SCAR=27.4
857 392 my ($info, @script) = @_;
858 392 ▶ if ($self->{debug_cgen}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug_cgen"}) 0 392 392
859 0 my Template $real = $info->{folder}; # XXX: type???
860 0 ▶ print STDERR "# compiling @{[$type//'undef']} code of @{[$real->{path}//'undef']}\n";
Condition0%0/4
$type // "undef"
l!l
00
$real->{"path"} // "undef"
l!l
00
MC/DC0%0/1
$type // "undef"
$type
MC/DC0%0/1
$real->{"path"} // "undef"
$real->{"path"}
Truth table0%0/2
A
A= $type
Aresult
11
00
Truth table0%0/2
A
A= $real->{"path"}
Aresult
11
00
861 0 ▶ if ($self->{debug_cgen} >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug_cgen"} >= 2) 0 0 0
862 0 print STDERR "#--BEGIN--\n";
863 0 print STDERR @script, "\n";
864 0 print STDERR "#--END--\n\n"
865 }
866 }
867 #
868 392 $self->{_n_compiles}++;
869  
870 392 ckeval(@script);
871 })
872 422 ▶ }
Condition66%2/3
$opts->{'sink'} || sub { my($info, @script) = @_; if ($self->{'debug_cgen'}) { my YATT::Lite::Core::Template $real = $info->{'folder'}; print STDERR "# compiling @{[$type // 'undef'];} code of @{[$real->{'path'} // 'undef'];}\n"; if ($self->{'debug_cgen'} >= 2) { print STDERR "#--BEGIN--\n"; print STDERR @script, "\n"; print STDERR "#--END--\n\n"; } ; } ; ++$self->{'_n_compiles'}; ckeval(@script); }
l!l&&r!l&&!r
34190
MC/DC0%0/2
$opts->{'sink'} || sub { my($info, @script) = @_; if ($self->{'debug_cgen'}) { my YATT::Lite::Core::Template $real = $info->{'folder'}; print STDERR "# compiling @{[$type // 'undef'];} code of @{[$real->{'path'} // 'undef'];}\n"; if ($self->{'debug_cgen'} >= 2) { print STDERR "#--BEGIN--\n"; print STDERR @script, "\n"; print STDERR "#--END--\n\n"; } ; } ; ++$self->{'_n_compiles'}; ckeval(@script); }
$opts->{'sink'} sub { my($info, @script) = @_; if ($self->{'debug_cgen'}) { my YATT::Lite::Core::Template $real = $info->{'folder'}; print STDERR "# compiling @{[$type // 'undef'];} code of @{[$real->{'path'} // 'undef'];}\n"; if ($self->{'debug_cgen'} >= 2) { print STDERR "#--BEGIN--\n"; print STDERR @script, "\n"; print STDERR "#--END--\n\n"; } ; } ; ++$self->{'_n_compiles'}; ckeval(@script); }
Truth table66%2/3
A || B
A= $opts->{'sink'}B= sub { my($info, @script) = @_; if ($self->{'debug_cgen'}) { my YATT::Lite::Core::Template $real = $info->{'folder'}; print STDERR "# compiling @{[$type // 'undef'];} code of @{[$real->{'path'} // 'undef'];}\n"; if ($self->{'debug_cgen'} >= 2) { print STDERR "#--BEGIN--\n"; print STDERR @script, "\n"; print STDERR "#--END--\n\n"; } ; } ; ++$self->{'_n_compiles'}; ckeval(@script); }
ABresult
1X1
011
000
873  
874 #
875 # extract_lcmsg
876 # - filelist is a list(or scalar) of filename or item name(no ext).
877 # - msgdict is used to share same msgid.
878 # - msglist is used to keep msg order.
879 #
880 # XXX: find_product and extract_lcmsg is exclusive.
881 2 ▶ sub extract_lcmsg {
Subroutine extract_lcmsg: called CC=5 SCAR=16.4
Pod undocumented
882 2 (my MY $self, my ($filelist, $msglist, $msgdict)) = @_;
883 2 require Locale::PO;
884 2 ▶ $msglist //= [];
Condition50%1/2
$msglist //= []
l!l
20
MC/DC0%0/1
$msglist //= []
$msglist
Truth table50%1/2
A
A= $msglist
Aresult
11
00
885 2 ▶ $msgdict //= {};
Condition50%1/2
$msgdict //= {}
l!l
02
MC/DC0%0/1
$msgdict //= {}
$msgdict
Truth table50%1/2
A
A= $msgdict
Aresult
11
00
886 3 ▶ local $self->{lcmsg_sink} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
887 3 $self->define_lcmsg_in($msglist, $msgdict, @_);
888 2 };
889 2 my $type = 'perl';
890 2 foreach my $name (lexpand($filelist)) {
891 2 ▶ my Template $tmpl = $self->find_file($name)
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::Core::Template $tmpl = $self->find_file($name) or croak("No such template: $name") 2 0 2
892 or croak "No such template: $name";
893 2 $self->find_product($type => $tmpl);
894 }
895 # XXX: not wantarray
896 2 @$msglist;
897 }
898  
899  
900 3 ▶ sub define_lcmsg_in {
Subroutine define_lcmsg_in: called CC=4 SCAR=14.3
Pod undocumented
901 3 (my MY $self, my ($list, $dict, $place, $msgid, $other_msgs, $args)) = @_;
902 3 ▶ if (my $obj = $dict->{$msgid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $obj = $dict->{$msgid}) { } 0 3 3
903 0 $obj->reference(join " ", grep {defined $_} $obj->reference, $place);
904 } else {
905 3 my @o = (-msgid => $msgid);
906 3 ▶ if ($other_msgs and $other_msgs->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other_msgs and $other_msgs->[0]) { } 1 2 3
Condition66%2/3
$other_msgs and $other_msgs->[0]
!ll&&!rl&&r
201
MC/DC50%1/2
$other_msgs and $other_msgs->[0]
$other_msgs $other_msgs->[0]
Truth table66%2/3
A and B
A= $other_msgsB= $other_msgs->[0]
ABresult
0X0
100
111
907 1 push @o, -msgid_plural => $other_msgs->[0]
908 , -msgstr_n => {0 => '', 1 => ''};
909 } else {
910 2 push @o, -msgstr => '';
911 }
912 3 push @$list, my $po = $dict->{$msgid} = Locale::PO->new(@o);
913 3 $po->add_flag('perl-format');
914 3 $po->reference($place);
915 }
916 }
917  
918 453 ▶ sub YATT::Lite::Core::Template::after_create {
Subroutine after_create: called CC=4 SCAR=17.9
Pod undocumented
919 453 (my Template $tmpl, my MY $self) = @_;
920 # XXX: ここでは SUPER が使えない。
921 453 $tmpl->YATT::Lite::VFS::File::after_create($self);
922 ($tmpl->{name}) = $tmpl->{path} =~ m{(\w+)\.\w+$}
923 or $self->error("Can't extract part name from '%s'", [$tmpl->{path}])
924 434 ▶ if not defined $tmpl->{name} and defined $tmpl->{path};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $tmpl->{"name"} and defined $tmpl->{"path"} 0 434 434
Condition33%3/9
!defined($tmpl->{'name'}) && defined $tmpl->{'path'} && ((($tmpl->{'name'}) = $tmpl->{'path'} =~ /(\w+)\.\w+$/) || $self->error(q[Can't extract part name from '%s'], [$tmpl->{'path'}]))
!ll&&!rl&&r
43400
not defined $tmpl->{"name"} and defined $tmpl->{"path"}
!ll&&!rl&&r
43040
($tmpl->{"name"}) = $tmpl->{"path"} =~ /(\w+)\.\w+$/ or $self->error("Can't extract part name from '%s'", [$tmpl->{"path"}])
l!l&&r!l&&!r
000
MC/DC0%0/4
!defined($tmpl->{'name'}) && defined $tmpl->{'path'} && ((($tmpl->{'name'}) = $tmpl->{'path'} =~ /(\w+)\.\w+$/) || $self->error(q[Can't extract part name from '%s'], [$tmpl->{'path'}]))
not defined $tmpl->{"name"} defined $tmpl->{"path"} ($tmpl->{"name"}) = $tmpl->{"path"} =~ /(\w+)\.\w+$/ $self->error("Can't extract part name from '%s'", [$tmpl->{"path"}])
Truth table40%2/5
not(A) and B && C or D
A= not defined $tmpl->{"name"}B= defined $tmpl->{"path"}C= ($tmpl->{"name"}) = $tmpl->{"path"} =~ /(\w+)\.\w+$/D= $self->error("Can't extract part name from '%s'", [$tmpl->{"path"}])
ABCDresult
0XXX0
10XX0
11000
111X1
11011
925 }
926 487 ▶ sub YATT::Lite::Core::Template::reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod undocumented
927 487 (my Template $tmpl) = @_;
928 487 $tmpl->YATT::Lite::VFS::File::reset;
929 487 undef $tmpl->{_product};
930 487 undef $tmpl->{_parse_ok};
931 487 undef $tmpl->{subroutes};
932 487 undef $tmpl->{_argmacro_dict};
933 # delpkg($tmpl->{package}); # No way to avoid redef error.
934 }
935 833 ▶ sub YATT::Lite::Core::Template::refresh {
Subroutine refresh: called CC=12 SCAR=24.9
Pod undocumented
936 833 (my Template $tmpl, my MY $self) = @_;
937  
938 833 my $old_product = $tmpl->{_product};
939 833 my $old_signature;
940  
941 833 ▶ if ($tmpl->{path}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tmpl->{'path'}) { } 589 244 833
elsif ($tmpl->{'string'} and not $tmpl->{'mtime'}) { } 235 9 244
942 589 printf STDERR "template_refresh(%s)\n", $tmpl->{path} if DEBUG_REBUILD;
943 589 my $mtime = stat_mtime($tmpl->{path});
944 589 ▶ if (not defined $mtime) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $mtime) { } 0 589 589
elsif (not defined $tmpl->{'mtime'}) { } 219 370 589
elsif ($tmpl->{'mtime'} >= $mtime) { } 357 13 370
945 0 printf STDERR " => deleted\n" if DEBUG_REBUILD;
946 0 return; # XXX: ファイルが消された
947 } elsif (not defined $tmpl->{mtime}) {
948 219 if (DEBUG_REBUILD) {
949 printf STDERR " => found new. mtime($mtime) for tmpl=$tmpl\n";
950 }
951 } elsif ($tmpl->{mtime} >= $mtime) {
952 357 if (DEBUG_REBUILD) {
953 printf STDERR " => use cached. mtime(was=$tmpl->{mtime}"
954 .", now=$mtime) for tmpl=$tmpl\n";
955 }
956 357 ▶ $self->refresh_deps_for($tmpl) if $self->{always_refresh_deps};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"always_refresh_deps"} 345 12 357
957 357 return; # timestamp は、キャッシュと同じかむしろ古い
958 } else {
959 13 if (DEBUG_REBUILD) {
960 printf STDERR " => found update. mtime($mtime) for tmpl=$tmpl\n";
961 }
962 }
963 232 $tmpl->{mtime} = $mtime;
964 232 $old_signature = $tmpl->part_interface_signature;
965 232 my $parser = $self->get_parser;
966 # decl のみ parse.
967 # XXX: $tmpl->{package} の指すパッケージをこの段階で map {undef $_}
968 # すべきではないか?
969 232 $parser->load_file_into($tmpl, $tmpl->{path});
970 ▶ } elsif ($tmpl->{string} and not $tmpl->{mtime}) {
Condition66%2/3
$tmpl->{"string"} and not $tmpl->{"mtime"}
!ll&&!rl&&r
09235
MC/DC50%1/2
$tmpl->{"string"} and not $tmpl->{"mtime"}
$tmpl->{"string"} not $tmpl->{"mtime"}
Truth table66%2/3
A and not(B)
A= $tmpl->{"string"}B= not $tmpl->{"mtime"}
ABresult
0X0
100
111
971 # To avoid recompilation, use mtime to express generated time.
972 # Not so good.
973 235 $tmpl->{mtime} = time;
974  
975 235 my $parser = $self->get_parser;
976 $parser->load_string_into($tmpl, $tmpl->{string}
977 235 , scheme => "data", path => $tmpl->{name});
978 } else {
979 9 return;
980 }
981  
982 # $tmpl->YATT::Lite::VFS::Folder::vivify_base_descs($self);
983  
984 # If there was products, rebuild it too.
985 448 ▶ foreach my $type ($old_product ? keys %$old_product : ()) {
Branch: 1 branch
BranchTrueFalseTotal
$old_product ? : 13 435 448
986 13 $self->find_product($type => $tmpl);
987 }
988  
989 # part 宣言のインタフェースが変わった場合は、コンパイル済みの依存元
990 # (呼び出し側) も作り直す。gen_putargs が呼び出し側のコンパイル時に
991 # 名前付き実引数を位置引数へ変換しているため。本文だけの変更なら
992 # 静的呼び出しの CODE slot 差し替えで追随するので再生成しない。
993 # 依存元自体のソースは不変 (re-parse されない) なので、連鎖は一段で止まる。
994 # GH-255
995 448 ▶ if (($old_signature // '') ne $tmpl->part_interface_signature) {
Branch: 1 branch
BranchTrueFalseTotal
if (($old_signature // "") ne $tmpl->part_interface_signature) 438 10 448
Condition100%2/2
$old_signature // ""
l!l
226222
MC/DC100%1/1
$old_signature // ""
$old_signature
Truth table100%2/2
A
A= $old_signature
Aresult
11
00
996 438 $self->rebuild_products_of_dependents($tmpl);
997 }
998  
999 448 $tmpl;
1000 }
1001 680 ▶ sub YATT::Lite::Core::Template::part_interface_signature {
Subroutine part_interface_signature: called CC=9 SCAR=23.3
Pod undocumented
1002 680 (my Template $tmpl) = @_;
1003 join ";", map {
1004 698 my Part $part = $_;
1005 my $args = join ",", map {
1006 1085 ▶ my $var = $part->{_arg_dict} && $part->{_arg_dict}{$_};
Condition33%1/3
$part->{'_arg_dict'} && $part->{'_arg_dict'}{$_}
!ll&&!rl&&r
001085
MC/DC0%0/2
$part->{'_arg_dict'} && $part->{'_arg_dict'}{$_}
$part->{'_arg_dict'} $part->{'_arg_dict'}{$_}
Truth table33%1/3
A && B
A= $part->{'_arg_dict'}B= $part->{'_arg_dict'}{$_}
ABresult
0X0
100
111
1007 1085 ▶ $_ . "=" . (($var && eval {$var->type->[0]}) // '');
Condition40%2/5
$var && eval { do { $var->type->[0] } } // ""
l!l
10850
$var and eval { do { $var->type->[0] } }
!ll&&!rl&&r
001085
MC/DC0%0/2
$var && eval { do { $var->type->[0] } } // ""
$var eval { do { $var->type->[0] } }
Truth table33%1/3
A and B
A= $varB= eval { do { $var->type->[0] } }
ABresult
111
0X0
100
1008 698 ▶ } map {$_ ? @$_ : ()} $part->{_arg_order};
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 659 39 698
1009 698 ▶ join "\0", $part->{kind} // '', $part->{name} // ''
Branch: 1 branch
BranchTrueFalseTotal
$part->public ? : 475 223 698
Condition50%2/4
$part->{"kind"} // ""
l!l
6980
$part->{"name"} // ""
l!l
6980
MC/DC0%0/1
$part->{"kind"} // ""
$part->{"kind"}
MC/DC0%0/1
$part->{"name"} // ""
$part->{"name"}
Truth table50%1/2
A
A= $part->{"kind"}
Aresult
11
00
Truth table50%1/2
A
A= $part->{"name"}
Aresult
11
00
1010 , ($part->public ? 1 : 0), $args;
1011 680 ▶ } @{$tmpl->{_partlist} || []};
Condition100%2/2
$tmpl->{'_partlist'} || []
l!l
462218
MC/DC100%1/1
$tmpl->{'_partlist'} || []
$tmpl->{'_partlist'}
Truth table100%2/2
A
A= $tmpl->{'_partlist'}
Aresult
11
00
1012 }
1013 438 ▶ sub rebuild_products_of_dependents {
Subroutine rebuild_products_of_dependents: called CC=6 SCAR=19.6
Pod undocumented
1014 438 (my MY $self, my Template $tmpl) = @_;
1015 438 foreach my Template $dep ($tmpl->list_dependents) {
1016 3 my $old = $dep->{_product};
1017 3 ▶ next unless $old and %$old;
Branch: 1 branch
BranchTrueFalseTotal
unless $old and %$old 0 3 3
Condition33%1/3
$old and %$old
!ll&&!rl&&r
003
MC/DC0%0/2
$old and %$old
$old %$old
Truth table33%1/3
A and B
A= $oldB= %$old
ABresult
0X0
100
111
1018 printf STDERR "rebuilding products of dependent: %s\n", $dep->{path}
1019 3 if DEBUG_REBUILD;
1020 3 $dep->{_product} = +{};
1021 3 foreach my $type (keys %$old) {
1022 3 eval { $self->find_product($type => $dep) };
1023 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
1024 # 失敗した product を残すと古い stash が生き続けるので消しておく
1025 0 delete $dep->{_product}{$type};
1026 0 die $@;
1027 }
1028 }
1029 }
1030 }
1031 659 ▶ sub YATT::Lite::Core::Widget::fixup {
Subroutine fixup: called CC=5 SCAR=16.1
Pod undocumented
1032 659 (my Widget $widget, my Template $tmpl, my AbstParser $parser) = @_;
1033 659 foreach my $argName (@{$widget->{_arg_order}}) {
1034 $widget->{_has_required_arg} = 1
1035 454 ▶ if $widget->{_arg_dict}{$argName}->is_required;
Branch: 1 branch
BranchTrueFalseTotal
if $widget->{"_arg_dict"}{$argName}->is_required 8 446 454
1036 }
1037 659 ▶ $widget->{_arg_dict}{$parser->{body_argument}} ||= do {
Condition66%2/3
$widget->{"_arg_dict"}{$parser->{"body_argument"}} ||= do { () = $parser->parse_type_dflag_default($parser->{"body_argument_type"}); my $var = $parser->mkvar_at(undef, $type, $parser->{"body_argument"}, scalar @{$widget->{"_arg_order"} ||= [];}); $var->mark_body_argument; $parser->set_dflag_default_to($var, @dflag_default); push @{$$widget{"_arg_order"};}, $parser->{"body_argument"}; $var }
l!l&&r!l&&!r
146450
MC/DC0%0/2
$widget->{"_arg_dict"}{$parser->{"body_argument"}} ||= do { () = $parser->parse_type_dflag_default($parser->{"body_argument_type"}); my $var = $parser->mkvar_at(undef, $type, $parser->{"body_argument"}, scalar @{$widget->{"_arg_order"} ||= [];}); $var->mark_body_argument; $parser->set_dflag_default_to($var, @dflag_default); push @{$$widget{"_arg_order"};}, $parser->{"body_argument"}; $var }
$widget->{"_arg_dict"}{$parser->{"body_argument"}} do { () = $parser->parse_type_dflag_default($parser->{"body_argument_type"}); my $var = $parser->mkvar_at(undef, $type, $parser->{"body_argument"}, scalar @{$widget->{"_arg_order"} ||= [];}); $var->mark_body_argument; $parser->set_dflag_default_to($var, @dflag_default); push @{$$widget{"_arg_order"};}, $parser->{"body_argument"}; $var }
Truth table66%2/3
A ||= B
A= $widget->{"_arg_dict"}{$parser->{"body_argument"}}B= do { () = $parser->parse_type_dflag_default($parser->{"body_argument_type"}); my $var = $parser->mkvar_at(undef, $type, $parser->{"body_argument"}, scalar @{$widget->{"_arg_order"} ||= [];}); $var->mark_body_argument; $parser->set_dflag_default_to($var, @dflag_default); push @{$$widget{"_arg_order"};}, $parser->{"body_argument"}; $var }
ABresult
1X1
011
000
1038 my ($type, @dflag_default) = $parser->parse_type_dflag_default(
1039 $parser->{body_argument_type}
1040 645 );
1041  
1042 # lineno も入れるべきかも。 $widget->{bodyln} あたり.
1043 my $var = $parser->mkvar_at(undef
1044 , $type
1045 , $parser->{body_argument}
1046 645 ▶ , scalar @{$widget->{_arg_order} ||= []});
Condition50%1/2
$widget->{"_arg_order"} ||= []
l!l
6450
MC/DC0%0/1
$widget->{"_arg_order"} ||= []
$widget->{"_arg_order"}
Truth table50%1/2
A
A= $widget->{"_arg_order"}
Aresult
11
00
1047 # body_argument の印を付ける。public からは受理しないように.
1048 645 $var->mark_body_argument;
1049 645 $parser->set_dflag_default_to($var, @dflag_default);
1050  
1051 645 push @{$widget->{_arg_order}}, $parser->{body_argument};
1052 645 $var;
1053 };
1054 }
1055  
1056 89 ▶ sub YATT::Lite::Core::Template::match_subroutes {
Subroutine match_subroutes: called CC=2 SCAR=6.9
Pod undocumented
1057 89 my Template $tmpl = shift;
1058 89 ▶ return unless $tmpl->{subroutes};
Branch: 1 branch
BranchTrueFalseTotal
unless $tmpl->{"subroutes"} 2 87 89
1059 87 $tmpl->{subroutes}->match($_[0]);
1060 }
1061 }
1062  
1063 49 ▶use YATT::Lite::Breakpoint ();
Subroutine BEGIN: called CC=1 SCAR=0.0
1064 49 YATT::Lite::Breakpoint::break_load_core();
1065  
1066 49 1;
« blib/lib/YATT/Lite/LRXML.pm ↑ Summary blib/lib/YATT/Lite/CGen/Perl.pm »