blib/lib/YATT/Lite.pm

filter: Statementstmt 84.0% 322 / 383 Branchbran 61.2% 71 / 116 Conditioncond 46.0% 29 / 63 MC/DCmcdc 12.5% 5 / 40 Subroutinesub 84.4% 76 / 90 Podpod 8.7% 5 / 57 totaltotal 67.8% 508 / 749 CC 83 SCAR 19.0
CC
83
Cov
75%
prepare_part_handler
42.0
entity_stash
42.0
ensure_supplns
15.2
CRAP 6.7
« blib/lib/YATT/Lite/WebMVC0/SubRoutes.pm ↑ Summary blib/lib/YATT/Lite/Connection.pm »
1 package YATT::Lite; sub MY () {__PACKAGE__}
2 52 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 52 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 52 ▶use 5.010; no if $] >= 5.017011, warnings => "experimental";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 52 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 52 our $VERSION = '0.199_004';
8 52 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 52 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 52 ▶use List::MoreUtils qw/uniq/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 #
14 # YATT Internalへの Facade. YATT の初期化パラメータの保持者でもある。
15 #
16 52 ▶use parent qw/YATT::Lite::Object File::Spec/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 52 ▶use YATT::Lite::Partial::MarkAfterNew -as_base;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 52 ▶use YATT::Lite::MFields qw/_YATT
Subroutine BEGIN: called CC=1 SCAR=0.0
19 dir
20 vfs base
21 factory
22 header_charset
23 output_encoding
24 tmpl_encoding
25 index_name
26 ext_public
27 ext_private
28 app_ns
29 _entns
30 _cgen_class
31  
32 app_name
33 debug_cgen debug_parser namespace only_parse
34 special_entities no_lineinfo check_lineno
35 rc_script
36 tmpl_cache
37 dont_map_args
38 dont_debug_param
39 info
40 lcmsg_sink
41 always_refresh_deps
42 no_mro_c3
43 render_as_bytes
44  
45 default_lang
46  
47 entns2vfs_item
48 import
49 match_argsroute_first
50 stash_unknown_params_to
51 body_argument
52 body_argument_type
53 prefer_call_for_entity
54 no_conditional_call
55 allow_bare_entity_in_decl
56 no_chdir
57 52 /;
58  
59 52 ▶use constant DEBUG => $ENV{DEBUG_YATT_LITE};
Subroutine BEGIN: called CC=1 SCAR=0.0
60  
61 52 MY->cf_mkaccessors(qw/app_name/);
62  
63 # Entities を多重継承する理由は import も継承したいから。
64 # XXX: やっぱり、 YATT::Lite には固有の import を用意すべきではないか?
65 # yatt_default や cgen_perl を定義するための。
66 52 ▶use YATT::Lite::Entities -as_base, qw(*YATT *CON *SYS import);
Subroutine BEGIN: called CC=1 SCAR=0.0
67  
68 # For error, raise, DONE. This is inserted to ISA too.
69 52 ▶use YATT::Lite::Partial::ErrorReporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 52 ▶use YATT::Lite::Partial::AppPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 52 ▶use YATT::Lite::Util qw/globref lexpand extname ckrequire terse_dump escape
Subroutine BEGIN: called CC=1 SCAR=0.0
74 set_inc ostream try_invoke list_isa symtab
75 look_for_globref
76 subname ckeval ckrequire
77 secure_text_plain
78 raise_psgi_error
79 define_const
80 add_entity_into
81 52 /;
82  
83 sub Facade () {__PACKAGE__}
84 0 ▶sub default_app_ns {'MyYATT'}
Subroutine default_app_ns: not called CC=1 SCAR=6.9
Pod undocumented
85 174 ▶sub default_trans {'YATT::Lite::Core'}
Subroutine default_trans: called CC=1 SCAR=0.0
Pod undocumented
86 12 ▶sub default_export {(shift->SUPER::default_export, qw(Entity *SYS *CON))}
Subroutine default_export: called CC=1 SCAR=0.0
Pod undocumented
87 0 ▶sub default_index_name { '' }
Subroutine default_index_name: not called CC=1 SCAR=6.9
Pod undocumented
88 38 ▶sub default_ext_public {'yatt'}
Subroutine default_ext_public: called CC=1 SCAR=0.0
Pod undocumented
89 38 ▶sub default_ext_private {'ytmpl'}
Subroutine default_ext_private: called CC=1 SCAR=0.0
Pod undocumented
90 37 ▶sub default_body_argument { 'body' }
Subroutine default_body_argument: called CC=1 SCAR=0.0
Pod undocumented
91 37 ▶sub default_body_argument_type { 'code' }
Subroutine default_body_argument_type: called CC=1 SCAR=0.0
Pod undocumented
92 38 ▶sub default_output_encoding { 'utf-8' }
Subroutine default_output_encoding: called CC=1 SCAR=0.0
Pod undocumented
93  
94 394 ▶sub with_system {
Subroutine with_system: called CC=1 SCAR=0.0
Pod undocumented
95 394 (my MY $self, local $SYS, my $method) = splice @_, 0, 3;
96 394 local $YATT = $self;
97 394 $self->$method(@_);
98 }
99  
100 #
101 # "The cwd of a template is its directory" - scoped chdir with restore.
102 # Returns a guard object which restores the previous cwd when it goes
103 # out of scope (also when the scope dies). Returns undef (no-op) when
104 # this handler has no physical directory or no_chdir is configured.
105 # Note: chdir happens only for the entry dirhandler; templates in other
106 # directories called via base/import do not re-chdir. GH-267
107 #
108 396 ▶sub chdir_guard {
Subroutine chdir_guard: called CC=3 SCAR=11.0
Pod undocumented
109 396 (my MY $self) = @_;
110 396 ▶ return undef if $self->{no_chdir};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"no_chdir"} 1 395 396
111 395 ▶ defined(my $dir = $self->{dir}) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $dir = $self->{"dir"}) or return undef 395 0 395
112 395 YATT::Lite::ChdirGuard->new($dir);
113 }
114  
115 {
116 package YATT::Lite::ChdirGuard;
117 52 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 52 ▶ use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
119 52 require Cwd;
120 395 ▶ sub new {
Subroutine new: called CC=2 SCAR=7.0
121 395 my ($pack, $dir) = @_;
122 395 my $prev = Cwd::getcwd();
123 395 ▶ chdir($dir)
Branch: 1 branch
BranchTrueFalseTotal
chdir $dir or Carp::croak("Can't chdir '${dir}': $!") 395 0 395
124 or Carp::croak("Can't chdir '$dir': $!");
125 395 bless \$prev, $pack;
126 }
127 395 ▶ sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.2
128 395 my ($self) = @_;
129 # Best effort restore. Never die in DESTROY.
130 395 ▶ chdir($$self) if defined $$self;
Branch: 1 branch
BranchTrueFalseTotal
if defined $$self 395 0 395
131 }
132 }
133  
134 52 ▶sub after_new {
Subroutine after_new: called CC=7 SCAR=19.9
Pod documented
135 213 (my MY $self) = @_;
136 213 $self->SUPER::after_new;
137 213 ▶ $self->{index_name} //= "";
Condition100%2/2
$self->{"index_name"} //= ""
l!l
17538
MC/DC100%1/1
$self->{"index_name"} //= ""
$self->{"index_name"}
Truth table100%2/2
A
A= $self->{"index_name"}
Aresult
11
00
138 213 ▶ $self->{ext_public} //= $self->default_ext_public;
Condition66%2/3
$self->{"ext_public"} //= $self->default_ext_public
l!l&&r!l&&!r
175380
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
139 213 ▶ $self->{ext_private} //= $self->default_ext_private;
Condition66%2/3
$self->{"ext_private"} //= $self->default_ext_private
l!l&&r!l&&!r
175380
MC/DC0%0/2
$self->{"ext_private"} //= $self->default_ext_private
$self->{"ext_private"} $self->default_ext_private
Truth table66%2/3
A //= B
A= $self->{"ext_private"}B= $self->default_ext_private
ABresult
1X1
011
000
140 213 ▶ $self->{body_argument} //= $self->default_body_argument;
Condition66%2/3
$self->{"body_argument"} //= $self->default_body_argument
l!l&&r!l&&!r
176370
MC/DC0%0/2
$self->{"body_argument"} //= $self->default_body_argument
$self->{"body_argument"} $self->default_body_argument
Truth table66%2/3
A //= B
A= $self->{"body_argument"}B= $self->default_body_argument
ABresult
1X1
011
000
141 213 ▶ $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
176370
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
142 213 ▶ $self->{output_encoding} //= $self->default_output_encoding;
Condition66%2/3
$self->{"output_encoding"} //= $self->default_output_encoding
l!l&&r!l&&!r
175380
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
143 }
144  
145 213 ▶sub _after_after_new {
Subroutine _after_after_new: called CC=1 SCAR=0.0
146 213 (my MY $self) = @_;
147 213 weaken($self->{factory});
148 }
149  
150 0 ▶sub rel_app_name {
Subroutine rel_app_name: not called CC=2 SCAR=17.9
Pod undocumented
151 0 (my MY $self) = @_;
152 0 ▶ unless ($SYS) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($YATT::Lite::SYS) 0 0 0
153 0 Carp::croak "rel_app_name() is called without setting \$SYS!";
154 }
155 # XXX: This assumes $dir is somewhere under $app_root tree.
156 0 my $rel_app_name = substr($self->{dir}, length($SYS->app_root));
157 # Make sure leading / is removed.
158 0 $rel_app_name =~ s|^/||;
159 0 $rel_app_name;
160 }
161  
162 # XXX: kludge!
163 66 ▶sub find_neighbor_yatt {
Subroutine find_neighbor_yatt: called CC=1 SCAR=0.0
Pod undocumented
164 66 (my MY $self, my ($dir)) = @_;
165 66 $self->{factory}->load_yatt($dir);
166 }
167 65 ▶sub find_neighbor_vfs {
Subroutine find_neighbor_vfs: called CC=1 SCAR=0.0
Pod undocumented
168 65 (my MY $self, my ($dir)) = @_;
169 65 $self->find_neighbor_yatt($dir)->get_trans;
170 }
171 35 ▶sub find_neighbor {
Subroutine find_neighbor: called CC=1 SCAR=0.0
Pod undocumented
172 35 (my MY $self, my ($dir)) = @_;
173 35 $self->find_neighbor_vfs($dir)->root;
174 }
175  
176 #
177 # list all configs (named $name). (base first, then local one)
178 # (useful to avoid config repeation)
179 #
180 2 ▶sub cget_all {
Subroutine cget_all: called CC=2 SCAR=7.6
Pod undocumented
181 2 (my MY $self, my $name) = @_;
182 2 ▶ if ($name =~ /^_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^_/) 0 2 2
183 0 croak "Private field is prohibited: $name";
184 }
185 (map($_->cget_all($name)
186 , $self->list_base_obj)
187 2 , lexpand($self->{$name}));
188 }
189  
190 2 ▶sub list_base_obj {
Subroutine list_base_obj: called CC=1 SCAR=0.0
Pod undocumented
191 2 (my MY $self) = @_;
192 map {
193 2 $self->find_neighbor_yatt($self->app_path_normalize($_))
194 } $self->list_base_dir;
195 }
196  
197 2 ▶sub list_base_dir {
Subroutine list_base_dir: called CC=3 SCAR=11.7
Pod undocumented
198 2 (my MY $self) = @_;
199  
200 2 ▶ my $base = $self->{base} // do {
Condition33%1/3
$self->{"base"} // do { my(%vfs) = lexpand($self->{"vfs"}); [map({if (ref $_ eq "ARRAY") { my(%vfs_base) = @$_; $vfs_base{"dir"}; } else { $_->{"path"}; } ;} lexpand($vfs{"base"}))] }
l!l&&r!l&&!r
020
MC/DC0%0/2
$self->{"base"} // do { my(%vfs) = lexpand($self->{"vfs"}); [map({if (ref $_ eq "ARRAY") { my(%vfs_base) = @$_; $vfs_base{"dir"}; } else { $_->{"path"}; } ;} lexpand($vfs{"base"}))] }
$self->{"base"} do { my(%vfs) = lexpand($self->{"vfs"}); [map({if (ref $_ eq "ARRAY") { my(%vfs_base) = @$_; $vfs_base{"dir"}; } else { $_->{"path"}; } ;} lexpand($vfs{"base"}))] }
Truth table33%1/3
A // B
A= $self->{"base"}B= do { my(%vfs) = lexpand($self->{"vfs"}); [map({if (ref $_ eq "ARRAY") { my(%vfs_base) = @$_; $vfs_base{"dir"}; } else { $_->{"path"}; } ;} lexpand($vfs{"base"}))] }
ABresult
1X1
011
000
201 2 my %vfs = lexpand($self->{vfs});
202 [map {
203 #
204 # Each element of $vfs{base} is either ARRAY (of vfs spec)
205 # or YATT::Lite::VFS::Dir object (instantiated from spec).
206 #
207 1 ▶ if (ref $_ eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq 'ARRAY') { } 1 0 1
208 1 my %vfs_base = @$_;
209 1 $vfs_base{dir};
210 } else {
211 0 $_->{path};
212 }
213 2 } lexpand($vfs{base})];
214 };
215  
216 2 lexpand($base);
217 }
218  
219 #========================================
220 # file extension based handler dispatching.
221 #========================================
222  
223 331 ▶sub handle {
Subroutine handle: called CC=3 SCAR=11.2
Pod undocumented
224 331 (my MY $self, my ($ext, $con, $file)) = @_;
225 331 local ($YATT, $CON) = ($self, $con);
226 331 $con->configure(yatt => $self);
227 331 ▶ if (my $enc = $self->{output_encoding}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $enc = $self->{"output_encoding"}) 331 0 331
228 331 $con->configure(encoding => $enc);
229 }
230  
231 331 ▶ unless (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 331 331
232 0 confess "\n\nFilename for DirHandler->handle() is undef!"
233 ." in $self->{app_ns}.\n";
234 }
235  
236 331 my $sub = $YATT->find_handler($ext, $file, $CON);
237  
238 331 my $result = $sub->($YATT, $CON, $file);
239  
240 291 try_invoke($CON, 'flush_headers');
241  
242 291 $result;
243 }
244  
245 21 ▶sub render {
Subroutine render: called CC=2 SCAR=6.9
Pod documented
246 21 my MY $self = shift;
247 21 my $raw_bytes = $self->render_encoded(@_);
248 21 ▶ if ($self->{render_as_bytes}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'render_as_bytes'}) { } 1 20 21
249 1 $raw_bytes
250 } else {
251 20 Encode::decode(utf8 => $raw_bytes);
252 }
253 }
254  
255 21 ▶sub render_encoded {
Subroutine render_encoded: called CC=4 SCAR=13.9
Pod undocumented
256 21 my MY $self = shift;
257 21 my $buffer; {
258 21 ▶ my $encName = $self->{render_as_bytes} ? undef : $self->{output_encoding};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'render_as_bytes'} ? : 1 20 21
259 21 ▶ my $con = $SYS
Branch: 2 branches
BranchTrueFalseTotal
$YATT::Lite::SYS ? : 0 21 21
$encName ? : 20 1 21
260 ? $SYS->make_connection(undef, buffer => \$buffer, yatt => $self,
261 noheader => 1,
262 encoding => $encName)
263 : ostream(\$buffer, $encName ? ":encoding($encName)" : "");
264 21 $self->render_into($con, @_);
265 }
266 21 $buffer;
267 }
268  
269 87 ▶sub render_into {
Subroutine render_into: called CC=3 SCAR=11.0
Pod documented
270 87 (my MY $self, my ($con, $file, $args)) = @_;
271 87 local ($YATT, $CON) = ($self, $con);
272 87 ▶ if (ref $file eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file eq 'ARRAY') { } 1 86 87
273 # [$file, $type, $item]
274 1 $self->open_trans->render_into($CON, $file, $args);
275 } else {
276 $self->raw_render_into(
277 $con,
278 86 ▶ YATT::Lite::Util::rootname($file || $self->{index_name}),
Condition100%3/3
$file || $self->{'index_name'}
l!l&&r!l&&!r
7763
MC/DC100%2/2
$file || $self->{'index_name'}
$file $self->{'index_name'}
Truth table100%3/3
A || B
A= $fileB= $self->{'index_name'}
ABresult
1X1
011
000
279 $args,
280 );
281 }
282 87 try_invoke($con, 'flush_headers');
283 }
284  
285 86 ▶sub raw_render_into {
Subroutine raw_render_into: called CC=1 SCAR=0.0
Pod undocumented
286 86 (local ($YATT), my ($con, $file, $args)) = @_;
287 86 my ($part, $sub, $pkg) = $YATT->open_trans->find_part_renderer($file);
288 86 $sub->($pkg, $con, $part->reorder_hash_params($args));
289 }
290  
291 293 ▶sub find_handler {
Subroutine find_handler: called CC=5 SCAR=18.9
Pod documented
292 293 (my MY $self, my ($ext, $file, $con)) = @_;
293 293 ▶ $ext //= $self->cut_ext($file) || $self->{ext_public};
Condition16%1/6
$ext //= $self->cut_ext($file) || $self->{"ext_public"}
l!l&&r!l&&!r
29300
$self->cut_ext($file) || $self->{'ext_public'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$ext //= $self->cut_ext($file) || $self->{"ext_public"}
$ext $self->cut_ext($file) $self->{'ext_public'}
Truth table0%0/4
A //= B || C
A= $extB= $self->cut_ext($file)C= $self->{'ext_public'}
ABCresult
1XX1
01X1
0011
0000
294 293 ▶ $ext = "yatt" if $ext eq $self->{ext_public};
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq $self->{"ext_public"} 281 12 293
295 293 ▶ my $sub = $self->can("_handle_$ext")
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $self->can("_handle_$ext") or die "Unsupported file type: $ext" 293 0 293
296 or die "Unsupported file type: $ext";
297 293 $sub;
298 }
299  
300 #----------------------------------------
301  
302 # 直接呼ぶことは禁止。∵ $YATT, $CON を設定するのは handle の役目だから。
303 281 ▶sub _handle_yatt {
Subroutine _handle_yatt: called CC=1 SCAR=0.0
304 281 (my MY $self, my ($con, $file)) = @_;
305  
306 281 my ($part, $sub, $pkg, $args)
307 = $self->prepare_part_handler($con, $file);
308  
309 273 $sub->($pkg, $con, @$args);
310  
311 265 $con;
312 }
313  
314 0 ▶sub _handle_ytmpl {
Subroutine _handle_ytmpl: not called CC=1 SCAR=6.9
315 0 (my MY $self, my ($con, $file)) = @_;
316  
317 0 $self->raise_psgi_error(403, "Forbidden filetype: $file");
318 }
319  
320 #----------------------------------------
321  
322 0 ▶sub prepare_part_handler {
Subroutine prepare_part_handler: not called CC=6 SCAR=37.4
Pod undocumented
323 0 (my MY $self, my ($con, $file)) = @_;
324  
325 0 my $trans = $self->open_trans;
326  
327 0 my $mapped = [$file, my ($type, $item) = $con->sigil_type_item()];
328 0 ▶ if (not $self->{dont_debug_param}
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"dont_debug_param"} and -e ".htdebug_param") 0 0 0
Condition0%0/3
not $self->{"dont_debug_param"} and -e ".htdebug_param"
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"dont_debug_param"} and -e ".htdebug_param"
not $self->{"dont_debug_param"} -e ".htdebug_param"
Truth table0%0/3
not(A) and B
A= not $self->{"dont_debug_param"}B= -e ".htdebug_param"
ABresult
0X0
100
111
329 and -e ".htdebug_param") {
330 0 $self->dump($mapped, [map {[$_ => $con->param($_)]} $con->param]);
331 }
332  
333 # XXX: public に限定するのはどこで? ここで?それとも find_自体?
334 0 my ($part, $sub, $pkg) = $trans->find_part_handler($mapped);
335 0 ▶ unless ($part->public) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($part->public) 0 0 0
336 # XXX: refresh する手もあるだろう。
337 0 croak $self->error(q|Forbidden request %s|, terse_dump($mapped));
338 }
339  
340 0 my @args; @args = $trans->reorder_cgi_params($part, $con)
341 0 ▶ unless $self->{dont_map_args} || $part->isa($trans->Action);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"dont_map_args"} or $part->isa($trans->Action) 0 0 0
Condition0%0/3
$self->{"dont_map_args"} or $part->isa($trans->Action)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"dont_map_args"} or $part->isa($trans->Action)
$self->{"dont_map_args"} $part->isa($trans->Action)
Truth table0%0/3
A or B
A= $self->{"dont_map_args"}B= $part->isa($trans->Action)
ABresult
1X1
011
000
342  
343 0 ($part, $sub, $pkg, \@args);
344 }
345  
346 # XXX: deprecated
347 281 ▶sub parse_request_sigil {
Subroutine parse_request_sigil: called CC=1 SCAR=0.0
Pod undocumented
348 281 (my MY $self, my ($con)) = @_;
349 281 $con->sigil_type_item();
350 }
351  
352 331 ▶sub cut_ext {
Subroutine cut_ext: called CC=3 SCAR=11.4
Pod undocumented
353 331 my ($self, $fn) = @_;
354 331 ▶ croak "Undefined filename!" unless defined $fn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fn 0 331 331
355 331 ▶ return undef unless $fn =~ s/\.(\w+$)//;
Branch: 1 branch
BranchTrueFalseTotal
unless $fn =~ s/\.(\w+$)// 0 331 331
356 331 $1;
357 }
358  
359 #========================================
360 # hook
361 #========================================
362 404 ▶sub finalize_connection {}
Subroutine finalize_connection: called CC=1 SCAR=0.0
Pod undocumented
363  
364 #========================================
365 # Output encoding. Used in scripts/yatt*
366 #========================================
367 3 ▶sub fconfigure_encoding {
Subroutine fconfigure_encoding: called CC=4 SCAR=14.0
Pod undocumented
368 3 my MY $self = shift;
369 3 ▶ return unless $self->{output_encoding};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"output_encoding"} 0 3 3
370 3 my $enc = "encoding($self->{output_encoding})";
371 3 require PerlIO;
372 3 foreach my $fh (@_) {
373 6 ▶ next if grep {$_ eq $enc} PerlIO::get_layers($fh);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $enc;} &PerlIO::get_layers($fh) 0 6 6
374 6 binmode($fh, ":$enc");
375 }
376 3 $self;
377 }
378  
379 #========================================
380 # Delayed loading of YATT::Lite::Core
381 #========================================
382  
383 52 *open_vfs = *open_trans; *open_vfs = *open_trans;
384 422 ▶sub open_trans {
Subroutine open_trans: called CC=1 SCAR=0.0
Pod undocumented
385 422 (my MY $self) = @_;
386 422 my $trans = $self->get_trans;
387 422 $trans->reset_refresh_mark;
388 422 $trans;
389 }
390  
391 52 *get_vfs = *get_trans; *get_vfs = *get_trans;
392 1070 ▶sub get_trans {
Subroutine get_trans: called CC=2 SCAR=6.9
Pod undocumented
393 1070 (my MY $self) = @_;
394 1070 ▶ $self->{_YATT} || $self->build_trans($self->{tmpl_cache});
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_YATT"} or $self->build_trans($self->{"tmpl_cache"}) 896 174 1070
395 }
396  
397 174 ▶sub build_trans {
Subroutine build_trans: called CC=3 SCAR=11.4
Pod undocumented
398 174 (my MY $self, my ($vfscache, $vfsspec, @rest)) = @_;
399 174 my $class = $self->default_trans;
400 174 ckrequire($class);
401  
402 174 ▶ my @vfsspec = @{$vfsspec || $self->{vfs}};
Condition33%1/3
$vfsspec || $self->{'vfs'}
l!l&&r!l&&!r
01740
MC/DC0%0/2
$vfsspec || $self->{'vfs'}
$vfsspec $self->{'vfs'}
Truth table33%1/3
A || B
A= $vfsspecB= $self->{'vfs'}
ABresult
1X1
011
000
403 174 ▶ push @vfsspec, base => $self->{base} if $self->{base};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"base"} 0 174 174
404  
405 $self->{_YATT} = $class->new
406 (\@vfsspec
407 , facade => $self
408 , cache => $vfscache
409 , entns2vfs_item => $self->{entns2vfs_item}
410 , entns => $self->{_entns}
411 , @rest
412 174 , $self->cf_delegate_defined($self->_cf_delegates));
413 }
414  
415 175 ▶sub _cf_delegates {
Subroutine _cf_delegates: called CC=1 SCAR=0.0
416 175 qw(namespace
417 base
418 die_in_error
419 tmpl_encoding
420 debug_cgen
421 debug_parser
422 special_entities
423 no_lineinfo
424 check_lineno
425 index_name
426 ext_public
427 ext_private
428 rc_script
429 lcmsg_sink
430 only_parse
431 always_refresh_deps
432 no_mro_c3
433 import
434 match_argsroute_first
435 stash_unknown_params_to
436 body_argument
437 body_argument_type
438 prefer_call_for_entity
439 no_conditional_call
440 allow_bare_entity_in_decl
441 )
442 }
443  
444 213 ▶sub _before_after_new {
Subroutine _before_after_new: called CC=2 SCAR=7.6
445 213 (my MY $self) = @_;
446 213 ▶ $self->{app_ns} //= $self->default_app_ns;
Condition33%1/3
$self->{"app_ns"} //= $self->default_app_ns
l!l&&r!l&&!r
21300
MC/DC0%0/2
$self->{"app_ns"} //= $self->default_app_ns
$self->{"app_ns"} $self->default_app_ns
Truth table33%1/3
A //= B
A= $self->{"app_ns"}B= $self->default_app_ns
ABresult
1X1
011
000
447 213 $self->{_entns} = $self->ensure_entns($self->{app_ns});
448 }
449  
450 #========================================
451 # Code generator class
452 #========================================
453  
454 sub root_CGEN_perl () { 'YATT::Lite::CGen::Perl' }
455 52 *CGEN_perl = *root_CGEN_perl; *CGEN_perl = *root_CGEN_perl;
456 153 ▶sub ensure_cgen_for {
Subroutine ensure_cgen_for: called CC=1 SCAR=0.0
Pod undocumented
457 153 my ($mypack, $type, $app_ns) = @_;
458 153 $mypack->ensure_supplns("CGEN_$type" => $app_ns);
459 }
460  
461 422 ▶sub get_cgen_class {
Subroutine get_cgen_class: called CC=3 SCAR=11.3
Pod undocumented
462 422 (my MY $self, my $type) = @_;
463 422 my $name = "CGEN_$type";
464 422 ▶ my $sub = $self->can("root_$name")
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $self->can("root_$name") or croak("Unknown cgen class: $type") 422 0 422
465 or croak "Unknown cgen class: $type";
466 $self->{_cgen_class}{$type}
467 422 ▶ ||= $self->ensure_cgen_for($type, $self->{app_ns});
Condition66%2/3
$self->{"_cgen_class"}{$type} ||= $self->ensure_cgen_for($type, $self->{"app_ns"})
l!l&&r!l&&!r
2691530
MC/DC0%0/2
$self->{"_cgen_class"}{$type} ||= $self->ensure_cgen_for($type, $self->{"app_ns"})
$self->{"_cgen_class"}{$type} $self->ensure_cgen_for($type, $self->{"app_ns"})
Truth table66%2/3
A ||= B
A= $self->{"_cgen_class"}{$type}B= $self->ensure_cgen_for($type, $self->{"app_ns"})
ABresult
1X1
011
000
468 }
469  
470 22 ▶sub is_default_cgen_ready {
Subroutine is_default_cgen_ready: called CC=1 SCAR=0.0
Pod undocumented
471 22 (my MY $self) = @_;
472 22 $self->{_cgen_class}{perl};
473 }
474  
475 #========================================
476 # Entity
477 #========================================
478  
479 110 ▶sub root_EntNS { 'YATT::Lite::Entities' }
Subroutine root_EntNS: called CC=1 SCAR=0.0
Pod undocumented
480  
481 # ${app_ns}::EntNS を作り、(YATT::Lite::Entities へ至る)継承関係を設定する。
482 # $app_ns に EntNS constant を追加する。
483 # 複数回呼ばれた場合、既に定義済みの entns を返す
484  
485 1993 ▶sub should_use_mro_c3 {
Subroutine should_use_mro_c3: called CC=2 SCAR=6.9
Pod undocumented
486 1993 (my MY $self_or_pack) = @_;
487 1993 ▶ if (ref $self_or_pack) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self_or_pack) { } 925 1068 1993
488 not $self_or_pack->{no_mro_c3}
489 925 } else {
490 1068 mro::get_mro($self_or_pack) eq 'c3';
491 }
492 }
493  
494 #========================================
495  
496 # These ns-related methods (ensure_...) are called as Class Methods.
497 # This means you can't touch instance fields.
498  
499 # Old interface.
500 # ensure_entns($app_ns, @base_entns)
501 # returns EntNS for $app_ns with correct inheritance settings.
502 #
503 1182 ▶sub ensure_entns {
Subroutine ensure_entns: called CC=1 SCAR=0.0
Pod undocumented
504 1182 my ($mypack, $app_ns, @base_entns) = @_;
505 1182 my $entns = $mypack->ensure_supplns(EntNS => $app_ns, \@base_entns
506 , undef, +{no_fields => 1});
507 1182 $entns;
508 }
509  
510 # New interface.
511 # ensure_supplns($kind, $app_ns, [@base_suppls], [@base_mains], {%opts})
512 # returns ${app_ns}::${kind} with correct inheritance.
513 #
514 # [@base_suppls] gives base supplemental classes for this supplns.
515 # [@base_mains] gives (not supplemental but) main classes for this.
516 #
517 # If both base_suppls and base_mains is empty, base_mains is derived
518 # from current @ISA of $app_ns.
519 #
520 1622 ▶sub ensure_supplns {
Subroutine ensure_supplns: called CC=15 SCAR=27.2
Pod undocumented
521 1622 my ($mypack, $kind, $app_ns, $base_suppls, $base_mains, $opts) = @_;
522  
523 1622 my $supplns = join("::", $app_ns, $kind);
524  
525 52 ▶ my $sym = do {no strict 'refs'; \*{$supplns}};
Subroutine BEGIN: called CC=1 SCAR=0.0
526 1622 ▶ if (*{$sym}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*{$sym;}{"CODE"}) 767 855 1622
527 # croak "$kind for $app_ns is already defined!";
528 767 return $supplns;
529 }
530  
531 855 my $app_ns_filename = do {
532 855 my $sub = $app_ns->can("filename");
533 855 ▶ $sub ? ("(For path '".($sub->() // '')."')") : "";
Branch: 1 branch
BranchTrueFalseTotal
$sub ? : 309 546 855
Condition100%2/2
&$sub() // ""
l!l
3045
MC/DC100%1/1
&$sub() // ""
&$sub()
Truth table100%2/2
A
A= &$sub()
Aresult
11
00
534 };
535  
536 855 print STDERR "# First ensure_supplns $kind for $app_ns $app_ns_filename: "
537 , terse_dump($base_suppls, $base_mains, $opts), "\n" if DEBUG;
538  
539 855 ▶ if (not $base_suppls and not $base_mains) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($base_suppls or $base_mains) 283 572 855
Condition66%2/3
$base_suppls or $base_mains
l!l&&r!l&&!r
5720283
MC/DC50%1/2
$base_suppls or $base_mains
$base_suppls $base_mains
Truth table66%2/3
A or B
A= $base_supplsB= $base_mains
ABresult
1X1
011
000
540 283 my @isa = list_isa($app_ns);
541 283 print STDERR "# app_ns $app_ns isa: "
542 , terse_dump(@isa), "\n" if DEBUG;
543  
544 283 ▶ $base_mains = $mypack->should_use_mro_c3
Branch: 1 branch
BranchTrueFalseTotal
$mypack->should_use_mro_c3 ? : 283 0 283
545 ? [reverse @isa] : \@isa;
546 }
547  
548 my @baseclass = (lexpand($base_suppls), map {
549 855 $mypack->ensure_supplns($kind => $_, undef, undef, $opts);
550 } lexpand($base_mains));
551  
552 855 ▶ if ($mypack->should_use_mro_c3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mypack->should_use_mro_c3) { } 853 2 855
553 853 print STDERR "# $kind - Set mro c3 for $supplns $app_ns_filename since $mypack uses c3\n" if DEBUG;
554 853 mro::set_mro($supplns, 'c3')
555 } else {
556 2 print STDERR "# $kind - Keep mro dfs for $supplns $app_ns_filename since $mypack uses dfs\n" if DEBUG;
557 }
558  
559 # $app_ns が %FIELDS 定義を持たない時(ex YLObjectでもPartialでもない)に限り、
560 # YATT::Lite への継承を設定する
561 855 ▶ unless (YATT::Lite::MFields->has_fields($app_ns)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("YATT::Lite::MFields"->has_fields($app_ns)) 38 817 855
562 # XXX: $mypack への継承にすると、あちこち動かなくなるぜ?なんで?
563 38 print STDERR "# app_ns - Add ISA for '$app_ns' with fields: ",MY,"\n"
564 if DEBUG;
565 38 YATT::Lite::MFields->add_isa_to($app_ns, MY)->define_fields($app_ns);
566 }
567  
568 855 ▶ unless (grep {$_->can($kind)} @baseclass) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->can($kind);} @baseclass) 855 0 855
569 855 ▶ my $base = try_invoke($app_ns, $kind) // $mypack->can("root_$kind")->();
Condition66%2/3
try_invoke($app_ns, $kind) // $mypack->can("root_$kind")->()
l!l&&r!l&&!r
7451100
MC/DC0%0/2
try_invoke($app_ns, $kind) // $mypack->can("root_$kind")->()
try_invoke($app_ns, $kind) $mypack->can("root_$kind")->()
Truth table66%2/3
A // B
A= try_invoke($app_ns, $kind)B= $mypack->can("root_$kind")->()
ABresult
1X1
011
000
570 855 ckrequire($base);
571 855 print STDERR "# $kind - Set default base for $supplns <- ($base)\n" if DEBUG;
572 855 ▶ if ($mypack->should_use_mro_c3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mypack->should_use_mro_c3) { } 853 2 855
573 853 push @baseclass, $base;
574 } else {
575 2 unshift @baseclass, $base;
576 }
577 }
578  
579 855 do {
580 855 my @cls = uniq @baseclass;
581 855 print STDERR "# $kind - Add ISA for $supplns <- (@cls)\n" if DEBUG;
582 855 YATT::Lite::MFields->add_isa_to($supplns, @cls);
583 };
584 855 ▶ if (not $opts->{no_fields}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"no_fields"}) 283 572 855
585 283 YATT::Lite::MFields->define_fields($supplns);
586 }
587  
588 855 set_inc($supplns, 1);
589  
590 # $kind() を足すのは最後にしないと、再帰継承に陥る
591 855 ▶ unless (my $code = *{$sym}{CODE}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $code = *{$sym;}{'CODE'}) { } 0 855 855
if (do { (my $old = &$code()) ne $supplns }) { } 0 0 0
592 855 define_const($sym, $supplns);
593 } elsif ((my $old = $code->()) ne $supplns) {
594 0 croak "Can't add $kind() to '$app_ns'. Already has $kind as $old!";
595 } else {
596 # ok.
597 }
598 855 $supplns
599 }
600  
601 130 ▶sub list_entns {
Subroutine list_entns: called CC=2 SCAR=6.9
Pod undocumented
602 130 my ($pack, $inspected) = @_;
603 map {
604 130 ▶ defined(symtab($_)->{'EntNS'}) ? join("::", $_, 'EntNS') : ()
Branch: 1 branch
BranchTrueFalseTotal
defined symtab($_)->{'EntNS'} ? : 112 111 223
605 } list_isa($inspected)
606 }
607  
608 # use YATT::Lite qw(Entity); で呼ばれ、
609 # $callpack に Entity 登録関数を加える.
610 406 ▶sub define_Entity {
Subroutine define_Entity: called CC=5 SCAR=16.1
Pod undocumented
611 406 my ($myPack, $opts, $callpack, @base) = @_;
612  
613 # Entity を追加する先は、 $callpack が Object 系か、 stateless 系かで変化する
614 # Object 系の場合は、 ::EntNS を作ってそちらに加え, 同時に YATT() も定義する
615 406 my $is_objclass = is_objclass($callpack);
616 406 ▶ my $destns = $is_objclass
Branch: 1 branch
BranchTrueFalseTotal
$is_objclass ? : 400 6 406
617 ? $myPack->ensure_entns($callpack, @base)
618 : $callpack;
619  
620 # 既にあるなら何もしない。... バグの温床にならないことを祈る。
621 406 my $ent = globref($callpack, 'Entity');
622 406 ▶ unless (*{$ent}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (*{$ent;}{"CODE"}) 401 5 406
623 1281 ▶ *$ent = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
624 1281 my ($name, $sub) = @_;
625 1281 ▶ if ($myPack->add_entity_into($destns, $name, $sub)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($myPack->add_entity_into($destns, $name, $sub)) 1281 0 1281
626 1281 print STDERR "# defined entity $name in $destns\n" if DEBUG;
627 }
628 401 };
629 }
630  
631 406 ▶ if ($is_objclass) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_objclass) 400 6 406
632 400 *{globref($destns, 'YATT')} = *YATT;
633  
634 400 ▶ unless ($callpack->can("entity")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($callpack->can("entity")) 57 343 400
635 57 *{globref($callpack, "entity")} = $myPack->can('entity');
636 }
637 }
638  
639 406 return $destns;
640 }
641  
642 #
643 # Note about 'Action' registration mechanism in .htyattrc.pl
644 #
645 # First, *globref() = $action is not enough. Because...
646 #
647 # There are 2 places to hold actions.
648 # 1. $YATT->{Action} <= comes from *.ydo
649 # 2. $vfs_folder->{Item} <= comes from !yatt:action in templates
650 #
651 # Action in .htyattrc.pl is, special case of 2.
652 # Since 2. is managed by yatt vfs, it must be wrapped by Action object
653 # so that $vfs->find_part_handler works well.
654 #
655 #
656 # This is bit complicated because .htyattrc.pl is loaded *BEFORE* $YATT
657 # is instantiated. This means "Action => name, $handler" can not touch $YATT
658 # at that time. So, I need to delay actual registration until $YATT is created.
659 #
660 # To achieve this, $handler is registered first in %Actions of caller,
661 # then installed into actual vfs.
662 #
663 # Also note: loading of .htyattrc.pl is handled by Factory.
664 #
665 sub ACTION_DICT_SYM () {'Actions'}
666 1 ▶sub define_Action {
Subroutine define_Action: called CC=1 SCAR=0.0
Pod undocumented
667 1 my ($myPack, $opts, $callpack) = @_;
668  
669 1 *{globref($callpack, ACTION_DICT_SYM)} = my $action_dict = +{};
670  
671 1 ▶ *{globref($callpack, 'Action')} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
672 1 my ($name, $sub) = @_;
673 1 my @caller = my ($callpack, $filename, $lineno) = caller;
674 1 ▶ if (defined (my $old = $action_dict->{$name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $old = $action_dict->{$name})) 0 1 1
675 0 croak "Duplicate definition of Action '$name'! previously"
676 ." at $old->[1][1] line $old->[1][2]\n new at $filename line $lineno\n";
677 }
678 1 $action_dict->{$name} = [$sub, \@caller];
679 1 };
680 }
681  
682 10 ▶sub setup_rc_actions {
Subroutine setup_rc_actions: called CC=3 SCAR=11.0
Pod undocumented
683 10 (my $self) = @_;
684 10 ▶ my $glob = look_for_globref($self, ACTION_DICT_SYM)
Branch: 1 branch
BranchTrueFalseTotal
my $glob = look_for_globref($self, "Actions") or return 1 9 10
685 or return;
686 1 my $dict = *{$glob}{HASH};
687  
688 1 my $vfs = $self->get_vfs;
689 1 foreach my $name (keys %$dict) {
690 1 $vfs->add_root_action_handler($name, @{$dict->{$name}});
691 }
692 }
693  
694 # ここで言う Object系とは、
695 # YATT::Lite::Object を継承してるか、
696 # 又は既に %FIELDS が定義されている class
697 # のこと
698 406 ▶sub is_objclass {
Subroutine is_objclass: called CC=3 SCAR=11.0
Pod undocumented
699 406 my ($class) = @_;
700 406 ▶ return 1 if UNIVERSAL::isa($class, 'YATT::Lite::Object');
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($class, "YATT::Lite::Object") 394 12 406
701 12 ▶ my $sym = look_for_globref($class, 'FIELDS')
Branch: 1 branch
BranchTrueFalseTotal
my $sym = look_for_globref($class, "FIELDS") or return 0 6 6 12
702 or return 0;
703 6 *{$sym}{HASH};
704 }
705  
706 0 ▶sub entity {
Subroutine entity: not called CC=1 SCAR=6.9
Pod documented
707 0 (my MY $yatt, my $name) = splice @_, 0, 2;
708 0 my $this = $yatt->EntNS;
709 0 $this->can("entity_$name")->($this, @_);
710 }
711  
712 52 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
713 52 MY->define_Entity(undef, MY);
714 }
715  
716 #========================================
717 # Locale gettext support.
718 #========================================
719  
720 0 ▶sub use_encoded_config {
Subroutine use_encoded_config: not called CC=1 SCAR=6.9
Pod undocumented
721 0 (my MY $self) = @_;
722 $self->{tmpl_encoding}
723 0 }
724  
725 52 ▶use YATT::Lite::Partial::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
726  
727 # Extract (and cache, for later merging) l10n msgs from filelist.
728 # By default, it merges $filelist into existing locale_cache.
729 # To get fresh list, explicitly pass $msglist=[].
730 #
731 2 ▶sub lang_extract_lcmsg {
Subroutine lang_extract_lcmsg: called CC=3 SCAR=13.3
Pod undocumented
732 2 (my MY $self, my ($lang, $filelist, $msglist, $msgdict)) = @_;
733  
734 2 ▶ if (not $msglist and not $msgdict) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($msglist or $msgdict) 0 2 2
Condition33%1/3
$msglist or $msgdict
l!l&&r!l&&!r
200
MC/DC0%0/2
$msglist or $msgdict
$msglist $msgdict
Truth table33%1/3
A or B
A= $msglistB= $msgdict
ABresult
1X1
011
000
735 0 ($msglist, $msgdict) = $self->lang_msgcat($lang)
736 }
737  
738 2 $self->get_trans->extract_lcmsg($filelist, $msglist, $msgdict);
739 }
740  
741 0 ▶sub default_default_lang { 'en' }
Subroutine default_default_lang: not called CC=1 SCAR=6.9
Pod undocumented
742 0 ▶sub default_lang {
Subroutine default_lang: not called CC=2 SCAR=17.9
Pod undocumented
743 0 (my MY $self) = @_;
744 0 ▶ $self->{default_lang} || $self->default_default_lang;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"default_lang"} or $self->default_default_lang 0 0 0
745 }
746  
747 #========================================
748 # Delegation to the core(Translator, which is useless for non-templating.)
749 #
750 # Note: these wrappers do not call YATT::Lite::VFS->reset_refresh_mark.
751 # This means once templates is compiled, it is not updated even if
752 # they are modified. You can avoid this behavior by
753 # directly using $YATT->open_trans->xxx instead.
754 #========================================
755 52 foreach
756 (qw/find_part
757 find_part_from_entns
758 find_file
759 find_product
760 find_renderer
761 find_part_handler
762 ensure_parsed
763  
764 list_items
765 list_base
766 list_internal_base_folders
767  
768 add_to
769 /
770 ) {
771 572 my $meth = $_;
772 572 *{globref(MY, $meth)} = subname(join("::", MY, $meth)
773 570 ▶ , sub { shift->get_trans->$meth(@_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
774 }
775  
776 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=6.9
Pod undocumented
777 0 my MY $self = shift;
778 # XXX: charset...
779 die [200, [$self->secure_text_plain]
780 0 , [map {terse_dump($_)."\n"} @_]];
781 }
782  
783 #========================================
784 # Builtin Entities.
785 #========================================
786  
787 3 ▶sub YATT::Lite::EntNS::entity_template {
Subroutine entity_template: called CC=2 SCAR=8.1
Pod undocumented
788 3 my ($this, $pkg) = @_;
789 3 ▶ $YATT->get_trans->find_template_from_package($pkg // $this);
Condition33%1/3
$pkg // $this
l!l&&r!l&&!r
030
MC/DC0%0/2
$pkg // $this
$pkg $this
Truth table33%1/3
A // B
A= $pkgB= $this
ABresult
1X1
011
000
790 };
791  
792 0 ▶sub YATT::Lite::EntNS::entity_stash {
Subroutine entity_stash: not called CC=6 SCAR=37.4
Pod undocumented
793 0 my $this = shift;
794 0 my $prop = $CON->prop;
795 0 ▶ my $stash = $prop->{_stash} //= {};
Condition0%0/2
$prop->{"_stash"} //= {}
l!l
00
MC/DC0%0/1
$prop->{"_stash"} //= {}
$prop->{"_stash"}
Truth table0%0/2
A
A= $prop->{"_stash"}
Aresult
11
00
796 0 ▶ unless (@_) {
Branch: 4 branches
BranchTrueFalseTotal
if (@_) { } 0 0 0
if (do { @_ > 1 }) { } 0 0 0
elsif (not defined $_[0]) { } 0 0 0
elsif (ref $_[0]) { } 0 0 0
797 0 $stash
798 } elsif (@_ > 1) {
799 0 %$stash = @_;
800 } elsif (not defined $_[0]) {
801 0 carp "Undefined argument for :stash()";
802 } elsif (ref $_[0]) {
803 0 $prop->{_stash} = $_[0]
804 } else {
805 0 $stash->{$_[0]};
806 }
807 };
808  
809 # drop "[]" from "qname[]" and returns "qname"
810 0 ▶sub YATT::Lite::EntNS::entity_trim_array_suffix {
Subroutine entity_trim_array_suffix: not called CC=1 SCAR=6.9
Pod undocumented
811 0 my ($this, $name) = @_;
812 0 $name =~ s/\[\]\z//;
813 0 $name;
814 }
815  
816 2 ▶sub YATT::Lite::EntNS::entity_mkhidden {
Subroutine entity_mkhidden: called CC=5 SCAR=17.8
Pod undocumented
817 2 my ($this) = shift;
818 2 my $no_nested_query = $CON->prop->{no_nested_query};
819 \ join "\n", map {
820 2 my $name = $_;
821 2 ▶ $name =~ s/\[\]\z// if not $no_nested_query;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_nested_query 2 0 2
822 map {
823 2 my $v = $_;
824 2 ▶ if (ref $v eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $v eq 'HASH') { } 0 2 2
elsif (ref $v eq 'ARRAY') { } 2 0 2
825 map {
826 0 _hidden_input(escape($name."[$_]"), $v->{$_});
827 } keys %$v;
828 } elsif (ref $v eq 'ARRAY') {
829 map {
830 2 _hidden_input(escape($name."[]"), $_);
831 } @$v;
832 } else {
833 0 _hidden_input(escape($name), $v);
834 }
835 } $CON->multi_param($name);
836 2 } do {
837 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 0 2
838 2 @_;
839 } else {
840 0 $CON->param
841 }
842 };
843 };
844  
845 4 ▶sub _hidden_input {
Subroutine _hidden_input: called CC=1 SCAR=0.0
846 4 sprintf(qq|<input type="hidden" name="%s" value="%s">|
847 , $_[0], escape($_[1]));
848 }
849  
850 0 ▶sub YATT::Lite::EntNS::entity_file_rootname {
Subroutine entity_file_rootname: not called CC=2 SCAR=17.9
Pod undocumented
851 0 my ($this, $fn) = @_;
852 0 ▶ $fn //= $CON->file();
Condition0%0/3
$fn //= $YATT::Lite::CON->file
l!l&&r!l&&!r
000
MC/DC0%0/2
$fn //= $YATT::Lite::CON->file
$fn $YATT::Lite::CON->file
Truth table0%0/3
A //= B
A= $fnB= $YATT::Lite::CON->file
ABresult
1X1
011
000
853 0 $fn =~ s/\.\w+$//;
854 0 $fn;
855 };
856  
857 0 ▶sub YATT::Lite::EntNS::entity_app_name {
Subroutine entity_app_name: not called CC=1 SCAR=6.9
Pod undocumented
858 0 my ($this) = @_;
859 0 $YATT->cget('app_name');
860 };
861  
862 #----------------------------------------
863 52 ▶use YATT::Lite::Breakpoint ();
Subroutine BEGIN: called CC=1 SCAR=0.0
864 52 YATT::Lite::Breakpoint::break_load_facade();
865  
866 52 1;
« blib/lib/YATT/Lite/WebMVC0/SubRoutes.pm ↑ Summary blib/lib/YATT/Lite/Connection.pm »