web/cgi-bin/yatt.lib/YATT/Registry.pm

filter: Statementstmt 90.9% 591 / 650 Branchbran 70.3% 180 / 256 Conditioncond 67.3% 62 / 92 MC/DCmcdc 38.8% 21 / 54 Subroutinesub 94.5% 121 / 128 Podpod 0.0% 0 / 62 totaltotal 78.5% 975 / 1242 CC 175 SCAR 16.6
CC
175
Cov
83%
widget_by_nsname
13.8
refresh_Dir
13.0
load_dir
12.4
CRAP 5.3
« web/cgi-bin/yatt.lib/YATT/Class/Configurable.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/LRXML/Node.pm »
1 # -*- mode: perl; coding: utf-8 -*-
2  
3 package YATT::Registry;
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use UNIVERSAL;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # Debugging aid.
10 4 require YATT;
11 4 ▶use YATT::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 {
14 4 ▶ package YATT::Registry::NS; use YATT::Inc;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶ BEGIN {require Exporter; *import = \&Exporter::import}
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶ use base qw(YATT::Class::Configurable);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶ use YATT::Fields qw(Widget
Subroutine BEGIN: called CC=1 SCAR=0.0
18 cf_nsid cf_parent_nsid cf_base_nsid
19 cf_pkg cf_special_entities
20 cf_name cf_vpath cf_loadkey
21 cf_mtime cf_age
22 ^is_loaded
23 4 );
24 # When fields is empty, %FIELDS doesn't blessed.
25 # This causes "Pseudo-hashes are deprecated"
26  
27 use YATT::Types
28 4 ▶ ([Dir => [qw(cf_base_template)]
Subroutine BEGIN: called CC=1 SCAR=0.0
29 , 'Dir'
30 , [Template => [qw(tree cf_base_template ^widget_list
31 ^cf_metainfo)]]
32 ]
33 , -base => [NS => __PACKAGE__]
34 , -alias => [Root => 'YATT::Registry'
35 , Registry => 'YATT::Registry']
36 , -default => [loader => 'YATT::Registry::Loader']
37 , -debug => $ENV{YATT_DEBUG_TYPES}
38 4 , qw(:type_name :export_alias)
39 4 );
40 }
41  
42 4 ▶use YATT::Util qw(checked_eval checked lsearch);
Subroutine BEGIN: called CC=1 SCAR=0.0
43 4 ▶use YATT::Util::Taint;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 4 ▶use YATT::Registry::NS;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 4 ▶use YATT::Util::Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 4 ▶use base Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 4 ▶use YATT::Fields qw(^Loader NS last_nsid
Subroutine BEGIN: called CC=1 SCAR=0.0
49 cf_auto_reload
50 cf_type_map
51 cf_debug_registry
52 cf_rc_global
53 cf_template_global
54 cf_no_lineinfo
55 current_parser
56 cf_default_base_class
57 cf_use
58 loading
59 nspattern
60 )
61 , ['^cf_namespace' => qw(yatt perl)]
62 , ['^cf_app_prefix' => "::"]
63 4 ;
64  
65 20 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
66 20 my $nsid = 0;
67 20 my Root $root = shift->SUPER::new(@_, vpath => '/', nsid => $nsid);
68  
69 20 ▶ if (defined $ENV{YATT_CF_LINEINFO}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"YATT_CF_LINEINFO"}) 0 20 20
70 0 $root->{cf_no_lineinfo} = not $ENV{YATT_CF_LINEINFO};
71 }
72  
73 # $root->{NS}{$nsid} = $root; # ← サイクルするってば。
74 # 一回、空呼び出し。
75 20 $root->get_package($root);
76  
77 # root は new 時に強制 refresh.
78 # after_configure だと、configure の度なので、new のみに。
79 20 $root->refresh($root);
80  
81 # Now safe to lift @ISA.
82 20 $root->{is_loaded} = 1;
83  
84 20 $root;
85 }
86  
87 20 ▶sub configure_loader {
Subroutine configure_loader: called CC=1 SCAR=0.0
Pod undocumented
88 20 (my Root $root, my ($desc)) = @_;
89 20 my ($type, $loadkey, @args) = @$desc;
90 20 $root->{Loader} = $root->default_loader->$type->new($loadkey, @args);
91 20 $root->{cf_loadkey} = $loadkey;
92 }
93  
94 0 ▶sub configure_DIR {
Subroutine configure_DIR: not called CC=1 SCAR=6.9
Pod undocumented
95 0 (my Root $root, my ($dir)) = @_;
96 0 $root->{Loader} = $root->default_loader->DIR->new($dir);
97 0 $root->{cf_loadkey} = $dir;
98 }
99  
100 20 ▶sub after_configure {
Subroutine after_configure: called CC=1 SCAR=0.0
Pod undocumented
101 20 (my Root $root) = @_;
102 20 my $nspat = join("|" , @{$root->namespace});
103 20 $root->{nspattern} = qr{^(?:$nspat)$};
104 }
105  
106 #========================================
107 # use YATT::Registry ** => ** 系.
108  
109 {
110 4 our Root $ROOT;
111 4 our NS $CURRENT;
112  
113 18 ▶ sub eval_in_dir {
Subroutine eval_in_dir: called CC=5 SCAR=16.1
Pod undocumented
114 # XXX: should take care for variable capture.
115 18 (my Root $root, my NS $target, my ($script, @args)) = @_;
116 18 ▶ if (is_tainted($script)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&is_tainted($script)) 0 18 18
117 0 confess "script is tainted: $script\n";
118 }
119  
120 18 my $targetClass = $root->get_package($target);
121  
122 18 my $prog = "package $targetClass;"
123 . " use strict;"
124 . " use warnings FATAL => qw(all);"
125 . " $script";
126 18 local @_ = (@args);
127 18 local ($ROOT, $CURRENT) = ($root, $target);
128 18 &YATT::break_eval;
129 18 my @result;
130 18 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 18 18
131 0 @result = eval $prog;
132 } else {
133 2 ▶ $result[0] = eval $prog;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
134 }
135 # XXX: $prog をどう見せたいかが、状況で色々変化する。
136 18 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 18 18
137 18 ▶ wantarray ? @result : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 18 18
138 }
139  
140 17 ▶ sub import {
Subroutine import: called CC=7 SCAR=19.6
141 17 my $modpack = shift;
142 17 my $callpack = caller;
143 17 $modpack->install_builtins($callpack);
144  
145 17 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 4 14 18
146  
147 17 ▶ croak "Odd number of arguments for 'use $modpack @_'" if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 14 14
148  
149 18 my $fields = $CURRENT->fields_hash;
150 18 ▶ while (my ($name, $value) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 14 14 28
151 18 ▶ if (my $sub = $modpack->can("import_$name")) {
Branch: 3 branches
BranchTrueFalseTotal
if (my $sub = $modpack->can("import_$name")) { } 13 1 14
elsif ($sub = $YATT::Registry::CURRENT->can("configure_$name")) { } 0 1 1
elsif ($$fields{"cf_$name"}) { } 1 0 1
152 17 $sub->($modpack, $callpack, $value);
153 } elsif ($sub = $CURRENT->can("configure_$name")) {
154 4 $sub->($CURRENT, $value);
155 } elsif ($fields->{"cf_$name"}) {
156 5 $CURRENT->{"cf_$name"} = $value;
157 } else {
158 3 croak "Unknown YATT::Registry parameter: $name";
159 }
160 }
161 }
162  
163 # Root 以外の Dir では、こちらが呼ばれる(はず)
164 17 ▶ sub import_base {
Subroutine import_base: called CC=3 SCAR=11.3
Pod undocumented
165 16 ▶ croak "Can't find current registry" unless defined $ROOT;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $YATT::Registry::ROOT 0 13 13
166 16 my ($modpack, $targetClass, $vpath) = @_;
167 16 ▶ my Dir $dir = $CURRENT->lookup_dir($ROOT, split '/', $vpath)
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Registry::NS::Dir $dir = $YATT::Registry::CURRENT->lookup_dir($YATT::Registry::ROOT, split(m[/], $vpath, 0)) or croak("Can't find directory: $vpath") 13 0 13
168 or croak "Can't find directory: $vpath";
169 14 $CURRENT->{cf_base_nsid} = $dir->{cf_nsid};
170 14 lift_isa_to($ROOT->get_package($dir), $targetClass);
171 }
172 }
173  
174 # これが呼ばれるのは Root の時だけ。
175 4 ▶sub configure_base {
Subroutine configure_base: called CC=2 SCAR=7.1
Pod undocumented
176 3 (my MY $root, my $realdir) = @_;
177 3 ▶ unless (-d $realdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $realdir) 0 0 0
178 8 croak "No such directory for base='$realdir'";
179 }
180  
181 1 my $base_nsid = $root->createNS
182 (Dir => loadkey => untaint_any($realdir));
183  
184 1 $root->{cf_base_nsid} = $base_nsid;
185 1 lift_isa_to($root->get_package(my $base = $root->nsobj($base_nsid))
186 , $root->get_package($root));
187  
188 1 $root->refresh($base);
189  
190 1 $root;
191 }
192  
193 #----------------------------------------
194  
195 {
196 4 our $IS_RELOADING;
197 8 ▶ sub is_reloading { $IS_RELOADING }
Subroutine is_reloading: called CC=1 SCAR=0.0
Pod undocumented
198 19 ▶ sub with_reloading_flag {
Subroutine with_reloading_flag: called CC=1 SCAR=0.0
Pod undocumented
199 19 (my Root $root, my ($flag, $sub)) = @_;
200 18 local $IS_RELOADING = $flag;
201 18 $sub->();
202 }
203 }
204  
205 #----------------------------------------
206  
207 4 ▶sub Entity (*$) {
Subroutine Entity: called CC=3 SCAR=11.0
Pod undocumented
208 4 my ($name, $sub) = @_;
209 4 my ($instClass) = caller;
210 4 my $glob = globref($instClass, "entity_$name");
211 4 ▶ if (MY->is_reloading and defined *{$glob}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ("YATT::Registry"->is_reloading and defined *{$glob;}{"CODE"}) 1 3 4
Condition66%2/3
"YATT::Registry"->is_reloading and defined *{$glob;}{"CODE"}
!ll&&!rl&&r
301
MC/DC50%1/2
"YATT::Registry"->is_reloading and defined *{$glob;}{"CODE"}
"YATT::Registry"->is_reloading defined *{$glob;}{"CODE"}
Truth table66%2/3
A and B
A= "YATT::Registry"->is_reloadingB= defined *{$glob;}{"CODE"}
ABresult
0X0
100
111
212 # To avoid 'Subroutine MyApp5::entity_bar redefined'.
213 1 undef *$glob;
214 }
215 4 *$glob = $sub;
216 }
217  
218 1 ▶sub ElementMacro (*$) {
Subroutine ElementMacro: called CC=1 SCAR=6.9
Pod undocumented
219 0 my ($name, $sub) = @_;
220 0 my ($instClass) = caller;
221 0 *{globref($instClass, "macro_$name")} = $sub;
222 }
223  
224 14 ▶sub list_builtins { qw(Entity ElementMacro) }
Subroutine list_builtins: called CC=1 SCAR=0.0
Pod undocumented
225  
226 14 ▶sub install_builtins {
Subroutine install_builtins: called CC=3 SCAR=11.1
Pod undocumented
227 14 my ($modpack, $destpack) = @_;
228 14 foreach my $name ($modpack->list_builtins) {
229 28 ▶ my $sub = $modpack->can($name)
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $modpack->can($name) or die "Can't find builtin: $name" 28 0 28
230 or die "Can't find builtin: $name";
231 28 *{globref($destpack, $name)} = $sub;
232 }
233 }
234  
235 #========================================
236  
237 267 ▶sub next_nsid {
Subroutine next_nsid: called CC=1 SCAR=0.0
Pod undocumented
238 267 my Root $root = shift;
239 267 ++$root->{last_nsid};
240 }
241  
242 267 ▶sub createNS {
Subroutine createNS: called CC=3 SCAR=11.0
Pod undocumented
243 267 (my Root $root, my ($type)) = splice @_, 0, 2;
244 # class_id は?
245 267 my $nsid = $root->next_nsid;
246 267 my NS $nsobj = $root->{NS}{$nsid} = $root->$type->new(nsid => $nsid, @_);
247 267 my $pkg = $root->get_package($nsobj);
248 267 ▶ foreach my $name (map {defined $_ ? @$_ : ()} $root->{cf_rc_global}) {
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 2 265 267
249 14 *{globref($pkg, $name)} = *{globref($root->{cf_app_prefix}, $name)};
250 }
251 267 $nsid;
252 }
253  
254 2279 ▶sub nsobj {
Subroutine nsobj: called CC=3 SCAR=11.3
Pod undocumented
255 2279 (my Root $root, my ($nsid)) = @_;
256 2279 ▶ unless (defined $nsid) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nsid) 0 2279 2279
257 0 croak "nsobj: undefined nsid!";
258 }
259 2279 ▶ return $root if $nsid == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $nsid == 0 473 1806 2279
260 1806 $root->{NS}{$nsid};
261 }
262  
263 1538 ▶sub get_package {
Subroutine get_package: called CC=7 SCAR=19.5
Pod undocumented
264 1538 (my Root $root, my NS $nsobj, my ($sep)) = @_;
265 # nsid のまま渡しても良いように。
266 1538 ▶ $nsobj = $root->nsobj($nsobj) unless ref $nsobj;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $nsobj 156 1382 1538
267  
268 1538 ▶ $nsobj->{cf_pkg} ||= do {
Condition66%2/3
$nsobj->{"cf_pkg"} ||= do { my $pkg = do { if ($root == $nsobj) { $root->{"cf_app_prefix"} or "::"; } else { join $sep || "::", $root->{"cf_app_prefix"} || "::", sprintf("%.1s%d", $nsobj->type_name, $nsobj->{"cf_nsid"}); } }; $root->checked_eval("package $pkg"); $pkg }
l!l&&r!l&&!r
12512870
MC/DC0%0/2
$nsobj->{"cf_pkg"} ||= do { my $pkg = do { if ($root == $nsobj) { $root->{"cf_app_prefix"} or "::"; } else { join $sep || "::", $root->{"cf_app_prefix"} || "::", sprintf("%.1s%d", $nsobj->type_name, $nsobj->{"cf_nsid"}); } }; $root->checked_eval("package $pkg"); $pkg }
$nsobj->{"cf_pkg"} do { my $pkg = do { if ($root == $nsobj) { $root->{"cf_app_prefix"} or "::"; } else { join $sep || "::", $root->{"cf_app_prefix"} || "::", sprintf("%.1s%d", $nsobj->type_name, $nsobj->{"cf_nsid"}); } }; $root->checked_eval("package $pkg"); $pkg }
Truth table66%2/3
A ||= B
A= $nsobj->{"cf_pkg"}B= do { my $pkg = do { if ($root == $nsobj) { $root->{"cf_app_prefix"} or "::"; } else { join $sep || "::", $root->{"cf_app_prefix"} || "::", sprintf("%.1s%d", $nsobj->type_name, $nsobj->{"cf_nsid"}); } }; $root->checked_eval("package $pkg"); $pkg }
ABresult
1X1
011
000
269 287 my $pkg = do {
270 287 ▶ if ($root == $nsobj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root == $nsobj) { } 20 267 287
271 20 ▶ $root->{cf_app_prefix} || '::'
Condition100%2/2
$root->{'cf_app_prefix'} || '::'
l!l
182
MC/DC100%1/1
$root->{'cf_app_prefix'} || '::'
$root->{'cf_app_prefix'}
Truth table100%2/2
A
A= $root->{'cf_app_prefix'}
Aresult
11
00
272 } else {
273 join $sep || "::"
274 , $root->{cf_app_prefix} || '::'
275 , sprintf '%.1s%d', $nsobj->type_name
276 267 ▶ , $nsobj->{cf_nsid};
Condition75%3/4
$sep || '::'
l!l
0267
$root->{'cf_app_prefix'} || '::'
l!l
2625
MC/DC0%0/1
$sep || '::'
$sep
MC/DC100%1/1
$root->{'cf_app_prefix'} || '::'
$root->{'cf_app_prefix'}
Truth table50%1/2
A
A= $sep
Aresult
11
00
Truth table100%2/2
A
A= $root->{'cf_app_prefix'}
Aresult
11
00
277 }
278 };
279 287 $root->checked_eval(qq{package $pkg});
280 287 $pkg;
281 };
282 }
283  
284 553 ▶sub refresh {
Subroutine refresh: called CC=9 SCAR=22.4
Pod undocumented
285 553 (my Root $root, my NS $node) = @_;
286 553 ▶ $node ||= $root;
Condition33%1/3
$node ||= $root
l!l&&r!l&&!r
55300
MC/DC0%0/2
$node ||= $root
$node $root
Truth table33%1/3
A ||= B
A= $nodeB= $root
ABresult
1X1
011
000
287 553 ▶ return unless $node->{cf_loadkey};
Branch: 1 branch
BranchTrueFalseTotal
unless $node->{"cf_loadkey"} 0 553 553
288 553 ▶ return if $node->{cf_age} and not $root->{cf_auto_reload};
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"cf_age"} and not $root->{"cf_auto_reload"} 322 231 553
Condition100%3/3
$node->{"cf_age"} and not $root->{"cf_auto_reload"}
!ll&&!rl&&r
19635322
MC/DC100%2/2
$node->{"cf_age"} and not $root->{"cf_auto_reload"}
$node->{"cf_age"} not $root->{"cf_auto_reload"}
Truth table100%3/3
A and not(B)
A= $node->{"cf_age"}B= not $root->{"cf_auto_reload"}
ABresult
0X0
100
111
289 231 ▶ return unless $root->{Loader};
Branch: 1 branch
BranchTrueFalseTotal
unless $root->{"Loader"} 0 231 231
290  
291 # age があるのに、 is_loaded に達してない == まだ構築の途中。
292 231 ▶ return if $node->{cf_age} and not $node->{is_loaded};
Branch: 1 branch
BranchTrueFalseTotal
if $node->{"cf_age"} and not $node->{"is_loaded"} 8 223 231
Condition100%3/3
$node->{"cf_age"} and not $node->{"is_loaded"}
!ll&&!rl&&r
196278
MC/DC100%2/2
$node->{"cf_age"} and not $node->{"is_loaded"}
$node->{"cf_age"} not $node->{"is_loaded"}
Truth table100%3/3
A and not(B)
A= $node->{"cf_age"}B= not $node->{"is_loaded"}
ABresult
0X0
100
111
293 223 $root->{loading}{$node->{cf_nsid}} = 1;
294  
295 print STDERR "Referesh: $node->{cf_loadkey}\n"
296 223 ▶ if $root->{cf_debug_registry};
Branch: 1 branch
BranchTrueFalseTotal
if $root->{"cf_debug_registry"} 0 223 223
297  
298 223 $root->{Loader}->handle_refresh($root, $node);
299 217 $node->{is_loaded} = 1;
300 217 delete $root->{loading}{$node->{cf_nsid}};
301 }
302  
303 1 ▶sub mark_load_failure {
Subroutine mark_load_failure: called CC=2 SCAR=6.9
Pod undocumented
304 1 my Root $root = shift;
305 1 ▶ while ((my $nsid, undef) = each %{$root->{loading}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($nsid, undef) = each %{$$root{"loading"};}) 1 1 2
306 1 my NS $ns = $root->nsobj($nsid);
307 # 仮に、一度は load 済みだとする。
308 1 $ns->{is_loaded} = 1;
309 1 delete $root->{loading}{$nsid};
310 }
311 }
312  
313 6 ▶sub get_ns {
Subroutine get_ns: called CC=1 SCAR=0.0
Pod undocumented
314 6 (my Root $root, my ($elempath)) = @_;
315 6 $root->vivify_ns($root, @$elempath);
316 }
317  
318 21 ▶sub get_package_from_node {
Subroutine get_package_from_node: called CC=1 SCAR=0.0
Pod undocumented
319 21 (my Root $root, my ($node)) = @_;
320 21 my Dir $dir = $root->get_dir_from_node($node);
321 21 $root->get_package($dir);
322 }
323  
324 21 ▶sub get_dir_from_node {
Subroutine get_dir_from_node: called CC=1 SCAR=0.0
Pod undocumented
325 21 (my Root $root, my ($node)) = @_;
326 21 my Template $tmpl = $root->get_template_from_node($node);
327 21 $root->nsobj($tmpl->{cf_parent_nsid});
328 }
329  
330 284 ▶sub get_template_from_node {
Subroutine get_template_from_node: called CC=1 SCAR=0.0
Pod undocumented
331 284 (my Root $root, my ($node)) = @_;
332 284 $root->nsobj($node->metainfo->cget('nsid'));
333 }
334  
335 161 ▶sub get_widget {
Subroutine get_widget: called CC=1 SCAR=0.0
Pod undocumented
336 161 my Root $root = shift;
337 161 $root->get_widget_from_dir($root, @_);
338 }
339  
340 101 ▶sub get_widget_from_template {
Subroutine get_widget_from_template: called CC=5 SCAR=17.2
Pod undocumented
341 101 (my Root $root, my Template $tmpl, my ($nsname)) = splice @_, 0, 3;
342 101 my $widget;
343  
344 # Relative lookup. ($nsname case is for [delegate])
345 101 ▶ $widget = $tmpl->lookup_widget($root, @_ ? @_ : $nsname)
Branch: 2 branches
BranchTrueFalseTotal
$widget = $tmpl->lookup_widget($root, @_ ? @_ : $nsname) and return $widget 98 2 100
@_ ? : 94 7 101
346 and return $widget;
347  
348 # Absolute, ns-specific lookup.
349 2 ▶ if ($root->has_ns($root, $nsname)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root->has_ns($root, $nsname)) 0 2 2
350 0 ▶ $widget = $root->get_widget_from_dir($root, $nsname, @_)
Branch: 1 branch
BranchTrueFalseTotal
$widget = $root->get_widget_from_dir($root, $nsname, @_) and return $widget 0 0 0
351 and return $widget;
352 }
353  
354 # Absolute, general lookup.
355 2 return $root->get_widget_from_dir($root, @_);
356 }
357  
358 164 ▶sub get_widget_from_dir {
Subroutine get_widget_from_dir: called CC=4 SCAR=14.6
Pod undocumented
359 164 (my Root $root, my Dir $dir) = splice @_, 0, 2;
360 164 my @elempath = @_;
361 164 $dir = $dir->vivify_ns($root, splice @elempath, 0, @elempath - 2);
362 164 ▶ unless ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dir) 0 164 164
363 0 croak "Can't find widget: ", join(":", @_);
364 }
365 164 ▶ if (@elempath == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (@elempath == 2) { } 19 145 164
elsif (@elempath == 1) { } 145 0 145
366 19 $dir->widget_by_nsname($root, @elempath);
367 } elsif (@elempath == 1) {
368 145 $dir->widget_by_name($root, @elempath);
369 } else {
370 0 return;
371 }
372 }
373  
374 {
375 0 ▶ sub YATT::Registry::NS::list_declared_widget_names {
Subroutine list_declared_widget_names: not called CC=3 SCAR=24.8
Pod undocumented
376 0 (my NS $tmpl) = @_;
377 0 my @result;
378 0 foreach my $name (keys %{$tmpl->{Widget}}) {
379 0 my $w = $tmpl->{Widget}{$name};
380 0 ▶ next unless $w->declared;
Branch: 1 branch
BranchTrueFalseTotal
unless $w->declared 0 0 0
381 0 push @result, $name;
382 }
383 0 @result;
384 }
385  
386 # For relative lookup.
387 101 ▶ sub YATT::Registry::NS::Template::lookup_widget {
Subroutine lookup_widget: called CC=9 SCAR=23.5
Pod undocumented
388 101 (my Template $tmpl, my Root $root) = splice @_, 0, 2;
389 101 ▶ croak "lookup_widget: argument type mismatch for \$root."
Branch: 1 branch
BranchTrueFalseTotal
unless defined $root and ref $root and $root->isa("YATT::Registry") 0 101 101
Condition33%2/6
defined $root and ref $root and $root->isa("YATT::Registry")
!ll&&!rl&&r
00101
defined $root and ref $root
!ll&&!rl&&r
00101
MC/DC0%0/3
defined $root and ref $root and $root->isa("YATT::Registry")
defined $root ref $root $root->isa("YATT::Registry")
Truth table25%1/4
A and B and C
A= defined $rootB= ref $rootC= $root->isa("YATT::Registry")
ABCresult
0XX0
10X0
1100
1111
390 unless defined $root and ref $root and $root->isa(Root);
391 101 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 101 101
392  
393 101 foreach my NS $start ($tmpl, $root->nsobj($tmpl->{cf_parent_nsid})) {
394 103 my @elempath = @_;
395  
396 103 my NS $ns = do {
397 103 ▶ if (@elempath <= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@elempath <= 2) { } 103 0 103
398 103 $start;
399 } else {
400 0 $start->lookup_dir($root, splice @elempath, 0, @elempath - 2);
401 }
402 };
403  
404 103 my $found = do {
405 103 ▶ if (@elempath == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@elempath == 2) { } 1 102 103
406 1 $ns->widget_by_nsname($root, @elempath);
407 } else {
408 102 $ns->widget_by_name($root, @elempath);
409 }
410 };
411 102 ▶ return $found if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 98 4 102
412 }
413 }
414  
415 4 ▶ sub YATT::Registry::NS::Template::lookup_template {
Subroutine lookup_template: called CC=1 SCAR=0.0
Pod undocumented
416 4 (my Template $tmpl, my Root $root, my ($name)) = @_;
417 4 $root->nsobj($tmpl->{cf_parent_nsid})->lookup_template($root, $name)
418 }
419  
420 0 ▶ sub YATT::Registry::NS::Template::lookup_dir {
Subroutine lookup_dir: not called CC=1 SCAR=6.9
Pod undocumented
421 0 (my Template $tmpl, my Root $root) = splice @_, 0, 2;
422 0 $root->nsobj($tmpl->{cf_parent_nsid})->lookup_dir($root, @_);
423 }
424  
425 2 ▶ sub YATT::Registry::NS::Dir::has_ns {
Subroutine has_ns: called CC=4 SCAR=16.4
Pod undocumented
426 2 (my Dir $dir, my Root $root, my ($nsname)) = @_;
427 2 my $nsid;
428  
429 2 ▶ $nsid = $dir->{Dir}{$nsname} || $dir->{Template}{$nsname}
Branch: 1 branch
BranchTrueFalseTotal
$nsid = $dir->{"Dir"}{$nsname} || $dir->{"Template"}{$nsname} and return $root->nsobj($nsid) 0 2 2
Condition33%1/3
$dir->{'Dir'}{$nsname} || $dir->{'Template'}{$nsname}
l!l&&r!l&&!r
002
MC/DC0%0/2
$dir->{'Dir'}{$nsname} || $dir->{'Template'}{$nsname}
$dir->{'Dir'}{$nsname} $dir->{'Template'}{$nsname}
Truth table33%1/3
A || B
A= $dir->{'Dir'}{$nsname}B= $dir->{'Template'}{$nsname}
ABresult
1X1
011
000
430 and return $root->nsobj($nsid);
431  
432 2 ▶ return unless $dir->{cf_base_nsid};
Branch: 1 branch
BranchTrueFalseTotal
unless $dir->{"cf_base_nsid"} 2 0 2
433  
434 0 $root->nsobj($dir->{cf_base_nsid})->has_ns($root, $nsname);
435 }
436  
437 4 ▶ sub YATT::Registry::NS::Dir::lookup_template {
Subroutine lookup_template: called CC=4 SCAR=14.0
Pod undocumented
438 4 (my Dir $dir, my Root $root, my ($name)) = @_;
439 4 my $nsid;
440 4 ▶ while (not($nsid = $dir->{Template}{$name})
Branch: 1 branch
BranchTrueFalseTotal
if (not $nsid = $dir->{"Template"}{$name} and $dir->{"cf_base_nsid"}) 2 4 6
Condition66%2/3
not $nsid = $dir->{"Template"}{$name} and $dir->{"cf_base_nsid"}
!ll&&!rl&&r
402
MC/DC50%1/2
not $nsid = $dir->{"Template"}{$name} and $dir->{"cf_base_nsid"}
not $nsid = $dir->{"Template"}{$name} $dir->{"cf_base_nsid"}
Truth table66%2/3
not(A) and B
A= not $nsid = $dir->{"Template"}{$name}B= $dir->{"cf_base_nsid"}
ABresult
0X0
100
111
441 and $dir->{cf_base_nsid}) {
442 2 $dir = $root->nsobj($dir->{cf_base_nsid});
443 2 $root->refresh($dir);
444 }
445 4 ▶ return unless $nsid;
Branch: 1 branch
BranchTrueFalseTotal
unless $nsid 0 4 4
446 4 $root->nsobj($nsid);
447 }
448  
449 4 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
450 13 ▶ sub YATT::Registry::NS::Dir::lookup_dir {
Subroutine lookup_dir: called CC=9 SCAR=23.6
Pod undocumented
451 13 (my Dir $dir, my Root $root, my (@nspath)) = @_;
452 13 ▶ croak "argtype mismatch! not a Root." unless UNIVERSAL::isa($root, Root);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($root, "YATT::Registry") 0 13 13
453 13 ▶ return $root unless @nspath;
Branch: 1 branch
BranchTrueFalseTotal
unless @nspath 0 13 13
454 13 (my Dir $start, my (@orig)) = ($dir, @nspath);
455 13 $root->refresh($dir);
456 13 ▶ while ($dir and defined (my $ns = shift @nspath)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir and defined(my $ns = shift @nspath)) 20 13 33
Condition66%2/3
$dir and defined(my $ns = shift @nspath)
!ll&&!rl&&r
01320
MC/DC50%1/2
$dir and defined(my $ns = shift @nspath)
$dir defined(my $ns = shift @nspath)
Truth table66%2/3
A and B
A= $dirB= defined(my $ns = shift @nspath)
ABresult
0X0
100
111
457 20 ▶ $dir = $root and next if $ns eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $ns eq "" 7 13 20
Condition60%3/5
$ns eq '' && (($dir = $root) && (next))
!ll
1370
$dir = $root and next
!ll
07
MC/DC0%0/2
$ns eq '' && (($dir = $root) && (next))
$ns eq '' $dir = $root
Truth table33%1/3
A && B
A= $ns eq ''B= $dir = $root
ABresult
0X0
100
111
458 13 my $nsid = $dir->{Dir}{$ns};
459 13 ▶ unless ($nsid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nsid) 0 13 13
460 return $start->{cf_base_nsid}
461 0 ▶ ? $root->nsobj($start->{cf_base_nsid})->lookup_dir($root, @orig)
Branch: 1 branch
BranchTrueFalseTotal
$start->{'cf_base_nsid'} ? : 0 0 0
462 : undef;
463 }
464 13 $dir = $root->nsobj($nsid);
465 13 $root->refresh($dir);
466 }
467 13 $dir;
468 }
469  
470 4 ▶ sub YATT::Registry::NS::Dir::list_ns {
Subroutine list_ns: called CC=6 SCAR=18.1
Pod undocumented
471 4 (my Dir $dir, my ($dict)) = @_;
472 4 ▶ $dict ||= {};
Condition50%1/2
$dict ||= {}
l!l
04
MC/DC0%0/1
$dict ||= {}
$dict
Truth table50%1/2
A
A= $dict
Aresult
11
00
473 4 my @list;
474 4 foreach my $type (qw(Template Dir)) {
475 8 foreach my $key (keys %{$dir->{$type}}) {
476 9 ▶ push @list, $key unless $dict->{$key}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $dict->{$key}++ 8 1 9
477 }
478 }
479 4 ▶ wantarray ? @list : \@list;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 0 4
480 }
481  
482 170 ▶ sub YATT::Registry::NS::Dir::vivify_ns {
Subroutine vivify_ns: called CC=6 SCAR=18.0
Pod undocumented
483 170 (my Dir $dir, my Root $root, my (@nspath)) = @_;
484 170 my @orig = @nspath;
485 170 ▶ while (@nspath) {
Branch: 1 branch
BranchTrueFalseTotal
if (@nspath) 7 170 177
486 7 $root->refresh($dir);
487 7 $dir = do {
488 7 my $ns = shift @nspath;
489 7 my Dir $d = $dir;
490 7 my $nsid;
491 7 ▶ while (not($nsid = $d->{Dir}{$ns})
Branch: 1 branch
BranchTrueFalseTotal
if (not +($nsid = $d->{"Dir"}{$ns}) || ($nsid = $d->{"Template"}{$ns}) and $d->{"cf_base_nsid"}) 2 7 9
Condition83%5/6
not +($nsid = $d->{"Dir"}{$ns}) || ($nsid = $d->{"Template"}{$ns}) and $d->{"cf_base_nsid"}
!ll&&!rl&&r
702
($nsid = $d->{'Dir'}{$ns}) || ($nsid = $d->{'Template'}{$ns})
l!l&&r!l&&!r
162
MC/DC66%2/3
not +($nsid = $d->{"Dir"}{$ns}) || ($nsid = $d->{"Template"}{$ns}) and $d->{"cf_base_nsid"}
($nsid = $d->{'Dir'}{$ns}) ($nsid = $d->{'Template'}{$ns}) $d->{"cf_base_nsid"}
Truth table75%3/4
not(A || B) and C
A= ($nsid = $d->{'Dir'}{$ns})B= ($nsid = $d->{'Template'}{$ns})C= $d->{"cf_base_nsid"}
ABCresult
1XX0
01X0
0000
0011
492 and not($nsid = $d->{Template}{$ns})
493 and $d->{cf_base_nsid}) {
494 2 $d = $root->nsobj($d->{cf_base_nsid});
495 2 $root->refresh($d);
496 }
497 7 ▶ unless ($nsid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nsid) 0 7 7
498 0 croak "No such ns '$ns': " . join ":", @orig;
499 }
500 7 $root->nsobj($nsid);
501 };
502 }
503 170 $dir;
504 }
505  
506 18 ▶ sub YATT::Registry::NS::Dir::after_rc_loaded {
Subroutine after_rc_loaded: called CC=3 SCAR=11.0
Pod undocumented
507 18 (my Dir $dir, my Root $root) = @_;
508 18 ▶ if (defined(my $base = $dir->{cf_base_nsid})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $base = $dir->{"cf_base_nsid"})) 13 5 18
509 13 foreach my Template $tmpl (map {$root->nsobj($_)}
510 13 values %{$dir->{Template}}) {
511 14 $tmpl->{cf_base_nsid} = $base;
512 }
513 }
514 }
515  
516 22 ▶ sub YATT::Registry::NS::Dir::widget_by_nsname {
Subroutine widget_by_nsname: called CC=8 SCAR=23.4
Pod undocumented
517 22 (my Dir $dir, my Root $root, my ($ns, $name)) = @_;
518 22 $root->refresh($dir);
519 22 ▶ if (defined $dir->{cf_name} and $dir->{cf_name} eq $ns) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir->{"cf_name"} and $dir->{"cf_name"} eq $ns) 0 22 22
Condition66%2/3
defined $dir->{"cf_name"} and $dir->{"cf_name"} eq $ns
!ll&&!rl&&r
2020
MC/DC0%0/2
defined $dir->{"cf_name"} and $dir->{"cf_name"} eq $ns
defined $dir->{"cf_name"} $dir->{"cf_name"} eq $ns
Truth table66%2/3
A and B
A= defined $dir->{"cf_name"}B= $dir->{"cf_name"} eq $ns
ABresult
0X0
100
111
520 0 my $widget = $dir->widget_by_name($root, $name);
521 0 ▶ return $widget if $widget;
Branch: 1 branch
BranchTrueFalseTotal
if $widget 0 0 0
522 }
523 # [1] dir:template
524 # [2] template:widget
525 22 foreach my $type (qw(Dir Template)) {
526 23 ▶ next unless my $nsid = $dir->{$type}{$ns};
Branch: 1 branch
BranchTrueFalseTotal
unless my $nsid = $dir->{$type}{$ns} 2 21 23
527 21 ▶ next unless my $widget = $root->nsobj($nsid)
Branch: 1 branch
BranchTrueFalseTotal
unless my $widget = $root->nsobj($nsid)->widget_by_name($root, $name) 0 21 21
528 ->widget_by_name($root, $name);
529 21 return $widget;
530 }
531 1 ▶ return unless $dir->{cf_base_nsid};
Branch: 1 branch
BranchTrueFalseTotal
unless $dir->{"cf_base_nsid"} 0 1 1
532 1 $root->nsobj($dir->{cf_base_nsid})->widget_by_nsname($root, $ns, $name);
533 }
534  
535 192 ▶ sub YATT::Registry::NS::Dir::widget_by_name {
Subroutine widget_by_name: called CC=4 SCAR=13.9
Pod undocumented
536 192 (my Dir $dir, my Root $root, my ($name)) = @_;
537 192 $root->refresh($dir);
538 192 ▶ if (my $nsid = $dir->{Template}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $nsid = $dir->{"Template"}{$name}) 175 17 192
539 175 $root->refresh($root->nsobj($nsid));
540 }
541 $dir->{Widget}{$name}
542 || $dir->{cf_base_nsid}
543 186 ▶ && $root->nsobj($dir->{cf_base_nsid})->widget_by_name($root, $name);
Branch: 1 branch
BranchTrueFalseTotal
$dir->{"Widget"}{$name} or $dir->{"cf_base_nsid"} and $root->nsobj($dir->{"cf_base_nsid"})->widget_by_name($root, $name) 169 17 186
Condition100%6/6
$dir->{'Widget'}{$name} || $dir->{'cf_base_nsid'} && $root->nsobj($dir->{'cf_base_nsid'})->widget_by_name($root, $name)
l!l&&r!l&&!r
169611
$dir->{"cf_base_nsid"} and $root->nsobj($dir->{"cf_base_nsid"})->widget_by_name($root, $name)
!ll&&!rl&&r
926
MC/DC100%3/3
$dir->{'Widget'}{$name} || $dir->{'cf_base_nsid'} && $root->nsobj($dir->{'cf_base_nsid'})->widget_by_name($root, $name)
$dir->{'Widget'}{$name} $dir->{"cf_base_nsid"} $root->nsobj($dir->{"cf_base_nsid"})->widget_by_name($root, $name)
Truth table100%4/4
A || B and C
A= $dir->{'Widget'}{$name}B= $dir->{"cf_base_nsid"}C= $root->nsobj($dir->{"cf_base_nsid"})->widget_by_name($root, $name)
ABCresult
1XX1
0111
00X0
0100
544 }
545  
546 1 ▶ sub YATT::Registry::NS::Template::widget_by_nsname {
Subroutine widget_by_nsname: called CC=6 SCAR=26.2
Pod undocumented
547 1 (my Template $tmpl, my Root $root, my ($ns, $name)) = @_;
548 1 ▶ if ($tmpl->{cf_name} eq $ns) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpl->{"cf_name"} eq $ns) 0 1 1
549 0 my $widget = $tmpl->widget_by_name($root, $name);
550 0 ▶ return $widget if $widget;
Branch: 1 branch
BranchTrueFalseTotal
if $widget 0 0 0
551 }
552 1 my Dir $parent = $root->nsobj($tmpl->{cf_parent_nsid});
553 1 ▶ if (defined $parent->{cf_name} and $parent->{cf_name} eq $ns) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent->{"cf_name"} and $parent->{"cf_name"} eq $ns) 0 1 1
Condition33%1/3
defined $parent->{"cf_name"} and $parent->{"cf_name"} eq $ns
!ll&&!rl&&r
100
MC/DC0%0/2
defined $parent->{"cf_name"} and $parent->{"cf_name"} eq $ns
defined $parent->{"cf_name"} $parent->{"cf_name"} eq $ns
Truth table33%1/3
A and B
A= defined $parent->{"cf_name"}B= $parent->{"cf_name"} eq $ns
ABresult
0X0
100
111
554 0 my $widget = $tmpl->widget_by_name($root, $name);
555 0 ▶ return $widget if $widget;
Branch: 1 branch
BranchTrueFalseTotal
if $widget 0 0 0
556 }
557 1 $parent->widget_by_nsname($root, $ns, $name);
558 }
559  
560 103 ▶ sub YATT::Registry::NS::Template::widget_by_name {
Subroutine widget_by_name: called CC=7 SCAR=20.2
Pod undocumented
561 103 (my Template $tmpl, my Root $root, my ($name)) = @_;
562 103 $root->refresh($tmpl);
563 103 my $widget;
564 103 ▶ $widget = $tmpl->{Widget}{$name}
Branch: 1 branch
BranchTrueFalseTotal
$widget = $tmpl->{"Widget"}{$name} and return $widget 87 16 103
565 and return $widget;
566  
567 # 同一ディレクトリのテンプレートを先に検索するため。
568 # XXX: しかし、継承順序に問題が出ているはず。
569 $widget = $root->nsobj($tmpl->{cf_parent_nsid})
570 16 ▶ ->widget_by_name($root, $name)
Branch: 1 branch
BranchTrueFalseTotal
$widget = $root->nsobj($tmpl->{"cf_parent_nsid"})->widget_by_name($root, $name) and return $widget 10 5 15
571 and return $widget;
572  
573 5 ▶ if ($tmpl->{cf_base_template}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpl->{"cf_base_template"}) 3 2 5
574 $widget = $root->nsobj($tmpl->{cf_base_template})
575 3 ▶ ->widget_by_name($root, $name)
Branch: 1 branch
BranchTrueFalseTotal
$widget = $root->nsobj($tmpl->{"cf_base_template"})->widget_by_name($root, $name) and return $widget 3 0 3
576 and return $widget;
577 }
578  
579 2 ▶ if ($tmpl->{cf_base_nsid}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpl->{"cf_base_nsid"}) 0 2 2
580 $widget = $root->nsobj($tmpl->{cf_base_nsid})
581 0 ▶ ->widget_by_name($root, $name)
Branch: 1 branch
BranchTrueFalseTotal
$widget = $root->nsobj($tmpl->{"cf_base_nsid"})->widget_by_name($root, $name) and return $widget 0 0 0
582 and return $widget;
583 }
584  
585 2 return;
586 }
587 }
588  
589 4 ▶sub node_error {
Subroutine node_error: called CC=2 SCAR=7.1
Pod undocumented
590 18 (my Root $root, my ($node, $fmt)) = splice @_, 0, 3;
591 18 ▶ $root->node_error_obj($node
Branch: 1 branch
BranchTrueFalseTotal
ref $fmt ? : 0 18 18
592 , error_fmt => ref $fmt ? join(" ", $fmt) : $fmt
593 , error_param => [@_]
594 , caller => [caller]);
595 }
596  
597 18 ▶sub node_error_obj {
Subroutine node_error_obj: called CC=1 SCAR=0.0
Pod undocumented
598 18 (my Root $root, my ($node, @param)) = @_;
599 # XXX: $root->{cf_backtrace} なら longmess も append, とか。
600 # XXX: Error オブジェクトにするべきかもね。でも依存は嫌。
601 # ← die を $root->raise で wrap すれば良い?
602 18 my $stringify = $root->checked(stringify => "(Can't stringify: %s)", $node);
603 18 my $filename = $root->checked(filename => "(Can't get filename %s)", $node);
604 18 my $linenum = $root->checked(linenum => "(Can't get linenum %s)", $node);
605 18 $root->Exception->new(@param
606 , node_obj => $node
607 , node => $stringify, file => $filename
608 , line => $linenum);
609 }
610  
611 0 ▶sub node_nimpl {
Subroutine node_nimpl: not called CC=2 SCAR=17.9
Pod undocumented
612 0 (my Root $root, my ($node, $msg)) = @_;
613 0 my $caller = [my ($pack, $file, $line) = caller];
614 0 ▶ $root->node_error_obj($node
Condition0%0/2
$msg || 'Not yet implemented'
l!l
00
MC/DC0%0/1
$msg || 'Not yet implemented'
$msg
Truth table0%0/2
A
A= $msg
Aresult
11
00
615 , error_fmt => join(' '
616 , ($msg || "Not yet implemented")
617 , "(perl file $file line $line)")
618 , caller => $caller);
619 }
620  
621 811 ▶sub strip_ns {
Subroutine strip_ns: called CC=1 SCAR=0.0
Pod undocumented
622 811 (my Root $root, my ($list)) = @_;
623 811 $root->shift_ns_by($root->{nspattern}, $list);
624 }
625  
626 862 ▶sub shift_ns_by {
Subroutine shift_ns_by: called CC=6 SCAR=17.9
Pod undocumented
627 862 (my Root $root, my ($pattern, $list)) = @_;
628 862 ▶ return unless @$list;
Branch: 1 branch
BranchTrueFalseTotal
unless @$list 8 854 862
629 854 ▶ return unless defined $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern 0 854 854
630 854 ▶ if (ref $pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pattern) { } 809 45 854
631 809 ▶ return unless $list->[0] =~ $pattern
Branch: 1 branch
BranchTrueFalseTotal
unless $list->[0] =~ /$pattern/ 26 783 809
632 } else {
633 45 ▶ return unless $list->[0] eq $pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless $list->[0] eq $pattern 10 35 45
634 }
635 818 shift @$list;
636 }
637  
638 #========================================
639  
640 4 ▶use YATT::LRXML::Node qw(DECLARATOR_TYPE node_path create_node);
Subroutine BEGIN: called CC=1 SCAR=0.0
641 sub DEFAULT_WIDGET () {''}
642  
643 4 ▶use YATT::LRXML::MetaInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
644 4 ▶use YATT::Widget;
Subroutine BEGIN: called CC=1 SCAR=0.0
645  
646 4 ▶use YATT::LRXML; # for Builder.
Subroutine BEGIN: called CC=1 SCAR=0.0
647 use YATT::Types
648 4 ▶ ([WidgetBuilder => [qw(cf_widget ^cf_template cf_root_builder)]]
Subroutine BEGIN: called CC=1 SCAR=0.0
649 , -base => qw(YATT::LRXML::Builder)
650 , -alias => [Builder => __PACKAGE__ . '::WidgetBuilder'
651 , Scanner => 'YATT::LRXML::Scanner']
652 4 );
653  
654 # XXX: 名前が紛らわしい。lrxml tree の root か、Registry の root か、と。
655 156 ▶sub new_root_builder {
Subroutine new_root_builder: called CC=1 SCAR=0.0
Pod undocumented
656 156 (my Root $root, my $parser, my Scanner $scan) = @_;
657 156 my MetaInfo $meta = $parser->metainfo;
658 156 my Template $tmpl = $root->nsobj($meta->{cf_nsid});
659  
660 my $widget = $root->create_widget_in
661 ($tmpl, DEFAULT_WIDGET
662 , filename => $meta->cget('filename')
663 , decl_start => $scan->{cf_linenum}
664 156 , body_start => $scan->{cf_linenum} + $scan->number_of_lines);
665  
666 # 親ディレクトリに登録。
667 156 my Dir $parent = $root->nsobj($tmpl->{cf_parent_nsid});
668  
669 156 $parent->{Widget}{$tmpl->{cf_name}} = $widget;
670  
671 156 $parser->configure(tree => my $sink = $widget->cget('root'));
672  
673 $root->Builder->new($sink, undef
674 , widget => $widget
675 , template => $tmpl
676 , startpos => 0
677 , startline => $scan->{cf_linenum}
678 156 , linenum => $scan->{cf_linenum});
679 }
680  
681 19 ▶sub fake_cursor_from {
Subroutine fake_cursor_from: called CC=2 SCAR=6.9
Pod undocumented
682 19 (my MY $trans, my ($cursor, $node, $is_opened)) = @_;
683 19 my $parent = $cursor->Path->new($node, $cursor->cget('path'));
684 19 ▶ my $path = $is_opened ? $parent
Branch: 1 branch
BranchTrueFalseTotal
$is_opened ? : 6 13 19
685 : $cursor->Path->new($trans->create_node(unknown => undef, $node)
686 , $parent);
687 19 $cursor->clone($path);
688 }
689  
690 194 ▶sub fake_cursor {
Subroutine fake_cursor: called CC=1 SCAR=0.0
Pod undocumented
691 194 (my MY $gen, my Widget $widget, my ($metainfo)) = splice @_, 0, 3;
692 194 my $cursor = $widget->cursor(metainfo => $metainfo);
693 194 my $node = $gen->create_node(unknown => undef, @_);
694 194 $cursor->clone($cursor->Path->new($node, $cursor->cget('path')));
695 }
696  
697 184 ▶sub fake_cursor_to_build {
Subroutine fake_cursor_to_build: called CC=1 SCAR=0.0
Pod undocumented
698 184 (my MY $root, my Builder $builder, my Scanner $scan
699 , my ($elem)) = @_;
700 $root->fake_cursor($builder->{cf_widget}
701 , $builder->{cf_template}->metainfo
702 ->clone(startline => $scan->{cf_linenum})
703 184 , $elem);
704 }
705  
706 183 ▶sub new_decl_builder {
Subroutine new_decl_builder: called CC=4 SCAR=13.9
Pod undocumented
707 183 (my MY $root, my Builder $builder, my Scanner $scan
708 , my ($elem, $parser)) = @_;
709 183 foreach my $shift (0, 1) {
710 366 my $path = [node_path($elem)];
711 366 ▶ $root->strip_ns($path) if $shift;
Branch: 1 branch
BranchTrueFalseTotal
if $shift 183 183 366
712 366 my $handler_name = join("_", declare => @$path);
713  
714 366 ▶ if (my $handler = $root->can($handler_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $root->can($handler_name)) 181 185 366
715 181 my $nc = $root->fake_cursor_to_build($builder, $scan, $elem)->open;
716 181 return $handler->($root, $builder, $scan, $nc, $parser);
717 }
718 }
719  
720 2 die $root->node_error($root->fake_cursor_to_build($builder, $scan, $elem)
721 , "Unknown declarator");
722 }
723  
724 4 ▶sub declare_base {
Subroutine declare_base: called CC=3 SCAR=11.3
Pod undocumented
725 4 (my Root $root, my Builder $builder, my ($scan, $args, $parser)) = @_;
726 4 ▶ if ($builder->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($builder->{"parent"}) 0 4 4
727 0 die $scan->token_error("Misplaced yatt:base");
728 }
729 4 my $path = $args->node_body;
730 4 my Template $this = $builder->{cf_template};
731 4 ▶ my Template $base = $this->lookup_template($root, $path)
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Registry::NS::Template $base = $this->lookup_template($root, $path) or die $scan->token_error("Can't find template $path") 4 0 4
732 or die $scan->token_error("Can't find template $path");
733  
734 # XXX: refresh は lookup_template の中ですべきか?
735 4 $root->refresh($base);
736  
737 # 名前は保存しなくていいの?
738 4 $this->{cf_base_template} = $base->{cf_nsid};
739  
740 4 $root->add_isa($root->get_package($this)
741 , $root->get_package($base));
742  
743 # builder を返すことを忘れずに。
744 4 $builder;
745 }
746  
747 87 ▶sub declare_args {
Subroutine declare_args: called CC=4 SCAR=14.0
Pod undocumented
748 87 (my Root $root, my Builder $builder
749 , my ($scan, $nc, $parser, @configs)) = @_;
750 87 ▶ if ($builder->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($builder->{"parent"}) 0 87 87
751 0 die $scan->token_error("Misplaced yatt:args");
752 }
753 # widget -> args の順番で出現する場合もある。
754 # root 用の builder を取り出し直す
755 87 ▶ if ($builder->{cf_root_builder}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($builder->{"cf_root_builder"}) 2 85 87
756 2 $builder = $builder->{cf_root_builder};
757 }
758 87 my Widget $widget = $builder->{cf_widget};
759 87 $widget->{cf_declared} = 1;
760 87 $widget->{cf_decl_start} = $scan->{cf_last_linenum};
761 87 $widget->{cf_body_start} = $scan->{cf_last_linenum} + $scan->{cf_last_nol};
762 87 ▶ $widget->configure(@configs) if @configs;
Branch: 1 branch
BranchTrueFalseTotal
if @configs 0 87 87
763 87 $root->define_args($widget, $nc);
764 87 $root->after_define_args($widget);
765 87 $builder;
766 }
767  
768 0 ▶sub declare_params {
Subroutine declare_params: not called CC=1 SCAR=6.9
Pod undocumented
769 0 shift->declare_args(@_, public => 1);
770 }
771  
772 90 ▶sub declare_widget {
Subroutine declare_widget: called CC=4 SCAR=14.0
Pod undocumented
773 90 (my Root $root, my Builder $builder, my Scanner $scan
774 , my ($args, $parser)) = @_;
775  
776 90 ▶ if ($builder->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($builder->{"parent"}) 1 89 90
777 1 die $root->node_error($root->fake_cursor_to_build($builder, $scan
778 , $builder->product)
779 , "Misplaced yatt:widget in:");
780 }
781  
782 89 ▶ defined (my $name = $args->node_name)
Branch: 1 branch
BranchTrueFalseTotal
defined(my $name = $args->node_name) or die $root->node_error($args, "widget name is missing") 89 0 89
783 or die $root->node_error($args, "widget name is missing");
784  
785 # XXX: filename, lineno
786 my Widget $widget = $root->create_widget_in
787 ($builder->{cf_template}, $name
788 , declared => 1
789 , filename => $builder->{cf_template}->metainfo->cget('filename')
790 , decl_start => $scan->{cf_last_linenum}
791 89 , body_start => $scan->{cf_last_linenum} + $scan->{cf_last_nol});
792  
793 89 $root->define_args($widget, $args->go_next);
794 88 $root->after_define_args($widget);
795  
796 $root->Builder->new($widget->cget('root'), undef
797 , widget => $widget
798 , template => $builder->{cf_template}
799 , startpos => $scan->{cf_index}
800 , startline => $scan->{cf_linenum}
801 , linenum => $scan->{cf_linenum}
802 # widget -> args に戻るためには root_builder を
803 # 渡さねばならぬ
804 , root_builder =>
805 88 ▶ $builder->{cf_root_builder} || $builder
Condition66%2/3
$builder->{'cf_root_builder'} || $builder
l!l&&r!l&&!r
17710
MC/DC0%0/2
$builder->{'cf_root_builder'} || $builder
$builder->{'cf_root_builder'} $builder
Truth table66%2/3
A || B
A= $builder->{'cf_root_builder'}B= $builder
ABresult
1X1
011
000
806 );
807 }
808  
809 245 ▶sub create_widget_in {
Subroutine create_widget_in: called CC=1 SCAR=0.0
Pod undocumented
810 245 (my Root $root, my Template $tmpl, my ($name)) = splice @_, 0, 3;
811 my $widget = YATT::Widget->new
812 (name => $name, template_nsid => $tmpl->{cf_nsid}
813 245 , @_);
814 245 $tmpl->{Widget}{$name} = $widget;
815 245 push @{$tmpl->{widget_list}}, $widget;
816 245 $widget;
817 }
818  
819 0 ▶sub current_parser {
Subroutine current_parser: not called CC=1 SCAR=6.9
Pod undocumented
820 0 my Root $root = shift;
821 0 $root->{current_parser}[0];
822 }
823  
824 2 ▶sub after_define_args {shift; shift}
Subroutine after_define_args: called CC=1 SCAR=0.0
Pod undocumented
825  
826 194 ▶sub define_args {
Subroutine define_args: called CC=3 SCAR=11.0
Pod undocumented
827 194 (my Root $root, my ($target, $args)) = @_;
828  
829 # $target は has_arg($name) と add_arg($name, $arg) を実装しているもの。
830 # *: widget
831 # *: codevar
832  
833 194 ▶ for (; $args->readable; $args->next) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->readable) 309 193 502
834 # マクロ引数呼び出し %name(); がここで出現
835 # comment も現れうる。
836 # body = [code title=html] みたいなグループ引数もここで。
837  
838 309 ▶ my $sub = $root->can("add_decl_" . $args->node_type_name)
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $root->can('add_decl_' . $args->node_type_name) or next 290 19 309
839 or next;
840  
841 290 $sub->($root, $target, $args);
842 }
843  
844 # おまけ。使わないけど、デバッグ時に少し幸せ。
845 193 $root;
846 }
847  
848 239 ▶sub add_decl_attribute {
Subroutine add_decl_attribute: called CC=6 SCAR=18.1
Pod undocumented
849 239 (my Root $root, my ($target, $args)) = @_;
850 239 my $argname = $args->node_name;
851 239 ▶ unless (defined $argname) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $argname) 0 239 239
852 0 die $root->node_error($args, "Undefined att name!");
853 }
854 239 ▶ if ($target->has_arg($argname)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target->has_arg($argname)) 0 239 239
855 0 die $root->node_error($args, "Duplicate argname: $argname");
856 }
857  
858 239 my ($type, @param) = $args->parse_typespec;
859 239 my ($typename, $subtype) = do {
860 239 ▶ if (ref $type) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $type) { } 3 236 239
861 3 ($type->[0], [@{$type}[1 .. $#$type]])
862 } else {
863 236 ($type, undef);
864 }
865 };
866 239 ▶ if (defined $typename and my $sub = $root->can("attr_declare_$typename")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $typename and my $sub = $root->can("attr_declare_$typename")) { } 7 232 239
Condition100%3/3
defined $typename and my $sub = $root->can("attr_declare_$typename")
!ll&&!rl&&r
136967
MC/DC100%2/2
defined $typename and my $sub = $root->can("attr_declare_$typename")
defined $typename my $sub = $root->can("attr_declare_$typename")
Truth table100%3/3
A and B
A= defined $typenameB= my $sub = $root->can("attr_declare_$typename")
ABresult
0X0
100
111
867 7 $sub->($root, $target, $args, $argname, $subtype, @param);
868 } else {
869 232 $target->add_arg($argname, $root->create_var($type, $args, @param));
870 }
871 }
872  
873 427 ▶sub create_var {
Subroutine create_var: called CC=7 SCAR=19.5
Pod undocumented
874 427 (my Root $root, my ($type, $args, @param)) = @_;
875 427 ▶ $type = '' unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 150 277 427
876 427 ▶ my ($primary, @subtype) = ref $type ? @$type : $type;
Branch: 1 branch
BranchTrueFalseTotal
ref $type ? : 1 426 427
877 427 ▶ defined (my $class = $root->{cf_type_map}{$primary})
Branch: 1 branch
BranchTrueFalseTotal
defined(my $class = $root->{"cf_type_map"}{$primary}) or croak($root->node_error($args, "No such type: %s", $primary)) 427 0 427
878 or croak $root->node_error($args, "No such type: %s", $primary);
879 427 ▶ unshift @param, subtype => @subtype >= 2 ? \@subtype : $subtype[0]
Branch: 2 branches
BranchTrueFalseTotal
if @subtype 1 426 427
@subtype >= 2 ? : 0 1 1
880 if @subtype;
881 427 ▶ if (my $sub = $root->can("create_var_$primary")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $root->can("create_var_$primary")) { } 172 255 427
882 172 $sub->($root, $args, @param);
883 } else {
884 255 $class->new(@param);
885 }
886 }
887  
888 #========================================
889 {
890 4 ▶ package YATT::Registry::Loader; use YATT::Inc;
Subroutine BEGIN: called CC=1 SCAR=0.0
891 4 ▶ use base qw(YATT::Class::Configurable);
Subroutine BEGIN: called CC=1 SCAR=0.0
892 4 ▶ use YATT::Fields qw(Cache);
Subroutine BEGIN: called CC=1 SCAR=0.0
893 4 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
894 4 ▶ use YATT::Registry::NS;
Subroutine BEGIN: called CC=1 SCAR=0.0
895  
896 sub DIR () { 'YATT::Registry::Loader::DIR' }
897  
898 223 ▶ sub handle_refresh {
Subroutine handle_refresh: called CC=2 SCAR=7.4
Pod undocumented
899 223 (my MY $loader, my Root $root, my NS $node) = @_;
900 223 my $type = $node->type_name;
901 223 ▶ if (my $sub = $loader->can("refresh_$type")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $loader->can("refresh_$type")) { } 223 0 223
902 223 $sub->($loader, $root, $node);
903 } else {
904 0 confess "Can't refresh type: $type";
905 }
906 }
907  
908 223 ▶ sub is_modified {
Subroutine is_modified: called CC=3 SCAR=11.0
Pod undocumented
909 223 my MY $loader = shift;
910 223 my ($item, $old) = @_;
911 223 my $mtime = $loader->mtime($item);
912 223 ▶ return if defined $old and $old >= $mtime;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old and $old >= $mtime 23 200 223
Condition100%3/3
defined $old and $old >= $mtime
!ll&&!rl&&r
196423
MC/DC100%2/2
defined $old and $old >= $mtime
defined $old $old >= $mtime
Truth table100%3/3
A and B
A= defined $oldB= $old >= $mtime
ABresult
0X0
100
111
913 200 $_[1] = $mtime;
914 200 return 1;
915 }
916  
917 package YATT::Registry::Loader::DIR;
918  
919 4 ▶ use base qw(YATT::Registry::Loader File::Spec);
Subroutine BEGIN: called CC=1 SCAR=0.0
920 4 ▶ use YATT::Fields qw(cf_DIR cf_LIB);
Subroutine BEGIN: called CC=1 SCAR=0.0
921 20 ▶ sub initargs { qw(cf_DIR) }
Subroutine initargs: called CC=1 SCAR=0.0
922 20 ▶ sub init {
Subroutine init: called CC=2 SCAR=6.9
923 20 my ($self, $dir) = splice @_, 0, 2;
924 20 $self->SUPER::init($dir, @_);
925 20 ▶ if (-d (my $libdir = "$dir/lib")) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d (my $libdir = "$dir/lib")) 1 19 20
926 1 require lib; import lib $libdir
927 }
928 20 $self;
929 }
930  
931 4 ▶ use YATT::Registry::NS;
Subroutine BEGIN: called CC=1 SCAR=0.0
932 4 ▶ use YATT::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
933 4 ▶ use YATT::Util::Taint;
Subroutine BEGIN: called CC=1 SCAR=0.0
934  
935 223 ▶ sub mtime { shift; (stat(shift))[9]; }
Subroutine mtime: called CC=1 SCAR=0.0
936  
937 sub RCFILE () {'.htyattrc'}
938 sub Parser () {'YATT::LRXML::Parser'}
939  
940 4 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
941  
942 18 ▶ sub checked_read_file {
Subroutine checked_read_file: called CC=4 SCAR=14.6
943 18 (my MY $loader, my ($fn, $layer)) = @_;
944 18 ▶ croak "Given path is tainted! $fn" if is_tainted($fn);
Branch: 1 branch
BranchTrueFalseTotal
if &is_tainted($fn) 0 18 18
945 18 ▶ open my $fh, '<' . ($layer || ''), $fn
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, '<' . ($layer || ""), $fn or die "Can't open $fn! $!" 18 0 18
Condition50%1/2
$layer || ''
l!l
018
MC/DC0%0/1
$layer || ''
$layer
Truth table50%1/2
A
A= $layer
Aresult
11
00
946 or die "Can't open $fn! $!";
947 18 local $/;
948 18 scalar <$fh>;
949 }
950  
951 65 ▶ sub refresh_Dir {
Subroutine refresh_Dir: called CC=13 SCAR=25.7
952 65 (my MY $loader, my Root $root, my Dir $dir) = @_;
953 65 my $dirname = $dir->{cf_loadkey};
954 # ファイルリストの処理.
955 65 ▶ return unless $loader->is_modified($dirname, $dir->{cf_mtime}{$dirname});
Branch: 1 branch
BranchTrueFalseTotal
unless $loader->is_modified($dirname, $dir->{"cf_mtime"}{$dirname}) 21 44 65
956  
957 44 my $is_reload = $dir->{cf_age}++;
958 44 undef $dir->{is_loaded};
959  
960 44 ▶ if (is_tainted($dirname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&is_tainted($dirname)) 0 44 44
961 0 croak "Directory $dirname is tainted"
962 }
963  
964 44 ▶ if ($root == $dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root == $dir) { } 22 22 44
965 22 ▶ foreach my $d ($dirname, map {!defined $_ ? () : ref $_ ? @$_ : $_}
Branch: 2 branches
BranchTrueFalseTotal
!defined($_) ? : 5 17 22
ref $_ ? : 0 17 17
966 $loader->{cf_LIB}) {
967 39 $loader->load_dir($root, $dir, $d);
968 }
969 } else {
970 22 $loader->load_dir($root, $dir, $dirname);
971 }
972  
973 # RC 読み込みの前に、 default_base_class を設定。
974 44 ▶ if ($root->{cf_default_base_class}
Branch: 1 branch
BranchTrueFalseTotal
if ($root->{"cf_default_base_class"} and $root->{"cf_default_base_class"} ne $root->{"cf_pkg"} || $root->{"is_loaded"}) 5 39 44
Condition100%6/6
$root->{"cf_default_base_class"} and $root->{"cf_default_base_class"} ne $root->{"cf_pkg"} || $root->{"is_loaded"}
!ll&&!rl&&r
3815
$root->{"cf_default_base_class"} ne $root->{"cf_pkg"} or $root->{"is_loaded"}
l!l&&r!l&&!r
411
MC/DC100%3/3
$root->{"cf_default_base_class"} and $root->{"cf_default_base_class"} ne $root->{"cf_pkg"} || $root->{"is_loaded"}
$root->{"cf_default_base_class"} $root->{"cf_default_base_class"} ne $root->{"cf_pkg"} $root->{"is_loaded"}
Truth table100%4/4
A and B or C
A= $root->{"cf_default_base_class"}B= $root->{"cf_default_base_class"} ne $root->{"cf_pkg"}C= $root->{"is_loaded"}
ABCresult
0XX0
1000
11X1
1011
975 and ($root->{cf_default_base_class} ne $root->{cf_pkg}
976 or $root->{is_loaded})) {
977 # XXX: add_isa じゃなくて ensure_isa だね。
978 #print STDERR "loading default_base_class $root->{cf_default_base_class}"
979 # . " for dir $dirname\n";
980 5 $root->checked_eval(qq{require $root->{cf_default_base_class}});
981 $root->add_isa(my $pkg = $root->get_package($dir)
982 5 , $root->{cf_default_base_class});
983 }
984  
985 # RC 読み込みは、最後に
986 44 my $rcfile = $loader->catfile($dirname, $loader->RCFILE);
987 44 ▶ if (-r $rcfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-r $rcfile) 18 26 44
988 18 my $script = "";
989 18 ▶ $script .= ";no warnings 'redefine';" if $is_reload;
Branch: 1 branch
BranchTrueFalseTotal
if $is_reload 3 15 18
990 $script .= sprintf(qq{\n#line 1 "%s"\n}, $rcfile)
991 18 ▶ unless $root->{cf_no_lineinfo};
Branch: 1 branch
BranchTrueFalseTotal
unless $root->{"cf_no_lineinfo"} 10 8 18
992 18 $script .= untaint_any($loader->checked_read_file($rcfile));
993 18 &YATT::break_rc;
994 $root->with_reloading_flag
995 18 ▶ ($is_reload, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
996 18 $root->eval_in_dir($dir, $script);
997 18 });
998 18 &YATT::break_after_rc;
999  
1000 18 $dir->after_rc_loaded($root);
1001 }
1002  
1003 44 $dir;
1004 }
1005  
1006 61 ▶ sub load_dir {
Subroutine load_dir: called CC=11 SCAR=25.2
1007 61 (my MY $loader, my Root $root, my Dir $dir, my ($dirname)) = @_;
1008 61 local *DIR;
1009 61 ▶ opendir DIR, $dirname or die "Can't open dir '$dirname': $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, $dirname or die "Can't open dir '${dirname}': $!" 61 0 61
1010 61 ▶ while (my $name = readdir(DIR)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $name = readdir DIR)) 560 61 621
1011 560 ▶ next if $name =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /^\./ 154 406 560
1012 406 my $path = $loader->catfile($dirname, $name);
1013 # entry を作るだけ。load はしない。→ mtime も、子供側で。
1014 406 ▶ if (-d $path) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $path) { } 109 297 406
elsif ($name =~ /^(\w+)\.html?$/) { } 164 133 297
1015 109 ▶ next unless $name =~ /^(?:\w|-)+$/; # Not CC for future widechar.
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^(?:\w|-)+$/ 0 109 109
1016 $dir->{Dir}{$name} ||= $loader->{Cache}{$path}
1017 ||= $root->createNS(Dir => name => $name
1018 , loadkey => untaint_any($path)
1019 , parent_nsid => $dir->{cf_nsid}
1020 , base_nsid => $dir->{cf_base_nsid}
1021 109 ▶ );
Condition50%3/6
$dir->{"Dir"}{$name} ||= ($loader->{"Cache"}{$path} ||= $root->createNS("Dir", "name", $name, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"}))
l!l&&r!l&&!r
31060
$loader->{"Cache"}{$path} ||= $root->createNS("Dir", "name", $name, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"})
l!l&&r!l&&!r
01060
MC/DC0%0/2
$dir->{"Dir"}{$name} ||= ($loader->{"Cache"}{$path} ||= $root->createNS("Dir", "name", $name, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"}))
$dir->{"Dir"}{$name} ($loader->{"Cache"}{$path} ||= $root->createNS("Dir", "name", $name, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"}))
MC/DC0%0/2
$loader->{"Cache"}{$path} ||= $root->createNS("Dir", "name", $name, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"})
$loader->{"Cache"}{$path} $root->createNS("Dir", "name", $name, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"})
Truth table66%2/3
A ||= B
A= $dir->{"Dir"}{$name}B= ($loader->{"Cache"}{$path} ||= $root->createNS("Dir", "name", $name, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"}))
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $loader->{"Cache"}{$path}B= $root->createNS("Dir", "name", $name, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"})
ABresult
1X1
011
000
1022 } elsif ($name =~ /^(\w+)\.html?$/) { # XXX: Should allow '-'.
1023 $dir->{Template}{$1} ||= $loader->{Cache}{$path}
1024 ||= $root->createNS(Template => name => $1
1025 , loadkey => untaint_any($path)
1026 , parent_nsid => $dir->{cf_nsid}
1027 , base_nsid => $dir->{cf_base_nsid}
1028 164 ▶ );
Condition50%3/6
$dir->{"Template"}{$1} ||= ($loader->{"Cache"}{$path} ||= $root->createNS("Template", "name", $1, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"}))
l!l&&r!l&&!r
31610
$loader->{"Cache"}{$path} ||= $root->createNS("Template", "name", $1, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"})
l!l&&r!l&&!r
01610
MC/DC0%0/2
$dir->{"Template"}{$1} ||= ($loader->{"Cache"}{$path} ||= $root->createNS("Template", "name", $1, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"}))
$dir->{"Template"}{$1} ($loader->{"Cache"}{$path} ||= $root->createNS("Template", "name", $1, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"}))
MC/DC0%0/2
$loader->{"Cache"}{$path} ||= $root->createNS("Template", "name", $1, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"})
$loader->{"Cache"}{$path} $root->createNS("Template", "name", $1, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"})
Truth table66%2/3
A ||= B
A= $dir->{"Template"}{$1}B= ($loader->{"Cache"}{$path} ||= $root->createNS("Template", "name", $1, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"}))
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $loader->{"Cache"}{$path}B= $root->createNS("Template", "name", $1, "loadkey", &untaint_any($path), "parent_nsid", $dir->{"cf_nsid"}, "base_nsid", $dir->{"cf_base_nsid"})
ABresult
1X1
011
000
1029 }
1030 }
1031 # XXX: 無くなったファイルの開放は?
1032 61 closedir DIR;
1033 }
1034  
1035 158 ▶ sub refresh_Template {
Subroutine refresh_Template: called CC=8 SCAR=21.8
1036 158 (my MY $loader, my Root $root, my Template $tmpl) = @_;
1037 158 my $path = $tmpl->{cf_loadkey};
1038 158 ▶ unless ($loader->is_modified($path, $tmpl->{cf_mtime}{$path})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loader->is_modified($path, $tmpl->{"cf_mtime"}{$path})) 2 156 158
1039 print STDERR "refresh_Template: not modified: $path\n"
1040 2 ▶ if $root->{cf_debug_registry};
Branch: 1 branch
BranchTrueFalseTotal
if $root->{"cf_debug_registry"} 0 2 2
1041 2 return;
1042 }
1043  
1044 156 ▶ if (is_tainted($path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&is_tainted($path)) 0 156 156
1045 0 croak "template path $path is tainted";
1046 }
1047  
1048 156 ▶ if (my $cleaner = $root->can("forget_template")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cleaner = $root->can("forget_template")) 146 10 156
1049 146 $cleaner->($root, $tmpl);
1050 }
1051  
1052 156 my $is_reload = $tmpl->{cf_age}++;
1053 156 undef $tmpl->{is_loaded};
1054  
1055 $root->add_isa(my $pkg = $root->get_package($tmpl)
1056 156 , $root->get_package($tmpl->{cf_parent_nsid}));
1057 156 ▶ foreach my $name (map {defined $_ ? @$_ : ()}
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 156 156
1058 $root->{cf_template_global}) {
1059 0 *{globref($pkg, $name)} = *{globref($root->{cf_app_prefix}, $name)};
1060 }
1061  
1062 # XXX: There can be a race. (mtime vs open)
1063 my $parser = $loader->call_type
1064 (Parser => new => untaint => 1
1065 , registry => $root
1066 156 , special_entities => $root->{cf_special_entities});
1067 156 local $root->{current_parser}[0] = $parser;
1068  
1069 156 ▶ open my $fh, '<', $path or die "Can't open $path";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $path or die "Can't open $path" 156 0 156
1070  
1071 $tmpl->{cf_metainfo} = $parser->configure_metainfo
1072 (nsid => $tmpl->{cf_nsid}
1073 156 , namespace => $root->namespace
1074 , filename => $path);
1075  
1076 156 $tmpl->{tree} = $parser->parse_handle($fh);
1077  
1078 # XXX: ついでに <!yatt:widget> を解釈. ← parser に前倒し。
1079 # $root->process_declarations($tmpl);
1080 }
1081 }
1082  
1083 #========================================
1084  
1085 4 ▶sub _lined {
Subroutine _lined: not called CC=3 SCAR=22.8
1086 0 my $i = 1;
1087 0 my $result;
1088 0 foreach my $line (split /\n/, $_[0]) {
1089 0 ▶ if ($line =~ /^\#line (\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\#line (\d+)/) { } 0 0 0
1090 0 $i = $1;
1091 0 $result .= $line . "\n";
1092 } else {
1093 0 $result .= sprintf "% 3d %s\n", $i++, $line;
1094 }
1095 }
1096 $result
1097 0 }
1098  
1099 4 1;
« web/cgi-bin/yatt.lib/YATT/Class/Configurable.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/LRXML/Node.pm »