blib/lib/YATT/Lite/Factory.pm

filter: Statementstmt 89.4% 575 / 643 Branchbran 69.8% 169 / 242 Conditioncond 59.6% 96 / 161 MC/DCmcdc 22.1% 21 / 95 Subroutinesub 93.5% 116 / 124 Podpod 9.5% 8 / 84 totaltotal 73.0% 985 / 1349 CC 188 SCAR 21.5
CC
188
Cov
80%
after_new
48.7
_list_base_spec_in
18.4
load_factory_for_psgi
17.4
CRAP 8.6
« blib/lib/YATT/Lite/LRXML/ParseEntpath.pm ↑ Summary blib/lib/YATT/Lite/PSGIEnv.pm »
1 package YATT::Lite::Factory;
2 72 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 72 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 72 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 72 ▶use YATT::Lite::Breakpoint;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 sub MY () {__PACKAGE__}
7 72 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 72 ▶use constant DEBUG_FACTORY => $ENV{DEBUG_YATT_FACTORY};
Subroutine BEGIN: called CC=1 SCAR=0.0
10 72 ▶use constant DEBUG_REFCNT => $ENV{DEBUG_YATT_REFCNT};
Subroutine BEGIN: called CC=1 SCAR=0.0
11 72 ▶use if DEBUG_REFCNT, B => qw/svref_2object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 72 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 72 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 72 ▶use Encode qw/decode/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 72 ▶use parent qw/File::Spec YATT::Lite::Site YATT::Lite::NSBuilder/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 72 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 72 ▶use File::Basename qw/dirname/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 72 ▶use YATT::Lite::PSGIEnv;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 #----------------------------------------
24  
25 # Subclass may override this to 0 to revert old behavior.
26 24 ▶sub use_sibling_config_dir { 1 }
Subroutine use_sibling_config_dir: called CC=1 SCAR=0.0
Pod undocumented
27  
28 #----------------------------------------
29  
30 # Note: Definition of default values are not yet gathered here.
31 # Some are in YATT::Lite, others are in YATT::Lite::Core, CGen.. and so on.
32  
33 use YATT::Lite::MFields
34 72 ▶([namespace =>
Subroutine BEGIN: called CC=1 SCAR=0.0
35 (doc => "namespace prefix for yatt. (default: [yatt, perl])")]
36  
37 , ["^doc_root" =>
38 (doc => "Primary template directory")]
39  
40 # Note: Don't confuse 'app_rootname' below with 'app_root'.
41 # 'app_root' is defined in YATT::Lite::Partial::AppPath.
42 #
43 , [app_rootname =>
44 (doc => "rootname() of app.psgi. Used to find app.site_config.yml")]
45  
46 , ["^app_base" =>
47 (doc => "Base template dir for all DirApps")]
48  
49 , ["^site_prefix" =>
50 (doc => "Location prefix for this siteapp")]
51  
52 , [index_name =>
53 (doc => "Rootname of index template. (default: index)")]
54  
55 , [ext_public =>
56 (doc => "public file extension for yatt. (default: yatt)")]
57  
58 , [ext_private =>
59 (doc => "hidden file extension for yatt. (default: ytmpl)")]
60  
61 , [header_charset =>
62 (doc => "Charset for outgoing HTTP Content-Type. (default: utf-8)")]
63  
64 , [tmpl_encoding =>
65 (doc => "Perl encoding used while reading yatt templates. (default: 'utf-8')")]
66  
67 , [output_encoding =>
68 (doc => "Perl encoding used for outgoing response body."
69 ." Also this is used to decode incoming request parameters and PATH_INFO."
70 ." (default: 'utf-8')")]
71  
72 , [render_as_bytes =>
73 (doc => "Force render() to return raw bytes. (default: false)")]
74  
75 , ["^offline" =>
76 (doc => "Whether header should be emitted or not.")]
77  
78 , [binary_config =>
79 (doc => "(This may be changed in future release) Whether .htyattconfig.* should be read with encoding or not.")]
80  
81 , [no_unicode =>
82 (doc => "(Compatibility option) Avoid use of utf8.")]
83  
84 , [no_unicode_params =>
85 (doc => "(Compatibility option) Avoid encoding conversion of input params.")]
86  
87 , [use_subpath =>
88 (doc => "pass sub-path_info")]
89  
90 , qw/
91 allow_missing_dir
92 no_preload_app_base
93  
94 _tmpldirs
95 _loc2yatt
96 _path2yatt
97  
98 _loc2psgi_re
99 _loc2psgi_dict
100  
101 _tmpl_cache
102  
103 _path2entns
104 _entns2vfs_item
105  
106 debug_cgen
107  
108 only_parse
109 config_filetypes
110  
111 dont_map_args
112 dont_debug_param
113 always_refresh_deps
114 no_mro_c3
115  
116 special_entities
117 default_lang
118 no_lineinfo
119 debug_parser
120 check_lineno
121  
122 _outer_psgi_app
123 _my_psgi_app
124  
125 match_argsroute_first
126 allow_bare_entity_in_decl
127 no_chdir
128 /
129 , [pagevars =>
130 (doc => "Package name of per-page compile-time constants (see YATT::Lite::PageConsts)")]
131 , [argmacro =>
132 (doc => "Map of argmacro name to Perl module which defines it, or list of such maps optionally paired with namespace like [[ns => {name => Module}], {...}] (see YATT::Lite::ArgMacro)")]
133 , [stash_unknown_params_to =>
134 (doc => "Stash unknown foreign parameters into this name. Set to 'yatt.unknown_params' when PLACK_ENV is *not* development.")]
135 , [body_argument =>
136 (doc => "Name of 'body' argument. (default: body)")]
137 , [body_argument_type =>
138 (doc => "Type of 'body' argument. (default: code)")]
139 , [prefer_call_for_entity =>
140 (doc => ":name is interpreted as call if appropriate")]
141 , [no_conditional_call =>
142 (doc => "Disable conditional call (if=/unless= in widget call arguments)")]
143 72 );
144  
145 72 ▶use YATT::Lite::Util::AsBase qw/-as_base import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
146 72 ▶use YATT::Lite::Util qw/lexpand globref untaint_any ckrequire dofile_in
Subroutine BEGIN: called CC=1 SCAR=0.0
147 lookup_dir fields_hash
148 lookup_path
149 trim_ext
150 secure_text_plain
151 psgi_error
152 psgi_text
153 globref_default
154 define_const
155 terse_dump
156 psgi_dump
157 raise_psgi_dump
158 raise_response
159 trimleft_length
160 get_entity_symbol
161 72 /;
162  
163 72 ▶use YATT::Lite::XHF ();
Subroutine BEGIN: called CC=1 SCAR=0.0
164  
165 72 ▶use YATT::Lite::Partial::ErrorReporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
166 72 ▶use YATT::Lite::Partial::AppPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
167  
168 72 ▶use YATT::Lite qw/Entity *SYS *YATT *CON/;
Subroutine BEGIN: called CC=1 SCAR=0.0
169 72 our @EXPORT_OK = qw/*CON/;
170  
171 72 ▶use YATT::Lite::Util::CycleDetector qw/Visits/;
Subroutine BEGIN: called CC=1 SCAR=0.0
172  
173 #========================================
174 #
175 #
176 #
177  
178 72 our $want_object;
179 20 ▶sub want_object { $want_object }
Subroutine want_object: called CC=1 SCAR=0.0
Pod undocumented
180  
181 4 ▶sub find_load_factory_script {
Subroutine find_load_factory_script: called CC=3 SCAR=11.2
Pod undocumented
182 4 my ($pack, %opts) = @_;
183 4 my $stop_at = delete $opts{stop_at};
184 my ($found) = $pack->find_factory_script(delete $opts{dir}
185 4 ▶ , stop_at => $stop_at)
Branch: 1 branch
BranchTrueFalseTotal
my($found) = $pack->find_factory_script(delete $opts{"dir"}, "stop_at", $stop_at) or return 4 0 4
186 or return;
187 4 ▶ my $self = $pack->load_factory_script($found)
Branch: 1 branch
BranchTrueFalseTotal
my $self = $pack->load_factory_script($found) or croak("Can't load YATT::Lite::Factory instance from $found") 4 0 4
188 or croak "Can't load YATT::Lite::Factory instance from $found";
189 4 $self->configure(%opts);
190 4 $self;
191 }
192  
193 2 ▶sub load_factory_offline {
Subroutine load_factory_offline: called CC=1 SCAR=0.0
Pod documented
194 2 shift->find_load_factory_script(offline => 1, @_);
195 }
196  
197 36 ▶sub configure_offline {
Subroutine configure_offline: called CC=2 SCAR=7.0
Pod undocumented
198 36 (my MY $self, my $value) = @_;
199 36 $self->{offline} = $value;
200 36 ▶ if ($self->{offline}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"offline"}) 36 0 36
201 9 ▶ $self->configure(error_handler => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
202 9 my ($type, $err) = @_;
203 9 die $err;
204 })
205 36 }
206 }
207  
208 #========================================
209  
210 #
211 # $class->create_factory_class($fresh_classname)
212 # Make $fresh_classname inherit Factory.
213 # Mainly for tests which create many factory classes in single run.
214 #
215 8 ▶sub create_factory_class {
Subroutine create_factory_class: called CC=1 SCAR=0.0
Pod undocumented
216 8 my ($pack, $factory_class) = @_;
217  
218 8 define_const(globref($factory_class, 'default_app_ns')
219 , $factory_class."::YATT");
220  
221 8 $pack->_import_as_base($factory_class);
222  
223 8 $factory_class;
224 }
225  
226 24 ▶sub load_factory_for_psgi {
Subroutine load_factory_for_psgi: called CC=14 SCAR=28.6
Pod documented
227 24 my ($pack, $psgi, %default) = @_;
228 24 ▶ unless (defined $psgi) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $psgi) 0 24 24
229 0 croak "Usage: Factory->load_factory_for_psgi(psgi_filename, \%opts)";
230 }
231 24 ▶ unless (-r $psgi) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $psgi) 0 24 24
232 0 croak "psgi is not readable: $psgi";
233 }
234 # GH-260: rel2abs does not collapse "..". Without normalization,
235 # "$app_root.config.d" built from ".../t/.." can never exist.
236 24 (my $app_rootname = YATT::Lite::Util::normalize_fs_path($pack->rel2abs($psgi)))
237 =~ s/\.psgi$//;
238  
239 24 ▶ $default{app_rootname} //= $app_rootname;
Condition33%1/3
$default{"app_rootname"} //= $app_rootname
l!l&&r!l&&!r
0240
MC/DC0%0/2
$default{"app_rootname"} //= $app_rootname
$default{"app_rootname"} $app_rootname
Truth table33%1/3
A //= B
A= $default{"app_rootname"}B= $app_rootname
ABresult
1X1
011
000
240  
241 #
242 # Assume app_root is safe.
243 #
244 24 my $app_root = untaint_any(dirname($app_rootname));
245 24 ▶ unless (-d $app_root) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $app_root) 0 24 24
246 0 croak "Can't find app_root for $psgi";
247 }
248  
249 24 ▶ $default{doc_root} ||= "$app_root/html";
Condition100%2/2
$default{"doc_root"} ||= "$app_root/html"
l!l
195
MC/DC100%1/1
$default{"doc_root"} ||= "$app_root/html"
$default{"doc_root"}
Truth table100%2/2
A
A= $default{"doc_root"}
Aresult
11
00
250 24 ▶ if (-d "$app_root/ytmpl") {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "$app_root/ytmpl") 3 21 24
251 3 ▶ $default{app_base} ||= '@ytmpl';
Condition100%2/2
$default{"app_base"} ||= "\@ytmpl"
l!l
21
MC/DC100%1/1
$default{"app_base"} ||= "\@ytmpl"
$default{"app_base"}
Truth table100%2/2
A
A= $default{"app_base"}
Aresult
11
00
252 }
253  
254 24 my $env = delete $default{environment};
255  
256 24 my (@cf) = $pack->list_app_config_files($app_root, File::Basename::basename($app_rootname));
257  
258 24 ▶ if (@cf and $env) {
Branch: 2 branches
BranchTrueFalseTotal
if (@cf and $env) { } 0 24 24
elsif (@cf > 1) { } 0 24 24
Condition66%2/3
@cf and $env
!ll&&!rl&&r
2130
MC/DC0%0/2
@cf and $env
@cf $env
Truth table66%2/3
A and B
A= @cfB= $env
ABresult
0X0
100
111
259 0 croak "Can't use environment and @cf at once!";
260 } elsif (@cf > 1) {
261 0 croak "Multiple configuration files!: @cf";
262 }
263  
264 24 ▶ if ($env) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env) 1 23 24
265 1 my $config = $pack->config_for_env($app_root, $env);
266 1 ▶ return $pack->_with_loading_file($config, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
267 1 $pack->new(app_root => $app_root, %default
268 , $pack->load_config($config));
269 1 });
270 }
271  
272 23 my MY $self = do {
273 23 ▶ if (@cf) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cf) { } 3 20 23
274 3 ▶ $pack->_with_loading_file($cf[0], sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
275 3 $pack->new(app_root => $app_root, %default
276 , $pack->read_file($cf[0]));
277 })
278 3 } else {
279 20 $pack->new(app_root => $app_root, %default);
280 }
281 };
282  
283 23 ▶ unless ($self->{__after_new_is_called__}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__after_new_is_called__"}) 0 23 23
284 0 Carp::croak("after_new is not called correctly!");
285 }
286  
287 23 $self;
288 }
289  
290 24 ▶sub list_app_config_files {
Subroutine list_app_config_files: called CC=4 SCAR=14.0
Pod undocumented
291 24 my ($pack, $app_root, $app_base) = @_;
292  
293 # When psgi is at $app_root/app.psgi,
294 # test $app_root.config.d/app.{xhf,yml} and return them if exists.
295 # Otherwise list $app_root/app.{xhf,yml}.
296  
297 24 ▶ if ($pack->use_sibling_config_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pack->use_sibling_config_dir) 24 0 24
298 24 my $sibling_config_dir = "$app_root.config.d";
299 24 ▶ if (-d $sibling_config_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $sibling_config_dir) 2 22 24
300 2 my @cf = $pack->list_config_files("$sibling_config_dir/$app_base");
301 2 ▶ return @cf if @cf;
Branch: 1 branch
BranchTrueFalseTotal
if @cf 2 0 2
302 }
303 }
304  
305 22 $pack->list_config_files("$app_root/$app_base");
306 }
307  
308 #
309 # Load Amon2 style config.pl
310 #
311 1 ▶sub config_for_env {
Subroutine config_for_env: called CC=1 SCAR=0.0
Pod undocumented
312 1 my ($pack, $app_root, $environment) = @_;
313 1 "$app_root/config/$environment.pl";
314 }
315  
316 1 ▶sub load_config {
Subroutine load_config: called CC=4 SCAR=15.9
Pod undocumented
317 1 my ($pack, $cf) = @_;
318 1 my $config = dofile_in($pack, $cf);
319 1 ▶ unless (defined $config) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $config) 0 1 1
320 0 croak "config script '$cf' returned undef!";
321 }
322 1 ▶ unless (ref $config eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $config eq "HASH") 0 1 1
323 0 croak "config script '$cf' doesn't return HASH! $config";
324 }
325 1 ▶ wantarray ? %$config : $config;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
326 }
327  
328 #========================================
329  
330 72 my ($_n_created, $_n_destroyed);
331 1 ▶sub n_created {$_n_created}
Subroutine n_created: called CC=1 SCAR=0.0
Pod undocumented
332 1 ▶sub n_destroyed {$_n_destroyed}
Subroutine n_destroyed: called CC=1 SCAR=0.0
Pod undocumented
333 {
334 72 our %sub2self;
335 176 ▶ DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.2
336 176 (my MY $self) = @_;
337 176 if (DEBUG_FACTORY) {
338 if (DEBUG_REFCNT) {
339 printf STDERR "# DESTROY %s refcnt=%d\n", $self, svref_2object($self)->REFCNT;
340 } else {
341 print STDERR "# DESTROY $self\n";
342 }
343 }
344 176 delete $self->{_my_psgi_app};
345 176 ▶ if (my $outer = delete $self->{_outer_psgi_app}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $outer = delete $self->{"_outer_psgi_app"}) 0 176 176
346 0 delete $sub2self{$outer};
347 }
348 176 ++$_n_destroyed;
349 };
350 0 ▶ sub to_app_and_forget {
Subroutine to_app_and_forget: not called CC=1 SCAR=6.9
Pod undocumented
351 0 (my MY $self) = @_;
352 0 my $sub = $self->to_app;
353 0 delete $self->{_my_psgi_app};
354 0 delete $self->{_outer_psgi_app};
355 0 delete $sub2self{$sub};
356 0 $sub;
357 }
358 86 ▶ sub to_app {
Subroutine to_app: called CC=5 SCAR=16.4
Pod undocumented
359 86 (my MY $self) = @_;
360 86 ▶ if (@_ >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2) 0 86 86
361 0 croak "cascade support is dropped.Use wrapped_by(builder {}) instead.";
362 }
363 86 ▶ $self->{_outer_psgi_app} // do {
Condition33%1/3
$self->{"_outer_psgi_app"} // do { if (my $old = delete $self->{"_my_psgi_app"}) { delete $YATT::Lite::Factory::sub2self{$old}; } ; $self->prepare_app; my $sub = sub { $self->call(@_); } ; $self->{"_my_psgi_app"} = $sub; builtin::weaken($self->{"_my_psgi_app"}) unless $YATT::Lite::Factory::want_object; builtin::weaken($YATT::Lite::Factory::sub2self{$sub} = $self); '???'; $sub }
l!l&&r!l&&!r
0860
MC/DC0%0/2
$self->{"_outer_psgi_app"} // do { if (my $old = delete $self->{"_my_psgi_app"}) { delete $YATT::Lite::Factory::sub2self{$old}; } ; $self->prepare_app; my $sub = sub { $self->call(@_); } ; $self->{"_my_psgi_app"} = $sub; builtin::weaken($self->{"_my_psgi_app"}) unless $YATT::Lite::Factory::want_object; builtin::weaken($YATT::Lite::Factory::sub2self{$sub} = $self); '???'; $sub }
$self->{"_outer_psgi_app"} do { if (my $old = delete $self->{"_my_psgi_app"}) { delete $YATT::Lite::Factory::sub2self{$old}; } ; $self->prepare_app; my $sub = sub { $self->call(@_); } ; $self->{"_my_psgi_app"} = $sub; builtin::weaken($self->{"_my_psgi_app"}) unless $YATT::Lite::Factory::want_object; builtin::weaken($YATT::Lite::Factory::sub2self{$sub} = $self); '???'; $sub }
Truth table33%1/3
A // B
A= $self->{"_outer_psgi_app"}B= do { if (my $old = delete $self->{"_my_psgi_app"}) { delete $YATT::Lite::Factory::sub2self{$old}; } ; $self->prepare_app; my $sub = sub { $self->call(@_); } ; $self->{"_my_psgi_app"} = $sub; builtin::weaken($self->{"_my_psgi_app"}) unless $YATT::Lite::Factory::want_object; builtin::weaken($YATT::Lite::Factory::sub2self{$sub} = $self); '???'; $sub }
ABresult
1X1
011
000
364 86 ▶ if (my $old = delete $self->{_my_psgi_app}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $old = delete $self->{"_my_psgi_app"}) 3 83 86
365 3 delete $sub2self{$old};
366 }
367 86 $self->prepare_app;
368 86 ▶ my $sub = sub { $self->call(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
369 86 $self->{_my_psgi_app} = $sub;
370 86 ▶ weaken($self->{_my_psgi_app}) if not $want_object;
Branch: 1 branch
BranchTrueFalseTotal
unless $YATT::Lite::Factory::want_object 77 9 86
371 86 weaken($sub2self{$sub} = $self);
372 86 print STDERR "to_app($self) returned $sub\n" if DEBUG_FACTORY;
373 86 $sub;
374 };
375 }
376 6 ▶ sub wrapped_by {
Subroutine wrapped_by: called CC=3 SCAR=11.3
Pod undocumented
377 6 my ($self, $outer_app) = @_;
378 6 ▶ unless ($self->{_my_psgi_app}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_my_psgi_app"}) 0 6 6
379 0 croak "wrapped_by is called without calling Site->to_app";
380 }
381 6 delete $sub2self{$self->{_my_psgi_app}};
382 6 $self->{_outer_psgi_app} = $outer_app;
383 6 $sub2self{$outer_app} = $self;
384 6 ▶ weaken($self->{_outer_psgi_app}) if not $want_object;
Branch: 1 branch
BranchTrueFalseTotal
unless $YATT::Lite::Factory::want_object 6 0 6
385 6 weaken($sub2self{$outer_app});
386 6 $outer_app;
387 }
388 28 ▶ sub load_psgi_script {
Subroutine load_psgi_script: called CC=4 SCAR=14.6
Pod undocumented
389 28 my ($pack, $fn) = @_;
390 28 local $want_object = 1;
391 28 local $0 = $fn;
392 28 my $sub = $pack->sandbox_dofile($fn);
393 27 ▶ if (ref $sub eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $sub eq 'CODE') { } 8 19 27
elsif ($sub->isa($pack) or $sub->isa('YATT::Lite::Factory')) { } 19 0 19
394 8 $sub2self{$sub};
395 ▶ } elsif ($sub->isa($pack) or $sub->isa(MY)) {
Condition33%1/3
$sub->isa($pack) or $sub->isa("YATT::Lite::Factory")
l!l&&r!l&&!r
1900
MC/DC0%0/2
$sub->isa($pack) or $sub->isa("YATT::Lite::Factory")
$sub->isa($pack) $sub->isa("YATT::Lite::Factory")
Truth table33%1/3
A or B
A= $sub->isa($pack)B= $sub->isa("YATT::Lite::Factory")
ABresult
1X1
011
000
396 19 $sub;
397 } else {
398 0 die "Unknown load result from: $fn";
399 }
400 }
401 88 ▶ sub prepare_app {
Subroutine prepare_app: called CC=1 SCAR=0.0
Pod undocumented
402 88 (my MY $self) = shift;
403 88 $self->maybe::next::method(@_);
404 }
405 204 ▶ sub prepare_deployment {
Subroutine prepare_deployment: called CC=2 SCAR=7.6
Pod undocumented
406 204 (my MY $self) = shift;
407 204 $self->maybe::next::method(@_);
408 $self->{stash_unknown_params_to}
409 204 ▶ //= $self->default_stash_unknown_params_to;
Condition33%1/3
$self->{"stash_unknown_params_to"} //= $self->default_stash_unknown_params_to
l!l&&r!l&&!r
02040
MC/DC0%0/2
$self->{"stash_unknown_params_to"} //= $self->default_stash_unknown_params_to
$self->{"stash_unknown_params_to"} $self->default_stash_unknown_params_to
Truth table33%1/3
A //= B
A= $self->{"stash_unknown_params_to"}B= $self->default_stash_unknown_params_to
ABresult
1X1
011
000
410 }
411 386 ▶ sub finalize_response { shift->maybe::next::method(@_) }
Subroutine finalize_response: called CC=1 SCAR=0.0
Pod undocumented
412  
413 72 our $load_count;
414 28 ▶ sub sandbox_dofile {
Subroutine sandbox_dofile: called CC=4 SCAR=14.3
Pod undocumented
415 28 my ($pack, $file) = @_;
416 28 my $sandbox = sprintf "%s::Sandbox::S%d", __PACKAGE__, ++$load_count;
417 28 my @__result__;
418 28 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 28 28
419 0 @__result__ = dofile_in($sandbox, $file);
420 } else {
421 28 $__result__[0] = dofile_in($sandbox, $file);
422 }
423 27 my $sym = globref($sandbox, 'filename');
424 27 ▶ unless (*{$sym}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (*{$sym;}{"CODE"}) 27 0 27
425 27 ▶ *$sym = sub {$file};
Subroutine __ANON__: called CC=1 SCAR=0.0
426 }
427 27 ▶ wantarray ? @__result__ : $__result__[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 27 27
428 }
429 }
430  
431 72 ▶sub load_factory_script {
Subroutine load_factory_script: called CC=6 SCAR=18.1
Pod undocumented
432 28 my ($pack, $fn) = @_;
433 28 my %was_loaded = map {$_ => 1} keys %INC;
434 28 my $result = eval {
435 28 local $want_object = 1;
436 28 local $0 = $fn;
437 28 local ($FindBin::Bin, $FindBin::Script
438 , $FindBin::RealBin, $FindBin::RealScript);
439 28 ▶ FindBin->again if FindBin->can("again");
Branch: 1 branch
BranchTrueFalseTotal
if "FindBin"->can("again") 28 0 28
440 28 ▶ if ($fn =~ /\.psgi$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fn =~ /\.psgi$/) { } 28 0 28
441 28 $pack->load_psgi_script($fn);
442 } else {
443 0 $pack->sandbox_dofile($fn);
444 }
445 };
446 28 my $err = $@;
447 # アプリが lib/ に同梱した YATT::Lite が、読み込み中の YATT::Lite と
448 # 混ざると、原因の分からないエラーになるので、先に報告する (GH-301)
449 28 ▶ if (my @mixed = $pack->list_mixed_yatt_lib(\%was_loaded)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@mixed) = $pack->list_mixed_yatt_lib(\%was_loaded)) 2 26 28
450 die join("", "Mixed YATT::Lite library roots while loading $fn.\n"
451 , "Running YATT::Lite is from ", $pack->yatt_lib_root, ", but:\n"
452 2 ▶ , map({" $_->[0] from $_->[1]\n"} @mixed)
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 1 1 2
453 , "The app may bundle another YATT::Lite in its library path.\n"
454 , $err ? "Original error: $err" : ());
455 }
456 26 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 26 26
457 26 $result;
458 }
459  
460 # YATT/Lite/Factory.pm (この file) を読み込んだ library root
461 30 ▶sub yatt_lib_root {
Subroutine yatt_lib_root: called CC=1 SCAR=0.0
Pod undocumented
462 30 _inc_root('YATT/Lite/Factory.pm');
463 }
464  
465 # $was_loaded に無い (=新たに読み込まれた) YATT::Lite の module のうち、
466 # yatt_lib_root と違う root から読まれ、しかも yatt_lib_root にも同じ
467 # module が有るもの (=別版で上書きされたもの) を [$key, $root] で返す。
468 # アプリ独自の YATT::Lite::* module は対象外。
469 28 ▶sub list_mixed_yatt_lib {
Subroutine list_mixed_yatt_lib: called CC=7 SCAR=19.5
Pod undocumented
470 28 my ($pack, $was_loaded) = @_;
471 28 ▶ my $root = $pack->yatt_lib_root // return;
Condition50%1/2
$pack->yatt_lib_root // (return)
l!l
280
MC/DC0%0/1
$pack->yatt_lib_root // (return)
$pack->yatt_lib_root
Truth table50%1/2
A
A= $pack->yatt_lib_root
Aresult
11
00
472 map {
473 124 my $r = _inc_root($_);
474 124 ▶ (defined $r and $r ne $root and -e "$root/$_") ? [$_, $r] : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $r && $r ne $root && -e "$root/$_" ? : 2 122 124
Condition100%6/6
defined $r and $r ne $root and -e "$root/$_"
!ll&&!rl&&r
12112
defined $r and $r ne $root
!ll&&!rl&&r
52693
MC/DC100%3/3
defined $r and $r ne $root and -e "$root/$_"
defined $r $r ne $root -e "$root/$_"
Truth table100%4/4
A and B and C
A= defined $rB= $r ne $rootC= -e "$root/$_"
ABCresult
0XX0
10X0
1100
1111
475 } grep {
476 28 ▶ m{^YATT/Lite[/.]} and not ($was_loaded and $was_loaded->{$_})
Condition83%5/6
m[^YATT/Lite[/.]] && !($was_loaded && $was_loaded->{$_})
!ll&&!rl&&r
51431571124
$was_loaded && $was_loaded->{$_}
!ll&&!rl&&r
01241571
MC/DC66%2/3
m[^YATT/Lite[/.]] && !($was_loaded && $was_loaded->{$_})
m[^YATT/Lite[/.]] $was_loaded $was_loaded->{$_}
Truth table75%3/4
A && not(B && C)
A= m[^YATT/Lite[/.]]B= $was_loadedC= $was_loaded->{$_}
ABCresult
0XX0
1110
10X1
1101
477 } sort keys %INC;
478 }
479  
480 # %INC の値から $key を取り除いた root。$INC{$key} = 1 のような
481 # 手で登録されたものは undef
482 154 ▶sub _inc_root {
Subroutine _inc_root: called CC=5 SCAR=17.5
483 154 my ($key) = @_;
484 154 my $path = $INC{$key};
485 154 ▶ return undef unless defined $path and not ref $path
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path and not ref $path and $path =~ s[/\Q$key\E\z][] 52 102 154
Condition50%3/6
defined $path and not ref $path and $path =~ s[/\Q$key\E\z][]
!ll&&!rl&&r
052102
defined $path and not ref $path
!ll&&!rl&&r
00154
MC/DC33%1/3
defined $path and not ref $path and $path =~ s[/\Q$key\E\z][]
defined $path not ref $path $path =~ s[/\Q$key\E\z][]
Truth table50%2/4
A and not(B) and C
A= defined $pathB= not ref $pathC= $path =~ s[/\Q$key\E\z][]
ABCresult
0XX0
10X0
1100
1111
486 and $path =~ s{/\Q$key\E\z}{};
487 102 require Cwd;
488 102 ▶ Cwd::realpath($path) // $path;
Condition33%1/3
Cwd::realpath($path) // $path
l!l&&r!l&&!r
10200
MC/DC0%0/2
Cwd::realpath($path) // $path
Cwd::realpath($path) $path
Truth table33%1/3
A // B
A= Cwd::realpath($path)B= $path
ABresult
1X1
011
000
489 }
490  
491 #
492 # find_factory_script($dir, %opts): search runyatt.psgi / app.psgi
493 # upward from $dir. With stop_at => $boundary the search never leaves
494 # $boundary (compared by realpath, so symlinked workspaces behave), and
495 # returns nothing instead. Tools working from their own cwd leave it
496 # unset; the language server sets it to the workspace root the client
497 # named, so a script planted above the workspace is never executed.
498 #
499 112 ▶sub find_factory_script {
Subroutine find_factory_script: called CC=8 SCAR=20.8
Pod undocumented
500 112 my $pack = shift;
501 112 my ($start, %opts) = @_;
502 112 ▶ my $dir = $pack->rel2abs($start // $pack->curdir);
Condition66%2/3
$start // $pack->curdir
l!l&&r!l&&!r
11110
MC/DC0%0/2
$start // $pack->curdir
$start $pack->curdir
Truth table66%2/3
A // B
A= $startB= $pack->curdir
ABresult
1X1
011
000
503 my $boundary = defined $opts{stop_at}
504 112 ▶ ? $pack->_canonical_dir($opts{stop_at}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $opts{'stop_at'} ? : 15 97 112
505 112 my @path = $pack->no_upwards($pack->splitdir($dir));
506 112 my $rootdir = $pack->rootdir;
507 112 ▶ while (@path and length($dir = $pack->catdir(@path)) > length($rootdir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path and length($dir = $pack->catdir(@path)) > length $rootdir) 279 33 312
Condition66%2/3
@path and length($dir = $pack->catdir(@path)) > length $rootdir
!ll&&!rl&&r
033279
MC/DC50%1/2
@path and length($dir = $pack->catdir(@path)) > length $rootdir
@path length($dir = $pack->catdir(@path)) > length $rootdir
Truth table66%2/3
A and B
A= @pathB= length($dir = $pack->catdir(@path)) > length $rootdir
ABresult
0X0
100
111
508 279 ▶ if (defined $boundary and not $pack->_dir_is_within($dir, $boundary)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $boundary and not $pack->_dir_is_within($dir, $boundary)) 9 270 279
Condition100%3/3
defined $boundary and not $pack->_dir_is_within($dir, $boundary)
!ll&&!rl&&r
242289
MC/DC100%2/2
defined $boundary and not $pack->_dir_is_within($dir, $boundary)
defined $boundary not $pack->_dir_is_within($dir, $boundary)
Truth table100%3/3
A and not(B)
A= defined $boundaryB= not $pack->_dir_is_within($dir, $boundary)
ABresult
0X0
100
111
509 9 return;
510 }
511 270 ▶ if (my ($found) = grep {-r} map {"$dir/$_.psgi"} qw(runyatt app)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($found) = grep({-r $_;} map({"$dir/$_.psgi";} "runyatt", "app"))) 70 200 270
512 70 return $found;
513 }
514 200 } continue { pop @path }
515 33 return;
516 }
517  
518 52 ▶sub _canonical_dir {
Subroutine _canonical_dir: called CC=2 SCAR=7.0
519 52 my ($pack, $dir) = @_;
520 52 require Cwd;
521 52 my $abs = $pack->rel2abs($dir);
522 52 ▶ Cwd::realpath($abs) // $abs;
Condition66%2/3
Cwd::realpath($abs) // $abs
l!l&&r!l&&!r
5110
MC/DC0%0/2
Cwd::realpath($abs) // $abs
Cwd::realpath($abs) $abs
Truth table66%2/3
A // B
A= Cwd::realpath($abs)B= $abs
ABresult
1X1
011
000
523 }
524  
525 37 ▶sub _dir_is_within {
Subroutine _dir_is_within: called CC=3 SCAR=11.0
526 37 my ($pack, $dir, $boundary) = @_;
527 37 my $real = $pack->_canonical_dir($dir);
528 37 ▶ return 1 if $boundary eq $pack->rootdir;
Branch: 1 branch
BranchTrueFalseTotal
if $boundary eq $pack->rootdir 0 37 37
529 37 ▶ $real eq $boundary or index($real, "$boundary/") == 0;
Branch: 1 branch
BranchTrueFalseTotal
$real eq $boundary or index($real, "$boundary/") == 0 14 23 37
530 }
531  
532 #========================================
533 # `use Factory -as_base` in app.psgi will come here.
534 #
535 44 ▶sub _import_as_base {
Subroutine _import_as_base: called CC=1 SCAR=0.0
536 44 my ($myPack, $callpack) = @_;
537 44 $myPack->SUPER::_import_as_base($callpack);
538 # To define EntNS in $callpack and set $myPack to @{$callpack::ISA}.
539 44 $myPack->default_default_app->define_Entity(undef, $callpack);
540 }
541  
542 # Just to allow writing `use Factory -Entity;` in your app.psgi.
543 # Not actually required.
544 0 ▶sub _import_Entity {
Subroutine _import_Entity: not called CC=1 SCAR=6.9
545 0 my ($myPack, $callpack) = @_;
546 0 $myPack->default_default_app->define_Entity(undef, $callpack);
547 }
548  
549 #========================================
550  
551 208 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
552 208 my ($class) = shift;
553 208 my MY $self = $class->SUPER::new(@_);
554 200 ▶ $self->preload_app_base unless $self->{no_preload_app_base};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"no_preload_app_base"} 200 0 200
555 200 ++$_n_created;
556 200 $self;
557 }
558  
559 #
560 # preload app_base (to avoid potential double-loading bug for base loading)
561 #
562 200 ▶sub preload_app_base {
Subroutine preload_app_base: called CC=3 SCAR=11.0
Pod undocumented
563 200 (my MY $self) = @_;
564  
565 200 foreach my $dir (lexpand($self->{app_base})) {
566 31 ▶ next if $dir =~ m{^::};
Branch: 1 branch
BranchTrueFalseTotal
if $dir =~ /^::/ 2 29 31
567 29 $self->load_yatt($self->app_path_expand($dir));
568 }
569 }
570  
571 208 ▶sub init_app_ns {
Subroutine init_app_ns: called CC=1 SCAR=0.0
Pod undocumented
572 208 (my MY $self) = @_;
573 208 $self->SUPER::init_app_ns;
574  
575 # EntNS is initialized here.
576 # Note: CGEN_perl is not initialized here and delayed until it is required.
577 # This helps to avoid loading CGen::Perl for *.ydo in CGI.
578 208 $self->{_default_app}->ensure_entns($self->{_app_ns});
579 }
580  
581 208 ▶sub after_new {
Subroutine after_new: called CC=21 SCAR=38.9
Pod documented
582 208 (my MY $self) = @_;
583 208 $self->SUPER::after_new;
584 208 ▶ $self->{app_root} //= YATT::Lite::Util::maybe_findbin_bin();
Condition66%2/3
$self->{"app_root"} //= YATT::Lite::Util::maybe_findbin_bin()
l!l&&r!l&&!r
20170
MC/DC0%0/2
$self->{"app_root"} //= YATT::Lite::Util::maybe_findbin_bin()
$self->{"app_root"} YATT::Lite::Util::maybe_findbin_bin()
Truth table66%2/3
A //= B
A= $self->{"app_root"}B= YATT::Lite::Util::maybe_findbin_bin()
ABresult
1X1
011
000
585 208 ▶ if (defined $self->{app_root}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"app_root"}) 208 0 208
586 208 $self->{app_root} = YATT::Lite::Util::normalize_fs_path($self->{app_root});
587 }
588 208 ▶ $self->{index_name} //= $self->default_index_name;
Condition33%1/3
$self->{"index_name"} //= $self->default_index_name
l!l&&r!l&&!r
02080
MC/DC0%0/2
$self->{"index_name"} //= $self->default_index_name
$self->{"index_name"} $self->default_index_name
Truth table33%1/3
A //= B
A= $self->{"index_name"}B= $self->default_index_name
ABresult
1X1
011
000
589 208 ▶ $self->{ext_public} //= $self->default_ext_public;
Condition66%2/3
$self->{"ext_public"} //= $self->default_ext_public
l!l&&r!l&&!r
22060
MC/DC0%0/2
$self->{"ext_public"} //= $self->default_ext_public
$self->{"ext_public"} $self->default_ext_public
Truth table66%2/3
A //= B
A= $self->{"ext_public"}B= $self->default_ext_public
ABresult
1X1
011
000
590 208 ▶ $self->{ext_private} //= $self->default_ext_private;
Condition33%1/3
$self->{"ext_private"} //= $self->default_ext_private
l!l&&r!l&&!r
02080
MC/DC0%0/2
$self->{"ext_private"} //= $self->default_ext_private
$self->{"ext_private"} $self->default_ext_private
Truth table33%1/3
A //= B
A= $self->{"ext_private"}B= $self->default_ext_private
ABresult
1X1
011
000
591 208 ▶ if ($self->{no_unicode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'no_unicode'}) { } 0 208 208
592 0 $self->{no_unicode_params} = 1;
593 0 $self->{binary_config} = 1;
594 $self->{header_charset}
595 0 ▶ //= ($self->{output_encoding} || $self->default_header_charset);
Condition0%0/6
$self->{"header_charset"} //= $self->{"output_encoding"} || $self->default_header_charset
l!l&&r!l&&!r
000
$self->{'output_encoding'} || $self->default_header_charset
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{"header_charset"} //= $self->{"output_encoding"} || $self->default_header_charset
$self->{"header_charset"} $self->{'output_encoding'} $self->default_header_charset
Truth table0%0/4
A //= B || C
A= $self->{"header_charset"}B= $self->{'output_encoding'}C= $self->default_header_charset
ABCresult
1XX1
01X1
0011
0000
596 $self->{output_encoding}
597 0 ▶ //= $self->compat_default_output_encoding;
Condition0%0/3
$self->{"output_encoding"} //= $self->compat_default_output_encoding
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"output_encoding"} //= $self->compat_default_output_encoding
$self->{"output_encoding"} $self->compat_default_output_encoding
Truth table0%0/3
A //= B
A= $self->{"output_encoding"}B= $self->compat_default_output_encoding
ABresult
1X1
011
000
598 0 $self->{render_as_bytes} = 1;
599 } else {
600 $self->{header_charset}
601 208 ▶ //= ($self->{output_encoding} // $self->default_header_charset);
Condition66%4/6
$self->{"header_charset"} //= $self->{"output_encoding"} // $self->default_header_charset
l!l&&r!l&&!r
291790
$self->{"output_encoding"} // $self->default_header_charset
l!l&&r!l&&!r
11780
MC/DC0%0/3
$self->{"header_charset"} //= $self->{"output_encoding"} // $self->default_header_charset
$self->{"header_charset"} $self->{"output_encoding"} $self->default_header_charset
Truth table0%0/4
A //= B // C
A= $self->{"header_charset"}B= $self->{"output_encoding"}C= $self->default_header_charset
ABCresult
1XX1
01X1
0011
0000
602 $self->{tmpl_encoding}
603 208 ▶ //= ($self->{output_encoding} // $self->default_tmpl_encoding);
Condition66%4/6
$self->{"tmpl_encoding"} //= $self->{"output_encoding"} // $self->default_tmpl_encoding
l!l&&r!l&&!r
271810
$self->{"output_encoding"} // $self->default_tmpl_encoding
l!l&&r!l&&!r
11800
MC/DC0%0/3
$self->{"tmpl_encoding"} //= $self->{"output_encoding"} // $self->default_tmpl_encoding
$self->{"tmpl_encoding"} $self->{"output_encoding"} $self->default_tmpl_encoding
Truth table0%0/4
A //= B // C
A= $self->{"tmpl_encoding"}B= $self->{"output_encoding"}C= $self->default_tmpl_encoding
ABCresult
1XX1
01X1
0011
0000
604 208 ▶ $self->{output_encoding} //= $self->default_output_encoding;
Condition66%2/3
$self->{"output_encoding"} //= $self->default_output_encoding
l!l&&r!l&&!r
281800
MC/DC0%0/2
$self->{"output_encoding"} //= $self->default_output_encoding
$self->{"output_encoding"} $self->default_output_encoding
Truth table66%2/3
A //= B
A= $self->{"output_encoding"}B= $self->default_output_encoding
ABresult
1X1
011
000
605 }
606 208 ▶ $self->{use_subpath} //= 1;
Condition100%2/2
$self->{"use_subpath"} //= 1
l!l
2206
MC/DC100%1/1
$self->{"use_subpath"} //= 1
$self->{"use_subpath"}
Truth table100%2/2
A
A= $self->{"use_subpath"}
Aresult
11
00
607  
608 208 ▶ $self->{always_refresh_deps} //= $self->default_always_refresh_deps;
Condition66%2/3
$self->{"always_refresh_deps"} //= $self->default_always_refresh_deps
l!l&&r!l&&!r
32050
MC/DC0%0/2
$self->{"always_refresh_deps"} //= $self->default_always_refresh_deps
$self->{"always_refresh_deps"} $self->default_always_refresh_deps
Truth table66%2/3
A //= B
A= $self->{"always_refresh_deps"}B= $self->default_always_refresh_deps
ABresult
1X1
011
000
609  
610 208 ▶ $self->{body_argument} //= $self->default_body_argument;
Condition33%1/3
$self->{"body_argument"} //= $self->default_body_argument
l!l&&r!l&&!r
02080
MC/DC0%0/2
$self->{"body_argument"} //= $self->default_body_argument
$self->{"body_argument"} $self->default_body_argument
Truth table33%1/3
A //= B
A= $self->{"body_argument"}B= $self->default_body_argument
ABresult
1X1
011
000
611 208 ▶ $self->{body_argument_type} //= $self->default_body_argument_type;
Condition66%2/3
$self->{"body_argument_type"} //= $self->default_body_argument_type
l!l&&r!l&&!r
12070
MC/DC0%0/2
$self->{"body_argument_type"} //= $self->default_body_argument_type
$self->{"body_argument_type"} $self->default_body_argument_type
Truth table66%2/3
A //= B
A= $self->{"body_argument_type"}B= $self->default_body_argument_type
ABresult
1X1
011
000
612  
613 # prepare_app is too late to set delegated params
614 208 ▶ if (($ENV{PLACK_ENV} // '') ne 'development') {
Branch: 1 branch
BranchTrueFalseTotal
if (($ENV{"PLACK_ENV"} // "") ne "development") 204 4 208
Condition100%2/2
$ENV{"PLACK_ENV"} // ""
l!l
10198
MC/DC100%1/1
$ENV{"PLACK_ENV"} // ""
$ENV{"PLACK_ENV"}
Truth table100%2/2
A
A= $ENV{"PLACK_ENV"}
Aresult
11
00
615 204 $self->prepare_deployment;
616 }
617 }
618  
619 0 ▶sub compat_default_output_encoding { '' }
Subroutine compat_default_output_encoding: not called CC=1 SCAR=6.9
Pod undocumented
620 180 ▶sub default_output_encoding { 'utf-8' }
Subroutine default_output_encoding: called CC=1 SCAR=0.0
Pod undocumented
621 178 ▶sub default_header_charset { 'utf-8' }
Subroutine default_header_charset: called CC=1 SCAR=0.0
Pod undocumented
622 180 ▶sub default_tmpl_encoding { 'utf-8' }
Subroutine default_tmpl_encoding: called CC=1 SCAR=0.0
Pod undocumented
623 208 ▶sub default_index_name { 'index' }
Subroutine default_index_name: called CC=1 SCAR=0.0
Pod undocumented
624 206 ▶sub default_ext_public {'yatt'}
Subroutine default_ext_public: called CC=1 SCAR=0.0
Pod undocumented
625 208 ▶sub default_ext_private {'ytmpl'}
Subroutine default_ext_private: called CC=1 SCAR=0.0
Pod undocumented
626 204 ▶sub default_stash_unknown_params_to {'yatt.unknown_params'}
Subroutine default_stash_unknown_params_to: called CC=1 SCAR=0.0
Pod undocumented
627 205 ▶sub default_always_refresh_deps { 1 }
Subroutine default_always_refresh_deps: called CC=1 SCAR=0.0
Pod undocumented
628  
629 208 ▶sub default_body_argument { 'body' }
Subroutine default_body_argument: called CC=1 SCAR=0.0
Pod undocumented
630 207 ▶sub default_body_argument_type { 'code' }
Subroutine default_body_argument_type: called CC=1 SCAR=0.0
Pod undocumented
631  
632 201 ▶sub _after_after_new {
Subroutine _after_after_new: called CC=8 SCAR=20.9
633 201 (my MY $self) = @_;
634 201 $self->SUPER::_after_after_new;
635  
636 201 ▶ if ($self->{doc_root}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"doc_root"}) 200 1 201
637 # GH-260: keep doc_root textually consistent with the normalized
638 # app_root; rel_app_name relies on prefix-length arithmetic.
639 200 $self->{doc_root} = YATT::Lite::Util::normalize_fs_path($self->{doc_root});
640 }
641 201 ▶ if (not $self->{allow_missing_dir}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"allow_missing_dir"} and $self->{"doc_root"} and not -d $self->{"doc_root"}) 0 201 201
Condition66%4/6
not $self->{"allow_missing_dir"} and $self->{"doc_root"} and not -d $self->{"doc_root"}
!ll&&!rl&&r
12000
not $self->{"allow_missing_dir"} and $self->{"doc_root"}
!ll&&!rl&&r
01200
MC/DC0%0/3
not $self->{"allow_missing_dir"} and $self->{"doc_root"} and not -d $self->{"doc_root"}
not $self->{"allow_missing_dir"} $self->{"doc_root"} not -d $self->{"doc_root"}
Truth table50%2/4
not(A) and B and not(C)
A= not $self->{"allow_missing_dir"}B= $self->{"doc_root"}C= not -d $self->{"doc_root"}
ABCresult
0XX0
10X0
1100
1111
642 and $self->{doc_root}
643 and not -d $self->{doc_root}) {
644 0 croak "document_root '$self->{doc_root}' is missing!";
645 }
646 201 ▶ if ($self->{doc_root}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"doc_root"}) 200 1 201
647 200 trim_slash($self->{doc_root});
648 }
649 # XXX: $self->{tmpldirs}
650  
651 201 ▶ $self->{site_prefix} //= "";
Condition100%2/2
$self->{"site_prefix"} //= ""
l!l
6195
MC/DC100%1/1
$self->{"site_prefix"} //= ""
$self->{"site_prefix"}
Truth table100%2/2
A
A= $self->{"site_prefix"}
Aresult
11
00
652  
653 201 $self->{_tmpldirs} = [];
654 201 ▶ if (my $dir = $self->{doc_root}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dir = $self->{"doc_root"}) 200 1 201
655 200 push @{$self->{_tmpldirs}}, $dir;
656 200 my $refcnt;
657 200 if (DEBUG_REFCNT) {
658 $refcnt = svref_2object($self)->REFCNT;
659 }
660 200 $self->get_yatt('/');
661 199 if (DEBUG_REFCNT) {
662 if (svref_2object($self)->REFCNT != $refcnt) {
663 croak "Reference count of $self is increased from $refcnt to "
664 . svref_2object($self)->REFCNT . "!";
665 }
666 }
667 }
668 200 $self;
669 }
670  
671 #========================================
672  
673 126 ▶sub render {
Subroutine render: called CC=2 SCAR=6.9
Pod documented
674 126 my MY $self = shift;
675 126 my $raw_bytes = $self->render_encoded(@_);
676 112 ▶ if ($self->{render_as_bytes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'render_as_bytes'}) { } 1 111 112
677 1 $raw_bytes;
678 } else {
679 111 decode(utf8 => $raw_bytes);
680 }
681 }
682  
683 133 ▶sub parse_path_info {
Subroutine parse_path_info: called CC=4 SCAR=15.0
Pod undocumented
684 133 (my MY $self, my ($reqrec)) = @_;
685 # [$path_info, $subpage, $action]
686 133 ▶ my ($path_info, @rest) = ref $reqrec ? @$reqrec : $reqrec;
Branch: 1 branch
BranchTrueFalseTotal
ref $reqrec ? : 0 133 133
687  
688 133 $path_info =~ s,^/*,/,;
689  
690 133 my ($tmpldir, $loc, $file, $trailer, $is_index)
691 = my @pi = $self->lookup_split_path_info($path_info);
692 133 ▶ unless (@pi) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@pi) 0 133 133
693 0 return;
694 }
695  
696 133 ▶ ($path_info, $tmpldir, $loc,
Branch: 1 branch
BranchTrueFalseTotal
@rest ? : 0 133 133
697 (@rest ? [$file, @rest] : $file),
698 , $self->pi_to_connection_quad(\@pi)
699 );
700 }
701  
702 133 ▶sub prepare_processing_context {
Subroutine prepare_processing_context: called CC=3 SCAR=12.0
Pod undocumented
703 133 (my MY $self, my ($reqrec, $args)) = @_;
704  
705 my ($path_info, $tmpldir, $loc, $widgetSpec, @rest)
706 133 ▶ = $self->parse_path_info($reqrec) or do {
Branch: 1 branch
BranchTrueFalseTotal
() = $self->parse_path_info($reqrec) or do { die 'No such location: ' . terse_dump($reqrec) } 133 0 133
707 0 die "No such location: ".terse_dump($reqrec);
708 };
709  
710 133 ▶ my $dh = $self->get_lochandler(map {untaint_any($_)} $loc, $tmpldir) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $dh = $self->get_lochandler(map({untaint_any($_);} $loc, $tmpldir)) or do { die "No such directory: $path_info" } 133 0 133
711 0 die "No such directory: $path_info";
712 };
713  
714 my $con = $self->make_connection
715 (
716 undef, @rest,
717 , yatt => $dh, noheader => 1, path_info => $path_info,
718 , encoding => $self->{output_encoding}
719 133 , $self->make_debug_params($reqrec, $args)
720 );
721  
722 133 ($dh, $con, $widgetSpec);
723 }
724  
725 126 ▶sub render_encoded {
Subroutine render_encoded: called CC=1 SCAR=0.0
Pod undocumented
726 126 (my MY $self, my ($reqrec, $args, @opts)) = @_;
727  
728 126 my ($dh, $con, $widgetSpec) = $self->prepare_processing_context($reqrec, $args);
729  
730 126 $self->render_into_context($dh, $con, $widgetSpec, $args, @opts);
731  
732 112 $con->buffer;
733 }
734  
735 0 ▶sub render_into {
Subroutine render_into: not called CC=3 SCAR=24.8
Pod undocumented
736 0 (my MY $self, my ($con, $reqrec, $args, @opts)) = @_;
737  
738 my ($path_info, $tmpldir, $loc, $widgetSpec, @rest)
739 0 ▶ = $self->parse_path_info($reqrec) or do {
Branch: 1 branch
BranchTrueFalseTotal
() = $self->parse_path_info($reqrec) or do { die 'No such location: ' . terse_dump($reqrec) } 0 0 0
740 0 die "No such location: ".terse_dump($reqrec);
741 };
742  
743 0 ▶ my $dh = $self->get_lochandler(map {untaint_any($_)} $loc, $tmpldir) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $dh = $self->get_lochandler(map({untaint_any($_);} $loc, $tmpldir)) or do { die "No such directory: $path_info" } 0 0 0
744 0 die "No such directory: $path_info";
745 };
746  
747 0 $con->configure(yatt => $dh);
748  
749 0 $self->render_into_context($dh, $con, $widgetSpec, $args, @opts);
750 }
751  
752 #
753 # Common context wrapper for the render path: sets $SYS/$YATT/$CON,
754 # runs before/after_dirhandler (site_config entities) and the chdir
755 # guard, but does NOT install the __DIE__/__WARN__ traps - that is the
756 # web handle path's intentional distinction (perl -d friendliness).
757 # GH-267
758 #
759 126 ▶sub render_into_context {
Subroutine render_into_context: called CC=1 SCAR=0.0
Pod undocumented
760 126 (my MY $self, my ($dh, $con, $widgetSpec, $args, @opts)) = @_;
761  
762 126 local ($SYS, $YATT, $CON) = ($self, $dh, $con);
763  
764 126 $self->before_dirhandler($dh, $con, lexpand($widgetSpec));
765  
766 126 my $chdir_guard = $dh->chdir_guard;
767  
768 126 $self->invoke_dirhandler
769 (
770 $dh,
771 , render_into => $con
772 , $widgetSpec
773 , $args, @opts
774 );
775  
776 112 $self->after_dirhandler($dh, $con, lexpand($widgetSpec));
777  
778 112 YATT::Lite::Util::try_invoke($con, 'flush_headers');
779 }
780  
781 0 ▶sub make_connection_for {
Subroutine make_connection_for: not called CC=1 SCAR=6.9
Pod undocumented
782 0 (my MY $self, my ($reqrec, $args, @other)) = @_;
783  
784 0 my ($path_info, $tmpldir, $loc, $widgetSpec, @rest)
785 = $self->parse_path_info($reqrec);
786  
787 $self->make_connection
788 (
789 undef, @rest,
790 , noheader => 1, path_info => $path_info,
791 , encoding => $self->{output_encoding},
792 0 , $self->make_debug_params($reqrec, $args),
793 , @other,
794 );
795 }
796  
797 176 ▶sub lookup_split_path_info {
Subroutine lookup_split_path_info: called CC=1 SCAR=0.0
Pod undocumented
798 176 (my MY $self, my $path_info) = @_;
799 lookup_path($path_info
800 , $self->{_tmpldirs}
801 , $self->{index_name}
802 , $self->{ext_public}
803 176 , $self->{use_subpath});
804 }
805  
806 #========================================
807  
808 sub K_MOUNT_MATCH () { "__yatt" }
809  
810 32 ▶sub lookup_psgi_mount {
Subroutine lookup_psgi_mount: called CC=6 SCAR=18.8
Pod undocumented
811 32 (my MY $self, my $path_info) = @_;
812 32 ▶ $self->{_loc2psgi_re} // $self->rebuild_psgi_mount;
Condition66%2/3
$self->{"_loc2psgi_re"} // $self->rebuild_psgi_mount
l!l&&r!l&&!r
2570
MC/DC0%0/2
$self->{"_loc2psgi_re"} // $self->rebuild_psgi_mount
$self->{"_loc2psgi_re"} $self->rebuild_psgi_mount
Truth table66%2/3
A // B
A= $self->{"_loc2psgi_re"}B= $self->rebuild_psgi_mount
ABresult
1X1
011
000
813 $path_info =~ $self->{_loc2psgi_re}
814 32 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$path_info =~ /$self->{"_loc2psgi_re"}/ or return 7 25 32
815 7 ▶ my @mount_match = grep {/^@{[K_MOUNT_MATCH()]}/o} keys %+
Branch: 1 branch
BranchTrueFalseTotal
my(@mount_match) = grep({/^@{["__yatt"];}/o;} keys %+) or return 7 0 7
816 or return;
817 7 ▶ if (@mount_match >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@mount_match >= 2) 0 7 7
818 croak "Multiple match found for psgi_mount: \n"
819 0 . join("\n ", map {$self->{_loc2psgi_dict}{$_}[0]} @mount_match);
820 }
821  
822 7 my $path_prefix = $+{$mount_match[0]};
823  
824 7 my $item = $self->{_loc2psgi_dict}{$path_prefix};
825  
826 7 ▶ wantarray ? @{$item}[1..$#$item] : $item->[2];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 0 7
827 }
828  
829 7 ▶sub mount_psgi {
Subroutine mount_psgi: called CC=4 SCAR=14.1
Pod undocumented
830 7 (my MY $self, my ($path_prefix, $app, @opts)) = @_;
831 7 ▶ unless (defined $path_prefix) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path_prefix) 0 7 7
832 0 croak "path_prefix is empty! mount_psgi(path_prefix, psgi_app)";
833 }
834 7 ▶ if (not ref $path_prefix) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $path_prefix) 7 0 7
835 7 $path_prefix =~ s,^/*,/,;
836 }
837 7 ▶ my $dict = $self->{_loc2psgi_dict} //= +{};
Condition100%2/2
$self->{"_loc2psgi_dict"} //= {}
l!l
61
MC/DC100%1/1
$self->{"_loc2psgi_dict"} //= {}
$self->{"_loc2psgi_dict"}
Truth table100%2/2
A
A= $self->{"_loc2psgi_dict"}
Aresult
11
00
838 7 my $key = K_MOUNT_MATCH() . (keys %$dict);
839 7 (my $strip = $path_prefix) =~ s,/\z,,;
840 7 $dict->{$path_prefix} = [$key => $strip => $app, @opts];
841  
842 7 undef $self->{_loc2psgi_re};
843  
844 # For cascading call
845 7 $self;
846 }
847  
848 7 ▶sub rebuild_psgi_mount {
Subroutine rebuild_psgi_mount: called CC=3 SCAR=11.0
Pod undocumented
849 7 (my MY $self) = @_;
850 7 my @re;
851 7 foreach my $path_prefix (sort {length($b) <=> length($a)}
852 7 ▶ keys %{$self->{_loc2psgi_dict} //= +{}}) {
Condition50%1/2
$self->{"_loc2psgi_dict"} //= {}
l!l
70
MC/DC0%0/1
$self->{"_loc2psgi_dict"} //= {}
$self->{"_loc2psgi_dict"}
Truth table50%1/2
A
A= $self->{"_loc2psgi_dict"}
Aresult
11
00
853 20 my ($key, undef, $app) = @{$self->{_loc2psgi_dict}{$path_prefix}};
854 20 push @re, qr{(?<$key>$path_prefix)};
855 }
856 7 my $all = join("|", @re);
857 7 $self->{_loc2psgi_re} = qr{^(?:$all)};
858 }
859  
860 4 ▶sub psgi_file_app {
Subroutine psgi_file_app: called CC=1 SCAR=0.0
Pod undocumented
861 4 my ($pack, $path) = @_;
862 4 require Plack::App::File;
863 4 Plack::App::File->new(root => $path)->to_app;
864 }
865  
866 1 ▶sub mount_static {
Subroutine mount_static: called CC=2 SCAR=7.1
Pod undocumented
867 1 (my MY $self, my ($location, $realpath)) = @_;
868 1 ▶ my $app = ref $realpath eq 'CODE' ? $realpath
Branch: 1 branch
BranchTrueFalseTotal
ref $realpath eq 'CODE' ? : 0 1 1
869 : $self->psgi_file_app($realpath);
870 1 $self->mount_psgi($location, $app);
871 }
872  
873 #========================================
874  
875 43 ▶sub mount_action {
Subroutine mount_action: called CC=4 SCAR=15.2
Pod undocumented
876 43 (my MY $self, my ($path_info, $action)) = @_;
877 43 ▶ if (my $ref = ref $path_info) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ref = ref $path_info) 0 43 43
878 0 croak "mount_action doesn't support $ref path_info, sorry";
879 }
880 43 my ($tmpldir, $loc, $file, $trailer, $is_index)
881 = my @pi = $self->lookup_split_path_info($path_info);
882 43 ▶ unless (@pi) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@pi) 0 43 43
883 0 croak "Can't find acutal directory for $path_info";
884 }
885 43 ▶ unless ($is_index) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_index) 0 43 43
886 0 croak "Conflicting mount_action($path_info) with file=$file\n";
887 }
888 43 my $realdir = $tmpldir.$loc;
889 43 my $dh = $self->get_dirhandler($realdir);
890 43 $dh->set_action_handler($trailer, $action);
891  
892 # For cascading call.
893 43 $self;
894 }
895  
896 #========================================
897  
898 sub Connection () {'YATT::Lite::Connection'};
899  
900 0 ▶sub make_simple_connection {
Subroutine make_simple_connection: not called CC=1 SCAR=6.9
Pod undocumented
901 0 (my MY $self, my ($quad, @rest)) = @_;
902 0 my @params = $self->pi_to_connection_quad($quad);
903 0 $self->make_connection(undef, @params, @rest);
904 }
905  
906 133 ▶sub pi_to_connection_quad {
Subroutine pi_to_connection_quad: called CC=3 SCAR=12.3
Pod undocumented
907 133 (my MY $self, my ($pi)) = @_;
908 133 my ($tmpldir, $loc, $file, $trailer, $is_index, $request_file) = @$pi;
909 133 my $virtdir = "$self->{doc_root}$loc";
910 133 my $realdir = "$tmpldir$loc";
911 # GH-251: When request_file is not given (e.g. synthetic quads),
912 # default to the canonical (extension-less) form.
913 133 ▶ $request_file //= $is_index ? '' : trim_ext($file, $self->{ext_public});
Branch: 1 branch
BranchTrueFalseTotal
$is_index ? : 0 0 0
Condition33%1/3
$request_file //= $is_index ? "" : trim_ext($file, $self->{"ext_public"})
l!l&&r!l&&!r
13300
MC/DC0%0/2
$request_file //= $is_index ? "" : trim_ext($file, $self->{"ext_public"})
$request_file $is_index ? "" : trim_ext($file, $self->{"ext_public"})
Truth table33%1/3
A //= B
A= $request_fileB= $is_index ? "" : trim_ext($file, $self->{"ext_public"})
ABresult
1X1
011
000
914 133 $self->connection_quad([$virtdir, $loc, $file, $trailer, $request_file]);
915 }
916  
917 133 ▶sub make_debug_params {
Subroutine make_debug_params: called CC=1 SCAR=0.0
Pod undocumented
918 133 (my MY $self, my ($reqrec, $args)) = @_;
919 133 ();
920 }
921  
922 680 ▶sub make_connection {
Subroutine make_connection: called CC=1 SCAR=0.0
Pod documented
923 680 (my MY $self, my ($fh, @params)) = @_;
924 680 require YATT::Lite::Connection;
925 $self->Connection->create(
926 $fh, @params, system => $self, root => $self->{doc_root}
927 680 );
928 }
929  
930 2 ▶sub finalize_connection {}
Subroutine finalize_connection: called CC=1 SCAR=0.0
Pod undocumented
931  
932 0 ▶sub connection_param {
Subroutine connection_param: not called CC=1 SCAR=6.9
Pod undocumented
933 0 croak "Use of YATT::Lite::Factory::connection_param is deprecated!\n";
934 }
935 626 ▶sub connection_quad {
Subroutine connection_quad: called CC=2 SCAR=7.1
Pod undocumented
936 626 (my MY $self, my ($quad)) = @_;
937 626 my ($virtdir, $loc, $file, $subpath, $request_file) = @$quad;
938 626 ▶ (dir => $virtdir
Branch: 1 branch
BranchTrueFalseTotal
defined $request_file ? : 626 0 626
939 , location => $loc
940 , file => $file
941 , subpath => $subpath
942 , (defined $request_file ? (request_file => $request_file) : ()));
943 }
944  
945 #========================================
946 #
947 # Hook for subclassing
948 #
949 495 ▶sub run_dirhandler {
Subroutine run_dirhandler: called CC=5 SCAR=16.6
Pod documented
950 495 (my MY $self, my ($dh, $con, $file)) = @_;
951 495 local ($SYS, $YATT, $CON) = ($self, $dh, $con);
952 495 $self->before_dirhandler($dh, $con, $file);
953 495 my $result = $self->invoke_dirhandler(
954 $dh,
955 handle => $dh->cut_ext($file), $con, $file
956 );
957 360 $self->after_dirhandler($dh, $con, $file);
958 360 ▶ if (defined $result
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result and ref $result eq "CODE" || ref $result eq "ARRAY" && @$result == 3) 3 357 360
Condition55%5/9
defined $result and ref $result eq "CODE" || ref $result eq "ARRAY" && @$result == 3
!ll&&!rl&&r
03573
ref $result eq "CODE" or ref $result eq "ARRAY" and @$result == 3
l!l&&r!l&&!r
30357
ref $result eq "ARRAY" and @$result == 3
!ll&&!rl&&r
35700
MC/DC25%1/4
defined $result and ref $result eq "CODE" || ref $result eq "ARRAY" && @$result == 3
defined $result ref $result eq "CODE" ref $result eq "ARRAY" @$result == 3
Truth table40%2/5
A and B or C and D
A= defined $resultB= ref $result eq "CODE"C= ref $result eq "ARRAY"D= @$result == 3
ABCDresult
0XXX0
100X0
10100
11XX1
10111
959 and (ref $result eq 'CODE'
960 or ref $result eq 'ARRAY' and @$result == 3)) {
961 3 $self->raise_response($result)
962 }
963 }
964  
965 612 ▶sub before_dirhandler { &maybe::next::method; }
Subroutine before_dirhandler: called CC=1 SCAR=0.0
Pod undocumented
966 479 ▶sub after_dirhandler { &maybe::next::method; }
Subroutine after_dirhandler: called CC=1 SCAR=0.0
Pod undocumented
967  
968 621 ▶sub invoke_dirhandler {
Subroutine invoke_dirhandler: called CC=1 SCAR=0.0
Pod undocumented
969 621 (my MY $self, my ($dh, $method, @args)) = @_;
970 621 $dh->with_system($self, $method, @args);
971 }
972  
973 7 ▶sub invoke_sub_in {
Subroutine invoke_sub_in: called CC=3 SCAR=11.0
Pod undocumented
974 7 (my MY $self, my ($reqrec, $args, $sub, @rest)) = @_;
975  
976 7 my $wantarray = wantarray;
977  
978 7 my ($dh, $con, $widgetSpec)
979 = $self->prepare_processing_context($reqrec, $args);
980  
981 7 local ($SYS, $YATT, $CON) = ($self, $dh, $con);
982  
983 7 $self->before_dirhandler($dh, $con, lexpand($widgetSpec));
984  
985 7 my @result;
986 7 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) { } 4 3 7
987 4 @result = $sub->($dh, $con, @rest);
988 } else {
989 3 $result[0] = $sub->($dh, $con, @rest);
990 }
991  
992 7 $self->after_dirhandler($dh, $con, lexpand($widgetSpec));
993  
994 7 YATT::Lite::Util::try_invoke($con, 'flush_headers');
995  
996 7 ▶ $wantarray ? @result : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
$wantarray ? : 4 3 7
997 }
998  
999 #========================================
1000  
1001 750 ▶sub get_lochandler {
Subroutine get_lochandler: called CC=3 SCAR=12.0
Pod undocumented
1002 750 (my MY $self, my ($location, $tmpldir)) = @_;
1003 750 ▶ $tmpldir //= $self->{doc_root};
Condition66%2/3
$tmpldir //= $self->{"doc_root"}
l!l&&r!l&&!r
6101400
MC/DC0%0/2
$tmpldir //= $self->{"doc_root"}
$tmpldir $self->{"doc_root"}
Truth table66%2/3
A //= B
A= $tmpldirB= $self->{"doc_root"}
ABresult
1X1
011
000
1004 750 ▶ $self->get_yatt($location) || do {
Branch: 1 branch
BranchTrueFalseTotal
$self->get_yatt($location) or do { $self->{"_loc2yatt"}{$location} = $self->load_yatt("$tmpldir$location") } 750 0 750
1005 0 $self->{_loc2yatt}{$location} = $self->load_yatt("$tmpldir$location");
1006 };
1007 }
1008  
1009 # location => yatt (dirhandler, dirapp)
1010  
1011 989 ▶sub get_yatt {
Subroutine get_yatt: called CC=3 SCAR=11.2
Pod documented
1012 989 (my MY $self, my $loc) = @_;
1013 989 ▶ if (my $yatt = $self->{_loc2yatt}{$loc}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $yatt = $self->{"_loc2yatt"}{$loc}) 1 988 989
1014 1 return $yatt;
1015 }
1016 # print STDERR Carp::longmess("get_yatt for $loc"
1017 # , YATT::Lite::Util::terse_dump($self->{_tmpldirs}));
1018 988 my ($realdir, $basedir) = lookup_dir(trim_slash($loc), $self->{_tmpldirs});
1019 988 ▶ unless ($realdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($realdir) 0 988 988
1020 0 $self->error("Can't find template directory for location '%s'", $loc);
1021 }
1022 988 $self->{_loc2yatt}{$loc} = $self->load_yatt($realdir, $basedir);
1023 }
1024  
1025 # phys-path => yatt
1026  
1027 72 *get_dirhandler = *load_yatt; *get_dirhandler = *load_yatt;
1028  
1029 1386 ▶sub load_yatt {
Subroutine load_yatt: called CC=11 SCAR=25.9
Pod undocumented
1030 1386 (my MY $self, my ($path, $basedir, $visits, $from)) = @_;
1031  
1032 1386 ▶ unless (defined $path and $path ne '') {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path and $path ne "") 0 1386 1386
Condition33%1/3
defined $path and $path ne ""
!ll&&!rl&&r
001386
MC/DC0%0/2
defined $path and $path ne ""
defined $path $path ne ""
Truth table33%1/3
A and B
A= defined $pathB= $path ne ""
ABresult
0X0
100
111
1033 0 croak "empty path for load_yatt!"
1034 }
1035  
1036 1386 $path = $self->rel2abs($path, $self->{app_root});
1037 1386 ▶ if (my $yatt = $self->{_path2yatt}{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $yatt = $self->{"_path2yatt"}{$path}) 1100 286 1386
1038 1100 return $yatt;
1039 }
1040 286 ▶ unless (-e $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $path) 0 286 286
1041 0 croak "Can't load YATT directory '$path'! No such directory!";
1042 }
1043 286 ▶ if (not $visits) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $visits) { } 246 40 286
elsif (my $preds = $visits->check_cycle($path, $from)) { } 1 39 40
1044 246 $visits = Visits->start($path);
1045 } elsif (my $preds = $visits->check_cycle($path, $from)) {
1046 1 $self->error("Template config error! base has cycle!:\n %s\n"
1047 , join "\n -> ", $from, @$preds);
1048 }
1049 #-- DFS-visits --
1050 285 ▶ if (not $self->{allow_missing_dir} and not -d $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"allow_missing_dir"} or -d $path) 0 285 285
Condition33%1/3
$self->{"allow_missing_dir"} or -d $path
l!l&&r!l&&!r
02850
MC/DC0%0/2
$self->{"allow_missing_dir"} or -d $path
$self->{"allow_missing_dir"} -d $path
Truth table33%1/3
A or B
A= $self->{"allow_missing_dir"}B= -d $path
ABresult
1X1
011
000
1051 0 croak "Can't find '$path'!";
1052 }
1053 285 ▶ if (my (@cf) = $self->list_config_files(untaint_any($path)."/.htyattconfig")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@cf) = $self->list_config_files(untaint_any($path) . '/.htyattconfig')) { } 20 265 285
1054 20 ▶ $self->error("Multiple configuration files!", @cf) if @cf > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @cf > 1 0 20 20
1055 20 ▶ _with_loading_file {$self} $cf[0], sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1056 20 $self->build_yatt($path, $basedir, $visits, $self->read_file($cf[0]));
1057 20 };
1058 } else {
1059 265 $self->build_yatt($path, $basedir, $visits);
1060 }
1061 }
1062  
1063 285 ▶sub build_yatt {
Subroutine build_yatt: called CC=9 SCAR=22.0
Pod undocumented
1064 285 (my MY $self, my ($path, $basedir, $visits, %opts)) = @_;
1065 285 trim_slash($path);
1066  
1067 285 my $app_name = $self->app_name_for($path, $basedir);
1068  
1069 #
1070 # base package と base vfs object の決定
1071 #
1072 285 my (@basepkg, @basevfs);
1073 285 $self->_list_base_spec_in($path, delete $opts{base}, $visits
1074 , \@basepkg, \@basevfs);
1075  
1076 282 my $app_ns = $self->buildns(my @log = (INST => \@basepkg, $path));
1077  
1078 282 print STDERR "# Factory::buildns("
1079 , terse_dump(@log), ") => $app_ns\n" if DEBUG_FACTORY;
1080  
1081 282 my $has_rc;
1082 282 ▶ if ($has_rc = (-e (my $rc = "$path/.htyattrc.pl"))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_rc = -e (my $rc = "$path/.htyattrc.pl")) 17 265 282
1083 # Note: This can do "use fields (...)"
1084 17 dofile_in($app_ns, $rc);
1085  
1086 17 print STDERR "# Loaded: $rc\n" if DEBUG_FACTORY;
1087 }
1088  
1089 282 my @vfs_opts;
1090 282 ▶ if (defined(my $prefix = $self->page_prefix_for($path))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prefix = $self->page_prefix_for($path))) 248 34 282
1091 248 push @vfs_opts, page_prefix => $prefix;
1092 }
1093  
1094 my @args = (vfs => [dir => $path
1095 , entns => $self->{_path2entns}{$path}
1096 , encoding => $self->{tmpl_encoding}
1097 , @vfs_opts
1098 , @basevfs ? (base => \@basevfs) : ()]
1099 , dir => $path
1100 , app_ns => $app_ns
1101 , app_name => $app_name
1102 , factory => $self
1103  
1104 # XXX: Design flaw! Use of tmpl_cache will cause problem.
1105 # because VFS->create for base do not respect Factory->get_yatt.
1106 # To solve this, I should redesign all Factory/VFS related stuffs.
1107 , tmpl_cache => $self->{_tmpl_cache} //= {}
1108 , entns2vfs_item => $self->{_entns2vfs_item} //= {}
1109  
1110 282 ▶ , $self->configparams_for(fields_hash($app_ns)));
Branch: 1 branch
BranchTrueFalseTotal
@basevfs ? : 44 238 282
Condition100%4/4
$self->{"_tmpl_cache"} //= {}
l!l
83199
$self->{"_entns2vfs_item"} //= {}
l!l
83199
MC/DC100%1/1
$self->{"_tmpl_cache"} //= {}
$self->{"_tmpl_cache"}
MC/DC100%1/1
$self->{"_entns2vfs_item"} //= {}
$self->{"_entns2vfs_item"}
Truth table100%2/2
A
A= $self->{"_tmpl_cache"}
Aresult
11
00
Truth table100%2/2
A
A= $self->{"_entns2vfs_item"}
Aresult
11
00
1111  
1112 282 ▶ if (my @unk = $app_ns->YATT::Lite::Object::cf_unknowns(%opts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@unk) = $app_ns->YATT::Lite::Object::cf_unknowns(%opts)) 0 282 282
1113 0 $self->error("Unknown option for yatt app '%s': '%s'"
1114 , $path, join(", ", @unk));
1115 }
1116  
1117 282 printf STDERR "build_yatt.before_app_ns_new: refcnt=%d\n", svref_2object($self)->REFCNT if DEBUG_REFCNT && DEBUG_FACTORY;
1118 282 my $yatt = $self->{_path2yatt}{$path} = $app_ns->new(@args, %opts);
1119 282 printf STDERR "build_yatt.after_app_ns_new: refcnt=%d\n", svref_2object($self)->REFCNT if DEBUG_REFCNT && DEBUG_FACTORY;
1120  
1121 282 ▶ unless ($yatt->after_new_is_called) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($yatt->after_new_is_called) 0 282 282
1122 0 Carp::croak("after_new is not called for $path!");
1123 }
1124  
1125 282 ▶ if ($has_rc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_rc) 17 265 282
1126 17 print STDERR "# setting up rc actions\n" if DEBUG_FACTORY;
1127 17 $yatt->setup_rc_actions;
1128 }
1129  
1130 282 $yatt;
1131 }
1132  
1133 285 ▶sub _list_base_spec_in {
Subroutine _list_base_spec_in: called CC=18 SCAR=29.1
1134 285 (my MY $self, my ($in, $desc, $visits, $basepkg, $basevfs)) = @_;
1135  
1136 print STDERR "# Factory::list_base_in("
1137 285 , terse_dump($in, $desc, $self->{app_base}), ")\n" if DEBUG_FACTORY;
1138  
1139 #
1140 # YATT::Lite->base can be either specified explicitly
1141 # or implicitly copied from YATT::Lite::Factory->app_base.
1142 #
1143 # Later case can lead circular inheritance for app_base itself.
1144 # To avoid this, $is_implicit flag is used.
1145 #
1146 285 my $is_implicit = not defined $desc;
1147  
1148 285 ▶ $desc //= $self->{app_base};
Condition100%3/3
$desc //= $self->{"app_base"}
l!l&&r!l&&!r
1862205
MC/DC100%2/2
$desc //= $self->{"app_base"}
$desc $self->{"app_base"}
Truth table100%3/3
A //= B
A= $descB= $self->{"app_base"}
ABresult
1X1
011
000
1149  
1150 #
1151 # First item in base is treated *primary* base.
1152 # Rest of them are treated mixin.
1153 #
1154 285 ▶ my ($base, @mixin) = lexpand($desc)
Branch: 1 branch
BranchTrueFalseTotal
() = lexpand($desc) or return 80 205 285
1155 or return;
1156  
1157 #
1158 # This builds [$package => $path] pairs and separately store
1159 # as primary and mixin.
1160 #
1161 80 my (@primary_pair, @mixin_pair);
1162 80 foreach my $task ([1, $base], [0, @mixin]) {
1163 160 my ($is_primary, @spec) = @$task;
1164 160 foreach my $basespec (@spec) {
1165 99 my ($pkg, $yatt);
1166 99 ▶ if ($basespec =~ /^::(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($basespec =~ /^::(.*)/) { } 5 94 99
elsif (my $realpath = $self->app_path_find_dir_in($in, $basespec)) { } 94 0 94
1167 5 ckrequire($1);
1168 5 ▶ push @{$is_primary ? \@primary_pair : \@mixin_pair}, [$1, undef];
Branch: 1 branch
BranchTrueFalseTotal
$is_primary ? : 5 0 5
1169 } elsif (my $realpath = $self->app_path_find_dir_in($in, $basespec)) {
1170  
1171 94 ▶ if ($is_implicit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_implicit) 58 36 94
1172 #
1173 # Simply drop circular inheritance for implicit case.
1174 #
1175 58 ▶ next if $visits->has_node($realpath);
Branch: 1 branch
BranchTrueFalseTotal
if $visits->has_node($realpath) 28 30 58
1176 }
1177 66 $visits->ensure_make_node($realpath);
1178  
1179 66 ▶ push @{$is_primary ? \@primary_pair : \@mixin_pair}, [undef, $realpath];
Branch: 1 branch
BranchTrueFalseTotal
$is_primary ? : 47 19 66
1180 } else {
1181 0 $self->error("Invalid base spec: %s", $basespec);
1182 }
1183 }
1184 }
1185  
1186 #
1187 # This builds $basevfs for YATT::Lite::VFS::Folder::vivify_base_descs()
1188 # This preallocates YATT::Lite and its entns for each realpath.
1189 #
1190 80 foreach my $pair (@primary_pair, @mixin_pair) {
1191 71 my ($pkg, $dir) = @$pair;
1192 71 ▶ next unless $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 5 66 71
1193 66 my $yatt = $self->load_yatt($dir, undef, $visits, $in);
1194 63 $pair->[0] = ref $yatt;
1195 63 my $realdir = $yatt->cget('dir');
1196 63 push @$basevfs, [dir => $realdir, entns => $self->{_path2entns}{$realdir}];
1197 }
1198  
1199 #
1200 # This builds $basepkg for buildns()
1201 #
1202 77 ▶ push @$basepkg, map {defined $_->[0] ? $_->[0] : ()} do {
Branch: 1 branch
BranchTrueFalseTotal
defined $_->[0] ? : 56 0 56
1203 77 ▶ if (not $self->{no_mro_c3}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'no_mro_c3'}) { } 77 0 77
1204 77 my %known_pkg;
1205 77 foreach my $pair (grep {defined $_->[0]} @primary_pair) {
1206 49 $known_pkg{$_} = 1 for @{mro::get_linear_isa($pair->[0])};
1207 }
1208 77 ▶ (grep(!$_->[0] || !$known_pkg{$_->[0]}, @mixin_pair)
Condition66%2/3
$_->[0] && $known_pkg{$_->[0]}
!ll&&!rl&&r
0712
MC/DC50%1/2
$_->[0] && $known_pkg{$_->[0]}
$_->[0] $known_pkg{$_->[0]}
Truth table66%2/3
A && B
A= $_->[0]B= $known_pkg{$_->[0]}
ABresult
0X0
100
111
1209 , @primary_pair);
1210 } else {
1211 0 @primary_pair;
1212 }
1213 };
1214  
1215 77 $visits->finish_node($in);
1216 }
1217  
1218 5 ▶sub get_yatt_by_entns {
Subroutine get_yatt_by_entns: called CC=1 SCAR=0.0
Pod undocumented
1219 5 (my MY $self, my $entns) = @_;
1220 5 $self->{_entns2vfs_item}{$entns};
1221 }
1222  
1223 #========================================
1224  
1225 282 ▶sub buildns {
Subroutine buildns: called CC=3 SCAR=11.0
Pod undocumented
1226 282 (my MY $self, my ($kind, $baselist, $path)) = @_;
1227 282 my $newns = $self->SUPER::buildns($kind, $baselist, $path);
1228  
1229 # EntNS を足し、Entity も呼べるようにする。
1230 $self->{_default_app}->define_Entity(undef, $newns
1231 282 , map {$_->EntNS} @$baselist);
1232  
1233 # instns には MY を定義しておく。
1234 282 my $my = globref($newns, 'MY');
1235 282 ▶ unless (*{$my}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (*{$my;}{"CODE"}) 282 0 282
1236 282 define_const($my, $newns);
1237 }
1238  
1239 # もし $newns の EntNS が Factory(SiteApp, app.psgi) の EntNS を継承していない
1240 # なら、継承する
1241 282 ▶ unless ($newns->EntNS->isa($self->EntNS)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($newns->EntNS->isa($self->EntNS)) 5 277 282
1242 5 push @{globref_default(globref($newns->EntNS, 'ISA')
1243 , [])}, $self->EntNS;
1244 }
1245  
1246 # basevfs に entns を渡せるように。
1247 282 $self->{_path2entns}{$path} = $newns->EntNS;
1248  
1249 282 $newns;
1250 }
1251  
1252 283 ▶sub _cf_delegates {
Subroutine _cf_delegates: called CC=1 SCAR=0.0
1253 283 qw(no_unicode
1254 no_unicode_params
1255 output_encoding
1256 header_charset
1257 tmpl_encoding
1258 render_as_bytes
1259 debug_cgen
1260 at_done
1261 app_root
1262 namespace
1263 index_name
1264 ext_public
1265 ext_private
1266 only_parse
1267 use_subpath
1268 dont_map_args
1269 dont_debug_param
1270 always_refresh_deps
1271 no_mro_c3
1272 die_in_error
1273 special_entities
1274 default_lang
1275 no_lineinfo
1276 ext_pattern
1277 debug_parser
1278 check_lineno
1279 match_argsroute_first
1280 stash_unknown_params_to
1281 body_argument
1282 body_argument_type
1283 prefer_call_for_entity
1284 no_conditional_call
1285 allow_bare_entity_in_decl
1286 no_chdir
1287 pagevars
1288 argmacro
1289 );
1290 }
1291  
1292 282 ▶sub configparams_for {
Subroutine configparams_for: called CC=3 SCAR=12.0
Pod undocumented
1293 282 (my MY $self, my $hash) = @_;
1294 # my @base = map { [dir => $_] } lexpand($self->{tmpldirs});
1295 # (@base ? (base => \@base) : ())
1296  
1297 282 my $debugging = YATT::Lite::Util::is_debugging();
1298 282 ▶ if ($debugging) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debugging) 0 282 282
1299 0 print STDERR "# Note: Factory->die_in_error is turned off for debugging\n";
1300 }
1301  
1302 (
1303 $self->cf_delegate_known(0, $hash, $self->_cf_delegates)
1304 , (exists $hash->{error_handler}
1305 282 ▶ ? (error_handler => \ $self->{error_handler}) : ())
Branch: 1 branch
BranchTrueFalseTotal
exists $hash->{'error_handler'} ? : 282 0 282
1306 , die_in_error => ! $debugging
1307 );
1308 }
1309  
1310 # XXX: Should have better interface.
1311 1 ▶sub error {
Subroutine error: called CC=1 SCAR=0.0
Pod undocumented
1312 1 (my MY $self, my ($fmt, @args)) = @_;
1313 1 croak sprintf $fmt, @args;
1314 }
1315  
1316 #========================================
1317  
1318 285 ▶sub app_name_for {
Subroutine app_name_for: called CC=5 SCAR=16.2
Pod undocumented
1319 285 (my MY $self, my ($path, $basedir)) = @_;
1320 285 ensure_slash($path);
1321 285 ▶ if ($basedir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($basedir) { } 235 50 285
1322 235 ensure_slash($basedir);
1323 235 ▶ $self->_extract_app_name($path, $basedir)
Condition33%1/3
$self->_extract_app_name($path, $basedir) // $self->error("Can't extract app_name path=%s, base=%s", $path, $basedir)
l!l&&r!l&&!r
23500
MC/DC0%0/2
$self->_extract_app_name($path, $basedir) // $self->error("Can't extract app_name path=%s, base=%s", $path, $basedir)
$self->_extract_app_name($path, $basedir) $self->error("Can't extract app_name path=%s, base=%s", $path, $basedir)
Truth table33%1/3
A // B
A= $self->_extract_app_name($path, $basedir)B= $self->error("Can't extract app_name path=%s, base=%s", $path, $basedir)
ABresult
1X1
011
000
1324 // $self->error("Can't extract app_name path=%s, base=%s"
1325 , $path, $basedir);
1326 } else {
1327 50 foreach my $tmpldir (lexpand($self->{_tmpldirs})) {
1328 50 ensure_slash(my $cp = $tmpldir);
1329 50 ▶ if (defined(my $app_name = $self->_extract_app_name($path, $cp))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $app_name = $self->_extract_app_name($path, $cp))) 16 34 50
1330 # Can be empty string.
1331 16 return $app_name;
1332 }
1333 }
1334 34 return '';
1335 }
1336 }
1337  
1338 # Prefix of page names in the directory $path: '' for a template dir
1339 # itself, 'sub/' for its subdirectory, undef when $path is not under
1340 # any template dir (ie. not a page directory, eg. ytmpl).
1341 282 ▶sub page_prefix_for {
Subroutine page_prefix_for: called CC=4 SCAR=13.9
Pod undocumented
1342 282 (my MY $self, my $path) = @_;
1343 282 ensure_slash($path);
1344 282 foreach my $tmpldir (lexpand($self->{_tmpldirs})) {
1345 282 ensure_slash(my $cp = $tmpldir);
1346 282 ▶ if (defined(my $rel = $self->_extract_app_name($path, $cp))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $rel = $self->_extract_app_name($path, $cp))) 248 34 282
1347 248 ▶ return $rel eq '' ? '' : "$rel/";
Branch: 1 branch
BranchTrueFalseTotal
$rel eq '' ? : 199 49 248
1348 }
1349 }
1350 34 return undef;
1351 }
1352  
1353 570 ▶sub _extract_app_name {
Subroutine _extract_app_name: called CC=2 SCAR=6.9
1354 570 (my MY $self, my ($path, $basedir)) = @_;
1355 570 my ($bs, $name) = unpack('A'.length($basedir).'A*', $path);
1356 570 ▶ return undef unless $bs eq $basedir;
Branch: 1 branch
BranchTrueFalseTotal
unless $bs eq $basedir 69 501 570
1357 501 $name =~ s{[/\\]+$}{};
1358 501 $name;
1359 }
1360  
1361 #========================================
1362  
1363 36 ▶sub read_file {
Subroutine read_file: called CC=3 SCAR=11.4
Pod undocumented
1364 36 (my MY $self, my $fn) = @_;
1365 36 ▶ my ($ext) = $fn =~ /\.(\w+)$/
Branch: 1 branch
BranchTrueFalseTotal
my($ext) = $fn =~ /\.(\w+)$/ or croak("Can't extract fileext from filename: $fn") 36 0 36
1366 or croak "Can't extract fileext from filename: $fn";
1367 36 ▶ my $sub = $self->can("read_file_$ext")
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $self->can("read_file_$ext") or croak("filetype $ext is not supported: $fn") 36 0 36
1368 or croak "filetype $ext is not supported: $fn";
1369 36 $sub->($self, $fn);
1370 }
1371  
1372 949 ▶sub default_config_filetypes {qw/xhf yml/}
Subroutine default_config_filetypes: called CC=1 SCAR=0.0
Pod undocumented
1373 949 ▶sub config_filetypes {
Subroutine config_filetypes: called CC=3 SCAR=12.0
Pod undocumented
1374 949 (my MY $self) = @_;
1375 949 ▶ if (ref $self and my $item = $self->{config_filetypes}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and my $item = $self->{'config_filetypes'}) { } 0 949 949
Condition66%2/3
ref $self and my $item = $self->{"config_filetypes"}
!ll&&!rl&&r
249250
MC/DC0%0/2
ref $self and my $item = $self->{"config_filetypes"}
ref $self my $item = $self->{"config_filetypes"}
Truth table66%2/3
A and B
A= ref $selfB= my $item = $self->{"config_filetypes"}
ABresult
0X0
100
111
1376 0 lexpand($item)
1377 } else {
1378 949 $self->default_config_filetypes
1379 }
1380 }
1381  
1382 1218 ▶sub find_unique_config_file {
Subroutine find_unique_config_file: called CC=4 SCAR=13.9
Pod undocumented
1383 1218 (my MY $self, my ($base_path, @rest)) = @_;
1384 1218 ▶ return if grep {not defined} $base_path, @rest;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not defined $_;} $base_path, @rest 578 640 1218
1385 640 my @cf = $self->list_config_files(join("", $base_path, @rest));
1386 640 ▶ $self->error("Multiple configuration files!", @cf) if @cf > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @cf > 1 0 640 640
1387 640 ▶ return $cf[0] if @cf;
Branch: 1 branch
BranchTrueFalseTotal
if @cf 10 630 640
1388 630 return;
1389 }
1390  
1391 949 ▶sub list_config_files {
Subroutine list_config_files: called CC=2 SCAR=6.9
Pod undocumented
1392 949 (my MY $self, my $base_path) = @_;
1393 map {
1394 949 my $cf = "$base_path.$_";
1395 1898 ▶ -e $cf ? $cf : ()
Branch: 1 branch
BranchTrueFalseTotal
-e $cf ? : 33 1865 1898
1396 } $self->config_filetypes
1397 }
1398  
1399 29 ▶sub read_file_xhf {
Subroutine read_file_xhf: called CC=2 SCAR=7.0
Pod undocumented
1400 29 (my MY $self, my $fn) = @_;
1401 29 ▶ my $bytes_semantics = ref $self && $self->{binary_config};
Condition66%2/3
ref $self && $self->{'binary_config'}
!ll&&!rl&&r
4250
MC/DC0%0/2
ref $self && $self->{'binary_config'}
ref $self $self->{'binary_config'}
Truth table66%2/3
A && B
A= ref $selfB= $self->{'binary_config'}
ABresult
0X0
100
111
1402 29 $self->YATT::Lite::XHF::read_file_xhf
1403 ($fn, bytes => $bytes_semantics);
1404 }
1405  
1406 7 ▶sub read_file_yml {
Subroutine read_file_yml: called CC=3 SCAR=11.2
Pod undocumented
1407 7 (my MY $self, my $fn) = @_;
1408 7 require YAML::Tiny;
1409 7 my $yaml = YAML::Tiny->read($fn);
1410 6 ▶ unless (defined $yaml) { # YAML::Tiny old version doesn't raise error.
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $yaml) 0 6 6
1411 0 Carp::croak(YAML::Tiny->errstr . ""); # errstr is deprecated, but only old version can reach this line.
1412 }
1413 6 ▶ wantarray ? lexpand($yaml->[0]) : $yaml->[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 4 6
1414 }
1415  
1416 #========================================
1417  
1418 1473 ▶sub trim_slash {
Subroutine trim_slash: called CC=1 SCAR=0.0
Pod undocumented
1419 1473 $_[0] =~ s,/*$,,;
1420 1473 $_[0];
1421 }
1422  
1423 1134 ▶sub ensure_slash {
Subroutine ensure_slash: called CC=4 SCAR=15.9
Pod undocumented
1424 1134 ▶ unless (defined $_[0] and $_[0] ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and $_[0] ne '') { } 1134 0 1134
Condition33%1/3
defined $_[0] and $_[0] ne ""
!ll&&!rl&&r
001134
MC/DC0%0/2
defined $_[0] and $_[0] ne ""
defined $_[0] $_[0] ne ""
Truth table33%1/3
A and B
A= defined $_[0]B= $_[0] ne ""
ABresult
0X0
100
111
1425 0 $_[0] = '/';
1426 } else {
1427 1134 my $abs = File::Spec->rel2abs($_[0]);
1428 1134 ▶ my $sep = $^O =~ /^MSWin/ ? "\\" : "/";
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /^MSWin/ ? : 0 1134 1134
1429 1134 $abs =~ s{(?:\Q$sep\E)?$}{$sep}; # Should end with path-separator.
1430 1134 $_[0] = $abs;
1431 }
1432 }
1433  
1434 #========================================
1435 {
1436 72 ▶ Entity site_prefix => sub {
Subroutine __ANON__: not called CC=1 SCAR=2.6
1437 0 my MY $self = $SYS;
1438 0 $self->{site_prefix};
1439 72 };
1440 }
1441  
1442  
1443 72 1;
« blib/lib/YATT/Lite/LRXML/ParseEntpath.pm ↑ Summary blib/lib/YATT/Lite/PSGIEnv.pm »