blib/lib/YATT/Lite/VFS.pm

filter: Statementstmt 83.0% 344 / 414 Branchbran 68.1% 124 / 182 Conditioncond 67.0% 53 / 79 MC/DCmcdc 48.0% 24 / 50 Subroutinesub 81.1% 69 / 85 Podpod 3.0% 2 / 66 totaltotal 70.3% 616 / 876 CC 129 SCAR 18.8
CC
129
Cov
77%
list_all_names
34.3
refresh_import
21.1
dirname
12.0
CRAP 6.5
« blib/lib/YATT/Lite/Connection.pm ↑ Summary blib/lib/YATT/Lite/Test/XHFTest.pm »
1 package YATT::Lite::VFS;
2 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 50 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 50 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 50 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 50 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 50 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 50 ▶use constant DEBUG_VFS => $ENV{DEBUG_YATT_VFS};
Subroutine BEGIN: called CC=1 SCAR=0.0
9 50 ▶use constant DEBUG_REBUILD => $ENV{DEBUG_YATT_REBUILD};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 50 ▶use constant DEBUG_MRO => $ENV{DEBUG_YATT_MRO};
Subroutine BEGIN: called CC=1 SCAR=0.0
11 50 ▶use constant DEBUG_LOOKUP => $ENV{DEBUG_YATT_VFS_LOOKUP};
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 50 require File::Spec;
14 50 require File::Basename;
15 50 require File::Glob;
16  
17 #========================================
18 # VFS 層. vfs_file (Template) のダミー実装を含む。
19 #========================================
20 {
21 sub MY () {__PACKAGE__}
22 use YATT::Lite::Types
23 50 ▶ ([Item => -fields => [qw(name public type)]
Subroutine BEGIN: called CC=1 SCAR=0.0
24 , -constants => [[can_generate_code => 0], [item_category => '']]
25 , [Folder => -fields => [qw(_Item path parent base
26 _argmacro_dict
27 entns)]
28 , -eval => q{use YATT::Lite::Util qw(cached_in);}
29 , [File => -fields => [qw(_partlist _boundarylist
30 string overlay imported
31 nlines
32 _dependency
33 _dependents
34 )]
35 , -alias => 'vfs_file']
36 , [Dir => -fields => [qw(encoding)]
37 50 , -alias => 'vfs_dir']]]);
38  
39 0 ▶ sub YATT::Lite::VFS::Item::after_create {}
Subroutine after_create: not called CC=1 SCAR=0.0
Pod undocumented
40 # item_key の符号化は class メソッド item_key_for($name) に集約する。
41 # Action/Entity などの subclass (YATT::Lite::Core) が override する。GH-256
42 995 ▶ sub YATT::Lite::VFS::Item::item_key_for {
Subroutine item_key_for: called CC=1 SCAR=0.0
Pod undocumented
43 995 (my $class, my $name) = @_;
44 995 $name;
45 }
46 695 ▶ sub YATT::Lite::VFS::Item::item_key {
Subroutine item_key: called CC=1 SCAR=0.0
Pod undocumented
47 695 (my Item $item) = @_;
48 695 $item->item_key_for($item->{name});
49 }
50 # 通常の Item は自分自身を返す。<!yatt:import> の alias Part
51 # (YATT::Lite::Core::Import) がこれを override する。GH-256
52 505 ▶ sub YATT::Lite::VFS::Item::resolve_alias { $_[0] }
Subroutine resolve_alias: called CC=1 SCAR=0.0
Pod undocumented
53 471 ▶ sub YATT::Lite::VFS::Folder::configure_parent {
Subroutine configure_parent: called CC=1 SCAR=0.0
Pod undocumented
54 471 my MY $self = shift;
55 # 循環参照対策
56 # XXX: Item に移すべきかもしれない。そうすれば、 Widget->parent が引ける。
57 471 weaken($self->{parent} = shift);
58 }
59 0 ▶ sub YATT::Lite::VFS::Folder::get_linear_isa_of_entns {
Subroutine get_linear_isa_of_entns: not called CC=2 SCAR=17.9
Pod undocumented
60 0 (my Folder $folder) = @_;
61 0 my $isa = mro::get_linear_isa($folder->{entns});
62 0 ▶ wantarray ? @$isa : $isa;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
63 }
64 0 ▶ sub YATT::Lite::VFS::Folder::list_parts {
Subroutine list_parts: not called CC=2 SCAR=17.9
Pod undocumented
65 0 (my Folder $folder) = @_;
66 0 ▶ return unless $folder->{_Item};
Branch: 1 branch
BranchTrueFalseTotal
unless $folder->{"_Item"} 0 0 0
67 0 values %{$folder->{_Item}};
68 }
69  
70 50 ▶ package YATT::Lite::VFS; BEGIN {$INC{"YATT/Lite/VFS.pm"} = 1}
Subroutine BEGIN: called CC=1 SCAR=0.0
71 sub VFS () {__PACKAGE__}
72 50 ▶ use parent qw(YATT::Lite::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
73 50 ▶ use YATT::Lite::MFields qw/ext_private ext_public cache no_auto_create
Subroutine BEGIN: called CC=1 SCAR=0.0
74 facade base
75 import
76 entns
77 always_refresh_deps
78 no_mro_c3
79 _on_memory
80 _root _extdict
81 mark
82 _n_creates
83 50 entns2vfs_item/;
84 50 ▶ use YATT::Lite::Util qw(lexpand rootname extname);
Subroutine BEGIN: called CC=1 SCAR=0.0
85 0 ▶ sub default_ext_public {'yatt'}
Subroutine default_ext_public: not called CC=1 SCAR=6.9
Pod undocumented
86 0 ▶ sub default_ext_private {'ytmpl'}
Subroutine default_ext_private: not called CC=1 SCAR=6.9
Pod undocumented
87 189 ▶ sub new {
Subroutine new: called CC=9 SCAR=23.3
Pod documented
88 189 my ($class, $spec) = splice @_, 0, 2;
89 189 (my VFS $vfs, my @task) = $class->SUPER::just_new(@_);
90 189 ▶ foreach my $desc ([1, ($vfs->{ext_public}
Condition33%2/6
$vfs->{"ext_public"} ||= $vfs->default_ext_public
l!l&&r!l&&!r
18900
$vfs->{"ext_private"} ||= $vfs->default_ext_private
l!l&&r!l&&!r
18900
MC/DC0%0/2
$vfs->{"ext_public"} ||= $vfs->default_ext_public
$vfs->{"ext_public"} $vfs->default_ext_public
MC/DC0%0/2
$vfs->{"ext_private"} ||= $vfs->default_ext_private
$vfs->{"ext_private"} $vfs->default_ext_private
Truth table33%1/3
A ||= B
A= $vfs->{"ext_public"}B= $vfs->default_ext_public
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $vfs->{"ext_private"}B= $vfs->default_ext_private
ABresult
1X1
011
000
91 ||= $vfs->default_ext_public)]
92 , [0, ($vfs->{ext_private}
93 ||= $vfs->default_ext_private)]) {
94 378 my ($value, @ext) = @$desc;
95 378 $vfs->{_extdict}{$_} = $value for @ext;
96 }
97  
98 189 ▶ if ($spec) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec) 189 0 189
99 189 my Folder $root = $vfs->root_create
100 (linsert($spec, 2, $vfs->cf_delegate(qw(entns))));
101 # Mark [data => ..] vfs as on_memory
102 189 ▶ $vfs->{_on_memory} = 1 if $spec->[0] eq 'data' or not $root->{path};
Branch: 1 branch
BranchTrueFalseTotal
if $spec->[0] eq "data" or not $root->{"path"} 37 152 189
Condition66%2/3
$spec->[0] eq "data" or not $root->{"path"}
l!l&&r!l&&!r
370152
MC/DC50%1/2
$spec->[0] eq "data" or not $root->{"path"}
$spec->[0] eq "data" not $root->{"path"}
Truth table66%2/3
A or not(B)
A= $spec->[0] eq "data"B= not $root->{"path"}
ABresult
1X1
011
000
103 }
104  
105 189 $$_[0]->($vfs, $$_[1]) for @task;
106 189 $vfs->after_new;
107 189 $vfs;
108 }
109 189 ▶ sub after_new {
Subroutine after_new: called CC=3 SCAR=11.4
Pod documented
110 189 my MY $self = shift;
111 189 ▶ confess __PACKAGE__ . ": facade is empty!" unless $self->{facade};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"facade"} 0 189 189
112 189 weaken($self->{facade});
113  
114 189 ▶ $self->refresh_import if $self->{import};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"import"} 0 189 189
115 }
116 62 ▶ sub error {
Subroutine error: called CC=1 SCAR=0.0
Pod undocumented
117 62 my MY $self = shift;
118 62 $self->{facade}->error(@_);
119 }
120 #========================================
121  
122 30 ▶ sub find_neighbor_file {
Subroutine find_neighbor_file: called CC=1 SCAR=0.0
Pod undocumented
123 30 (my VFS $vfs, my ($path)) = @_;
124 my VFS $other_vfs = $vfs->{facade}->find_neighbor_vfs
125 30 (File::Basename::dirname($path));
126 30 $other_vfs->find_file(File::Basename::basename($path));
127 }
128 31 ▶ sub find_neighbor_type {
Subroutine find_neighbor_type: called CC=5 SCAR=17.0
Pod undocumented
129 31 (my VFS $vfs, my ($kind, $path)) = @_;
130 31 ▶ $kind //= -d $path ? 'dir' : 'file';
Branch: 1 branch
BranchTrueFalseTotal
-d $path ? : 1 30 31
Condition33%1/3
$kind //= -d $path ? "dir" : "file"
l!l&&r!l&&!r
0310
MC/DC0%0/2
$kind //= -d $path ? "dir" : "file"
$kind -d $path ? "dir" : "file"
Truth table33%1/3
A //= B
A= $kindB= -d $path ? "dir" : "file"
ABresult
1X1
011
000
131 31 ▶ if ($kind eq 'file') {
Branch: 2 branches
BranchTrueFalseTotal
if ($kind eq 'file') { } 30 1 31
elsif ($kind eq 'dir') { } 1 0 1
132 30 $vfs->find_neighbor_file($path);
133 } elsif ($kind eq 'dir') {
134 1 $vfs->{facade}->find_neighbor($path);
135 } else {
136 0 croak "Unknown vfs type=$kind path=$path";
137 }
138 }
139  
140 0 ▶ sub refresh_import {
Subroutine refresh_import: not called CC=5 SCAR=30.5
Pod undocumented
141 0 (my VFS $vfs) = @_;
142 0 my Folder $root = $vfs->{_root};
143  
144 my @files = grep {
145 0 ▶ -f $_ && defined $vfs->{_extdict}{extname($_)}
Condition0%0/3
-f $_ && defined $vfs->{'_extdict'}{extname($_)}
!ll&&!rl&&r
000
MC/DC0%0/2
-f $_ && defined $vfs->{'_extdict'}{extname($_)}
-f $_ defined $vfs->{'_extdict'}{extname($_)}
Truth table0%0/3
A && B
A= -f $_B= defined $vfs->{'_extdict'}{extname($_)}
ABresult
0X0
100
111
146 } map {
147 0 my $fn = "$root->{path}/$_";
148 0 ▶ 1 while $fn =~ s,/[^/\.]+/\.\./,/,g;
Branch: 1 branch
BranchTrueFalseTotal
$fn =~ s[/[^/\.]+/\.\./][/]g and do { '???' } 0 0 0
149 0 ▶ glob($fn);
Subroutine BEGIN: called CC=1 SCAR=0.2
150 0 } lexpand($vfs->{import});
151  
152 0 if (DEBUG_VFS) {
153 printf STDERR "# vfs-import to %s from %s (actually: %s)\n"
154 , $root->{path}, sorted_dump($vfs->{import}), sorted_dump(\@files);
155 }
156  
157 0 foreach my $fn (@files) {
158 0 my Folder $file = $vfs->find_neighbor_file($fn);
159  
160 # Skip if it exists.
161 0 ▶ next if $root->lookup_1($vfs, $file->{name});
Branch: 1 branch
BranchTrueFalseTotal
if $root->lookup_1($vfs, $file->{"name"}) 0 0 0
162  
163 #
164 $root->{_Item}{$file->{name}}
165 0 = $vfs->create(file => $file->{path}, parent => $root
166 , imported => 1
167 );
168 }
169 }
170  
171 #========================================
172 658 ▶ sub find_file {
Subroutine find_file: called CC=3 SCAR=11.0
Pod undocumented
173 658 (my VFS $vfs, my $filename) = @_;
174 # XXX: 拡張子をどうしたい?
175 658 ▶ my ($name) = $filename =~ m{^(\w+)}
Branch: 1 branch
BranchTrueFalseTotal
my($name) = $filename =~ /^(\w+)/ or croak("Can't extract part name from filename '${filename}'") 658 0 658
176 or croak "Can't extract part name from filename '$filename'";
177 658 ▶ my $nameSpec = length($name) == length($filename)
Branch: 1 branch
BranchTrueFalseTotal
length $name == length $filename ? : 51 607 658
178 ? $name : [$name => $filename];
179 658 $vfs->{_root}->lookup($vfs, $nameSpec);
180 }
181 0 ▶ sub list_all_names {
Subroutine list_all_names: not called CC=1 SCAR=6.9
Pod undocumented
182 0 (my VFS $vfs) = @_;
183 0 $vfs->{_root}->list_all_names($vfs);
184 }
185 1 ▶ sub list_items {
Subroutine list_items: called CC=1 SCAR=0.0
Pod undocumented
186 1 (my VFS $vfs) = @_;
187 1 $vfs->{_root}->list_items($vfs);
188 }
189 0 ▶ sub list_base {
Subroutine list_base: not called CC=1 SCAR=6.9
Pod undocumented
190 0 (my VFS $vfs) = @_;
191 map {
192 0 my Folder $folder = $_; # Actually, only folders can be a 'base'.
193 0 $folder->{path};
194 } $vfs->list_internal_base_folders;
195 }
196  
197 # XXX: Incontrast to list_items, list_internal_base_items returns internal VFS items
198 0 ▶ sub list_internal_base_folders {
Subroutine list_internal_base_folders: not called CC=1 SCAR=6.9
Pod undocumented
199 0 (my VFS $vfs) = @_;
200 0 $vfs->{_root}->list_base($vfs);
201 }
202 32 ▶ sub resolve_path_from {
Subroutine resolve_path_from: called CC=5 SCAR=16.5
Pod undocumented
203 32 (my VFS $vfs, my Folder $from, my $fn) = @_;
204 # $fn usually comes from a decoded template string while paths are
205 # octets in YATT. Joining a utf8-flagged string with an octet dirname
206 # makes perl hand the utf8-encoded form to the filesystem. GH-275
207 32 ▶ utf8::encode($fn) if utf8::is_utf8($fn);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($fn) 32 0 32
208 32 my Folder $folder = $from->dirobj;
209 32 ▶ my $dirname = $folder->dirname
Branch: 1 branch
BranchTrueFalseTotal
my $dirname = $folder->dirname or return undef 32 0 32
210 or return undef;
211 32 my $abs = do {
212 32 ▶ if ($fn =~ /^@/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fn =~ /^@/) { } 0 32 32
elsif ($fn =~ s[^((?:\.\./)+)][]) { } 2 30 32
213 0 $vfs->{facade}->app_path_expand($fn);
214 } elsif ($fn =~ s!^((?:\.\./)+)!!) {
215 # leading upward relpath is treated specially.
216 2 my $up = length($1) / 3;
217 2 my @dirs = File::Spec->splitdir($dirname);
218 2 File::Spec->catfile(@dirs[0.. $#dirs - $up], $fn);
219 } else {
220 30 File::Spec->rel2abs($fn, $dirname);
221 }
222 };
223 32 $abs;
224 }
225  
226 #========================================
227 49 ▶ sub find_part {
Subroutine find_part: called CC=1 SCAR=0.0
Pod undocumented
228 49 my VFS $vfs = shift;
229 49 $vfs->{_root}->lookup($vfs, @_);
230 }
231 471 ▶ sub find_part_from {
Subroutine find_part_from: called CC=3 SCAR=11.0
Pod undocumented
232 471 (my VFS $vfs, my $from) = splice @_, 0, 2;
233 471 my Item $item = $from->lookup($vfs, @_);
234 471 ▶ if ($item and $item->isa($vfs->Folder)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item and $item->isa($vfs->Folder)) { } 108 363 471
Condition100%3/3
$item and $item->isa($vfs->Folder)
!ll&&!rl&&r
96267108
MC/DC100%2/2
$item and $item->isa($vfs->Folder)
$item $item->isa($vfs->Folder)
Truth table100%3/3
A and B
A= $itemB= $item->isa($vfs->Folder)
ABresult
0X0
100
111
235 108 (my Folder $folder = $item)->{_Item}{''}
236 } else {
237 363 $item;
238 }
239 }
240  
241 0 ▶ sub find_part_from_entns {
Subroutine find_part_from_entns: not called CC=2 SCAR=17.9
Pod undocumented
242 0 (my VFS $vfs, my $entns) = splice @_, 0, 2;
243 0 ▶ my Folder $folder = $vfs->{entns2vfs_item}{$entns}
Branch: 1 branch
BranchTrueFalseTotal
my YATT::Lite::VFS::Folder $folder = $vfs->{"entns2vfs_item"}{$entns} or croak("Unknown entns $entns!") 0 0 0
244 or croak "Unknown entns $entns!";
245 0 $vfs->find_part_from($folder, @_);
246 }
247  
248 # kind 指定の part 検索 dispatcher。kind ごとの検索ロジック
249 # (item-key の符号化を含む) は _find_kind_part__$kind として
250 # subclass (YATT::Lite::Core) が定義する。GH-256
251 154 ▶ sub find_kind_part_from {
Subroutine find_kind_part_from: called CC=2 SCAR=6.9
Pod undocumented
252 154 (my VFS $vfs, my ($from, $kind, $name)) = @_;
253 154 ▶ my $sub = $vfs->can("_find_kind_part__$kind")
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $vfs->can("_find_kind_part__$kind") or croak("Unknown part kind: $kind") 153 1 154
254 or croak "Unknown part kind: $kind";
255 153 $sub->($vfs, $from, $name);
256 }
257  
258 # To limit call of refresh atmost 1, use this.
259 422 ▶ sub reset_refresh_mark {
Subroutine reset_refresh_mark: called CC=2 SCAR=7.2
Pod undocumented
260 422 (my VFS $vfs) = shift;
261 422 ▶ $vfs->{mark} = @_ ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 422 422
262 }
263  
264 0 ▶ sub re_ext {
Subroutine re_ext: not called CC=1 SCAR=6.9
Pod undocumented
265 0 (my VFS $vfs) = @_;
266 0 my $ext = join("|", grep {defined}
267 0 $vfs->{ext_public}, $vfs->{ext_private});
268 0 qr{$ext};
269 }
270  
271 1230 ▶ sub YATT::Lite::VFS::Folder::lookup {
Subroutine lookup: called CC=2 SCAR=6.9
Pod undocumented
272 1230 print STDERR "# VFS: root->lookup(", sorted_dump(@_[2..$#_]), ")\n"
273 if DEBUG_LOOKUP;
274 1230 ▶ $_[0]->lookup_1(@_[1..$#_])
Condition100%3/3
$_[0]->lookup_1(@_[1 .. $#_]) // $_[0]->lookup_base(@_[1 .. $#_])
l!l&&r!l&&!r
100472140
MC/DC100%2/2
$_[0]->lookup_1(@_[1 .. $#_]) // $_[0]->lookup_base(@_[1 .. $#_])
$_[0]->lookup_1(@_[1 .. $#_]) $_[0]->lookup_base(@_[1 .. $#_])
Truth table100%3/3
A // B
A= $_[0]->lookup_1(@_[1 .. $#_])B= $_[0]->lookup_base(@_[1 .. $#_])
ABresult
1X1
011
000
275 // $_[0]->lookup_base(@_[1..$#_])
276 }
277  
278 0 ▶ sub YATT::Lite::VFS::Dir::dirobj { $_[0] }
Subroutine dirobj: not called CC=1 SCAR=6.9
Pod undocumented
279 32 ▶ sub YATT::Lite::VFS::File::dirobj {
Subroutine dirobj: called CC=1 SCAR=0.0
Pod undocumented
280 32 (my vfs_file $file) = @_;
281 32 $file->{parent};
282 }
283  
284 32 ▶ sub YATT::Lite::VFS::Dir::dirname {
Subroutine dirname: called CC=1 SCAR=0.0
Pod undocumented
285 32 (my vfs_dir $dir) = @_;
286 32 $dir->{path};
287 }
288 0 ▶ sub YATT::Lite::VFS::File::dirname {
Subroutine dirname: not called CC=3 SCAR=24.8
Pod undocumented
289 0 (my vfs_file $file) = @_;
290 0 ▶ if (my $parent = $file->{parent}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $parent = $file->{'parent'}) { } 0 0 0
elsif (my $path = $file->{'path'}) { } 0 0 0
291 0 $parent->dirname;
292 } elsif (my $path = $file->{path}) {
293 0 File::Basename::dirname(File::Spec->rel2abs($path));
294 } else {
295 0 undef;
296 }
297 }
298  
299 50 ▶ use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
300 436 ▶ sub YATT::Lite::VFS::File::fake_filename {
Subroutine fake_filename: called CC=2 SCAR=6.9
Pod undocumented
301 436 (my vfs_file $file) = @_;
302 436 ▶ $file->{path} // $file->{name};
Condition100%3/3
$file->{"path"} // $file->{"name"}
l!l&&r!l&&!r
2202124
MC/DC100%2/2
$file->{"path"} // $file->{"name"}
$file->{"path"} $file->{"name"}
Truth table100%3/3
A // B
A= $file->{"path"}B= $file->{"name"}
ABresult
1X1
011
000
303 }
304  
305 460 ▶ sub YATT::Lite::VFS::File::lookup_1 {
Subroutine lookup_1: called CC=7 SCAR=19.5
Pod undocumented
306 460 (my vfs_file $file, my VFS $vfs, my $nameSpec) = splice @_, 0, 3;
307 print STDERR "# VFS: $file->lookup_1("
308 460 , sorted_dump($nameSpec, @_), ") in (", sorted_dump($file->{path}), ")\n"
309 if DEBUG_LOOKUP;
310 460 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 430 30 460
311 # ファイルの中には、深さ 1 の name しか無いはずだから。
312 # mtime, refresh
313 430 ▶ $file->refresh($vfs) unless $vfs->{mark}{refaddr($file)}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $vfs->{"mark"}{builtin::refaddr($file)}++ 6 424 430
314 430 my ($name) = lexpand($nameSpec);
315 430 my Item $item = $file->{_Item}{$name};
316 # import alias はここでソース側 Part へ解決する。GH-256
317 # (data vfs では _Item に生の文字列等も入りうるので Item の時だけ)
318 430 ▶ return $item->resolve_alias($vfs)
Branch: 1 branch
BranchTrueFalseTotal
if $item and ref $item and UNIVERSAL::isa($item, "YATT::Lite::VFS::Item") 277 153 430
Condition83%5/6
$item and ref $item and UNIVERSAL::isa($item, "YATT::Lite::VFS::Item")
!ll&&!rl&&r
1530277
$item and ref $item
!ll&&!rl&&r
13320277
MC/DC66%2/3
$item and ref $item and UNIVERSAL::isa($item, "YATT::Lite::VFS::Item")
$item ref $item UNIVERSAL::isa($item, "YATT::Lite::VFS::Item")
Truth table75%3/4
A and B and C
A= $itemB= ref $itemC= UNIVERSAL::isa($item, "YATT::Lite::VFS::Item")
ABCresult
0XX0
10X0
1100
1111
319 if $item and ref $item and UNIVERSAL::isa($item, Item);
320 153 ▶ return $item if $item;
Branch: 1 branch
BranchTrueFalseTotal
if $item 20 133 153
321 }
322 163 undef;
323 }
324 966 ▶ sub YATT::Lite::VFS::Dir::lookup_1 {
Subroutine lookup_1: called CC=10 SCAR=23.0
Pod undocumented
325 966 (my vfs_dir $dir, my VFS $vfs, my $nameSpec) = splice @_, 0, 3;
326 print STDERR "# VFS: $dir->lookup_1("
327 966 , sorted_dump($nameSpec, @_), ") in (", sorted_dump($dir->{path}), ")\n"
328 if DEBUG_LOOKUP;
329 966 ▶ if (my Item $item = $dir->cached_in
Branch: 1 branch
BranchTrueFalseTotal
if (my YATT::Lite::VFS::Item $item = $dir->cached_in($dir->{"_Item"} //= {}, $nameSpec, $vfs, $vfs->{"mark"})) 796 164 960
Condition100%2/2
$dir->{"_Item"} //= {}
l!l
816150
MC/DC100%1/1
$dir->{"_Item"} //= {}
$dir->{"_Item"}
Truth table100%2/2
A
A= $dir->{"_Item"}
Aresult
11
00
330 ($dir->{_Item} //= {}, $nameSpec, $vfs, $vfs->{mark})) {
331 796 ▶ if ((not ref $item or not UNIVERSAL::isa($item, Item))
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $item and UNIVERSAL::isa($item, "YATT::Lite::VFS::Item") or $vfs->{"no_auto_create"}) 210 586 796
Condition100%6/6
ref $item and UNIVERSAL::isa($item, "YATT::Lite::VFS::Item") or $vfs->{"no_auto_create"}
l!l&&r!l&&!r
5815210
ref $item and UNIVERSAL::isa($item, "YATT::Lite::VFS::Item")
!ll&&!rl&&r
2123581
MC/DC100%3/3
ref $item and UNIVERSAL::isa($item, "YATT::Lite::VFS::Item") or $vfs->{"no_auto_create"}
ref $item UNIVERSAL::isa($item, "YATT::Lite::VFS::Item") $vfs->{"no_auto_create"}
Truth table100%5/5
A and B or C
A= ref $itemB= UNIVERSAL::isa($item, "YATT::Lite::VFS::Item")C= $vfs->{"no_auto_create"}
ABCresult
11X1
0X11
1011
0X00
1000
332 and not $vfs->{no_auto_create}) {
333 # Special case (mostly for test)
334 # data vfs can contain vfs spec (string, array, hash).
335 210 my ($name) = lexpand($nameSpec);
336 210 $item = $dir->{_Item}{$name} = $vfs->create
337 (data => $item, parent => $dir, name => $name);
338 }
339 788 ▶ return $item unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 737 51 788
340 51 ▶ if (not $vfs->{no_mro_c3} and $dir->{entns}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $vfs->{'no_mro_c3'} and $dir->{'entns'}) { } 25 26 51
Condition66%2/3
not $vfs->{"no_mro_c3"} and $dir->{"entns"}
!ll&&!rl&&r
02625
MC/DC50%1/2
not $vfs->{"no_mro_c3"} and $dir->{"entns"}
not $vfs->{"no_mro_c3"} $dir->{"entns"}
Truth table66%2/3
not(A) and B
A= not $vfs->{"no_mro_c3"}B= $dir->{"entns"}
ABresult
0X0
100
111
341 25 $item = $item->lookup_1($vfs, @_);
342 } else {
343 26 $item = $item->lookup($vfs, @_);
344 }
345 51 ▶ return $item if $item;
Branch: 1 branch
BranchTrueFalseTotal
if $item 50 1 51
346 }
347 165 undef;
348 }
349 212 ▶ sub YATT::Lite::VFS::Folder::lookup_base {
Subroutine lookup_base: called CC=8 SCAR=20.8
Pod undocumented
350 212 (my Folder $item, my VFS $vfs, my $nameSpec) = splice @_, 0, 3;
351 print STDERR "# VFS: $item->lookup_base("
352 212 , sorted_dump($item->{path}) ,")(", sorted_dump($nameSpec, @_), ")\n"
353 if DEBUG_LOOKUP;
354  
355 212 ▶ if (not $vfs->{no_mro_c3} and $item->{entns}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $vfs->{'no_mro_c3'} and $item->{'entns'}) { } 185 27 212
Condition66%2/3
not $vfs->{"no_mro_c3"} and $item->{"entns"}
!ll&&!rl&&r
027185
MC/DC50%1/2
not $vfs->{"no_mro_c3"} and $item->{"entns"}
not $vfs->{"no_mro_c3"} $item->{"entns"}
Truth table66%2/3
not(A) and B
A= not $vfs->{"no_mro_c3"}B= $item->{"entns"}
ABresult
0X0
100
111
356 185 (undef, my @super_ns) = @{mro::get_linear_isa($item->{entns})};
357 my @super = map {
358 185 ▶ my $o = $vfs->{entns2vfs_item}{$_}; $o ? $o : ()
Branch: 1 branch
BranchTrueFalseTotal
$o ? : 197 917 1114
359 } @super_ns;
360 185 foreach my $super (@super) {
361 171 ▶ my $ans = $super->lookup_1($vfs, $nameSpec, @_) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $ans = $super->lookup_1($vfs, $nameSpec, @_) or next 55 116 171
362 55 return $ans;
363 }
364 } else {
365 27 my @super = $item->list_base;
366 27 foreach my $super (@super) {
367 26 ▶ my $ans = $super->lookup($vfs, $nameSpec, @_) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $ans = $super->lookup($vfs, $nameSpec, @_) or next 21 5 26
368 21 return $ans;
369 }
370 }
371 136 undef;
372 }
373 1353 ▶ sub YATT::Lite::VFS::Folder::list_base {
Subroutine list_base: called CC=2 SCAR=6.9
Pod undocumented
374 1353 ▶ my Folder $folder = shift; @{$folder->{base} ||= []}
Condition100%2/2
$folder->{"base"} ||= []
l!l
936417
MC/DC100%1/1
$folder->{"base"} ||= []
$folder->{"base"}
Truth table100%2/2
A
A= $folder->{"base"}
Aresult
11
00
375 }
376 1342 ▶ sub YATT::Lite::VFS::File::list_base {
Subroutine list_base: called CC=6 SCAR=17.9
Pod undocumented
377 1342 my vfs_file $file = shift;
378  
379 # $dir/$file.yatt inherits its own base decl,
380 1342 my (@local, @otherdir);
381 1342 foreach my Folder $super ($file->YATT::Lite::VFS::Folder::list_base) {
382 66 ▶ if ($super->{parent} and $file->{parent} == $super->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($super->{'parent'} and $file->{'parent'} == $super->{'parent'}) { } 46 20 66
Condition100%3/3
$super->{"parent"} and $file->{"parent"} == $super->{"parent"}
!ll&&!rl&&r
11946
MC/DC100%2/2
$super->{"parent"} and $file->{"parent"} == $super->{"parent"}
$super->{"parent"} $file->{"parent"} == $super->{"parent"}
Truth table100%3/3
A and B
A= $super->{"parent"}B= $file->{"parent"} == $super->{"parent"}
ABresult
0X0
100
111
383 46 push @local, $super;
384 } else {
385 20 push @otherdir, $super;
386 }
387 }
388  
389 1342 push @local, grep {$_} $file->{parent}, $file->{overlay};
390  
391 1342 ▶ if ($file->{entns} and mro::get_mro($file->{entns}) eq 'c3') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->{'entns'} and &mro::get_mro($file->{'entns'}) eq 'c3') { } 1326 16 1342
Condition66%2/3
$file->{"entns"} and &mro::get_mro($file->{"entns"}) eq "c3"
!ll&&!rl&&r
1601326
MC/DC50%1/2
$file->{"entns"} and &mro::get_mro($file->{"entns"}) eq "c3"
$file->{"entns"} &mro::get_mro($file->{"entns"}) eq "c3"
Truth table66%2/3
A and B
A= $file->{"entns"}B= &mro::get_mro($file->{"entns"}) eq "c3"
ABresult
0X0
100
111
392 print STDERR "use c3 for $file->{entns}"
393 , "\n ".sorted_dump([local => map {
394 my Folder $f = $_;
395 mro::get_linear_isa($f->{entns})
396 } @local])
397 , "\n ".sorted_dump([other => map {
398 1326 my Folder $f = $_;
399 mro::get_linear_isa($f->{entns})
400 } @otherdir])
401 , "\n" if DEBUG_MRO;
402 1326 return (@local, @otherdir);
403 } else {
404 16 print STDERR "use dfs for $file->{entns}\n" if DEBUG_MRO;
405 16 return (@otherdir, @local);
406 }
407 }
408 0 ▶ sub YATT::Lite::VFS::File::list_items {
Subroutine list_items: not called CC=1 SCAR=6.9
Pod undocumented
409 0 croak "NIMPL";
410 }
411 0 ▶ sub YATT::Lite::VFS::Dir::list_all_names {
Subroutine list_all_names: not called CC=6 SCAR=35.4
Pod undocumented
412 0 (my vfs_dir $in, my VFS $vfs) = @_;
413 0 ▶ croak "BUG: vfs is undef!" unless defined $vfs;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vfs 0 0 0
414 0 ▶ return unless defined $in->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in->{"path"} 0 0 0
415 0 my (@names, %seen);
416 {
417 50 ▶ use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.4
418 0 my $extRe = $vfs->re_ext;
419 0 local $_;
420 0 opendir my $dh, "$in->{path}/";
421 0 ▶ while (readdir $dh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readdir $dh)) 0 0 0
422 0 ▶ /^(\w+)(?:\.$extRe)?\z/
Branch: 1 branch
BranchTrueFalseTotal
/^(\w+)(?:\.$extRe)?\z/u or next 0 0 0
423 or next;
424 0 ▶ next if $seen{$1}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$1}++ 0 0 0
425 0 push @names, $1;
426 }
427 0 closedir $dh;
428 }
429 0 @names;
430 }
431 1 ▶ sub YATT::Lite::VFS::Dir::list_items {
Subroutine list_items: called CC=6 SCAR=19.3
Pod undocumented
432 1 (my vfs_dir $in, my VFS $vfs) = @_;
433 1 ▶ croak "BUG: vfs is undef!" unless defined $vfs;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vfs 0 1 1
434 1 ▶ return unless defined $in->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in->{"path"} 0 1 1
435 1 my %dup;
436 my @exts = map {
437 2 ▶ if (defined $_ and not $dup{$_}++) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_ and not $dup{$_}++) { } 2 0 2
Condition33%1/3
defined $_ and not $dup{$_}++
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_ and not $dup{$_}++
defined $_ not $dup{$_}++
Truth table33%1/3
A and not(B)
A= defined $_B= not $dup{$_}++
ABresult
0X0
100
111
438 2 $_
439 0 } else { () }
440 1 } ($vfs->{ext_public}, $vfs->{ext_private});
441 1 my %dup2;
442 map {
443 1 my $name = substr($_, length($in->{path})+1);
444 2 $name =~ s/\.\w+$//;
445 2 ▶ $dup2{$name}++ ? () : $name;
Branch: 1 branch
BranchTrueFalseTotal
$dup2{$name}++ ? : 0 2 2
446 # Not CORE::glob: it splits the pattern on whitespace in the path. GH-275
447 } File::Glob::bsd_glob("$in->{path}/[a-z]*.{".join(",", @exts)."}");
448 }
449 #----------------------------------------
450 331 ▶ sub YATT::Lite::VFS::Dir::load {
Subroutine load: called CC=11 SCAR=24.0
Pod undocumented
451 331 (my vfs_dir $in, my VFS $vfs, my $nameSpec) = @_;
452 331 ▶ return unless defined $in->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in->{"path"} 24 307 331
453 307 print STDERR "# VFS: Dir::load(", sorted_dump($nameSpec), ") in $in\n"
454 if DEBUG_LOOKUP;
455 307 my ($partName, $realFile) = lexpand($nameSpec);
456  
457 # When $partName contains NUL like 'do\0action',
458 # we should avoid filesystem testings.
459 307 ▶ if ($partName =~ /\0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($partName =~ /\0/) 21 286 307
460 21 print STDERR "# VFS: -> avoid fs lookup for \\0 in $in\n"
461 if DEBUG_LOOKUP;
462 21 return;
463 }
464  
465 286 ▶ $realFile ||= $partName;
Condition66%2/3
$realFile ||= $partName
l!l&&r!l&&!r
1691170
MC/DC0%0/2
$realFile ||= $partName
$realFile $partName
Truth table66%2/3
A ||= B
A= $realFileB= $partName
ABresult
1X1
011
000
466 # Template-derived names are decoded strings; paths are octets. GH-275
467 286 ▶ utf8::encode($realFile) if utf8::is_utf8($realFile);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($realFile) 88 198 286
468  
469 286 my $vfsname = "$in->{path}/$realFile";
470 286 my @opt = (name => $partName, parent => $in);
471 286 my ($kind, $path, @other) = do {
472 286 ▶ if (ref $nameSpec) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref $nameSpec) { } 169 117 286
elsif (my $fn = $vfs->find_ext($vfsname, $vfs->{'ext_public'})) { } 52 65 117
elsif ($fn = $vfs->find_ext($vfsname, $vfs->{'ext_private'})) { } 14 51 65
elsif (-d $vfsname) { } 1 50 51
473 169 my $ext = extname($vfsname);
474 (file => $vfsname
475 , ($ext eq $vfs->{ext_public}
476 169 ▶ ? (public => 1) : ()));
Branch: 1 branch
BranchTrueFalseTotal
$ext eq $vfs->{'ext_public'} ? : 150 19 169
477 } elsif (my $fn = $vfs->find_ext($vfsname, $vfs->{ext_public})) {
478 52 (file => $fn, public => 1);
479 } elsif ($fn = $vfs->find_ext($vfsname, $vfs->{ext_private})) {
480 # dir の場合、 new_tmplpkg では?
481 14 ▶ my $kind = -d $fn ? 'dir' : 'file';
Branch: 1 branch
BranchTrueFalseTotal
-d $fn ? : 0 14 14
482 14 ($kind => $fn);
483 } elsif (-d $vfsname) {
484 1 return $vfs->{facade}->find_neighbor($vfsname);
485 } else {
486 50 return undef;
487 }
488 };
489 235 $vfs->create($kind, $path, @opt, @other);
490 }
491 182 ▶ sub find_ext {
Subroutine find_ext: called CC=5 SCAR=16.5
Pod undocumented
492 182 (my VFS $vfs, my ($vfsname, $spec)) = @_;
493 182 ▶ foreach my $ext (!defined $spec ? () : ref $spec ? @$spec : $spec) {
Branch: 2 branches
BranchTrueFalseTotal
!defined($spec) ? : 0 182 182
ref $spec ? : 0 182 182
494 182 my $fn = "$vfsname.$ext";
495 182 ▶ return $fn if -e $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -e $fn 66 116 182
496 }
497 }
498 #========================================
499 # 実験用、ダミーのパーサー
500 487 ▶ sub YATT::Lite::VFS::File::reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod undocumented
501 487 (my File $file) = @_;
502 487 undef $file->{_partlist};
503 487 undef $file->{_boundarylist};
504 487 undef $file->{_Item};
505 # undef $file->{string};
506 487 undef $file->{base};
507 487 $file->{_dependency} = +{};
508 }
509 2 ▶ sub YATT::Lite::VFS::Dir::refresh {}
Subroutine refresh: called CC=1 SCAR=0.0
Pod undocumented
510 23 ▶ sub YATT::Lite::VFS::File::refresh {
Subroutine refresh: called CC=8 SCAR=21.0
Pod undocumented
511 23 (my vfs_file $file, my VFS $vfs) = @_;
512 23 ▶ return unless $$file{path} || $$file{string};
Branch: 1 branch
BranchTrueFalseTotal
unless $file->{"path"} or $file->{"string"} 0 23 23
Condition66%2/3
$file->{"path"} or $file->{"string"}
l!l&&r!l&&!r
2030
MC/DC0%0/2
$file->{"path"} or $file->{"string"}
$file->{"path"} $file->{"string"}
Truth table66%2/3
A or B
A= $file->{"path"}B= $file->{"string"}
ABresult
1X1
011
000
513 # XXX: mtime!
514 23 my @part = do {
515 23 local $/; split /^!\s*(\w+)\s+(\S+)[^\n]*?\n/m, do {
516 23 ▶ if ($$file{path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->{'path'}) { } 20 3 23
517 open my $fh, '<', $$file{path}
518 20 ▶ or die "Can't open '$$file{path}': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file->{"path"} or die qq[Can't open '$file->{"path"}': $!] 20 0 20
519 scalar <$fh>
520 20 } else {
521 3 $$file{string};
522 }
523 };
524 };
525 23 $file->add_widget('', shift @part);
526 23 ▶ while (my ($kind, $name, $part) = splice @part, 0, 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@part, 0, 3)) 19 23 42
527 19 ▶ if (defined $kind and my $sub = $file->can("declare_$kind")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kind and my $sub = $file->can("declare_$kind")) { } 4 15 19
Condition66%2/3
defined $kind and my $sub = $file->can("declare_$kind")
!ll&&!rl&&r
0154
MC/DC50%1/2
defined $kind and my $sub = $file->can("declare_$kind")
defined $kind my $sub = $file->can("declare_$kind")
Truth table66%2/3
A and B
A= defined $kindB= my $sub = $file->can("declare_$kind")
ABresult
0X0
100
111
528 4 $sub->($file, $name, $vfs, $part);
529 } else {
530 15 $file->can("add_$kind")->($file, $name, $part);
531 }
532 }
533 }
534  
535 82 ▶ sub YATT::Lite::VFS::File::add_dependency {
Subroutine add_dependency: called CC=2 SCAR=6.9
Pod undocumented
536 82 (my File $file, my $wpath, my File $other) = @_;
537 82 Scalar::Util::weaken($file->{_dependency}{$wpath} = $other);
538 82 ▶ $other->add_dependent($file) if UNIVERSAL::isa($other, File);
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($other, "YATT::Lite::VFS::File") 81 1 82
539 }
540 81 ▶ sub YATT::Lite::VFS::File::add_dependent {
Subroutine add_dependent: called CC=1 SCAR=0.0
Pod undocumented
541 81 (my File $file, my File $other) = @_;
542 81 Scalar::Util::weaken($file->{_dependents}{refaddr($other)} = $other);
543 }
544 438 ▶ sub YATT::Lite::VFS::File::list_dependents {
Subroutine list_dependents: called CC=2 SCAR=6.9
Pod undocumented
545 438 (my File $file) = @_;
546 defined (my $deps = $file->{_dependents})
547 438 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $deps = $file->{"_dependents"}) or return 3 435 438
548 3 grep {defined} values %$deps;
549 }
550 345 ▶ sub YATT::Lite::VFS::File::list_dependency {
Subroutine list_dependency: called CC=4 SCAR=17.1
Pod undocumented
551 345 (my File $file, my $detail) = @_;
552 defined (my $deps = $file->{_dependency})
553 345 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $deps = $file->{"_dependency"}) or return 345 0 345
554 345 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) { } 0 345 345
555 0 ▶ wantarray ? map([$_ => $deps->{$_}], keys %$deps) : $deps;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
556 } else {
557 345 values %$deps;
558 }
559 }
560 345 ▶ sub refresh_deps_for {
Subroutine refresh_deps_for: called CC=3 SCAR=11.0
Pod undocumented
561 345 (my MY $self, my File $file) = @_;
562 345 print STDERR "refresh deps for: ", $file->{path}, "\n" if DEBUG_REBUILD;
563 345 foreach my $dep ($file->list_dependency) {
564 128 ▶ unless ($self->{mark}{refaddr($dep)}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"mark"}{builtin::refaddr($dep)}++) 103 25 128
565 103 print STDERR " refreshing: ", $dep->{path}, "\n" if DEBUG_REBUILD;
566 103 $dep->refresh($self);
567 }
568 }
569 }
570  
571 #========================================
572 26 ▶ sub add_to {
Subroutine add_to: called CC=4 SCAR=16.8
Pod undocumented
573 26 (my VFS $vfs, my ($path, $data)) = @_;
574 26 ▶ my @path = ref $path ? @$path : $path;
Branch: 1 branch
BranchTrueFalseTotal
ref $path ? : 0 26 26
575 26 my $lastName = pop @path;
576 26 my Folder $folder = $vfs->{_root};
577 26 ▶ while (@path) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path) 0 26 26
578 0 my $name = shift @path;
579 0 ▶ $folder = $folder->{_Item}{$name} ||= $vfs->create
Condition0%0/3
$folder->{"_Item"}{$name} ||= $vfs->create("data", {}, "name", $name, "parent", $folder)
l!l&&r!l&&!r
000
MC/DC0%0/2
$folder->{"_Item"}{$name} ||= $vfs->create("data", {}, "name", $name, "parent", $folder)
$folder->{"_Item"}{$name} $vfs->create("data", {}, "name", $name, "parent", $folder)
Truth table0%0/3
A ||= B
A= $folder->{"_Item"}{$name}B= $vfs->create("data", {}, "name", $name, "parent", $folder)
ABresult
1X1
011
000
580 (data => {}, name => $name, parent => $folder);
581 }
582 # XXX: path を足すと、memory 動作の時に困る
583 26 my Item $item = $vfs->create
584 (data => $data, name => $lastName, parent => $folder);
585 21 $folder->{_Item}{$item->item_key} = $item;
586 }
587 #========================================
588 39 ▶ sub root {(my VFS $vfs) = @_; $vfs->{_root}}
Subroutine root: called CC=1 SCAR=0.0
Pod undocumented
589  
590 # special hook for root creation.
591 189 ▶ sub root_create {
Subroutine root_create: called CC=2 SCAR=7.0
Pod undocumented
592 189 (my VFS $vfs, my ($kind, $primary, %rest)) = @_;
593 189 ▶ $rest{entns} //= $vfs->{entns};
Condition66%2/3
$rest{"entns"} //= $vfs->{"entns"}
l!l&&r!l&&!r
174015
MC/DC50%1/2
$rest{"entns"} //= $vfs->{"entns"}
$rest{"entns"} $vfs->{"entns"}
Truth table66%2/3
A //= B
A= $rest{"entns"}B= $vfs->{"entns"}
ABresult
1X1
011
000
594 189 $vfs->{_root} = $vfs->create($kind, $primary, %rest);
595 }
596 670 ▶ sub create {
Subroutine create: called CC=4 SCAR=14.2
Pod undocumented
597 670 (my VFS $vfs, my ($kind, $primary, %rest)) = @_;
598 # XXX: $vfs は className の時も有る。
599 670 ▶ if (my $sub = $vfs->can("create_$kind")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $vfs->can("create_$kind")) { } 496 174 670
600 496 $vfs->fixup_created(\@_, $sub->($vfs, $primary, %rest, type => $kind));
601 } else {
602 174 ▶ $vfs->{cache}{$primary} ||= do {
Condition33%1/3
$vfs->{"cache"}{$primary} ||= do { $rest{"entns"} //= $vfs->{"entns"}; $vfs->fixup_created(\@_, $vfs->can("vfs_$kind")->()->new(%rest, "path", $primary, "type", $kind)) }
l!l&&r!l&&!r
01740
MC/DC0%0/2
$vfs->{"cache"}{$primary} ||= do { $rest{"entns"} //= $vfs->{"entns"}; $vfs->fixup_created(\@_, $vfs->can("vfs_$kind")->()->new(%rest, "path", $primary, "type", $kind)) }
$vfs->{"cache"}{$primary} do { $rest{"entns"} //= $vfs->{"entns"}; $vfs->fixup_created(\@_, $vfs->can("vfs_$kind")->()->new(%rest, "path", $primary, "type", $kind)) }
Truth table33%1/3
A ||= B
A= $vfs->{"cache"}{$primary}B= do { $rest{"entns"} //= $vfs->{"entns"}; $vfs->fixup_created(\@_, $vfs->can("vfs_$kind")->()->new(%rest, "path", $primary, "type", $kind)) }
ABresult
1X1
011
000
603 # XXX: Really??
604 174 ▶ $rest{entns} //= $vfs->{entns};
Condition66%2/3
$rest{"entns"} //= $vfs->{"entns"}
l!l&&r!l&&!r
140034
MC/DC50%1/2
$rest{"entns"} //= $vfs->{"entns"}
$rest{"entns"} $vfs->{"entns"}
Truth table66%2/3
A //= B
A= $rest{"entns"}B= $vfs->{"entns"}
ABresult
1X1
011
000
605 174 $vfs->fixup_created
606 (\@_, $vfs->can("vfs_$kind")->()->new(%rest, path => $primary
607 , type => $kind
608 ));
609 };
610 }
611 }
612 0 ▶ sub sorted_dump {
Subroutine sorted_dump: not called CC=1 SCAR=6.9
Pod undocumented
613 0 require Data::Dumper;
614 join ", ", map {
615 0 Data::Dumper->new([$_])->Maxdepth(2)->Terse(1)->Indent(0)
616 ->Sortkeys(1)->Dump;
617 } @_;
618 }
619 670 ▶ sub fixup_created {
Subroutine fixup_created: called CC=10 SCAR=23.3
Pod undocumented
620 670 (my VFS $vfs, my $info, my Folder $folder) = @_;
621 670 if (DEBUG_VFS) {
622 printf STDERR "# VFS::create(%s) => %s(0x%x)\n"
623 , sorted_dump(@{$info}[1..$#$info])
624 , ref $folder, ($folder+0);
625 } elsif (DEBUG_LOOKUP) {
626 print STDERR "# VFS: created: $folder (path="
627 , sorted_dump($folder->{path}), ")\n";
628 } else {
629 # XXX: This is required for perl 5.18 and before.
630 }
631 # create の直後、 after_create より前に、mark を打つ。そうしないと、 delegate で困る。
632 670 ▶ if (ref $vfs) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $vfs) 668 2 670
633 668 $vfs->{_n_creates}++;
634 668 $vfs->{mark}{refaddr($folder)}++;
635 }
636  
637 670 ▶ if (my $path = $folder->{path} and not defined $folder->{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = $folder->{"path"} and not defined $folder->{"name"}) 157 513 670
Condition100%3/3
my $path = $folder->{"path"} and not defined $folder->{"name"}
!ll&&!rl&&r
278235157
MC/DC100%2/2
my $path = $folder->{"path"} and not defined $folder->{"name"}
my $path = $folder->{"path"} not defined $folder->{"name"}
Truth table100%3/3
A and not(B)
A= my $path = $folder->{"path"}B= not defined $folder->{"name"}
ABresult
0X0
100
111
638 157 $path =~ s/\.\w+$//;
639 157 $path =~ s!.*/!!;
640 157 $folder->{name} = $path;
641 }
642  
643 670 ▶ if (my Folder $parent = $folder->{parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my YATT::Lite::VFS::Folder $parent = $folder->{"parent"}) 471 199 670
644 471 ▶ if (defined $parent->{entns}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent->{"entns"}) 450 21 471
645 $folder->{entns} = join '::'
646 450 , $parent->{entns}, $folder->{name};
647 # XXX: base 指定だけで済むべきだが、Factory を呼んでないので出来ないorz...
648 YATT::Lite::MFields->add_isa_to
649 450 ($folder->{entns}, $parent->{entns});
650 }
651 }
652 670 ▶ if ($folder->{entns}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($folder->{"entns"}) 624 46 670
653 624 ▶ if (not $vfs->{no_mro_c3}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vfs->{"no_mro_c3"}) 624 0 624
654 624 mro::set_mro($folder->{entns}, 'c3');
655 }
656 624 ▶ if (defined (my Folder $old = $vfs->{entns2vfs_item}{$folder->{entns}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my YATT::Lite::VFS::Folder $old = $vfs->{"entns2vfs_item"}{$folder->{"entns"}})) 0 624 624
657 0 ▶ if ($old != $folder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old != $folder) 0 0 0
658 0 croak "EntNS confliction for $folder->{entns}! old=$old->{path} vs new=$folder->{path}";
659 }
660 }
661 624 $vfs->{entns2vfs_item}{$folder->{entns}} = $folder;
662 }
663 670 $folder->after_create($vfs);
664 651 $folder;
665 }
666  
667 # XXX: <=> find_part_from_entns
668 3 ▶ sub find_template_from_package {
Subroutine find_template_from_package: called CC=1 SCAR=0.0
Pod undocumented
669 3 (my MY $self, my $pkg) = @_;
670 3 $self->{entns2vfs_item}{$pkg};
671 }
672  
673 278 ▶ sub create_data {
Subroutine create_data: called CC=2 SCAR=6.9
Pod undocumented
674 278 (my VFS $vfs, my ($primary)) = splice @_, 0, 2;
675 278 ▶ if (ref $primary) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $primary) { } 40 238 278
676 # 直接 Folder slot にデータを。
677 40 my vfs_dir $item = $vfs->vfs_dir->new(@_);
678 40 $item->{_Item} = $primary;
679 40 $item;
680 } else {
681 238 $vfs->vfs_file->new(public => 1, @_, string => $primary);
682 }
683 }
684  
685 #
686 # This converts all descriptors in Folder->base into real item objects.
687 #
688 194 ▶ sub YATT::Lite::VFS::Folder::vivify_base_descs {
Subroutine vivify_base_descs: called CC=5 SCAR=16.2
Pod undocumented
689 194 (my Folder $folder, my VFS $vfs) = @_;
690 194 foreach my Folder $desc (@{$folder->{base}}) {
691 40 ▶ if (ref $desc eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $desc eq "ARRAY") 40 0 40
692 #
693 # This $desc structure *may* come from Factory->_list_base_spec_in
694 #
695 40 ▶ if ($desc->[0] eq 'dir') {
Branch: 1 branch
BranchTrueFalseTotal
if ($desc->[0] eq 'dir') { } 36 4 40
696 # To create YATT::Lite with .htyattconfig.xhf, Factory should be involved.
697 36 $desc = $vfs->{facade}->find_neighbor($desc->[1]);
698 } else {
699 4 $desc = $vfs->create(@$desc);
700 }
701 }
702 # parent がある == parent から指されている。なので、 weaken する必要が有る。
703 40 ▶ weaken($desc) if $desc->{parent};
Branch: 1 branch
BranchTrueFalseTotal
if $desc->{"parent"} 0 40 40
704 }
705 }
706 194 ▶ sub YATT::Lite::VFS::Dir::after_create {
Subroutine after_create: called CC=1 SCAR=0.0
Pod undocumented
707 194 (my vfs_dir $dir, my VFS $vfs) = @_;
708 194 $dir->YATT::Lite::VFS::Folder::vivify_base_descs($vfs);
709 # $dir->refresh($vfs);
710 194 $dir;
711 }
712 # file 系は create 時に必ず refresh. refresh は decl のみ parse.
713 476 ▶ sub YATT::Lite::VFS::File::after_create {
Subroutine after_create: called CC=1 SCAR=0.0
Pod undocumented
714 476 (my vfs_file $file, my VFS $vfs) = @_;
715 476 $file->refresh_overlay($vfs);
716 476 $file->refresh($vfs);
717 }
718 476 ▶ sub YATT::Lite::VFS::File::refresh_overlay {
Subroutine refresh_overlay: called CC=6 SCAR=18.4
Pod undocumented
719 476 (my vfs_file $file, my VFS $vfs) = @_;
720 476 ▶ return if $file->{overlay};
Branch: 1 branch
BranchTrueFalseTotal
if $file->{"overlay"} 0 476 476
721 476 ▶ return unless $file->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless $file->{"path"} 238 238 476
722 238 my $rootname = rootname($file->{path});
723 238 my @found = grep {-d $$_[-1]} ([1, $rootname]
724 , [0, "$rootname.$vfs->{ext_private}"]);
725 238 ▶ if (@found > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@found > 1) { } 0 238 238
elsif (not @found) { } 237 1 238
726 $vfs->error(q|Don't use %1$s and %1$s.%2$s at once|
727 0 , $rootname, $vfs->{ext_private});
728 } elsif (not @found) {
729 237 return;
730 }
731 1 $file->{overlay} = do {
732 1 my ($public, $path) = @{$found[0]};
733 1 ▶ if ($public) {
Branch: 1 branch
BranchTrueFalseTotal
if ($public) { } 1 0 1
734 1 $vfs->{facade}->find_neighbor($path);
735 } else {
736 $vfs->create
737 0 (dir => $path, parent => $file->{parent});
738 }
739 };
740 }
741 #----------------------------------------
742 4 ▶ sub YATT::Lite::VFS::File::declare_base {
Subroutine declare_base: called CC=1 SCAR=0.0
Pod undocumented
743 4 (my vfs_file $file, my ($spec), my VFS $vfs, my $part) = @_;
744 4 my ($kind, $path) = split /=/, $spec, 2;
745 # XXX: 物理 path だと困るよね? findINC 的な処理が欲しい
746 # XXX: 帰属ディレクトリより強くするため、先頭に。でも、不満。
747 4 unshift @{$file->{base}}, $vfs->create($kind => $path);
748 4 weaken($file->{base}[0]);
749 4 $file->{_Item}{''} .= $part;
750 }
751 38 ▶ sub YATT::Lite::VFS::File::add_widget {
Subroutine add_widget: called CC=1 SCAR=0.0
Pod undocumented
752 38 (my vfs_file $file, my ($name, $part)) = @_;
753 38 push @{$file->{_partlist}}, $file->{_Item}{$name} = $part;
754 }
755  
756 189 ▶ sub linsert {
Subroutine linsert: called CC=2 SCAR=7.0
Pod undocumented
757 189 my @ls = @{shift()};
758 189 splice @ls, shift, 0, @_;
759 189 ▶ wantarray ? @ls : \@ls;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 189 0 189
760 }
761 }
762  
763 50 ▶use YATT::Lite::Breakpoint;
Subroutine BEGIN: called CC=1 SCAR=0.0
764 50 YATT::Lite::Breakpoint::break_load_vfs();
765  
766 50 1;
« blib/lib/YATT/Lite/Connection.pm ↑ Summary blib/lib/YATT/Lite/Test/XHFTest.pm »