web/cgi-bin/yatt.lib/YATT/Toplevel/CGI.pm

filter: Statementstmt 29.0% 136 / 469 Branchbran 10.3% 23 / 222 Conditioncond 13.6% 13 / 95 MC/DCmcdc 0.0% 0 / 58 Subroutinesub 36.4% 31 / 85 Podpod 0.0% 0 / 55 totaltotal 20.6% 203 / 984 CC 156 SCAR 39.4
CC
156
Cov
22%
prepare_dispatch
272.0
heavy_configure
182.0
dispatch_error
132.0
CRAP 51.6
« web/cgi-bin/yatt.lib/YATT/Translator/Perl/macro_dbfetch.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/DBSchema.pm »
1 # -*- mode: perl; coding: utf-8 -*-
2 package YATT::Toplevel::CGI;
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 require Exporter; *import = \&Exporter::import;
8 2 $INC{'YATT/Toplevel/CGI.pm'} = __FILE__;
9 }
10  
11 2 ▶use base qw(File::Spec);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use UNIVERSAL;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #----------------------------------------
17 2 ▶use YATT;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use YATT::Types -alias => [MY => __PACKAGE__
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 , Translator => 'YATT::Translator::Perl'];
20  
21 2 require YATT::Inc;
22 2 ▶use YATT::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use YATT::Util::Finalizer;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use YATT::Util::Taint qw(untaint_any);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use YATT::Util::Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use YATT::Util::CmdLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 ▶use YATT::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 #----------------------------------------
31 2 ▶use base qw(YATT::Class::Configurable);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use YATT::Types -base => __PACKAGE__
Subroutine BEGIN: called CC=1 SCAR=0.0
33 , [Config => [qw(^cf_registry
34 cf_driver
35 cf_docs cf_tmpl
36 cf_charset
37 cf_language
38 cf_debug_allowed_ip
39 cf_translator_param
40 cf_user_config
41 cf_no_header
42 cf_allow_unknown_config
43 cf_auto_reload
44 cf_no_chdir
45 cf_rlimit
46 cf_use_session
47 )
48 , ['^cf_app_prefix' => 'YATT']
49 , ['^cf_find_root_upward' => 2]
50 ]]
51 2 , qw(:export_alias);
52  
53 2 Config->define(create => \&create_toplevel);
54  
55 #----------------------------------------
56  
57 2 ▶use vars map {'$'.$_} our @env_vars
Subroutine BEGIN: called CC=1 SCAR=0.0
58 = qw(DOCUMENT_ROOT
59 PATH_INFO
60 PATH_TRANSLATED
61 REDIRECT_REDIRECT_STATUS
62 REDIRECT_STATUS
63 REDIRECT_URL
64 REQUEST_URI
65 SCRIPT_FILENAME
66 2 );
67 push our @EXPORT, (qw(&use_env_vars
68 &rootname
69 &capture
70 &new_config
71 2 ), map {'*'.$_} our @env_vars);
72  
73 2 our Config $CONFIG;
74 2 our ($CGI, $SESSION, %COOKIE, %HEADER, $RANDOM_LIST, $RANDOM_INDEX);
75 4 ▶sub rc_global () { qw(CONFIG CGI SESSION HEADER COOKIE
Subroutine rc_global: called CC=1 SCAR=0.0
Pod undocumented
76 RANDOM_LIST RANDOM_INDEX) }
77 2 push our @EXPORT_OK, (@EXPORT, map {'*'.$_} rc_global);
78  
79 sub ROOT_CONFIG () {'.htyattroot'}
80  
81 #----------------------------------------
82 # run -> run_zzz -> dispatch(handler) -> dispatch_zzz(handler) -> handler
83  
84 # run は環境変数を整えるためのエントリー関数。
85  
86 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
87 0 my ($pack, $method) = splice @_, 0, 2;
88 0 use_env_vars();
89 0 ▶ my $sub = $pack->can("run_$method")
Branch: 1 branch
BranchTrueFalseTotal
my $sub = $pack->can("run_$method") or croak("Can't find handler for $method") 0 0 0
90 or croak "Can't find handler for $method";
91  
92 0 &YATT::break_run;
93 0 $sub->($pack, @_);
94 }
95  
96 0 ▶sub run_cgi {
Subroutine run_cgi: not called CC=2 SCAR=17.9
Pod undocumented
97 0 my $pack = shift;
98 0 my $cgi = $pack->new_cgi(shift);
99  
100 0 local $CONFIG = my Config $config = $pack->new_config(shift);
101  
102 0 my ($root, $file, $error, $param);
103 0 ▶ if (catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&catch(sub { ($pack, $root, $cgi, $file, $param) = $pack->prepare_dispatch($cgi, $config); } , \$error)) { } 0 0 0
104 0 ($pack, $root, $cgi, $file, $param)
105 = $pack->prepare_dispatch($cgi, $config);
106 } \ $error) {
107 0 $pack->dispatch_error($root, $error
108 , {phase => 'prepare', target => $file});
109 } else {
110 0 $pack->run_retry_max(3, $root, $file, $cgi, $param);
111 }
112 }
113  
114 0 ▶sub run_retry_max {
Subroutine run_retry_max: not called CC=8 SCAR=42.8
Pod undocumented
115 0 my ($pack, $max, $root_or_config, $file, $cgi, @param) = @_;
116 0 my $root = do {
117 0 ▶ if (UNIVERSAL::isa($root_or_config, Config)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($root_or_config, 'YATT::Toplevel::CGI::Config')) { } 0 0 0
118 0 my Config $config = $root_or_config;
119 $config->{cf_registry}
120 0 } else {
121 0 $root_or_config;
122 }
123 };
124 0 ▶ my $rc = catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
125 0 $pack->dispatch($root, $cgi, $file, @param);
126 0 } \ my $error;
127 0 ▶ if ($rc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc) 0 0 0
128 0 my ($i) = (0);
129 0 ▶ while ($rc and ($file, $cgi) = can_retry($error)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc and () = can_retry($error)) 0 0 0
Condition0%0/3
$rc and () = can_retry($error)
!ll&&!rl&&r
000
MC/DC0%0/2
$rc and () = can_retry($error)
$rc () = can_retry($error)
Truth table0%0/3
A and B
A= $rcB= () = can_retry($error)
ABresult
0X0
100
111
130 0 ▶ if ($i++ > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i++ > $max) 0 0 0
131 0 $pack->dispatch_error($root, $error
132 , {phase => 'retry', target => $file});
133 0 undef $error;
134 0 last;
135 }
136 0 ▶ $rc = catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
137 0 $pack->dispatch($root, $cgi, $file);
138 0 } \ $error;
139 }
140 }
141 0 ▶ if ($rc and not is_normal_end($error)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc and not is_normal_end($error)) 0 0 0
Condition0%0/3
$rc and not is_normal_end($error)
!ll&&!rl&&r
000
MC/DC0%0/2
$rc and not is_normal_end($error)
$rc not is_normal_end($error)
Truth table0%0/3
A and not(B)
A= $rcB= not is_normal_end($error)
ABresult
0X0
100
111
142 0 $pack->dispatch_error($root, $error
143 , {phase => 'action', target => $file});
144 }
145 }
146  
147 1 ▶sub create_toplevel {
Subroutine create_toplevel: called CC=4 SCAR=14.1
Pod undocumented
148 1 my $pack = shift;
149 1 my Config $config = $pack->new_config(shift);
150 1 ▶ $config->configure(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 0 1
151 1 ▶ my $dir = $config->{cf_docs} ||= '.';
Condition50%1/2
$config->{"cf_docs"} ||= "."
l!l
10
MC/DC0%0/1
$config->{"cf_docs"} ||= "."
$config->{"cf_docs"}
Truth table50%1/2
A
A= $config->{"cf_docs"}
Aresult
11
00
152 1 $pack->can('try_load_config')->($config, $dir);
153 1 my $instpkg = $pack->get_instpkg($config);
154  
155 1 my @loader = (DIR => $config->{cf_docs});
156 1 ▶ push @loader, LIB => $config->{cf_tmpl} if $config->{cf_tmpl};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"cf_tmpl"} 0 1 1
157  
158 1 my $trans = $config->{cf_registry} = $instpkg->new_translator
159 (\@loader, $config->translator_param);
160  
161 1 ($instpkg, $trans, $config);
162 }
163  
164 #
165 # XXX: should be: create_toplevel_from_cgi($cgi, $config)
166 # => ($instpkg, $trans, $config, $cgi, $file, $param);
167 # since $config->{cf_registry} points $translator.
168 #
169 0 ▶sub prepare_dispatch {
Subroutine prepare_dispatch: not called CC=16 SCAR=56.1
Pod undocumented
170 0 (my ($pack, $cgi), my Config $config) = @_;
171 0 my ($rootdir, $file, $loader, $param) = do {
172 0 ▶ if (not $config->{cf_registry} and $config->{cf_docs}) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $config->{'cf_registry'} and $config->{'cf_docs'}) { } 0 0 0
elsif ($YATT::Toplevel::CGI::REDIRECT_STATUS) { } 0 0 0
elsif ($YATT::Toplevel::CGI::PATH_INFO and $YATT::Toplevel::CGI::SCRIPT_FILENAME) { } 0 0 0
Condition0%0/3
not $config->{"cf_registry"} and $config->{"cf_docs"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $config->{"cf_registry"} and $config->{"cf_docs"}
not $config->{"cf_registry"} $config->{"cf_docs"}
Truth table0%0/3
not(A) and B
A= not $config->{"cf_registry"}B= $config->{"cf_docs"}
ABresult
0X0
100
111
173 # $config->try_load_config($config->{cf_docs});
174 ($config->{cf_docs}, $cgi->path_info
175 0 , [DIR => $config->{cf_docs}]);
176 } elsif ($REDIRECT_STATUS) {
177 # 404 Not found handling
178 0 ▶ my $target = $PATH_TRANSLATED || $DOCUMENT_ROOT . $REDIRECT_URL;
Condition0%0/3
$YATT::Toplevel::CGI::PATH_TRANSLATED || $YATT::Toplevel::CGI::DOCUMENT_ROOT . $YATT::Toplevel::CGI::REDIRECT_URL
l!l&&r!l&&!r
000
MC/DC0%0/2
$YATT::Toplevel::CGI::PATH_TRANSLATED || $YATT::Toplevel::CGI::DOCUMENT_ROOT . $YATT::Toplevel::CGI::REDIRECT_URL
$YATT::Toplevel::CGI::PATH_TRANSLATED $YATT::Toplevel::CGI::DOCUMENT_ROOT . $YATT::Toplevel::CGI::REDIRECT_URL
Truth table0%0/3
A || B
A= $YATT::Toplevel::CGI::PATH_TRANSLATEDB= $YATT::Toplevel::CGI::DOCUMENT_ROOT . $YATT::Toplevel::CGI::REDIRECT_URL
ABresult
1X1
011
000
179 # This ensures .htyattroot is loaded.
180 0 ▶ ($pack->param_for_redirect($target
Condition0%0/3
$YATT::Toplevel::CGI::SCRIPT_FILENAME || $0
l!l&&r!l&&!r
000
MC/DC0%0/2
$YATT::Toplevel::CGI::SCRIPT_FILENAME || $0
$YATT::Toplevel::CGI::SCRIPT_FILENAME $0
Truth table0%0/3
A || B
A= $YATT::Toplevel::CGI::SCRIPT_FILENAMEB= $0
ABresult
1X1
011
000
181 , $SCRIPT_FILENAME || $0, $config
182 , $REDIRECT_STATUS == 404
183 ));
184 ▶ } elsif ($PATH_INFO and $SCRIPT_FILENAME) {
Condition0%0/3
$YATT::Toplevel::CGI::PATH_INFO and $YATT::Toplevel::CGI::SCRIPT_FILENAME
!ll&&!rl&&r
000
MC/DC0%0/2
$YATT::Toplevel::CGI::PATH_INFO and $YATT::Toplevel::CGI::SCRIPT_FILENAME
$YATT::Toplevel::CGI::PATH_INFO $YATT::Toplevel::CGI::SCRIPT_FILENAME
Truth table0%0/3
A and B
A= $YATT::Toplevel::CGI::PATH_INFOB= $YATT::Toplevel::CGI::SCRIPT_FILENAME
ABresult
0X0
100
111
185 0 (untaint_any(dirname($SCRIPT_FILENAME))
186 , untaint_any($PATH_INFO)
187 , $pack->loader_for_script($SCRIPT_FILENAME, $config));
188 } else {
189 0 $pack->plain_error($cgi, <<END);
190 None of PATH_TRANSLATED and PATH_INFO is given.
191 END
192 }
193 };
194  
195 0 ▶ unless ($loader) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loader) 0 0 0
196 0 $pack->plain_error($cgi, <<END);
197 Can't find loader.
198 END
199 }
200  
201 0 ▶ unless (chdir($rootdir)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $rootdir) 0 0 0
202 0 $pack->plain_error($cgi, "Can't chdir to $rootdir: $!");
203 }
204  
205 0 ▶ unless ($PATH_INFO) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($YATT::Toplevel::CGI::PATH_INFO) 0 0 0
206 0 ▶ if ($PATH_TRANSLATED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YATT::Toplevel::CGI::PATH_TRANSLATED) 0 0 0
207 # XXX: ミス時に効率悪い。substr して eq に書き直すべき。
208 0 ▶ if (index($PATH_TRANSLATED, $rootdir) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($YATT::Toplevel::CGI::PATH_TRANSLATED, $rootdir) == 0) 0 0 0
209 0 $PATH_INFO = substr($PATH_TRANSLATED, length($rootdir));
210 }
211 }
212 }
213  
214 0 ▶ if (my $sub = $cgi->can('charset')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $cgi->can("charset")) 0 0 0
215 # print "\n\n", YATT::Util::terse_dump(CONFIG => $config);
216 0 ▶ $sub->($cgi, $config->{cf_charset} || 'utf-8');
Condition0%0/2
$config->{'cf_charset'} || 'utf-8'
l!l
00
MC/DC0%0/1
$config->{'cf_charset'} || 'utf-8'
$config->{'cf_charset'}
Truth table0%0/2
A
A= $config->{'cf_charset'}
Aresult
11
00
217 }
218  
219 0 my $instpkg = $pack->get_instpkg($config);
220  
221 my $root = $config->{cf_registry} ||= $instpkg->new_translator
222 ($loader, $config->translator_param
223 0 ▶ , debug_translator => $ENV{DEBUG});
Condition0%0/3
$config->{"cf_registry"} ||= $instpkg->new_translator($loader, $config->translator_param, "debug_translator", $ENV{"DEBUG"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{"cf_registry"} ||= $instpkg->new_translator($loader, $config->translator_param, "debug_translator", $ENV{"DEBUG"})
$config->{"cf_registry"} $instpkg->new_translator($loader, $config->translator_param, "debug_translator", $ENV{"DEBUG"})
Truth table0%0/3
A ||= B
A= $config->{"cf_registry"}B= $instpkg->new_translator($loader, $config->translator_param, "debug_translator", $ENV{"DEBUG"})
ABresult
1X1
011
000
224  
225 0 $instpkg->set_random_list;
226  
227 0 $instpkg->force_parameter_convention($cgi); # XXX: unless $config->{...}
228  
229 0 ($instpkg, $root, $cgi, $file, $param);
230 }
231  
232 2 our $PARAM_CONVENTION = qr{^[\w:\-]};
233  
234 1 ▶sub force_parameter_convention {
Subroutine force_parameter_convention: called CC=3 SCAR=11.0
Pod undocumented
235 1 my ($pack, $cgi) = @_;
236 1 my @deleted;
237 1 foreach my $name ($cgi->param) {
238 2 ▶ next if $name =~ $PARAM_CONVENTION;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /$YATT::Toplevel::CGI::PARAM_CONVENTION/ 0 2 2
239 2 push @deleted, [$name => $cgi->multi_param($name)];
240 2 $cgi->delete($name);
241 }
242 1 @deleted;
243 }
244  
245 2 *get_instpkg = \&prepare_export;
246 1 ▶sub prepare_export {
Subroutine prepare_export: called CC=5 SCAR=17.5
Pod undocumented
247 1 my ($pack, $config, $instpkg) = @_;
248 1 ▶ $instpkg ||= $config && $config->app_prefix || 'main';
Condition37%3/8
$instpkg ||= $config && $config->app_prefix || "main"
l!l&&r!l&&!r
010
$config && $config->app_prefix || 'main'
l!l
10
$config and $config->app_prefix
!ll&&!rl&&r
001
MC/DC0%0/3
$instpkg ||= $config && $config->app_prefix || "main"
$instpkg $config $config->app_prefix
Truth table0%0/4
A ||= B and C
A= $instpkgB= $configC= $config->app_prefix
ABCresult
1XX1
0111
00X0
0100
249  
250 1 $pack->add_isa($instpkg, $pack);
251 1 foreach my $name ($pack->rc_global) {
252 7 *{globref($instpkg, $name)} = *{globref(MY, $name)};
253 }
254 $instpkg
255 1 }
256  
257 0 ▶sub run_template {
Subroutine run_template: not called CC=5 SCAR=34.0
Pod undocumented
258 0 my ($pack, $file, $cgi, $config) = @_;
259  
260 0 ▶ if (defined $file and -r $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and -r $file) 0 0 0
Condition0%0/3
defined $file and -r $file
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file and -r $file
defined $file -r $file
Truth table0%0/3
A and B
A= defined $fileB= -r $file
ABresult
0X0
100
111
261 0 ($PATH_INFO, $REDIRECT_STATUS, $PATH_TRANSLATED) = ('', 200, $file);
262 0 ▶ die "really?" unless $ENV{REDIRECT_STATUS} == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"REDIRECT_STATUS"} == 200 0 0 0
263 0 ▶ die "really?" unless $ENV{PATH_TRANSLATED} eq $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"PATH_TRANSLATED"} eq $file 0 0 0
264 }
265  
266 0 $pack->run_cgi($cgi, $config);
267 }
268  
269 #========================================
270 # *: dispatch_zzz が無事に最後まで処理を終えた場合は bye を呼ぶ。
271 # *: dispatch_zzz の中では catch はしない。dispatch の外側(run)で catch する。
272  
273 0 ▶sub bye {
Subroutine bye: not called CC=2 SCAR=17.9
Pod undocumented
274 0 ▶ die shift->Exception->new(error => '', normal => shift || 1
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
275 , caller => [caller], @_);
276 }
277  
278 0 ▶sub raise_retry {
Subroutine raise_retry: not called CC=1 SCAR=6.9
Pod undocumented
279 0 my ($pack, $file, $cgi, @param) = @_;
280 0 die $pack->Exception->new(error => '', retry => [$file, $cgi, @param]
281 , caller => [caller])
282 }
283  
284 0 ▶sub dispatch {
Subroutine dispatch: not called CC=9 SCAR=45.0
Pod undocumented
285 0 my ($top, $root, $cgi, $file, @param) = @_;
286 0 &YATT::break_dispatch;
287  
288 0 $root->mark_load_failure;
289  
290 0 local $CGI = $cgi;
291 0 local ($SESSION, %COOKIE, %HEADER);
292 0 ▶ if ($CONFIG->{cf_use_session}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YATT::Toplevel::CGI::CONFIG->{"cf_use_session"}) 0 0 0
293 0 $SESSION = $top->new_session($cgi);
294 }
295 0 my @elpath = $root->parse_elempath($top->canonicalize_html_filename($file));
296 0 my ($found, $renderer, $pkg, $widget);
297  
298 0 ▶ if (catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 3 branches
BranchTrueFalseTotal
if (&catch(sub { $found = ($renderer, $pkg, $widget) = $root->lookup_handler_to('render', @elpath); } , \my $error)) { } 0 0 0
elsif (not $found) { } 0 0 0
elsif (not defined $renderer) { } 0 0 0
299 0 $found = ($renderer, $pkg, $widget)
300 = $root->lookup_handler_to(render => @elpath);
301 } \ my $error) {
302 0 $top->dispatch_error($root, $error
303 , {phase => 'get_handler', target => $file});
304 } elsif (not $found) {
305 # XXX: これも。
306 0 $top->dispatch_not_found($root, $file, @param);
307 } elsif (not defined $renderer) {
308 0 $top->dispatch_error($root, "Can't compile: $file"
309 , {phase => 'get_handler', target => $file});
310 } else {
311 0 ▶ unless ($CONFIG->{cf_no_chdir}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($YATT::Toplevel::CGI::CONFIG->{"cf_no_chdir"}) 0 0 0
312 # XXX: これもエラー処理を
313 0 my $dir = untaint_any(dirname($widget->filename));
314 0 chdir($dir);
315 }
316 0 ▶ if (not defined $param[0] and $widget->public) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $param[0] and $widget->public) 0 0 0
Condition0%0/3
not defined $param[0] and $widget->public
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $param[0] and $widget->public
not defined $param[0] $widget->public
Truth table0%0/3
not(A) and B
A= not defined $param[0]B= $widget->public
ABresult
0X0
100
111
317 0 $param[0] = $widget->reorder_cgi_params($cgi);
318 }
319 0 ▶ if (my $handler = $pkg->can('dispatch_action')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $pkg->can('dispatch_action')) { } 0 0 0
320 0 $handler->($top, $root, $renderer, $pkg, @param);
321 } else {
322 0 $top->dispatch_action($root, $renderer, $pkg, @param);
323 }
324 }
325 }
326  
327 0 ▶sub dispatch_not_found {
Subroutine dispatch_not_found: not called CC=1 SCAR=6.9
Pod undocumented
328 0 my ($top, $root, $file) = @_;
329 0 my $ERR = \*STDOUT;
330  
331 0 print $ERR "\n\nNot found: $file";
332 }
333  
334 # XXX: もう少し改善を。
335 0 ▶sub dispatch_error {
Subroutine dispatch_error: not called CC=11 SCAR=48.8
Pod undocumented
336 0 my ($top, $root, $error, $info) = @_;
337 0 my $ERR = \*STDOUT;
338 0 my ($found, $renderer, $pkg, $html);
339  
340 0 ▶ unless ($root) {
Branch: 4 branches
BranchTrueFalseTotal
if ($root) { } 0 0 0
if (do { &catch(sub { $found = ($renderer, $pkg) = $root->lookup_handler_to('render', 'error'); } , \my $load_error) }) { } 0 0 0
elsif (not $found) { } 0 0 0
elsif (&catch(sub { $html = &capture(sub { &$renderer($pkg, [$error, $info]); } ); } , \my YATT::Exception $error2)) { } 0 0 0
341 0 print $ERR "\n\nroot_load_error($error)";
342 0 ▶ } elsif (catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
343 0 $found = ($renderer, $pkg) = $root->lookup_handler_to(render => 'error')
344 } \ my $load_error) {
345 0 print $ERR "\n\nload_error($load_error), original_error=($error)";
346 } elsif (not $found) {
347 0 ▶ print $ERR $CGI ? $CGI->header : "\n\n";
Branch: 1 branch
BranchTrueFalseTotal
$YATT::Toplevel::CGI::CGI ? : 0 0 0
348 0 print $ERR $error;
349 0 ▶ $top->printenv_html($info, id => 'error_info') if $info;
Branch: 1 branch
BranchTrueFalseTotal
if $info 0 0 0
350 0 $top->printenv_html;
351 0 ▶ } elsif (catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
352 0 ▶ $html = capture {$renderer->($pkg, [$error, $info])};
Subroutine __ANON__: not called CC=1 SCAR=6.9
353 } \ my Exception $error2) {
354 0 ▶ unless (ref $error2) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $error2) { } 0 0 0
if (do { not UNIVERSAL::isa($error2, 'YATT::Exception') }) { } 0 0 0
elsif ($error2->is_normal) { } 0 0 0
355 0 print $ERR "\n\nerror in error page($error2), original_error=($error)";
356 } elsif (not UNIVERSAL::isa($error2, Exception)) {
357 0 print $ERR "\n\nUnknown error in error page($error2), original_error=($error)";
358 } elsif ($error2->is_normal) {
359 # should be ignored
360 } else {
361 0 print $ERR "\n\nerror in error page($error2->{cf_error}), original_error=($error)";
362 }
363 } else {
364 0 ▶ print $ERR $CGI ? $CGI->header : "Content-type: text/html\n\n";
Branch: 1 branch
BranchTrueFalseTotal
$YATT::Toplevel::CGI::CGI ? : 0 0 0
365 0 print $ERR $html;
366 }
367  
368 0 $top->bye;
369 }
370  
371 0 ▶sub dispatch_action {
Subroutine dispatch_action: not called CC=4 SCAR=30.0
Pod undocumented
372 0 my ($top, $root, $action, $pkg, @param) = @_;
373 0 &YATT::break_handler;
374 0 ▶ if ($CONFIG && $CONFIG->{cf_no_header}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YATT::Toplevel::CGI::CONFIG and $YATT::Toplevel::CGI::CONFIG->{'cf_no_header'}) { } 0 0 0
Condition0%0/3
$YATT::Toplevel::CGI::CONFIG and $YATT::Toplevel::CGI::CONFIG->{"cf_no_header"}
!ll&&!rl&&r
000
MC/DC0%0/2
$YATT::Toplevel::CGI::CONFIG and $YATT::Toplevel::CGI::CONFIG->{"cf_no_header"}
$YATT::Toplevel::CGI::CONFIG $YATT::Toplevel::CGI::CONFIG->{"cf_no_header"}
Truth table0%0/3
A and B
A= $YATT::Toplevel::CGI::CONFIGB= $YATT::Toplevel::CGI::CONFIG->{"cf_no_header"}
ABresult
0X0
100
111
375 0 $action->($pkg, @param);
376 } else {
377 0 ▶ my $html = capture { $action->($pkg, @param) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
378 # XXX: SESSION, COOKIE, HEADER...
379 0 ▶ print $SESSION ? $SESSION->header : $CGI->header;
Branch: 1 branch
BranchTrueFalseTotal
$YATT::Toplevel::CGI::SESSION ? : 0 0 0
380 0 print $html;
381 }
382 0 $top->bye;
383 }
384  
385 0 ▶sub plain_error {
Subroutine plain_error: not called CC=3 SCAR=24.8
Pod undocumented
386 0 my ($pack, $cgi, $message) = @_;
387 0 ▶ print $cgi->header if $cgi;
Branch: 1 branch
BranchTrueFalseTotal
if $cgi 0 0 0
388 0 print $message;
389 0 $pack->printenv_html;
390 0 ▶ $pack->plain_exit($cgi ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$cgi ? : 0 0 0
391 }
392  
393 0 ▶sub plain_exit {
Subroutine plain_exit: not called CC=1 SCAR=6.9
Pod undocumented
394 0 my ($pack, $exit_code) = @_;
395 0 exit $exit_code;
396 }
397  
398 0 ▶sub printenv_html {
Subroutine printenv_html: not called CC=4 SCAR=30.0
Pod undocumented
399 0 my ($pack, $env, %opts) = @_;
400 0 ▶ $opts{id} ||= 'printenv';
Condition0%0/2
$opts{"id"} ||= "printenv"
l!l
00
MC/DC0%0/1
$opts{"id"} ||= "printenv"
$opts{"id"}
Truth table0%0/2
A
A= $opts{"id"}
Aresult
11
00
401 0 my $ERR = \*STDOUT;
402 0 ▶ $env ||= \%ENV;
Condition0%0/2
$env ||= \%ENV
l!l
00
MC/DC0%0/1
$env ||= \%ENV
$env
Truth table0%0/2
A
A= $env
Aresult
11
00
403 0 print $ERR "<table id='$opts{id}'>\n";
404 0 foreach my $k (sort keys %$env) {
405 0 print $ERR "<tr><td>", $k, "</td><td>", $env->{$k}, "</td></tr>\n";
406 }
407 0 print $ERR "</table>\n";
408 }
409  
410 #========================================
411  
412 0 ▶sub loader_for_script {
Subroutine loader_for_script: not called CC=1 SCAR=6.9
Pod undocumented
413 0 my ($pack, $script_filename) = @_;
414 0 my $driver = untaint_any(rootname($script_filename));
415 0 my @loader = (DIR => untaint_any("$driver.docs")
416 , $pack->tmpl_for_driver($driver));
417 0 \@loader;
418 }
419  
420 0 ▶sub tmpl_for_driver {
Subroutine tmpl_for_driver: not called CC=2 SCAR=17.9
Pod undocumented
421 0 my ($pack, $rootname) = @_;
422 0 ▶ return unless -d (my $dir = "$rootname.tmpl");
Branch: 1 branch
BranchTrueFalseTotal
unless -d (my $dir = "$rootname.tmpl") 0 0 0
423 0 (LIB => $dir);
424 }
425  
426 0 ▶sub upward_find_file {
Subroutine upward_find_file: not called CC=5 SCAR=34.0
Pod undocumented
427 0 my ($pack, $file, $level) = @_;
428 0 my @path = $pack->splitdir($pack->rel2abs($file));
429 0 ▶ my $limit = defined $level ? @path - $level : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $level ? : 0 0 0
430 0 my ($dir);
431 0 ▶ for (my $i = $#path - 1; $i >= $limit; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $limit) 0 0 0
432 0 $dir = join "/", @path[0..$i];
433 0 $file = "$dir/" . $pack->ROOT_CONFIG;
434 0 ▶ next unless -r $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $file 0 0 0
435 0 ▶ return wantarray ? ($dir, $file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
436 }
437  
438 return
439 0 }
440  
441 1 ▶sub try_load_config {
Subroutine try_load_config: called CC=11 SCAR=37.0
Pod undocumented
442 1 (my Config $config, my ($file)) = @_;
443  
444 1 my $dir;
445 1 ▶ unless (defined $file and -r $file) {
Branch: 5 branches
BranchTrueFalseTotal
if (defined $file and -r $file) { } 1 0 1
if (do { -f $file }) { } 0 1 1
elsif (not -d $file) { } 0 1 1
elsif (-r (my $found = "$file/" . $config->ROOT_CONFIG)) { } 0 1 1
elsif ($config->find_root_upward and my(@found) = $config->upward_find_file($file, $config->find_root_upward)) { } 0 1 1
Condition33%1/3
defined $file and -r $file
!ll&&!rl&&r
001
MC/DC0%0/2
defined $file and -r $file
defined $file -r $file
Truth table33%1/3
A and B
A= defined $fileB= -r $file
ABresult
0X0
100
111
446 0 ▶ die "No such file or directory! "
Branch: 1 branch
BranchTrueFalseTotal
defined $file ? : 0 0 0
447 . (defined $file ? $file : "(undef)") . "\n";
448 } elsif (-f $file) {
449 # ok
450 0 $file = $config->rel2abs($file);
451 0 $dir = dirname($file);
452 } elsif (! -d $file) {
453 0 die "Unsupported file type! $file";
454 } elsif (-r (my $found = "$file/" . $config->ROOT_CONFIG)) {
455 0 ($dir, $file) = ($file, $found);
456 ▶ } elsif ($config->find_root_upward
Condition33%1/3
$config->find_root_upward and my(@found) = $config->upward_find_file($file, $config->find_root_upward)
!ll&&!rl&&r
100
MC/DC0%0/2
$config->find_root_upward and my(@found) = $config->upward_find_file($file, $config->find_root_upward)
$config->find_root_upward my(@found) = $config->upward_find_file($file, $config->find_root_upward)
Truth table33%1/3
A and B
A= $config->find_root_upwardB= my(@found) = $config->upward_find_file($file, $config->find_root_upward)
ABresult
0X0
100
111
457 and my @found = $config->upward_find_file
458 ($file, $config->find_root_upward)) {
459 0 ($dir, $file) = @found;
460 } else {
461 1 $dir = $file;
462 }
463  
464 1 $config->configure(docs => $dir);
465  
466 1 ▶ return unless -f $file and -r $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file and -r $file 1 0 1
Condition33%1/3
-f $file and -r $file
!ll&&!rl&&r
100
MC/DC0%0/2
-f $file and -r $file
-f $file -r $file
Truth table33%1/3
A and B
A= -f $fileB= -r $file
ABresult
0X0
100
111
467  
468 # XXX: configure_by_file
469 0 my @param = do {
470 0 require YATT::XHF;
471 0 my $parser = new YATT::XHF(filename => $file);
472 0 $parser->read_as('pairlist');
473 };
474 0 $config->heavy_configure(@param);
475 }
476  
477 0 ▶sub trim_trailing_pathinfo {
Subroutine trim_trailing_pathinfo: not called CC=5 SCAR=34.0
Pod undocumented
478 0 my ($pack, $strref, @prefix) = @_;
479 0 ▶ @prefix = ('') unless @prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless @prefix 0 0 0
480 0 my @dirs = $pack->splitdir($$strref);
481 0 my @found;
482 0 ▶ while (@dirs and -e join("/", @prefix, @found, $dirs[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dirs and -e join("/", @prefix, @found, $dirs[0])) 0 0 0
Condition0%0/3
@dirs and -e join("/", @prefix, @found, $dirs[0])
!ll&&!rl&&r
000
MC/DC0%0/2
@dirs and -e join("/", @prefix, @found, $dirs[0])
@dirs -e join("/", @prefix, @found, $dirs[0])
Truth table0%0/3
A and B
A= @dirsB= -e join("/", @prefix, @found, $dirs[0])
ABresult
0X0
100
111
483 0 push @found, shift @dirs;
484 }
485 0 $$strref = join("/", @found);
486 0 ▶ return unless @dirs;
Branch: 1 branch
BranchTrueFalseTotal
unless @dirs 0 0 0
487 0 join("/", @dirs);
488 }
489  
490 0 ▶sub param_for_redirect {
Subroutine param_for_redirect: not called CC=5 SCAR=34.0
Pod undocumented
491 0 (my ($pack, $path_translated, $script_filename)
492 , my Config $cfobj, my $not_found) = @_;
493 0 my $driver = untaint_any(rootname($script_filename));
494  
495 0 my @params;
496 0 ▶ if (not $not_found and not -e $path_translated) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($not_found or -e $path_translated) 0 0 0
Condition0%0/3
$not_found or -e $path_translated
l!l&&r!l&&!r
000
MC/DC0%0/2
$not_found or -e $path_translated
$not_found -e $path_translated
Truth table0%0/3
A or B
A= $not_foundB= -e $path_translated
ABresult
1X1
011
000
497 # not_found でもないのに、 path_translated が not exists であるケース
498 # == trailing path_info が有るケース。
499 0 push @params, $pack->trim_trailing_pathinfo(\$path_translated);
500 }
501  
502 # This should set $cfobj->{cf_docs}
503 0 ▶ unless ($cfobj->{cf_registry}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cfobj->{"cf_registry"}) 0 0 0
504 # .htyattroot の読み込みは、registry 作成前の一度で十分。
505 0 $cfobj->try_load_config(dirname(untaint_any($path_translated)));
506 }
507  
508 my $target = substr($path_translated
509 0 , length($cfobj->{cf_docs}));
510  
511 my @loader = (DIR => $cfobj->{cf_docs}
512 0 , $pack->tmpl_for_driver($driver));
513  
514 0 ▶ return ($cfobj->{cf_docs}, $target, \@loader, @params ? \@params : ());
Branch: 1 branch
BranchTrueFalseTotal
@params ? : 0 0 0
515 }
516  
517 #========================================
518  
519 1 ▶sub cgi_classes () { qw(CGI::Simple CGI) }
Subroutine cgi_classes: called CC=1 SCAR=0.0
Pod undocumented
520  
521 1 ▶sub new_cgi {
Subroutine new_cgi: called CC=11 SCAR=30.1
Pod undocumented
522 1 my ($pack, $oldcgi) = @_;
523 1 my $class;
524 1 foreach my $c ($pack->cgi_classes) {
525 2 eval qq{require $c};
526 2 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 1 1 2
527 1 $class = $c;
528 1 last;
529 }
530 }
531 1 ▶ unless ($class) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 1 1
532 0 die "Can't load any of cgi classes";
533 }
534  
535 1 ▶ if ($class eq "CGI" and not $class->can("multi_param")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "CGI" and not $class->can("multi_param")) 0 1 1
Condition33%1/3
$class eq "CGI" and not $class->can("multi_param")
!ll&&!rl&&r
010
MC/DC0%0/2
$class eq "CGI" and not $class->can("multi_param")
$class eq "CGI" not $class->can("multi_param")
Truth table33%1/3
A and not(B)
A= $class eq "CGI"B= not $class->can("multi_param")
ABresult
0X0
100
111
536 0 require YATT::Util::CGICompat;
537 0 import YATT::Util::CGICompat;
538 }
539 1 ▶ if ($class eq "CGI::Simple" and not $class->can("multi_param")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "CGI::Simple" and not $class->can("multi_param")) 0 1 1
Condition33%1/3
$class eq "CGI::Simple" and not $class->can("multi_param")
!ll&&!rl&&r
100
MC/DC0%0/2
$class eq "CGI::Simple" and not $class->can("multi_param")
$class eq "CGI::Simple" not $class->can("multi_param")
Truth table33%1/3
A and not(B)
A= $class eq "CGI::Simple"B= not $class->can("multi_param")
ABresult
0X0
100
111
540 0 *{globref($class, "multi_param")} = $class->can("param");
541 }
542 1 ▶ unless ($class->can("multi_param")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->can("multi_param")) 0 1 1
543 0 croak "cgi class($class) doesn't have multi_param method!";
544 }
545  
546 # 1. To make sure passing 'public' parameters only.
547 # 2. To avoid CGI::Simple eval()
548 1 ▶ if (UNIVERSAL::isa($oldcgi, $class)) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($oldcgi, $class)) { } 0 1 1
549 0 $class->new($pack->extract_cgi_params($oldcgi));
550 } else {
551 1 ▶ $class->new(defined $oldcgi ? $oldcgi : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $oldcgi ? : 1 0 1
552 }
553 }
554  
555 0 ▶sub new_session {
Subroutine new_session: not called CC=2 SCAR=17.9
Pod undocumented
556 0 my ($toplevel, $cgi) = @_;
557 0 require CGI::Session;
558 0 my ($dsn, @opts) = do {
559 0 ▶ if (ref $CONFIG->{cf_use_session}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $YATT::Toplevel::CGI::CONFIG->{'cf_use_session'}) { } 0 0 0
560 0 @{$CONFIG->{cf_use_session}}
561 } else {
562 $CONFIG->{cf_use_session}
563 0 }
564 };
565 0 CGI::Session->new($dsn, $cgi, @opts);
566 }
567  
568 0 ▶sub entity_session {
Subroutine entity_session: not called CC=1 SCAR=6.9
Pod undocumented
569 0 my ($pack, $name) = @_;
570 0 $SESSION->param($name);
571 }
572  
573 0 ▶sub entity_save_session {
Subroutine entity_save_session: not called CC=1 SCAR=6.9
Pod undocumented
574 0 $SESSION->save_param;
575 }
576  
577 1 ▶sub new_config {
Subroutine new_config: called CC=11 SCAR=33.1
Pod undocumented
578 1 my $pack = shift;
579 1 ▶ my Config $config = @_ == 1 ? shift : \@_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 1 0 1
580 1 ▶ return $config if defined $config
Branch: 1 branch
BranchTrueFalseTotal
if defined $config and ref $config and UNIVERSAL::isa($config, "YATT::Toplevel::CGI::Config") 0 1 1
Condition33%2/6
defined $config and ref $config and UNIVERSAL::isa($config, "YATT::Toplevel::CGI::Config")
!ll&&!rl&&r
100
defined $config and ref $config
!ll&&!rl&&r
010
MC/DC0%0/3
defined $config and ref $config and UNIVERSAL::isa($config, "YATT::Toplevel::CGI::Config")
defined $config ref $config UNIVERSAL::isa($config, "YATT::Toplevel::CGI::Config")
Truth table25%1/4
A and B and C
A= defined $configB= ref $configC= UNIVERSAL::isa($config, "YATT::Toplevel::CGI::Config")
ABCresult
0XX0
10X0
1100
1111
581 and ref $config and UNIVERSAL::isa($config, Config);
582  
583 1 ▶ if (ref $pack or not UNIVERSAL::isa($pack, Config)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pack or not UNIVERSAL::isa($pack, "YATT::Toplevel::CGI::Config")) 1 0 1
Condition33%1/3
ref $pack or not UNIVERSAL::isa($pack, "YATT::Toplevel::CGI::Config")
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $pack or not UNIVERSAL::isa($pack, "YATT::Toplevel::CGI::Config")
ref $pack not UNIVERSAL::isa($pack, "YATT::Toplevel::CGI::Config")
Truth table33%1/3
A or not(B)
A= ref $packB= not UNIVERSAL::isa($pack, "YATT::Toplevel::CGI::Config")
ABresult
1X1
011
000
584 1 $pack = $pack->Config;
585 }
586  
587 1 $config = $pack->new(do {
588 1 ▶ unless (defined $config) {
Branch: 4 branches
BranchTrueFalseTotal
if (defined $config) { } 1 0 1
if (do { not ref $config }) { } 1 0 1
elsif (ref $config eq 'ARRAY') { } 0 0 0
elsif (ref $config eq 'HASH') { } 0 0 0
589 ()
590 0 } elsif (not ref $config) {
591 1 (docs => $config)
592 } elsif (ref $config eq 'ARRAY') {
593 0 @$config
594 } elsif (ref $config eq 'HASH') {
595 0 %$config
596 } else {
597 0 $pack->plain_error(undef, <<END);
598 Invalid configuration parameter: $config
599 END
600 }
601 });
602  
603 1 $config->{cf_driver} = $0;
604  
605 1 $config;
606 }
607  
608 0 ▶sub heavy_configure {
Subroutine heavy_configure: not called CC=13 SCAR=52.0
Pod undocumented
609 0 my Config $config = shift;
610 0 my $config_keys = $config->fields_hash;
611 0 my $trans_keys = $config->load_type('Translator')->fields_hash_of_class;
612 0 my (@mine, @trans, @unknown);
613 0 ▶ while (my ($name, $value) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
614 0 my $mine = $config_keys->{"cf_$name"};
615 0 ▶ if ($mine) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mine) 0 0 0
616 0 push @mine, $name, $value;
617 }
618 0 ▶ if ($trans_keys->{"cf_$name"}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($$trans_keys{"cf_$name"}) { } 0 0 0
elsif (not $mine) { } 0 0 0
619 0 push @trans, [$name, $value];
620 } elsif (not $mine) {
621 0 push @unknown, [$name, $value];
622 }
623 }
624 0 ▶ $config->configure(@mine) if @mine;
Branch: 1 branch
BranchTrueFalseTotal
if @mine 0 0 0
625 0 foreach my $name ($config->configkeys) {
626 0 ▶ if ($trans_keys->{"cf_$name"}
Branch: 1 branch
BranchTrueFalseTotal
if ($$trans_keys{"cf_$name"} and defined(my $value = $$config{"cf_$name"})) 0 0 0
Condition0%0/3
$$trans_keys{"cf_$name"} and defined(my $value = $$config{"cf_$name"})
!ll&&!rl&&r
000
MC/DC0%0/2
$$trans_keys{"cf_$name"} and defined(my $value = $$config{"cf_$name"})
$$trans_keys{"cf_$name"} defined(my $value = $$config{"cf_$name"})
Truth table0%0/3
A and B
A= $$trans_keys{"cf_$name"}B= defined(my $value = $$config{"cf_$name"})
ABresult
0X0
100
111
627 and defined (my $value = $config->{"cf_$name"})) {
628 0 push @trans, [$name, $value];
629 }
630 }
631 0 $config->{cf_translator_param}{$_->[0]} = $_->[1] for @trans;
632 0 ▶ if (@unknown) {
Branch: 1 branch
BranchTrueFalseTotal
if (@unknown) 0 0 0
633 0 ▶ unless ($config->{cf_allow_unknown_config}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->{"cf_allow_unknown_config"}) 0 0 0
634 croak "Unknown config opts: "
635 0 . join(", ", map {join("=", @$_)} @unknown);
636 }
637 0 $config->{cf_user_config}{$_->[0]} = $_->[1] for @unknown;
638 }
639 0 $config;
640 }
641  
642 0 ▶sub configure_rlimit {
Subroutine configure_rlimit: not called CC=4 SCAR=30.0
Pod undocumented
643 0 (my Config $config, my $rlimit_hash) = @_;
644 0 my $class = 'YATT::Util::RLimit';
645 0 ▶ eval qq{require $class} or die $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $class" or die $@ 0 0 0
646 0 ▶ while (my ($rsrc, $limit) = each %$rlimit_hash) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$rlimit_hash) 0 0 0
647 0 ▶ if (my $sub = $class->can("rlimit_" . $rsrc)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $class->can('rlimit_' . $rsrc)) { } 0 0 0
648 0 $sub->($limit);
649 } else {
650 0 $class->can('rlimit')->("RLIMIT_" . uc($rsrc), $limit);
651 }
652 }
653 }
654  
655 0 ▶sub extract_cgi_params {
Subroutine extract_cgi_params: not called CC=3 SCAR=24.8
Pod undocumented
656 0 my ($pack, $cgi) = @_;
657 0 my %param;
658 0 foreach my $name ($cgi->param) {
659 0 my @value = $cgi->param($name);
660 0 ▶ if (@value > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@value > 1) { } 0 0 0
661 0 $param{$name} = \@value;
662 } else {
663 0 $param{$name} = $value[0];
664 }
665 }
666 0 \%param
667 }
668  
669 1 ▶sub new_translator {
Subroutine new_translator: called CC=2 SCAR=7.6
Pod undocumented
670 1 my ($self, $loader) = splice @_, 0, 2;
671 1 ▶ my $pack = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
672 1 $pack->call_type(Translator => new =>
673 app_prefix => $pack
674 , default_base_class => $pack
675 , rc_global => [$pack->rc_global]
676 , loader => $loader, @_);
677 }
678  
679 0 ▶sub use_env_vars {
Subroutine use_env_vars: not called CC=5 SCAR=34.0
Pod undocumented
680 0 my ($env) = @_;
681 0 ▶ $env = \%ENV unless defined $env;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $env 0 0 0
682 0 foreach my $vn (our @env_vars) {
683 0 *{globref(MY, $vn)} = do {
684 0 ▶ $env->{$vn} = '' unless defined $env->{$vn};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $env->{$vn} 0 0 0
685 0 \ $env->{$vn};
686 };
687 }
688 0 ▶ $SCRIPT_FILENAME ||= $0;
Condition0%0/3
$YATT::Toplevel::CGI::SCRIPT_FILENAME ||= $0
l!l&&r!l&&!r
000
MC/DC0%0/2
$YATT::Toplevel::CGI::SCRIPT_FILENAME ||= $0
$YATT::Toplevel::CGI::SCRIPT_FILENAME $0
Truth table0%0/3
A ||= B
A= $YATT::Toplevel::CGI::SCRIPT_FILENAMEB= $0
ABresult
1X1
011
000
689 }
690  
691 #========================================
692  
693 0 ▶sub set_random_list {
Subroutine set_random_list: not called CC=3 SCAR=24.8
Pod undocumented
694 0 my ($this, $random) = @_;
695 0 ▶ if (defined $random) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $random) { } 0 0 0
696 0 ▶ $RANDOM_LIST = ref $random ? $random : [split " ", $random];
Branch: 1 branch
BranchTrueFalseTotal
ref $random ? : 0 0 0
697 0 $RANDOM_INDEX = 0;
698 } else {
699 0 undef $RANDOM_LIST;
700 0 undef $RANDOM_INDEX;
701 }
702 }
703  
704 0 ▶sub entity_rand {
Subroutine entity_rand: not called CC=3 SCAR=24.8
Pod undocumented
705 0 my ($this, $scalar) = @_;
706 0 ▶ $scalar ||= 1;
Condition0%0/2
$scalar ||= 1
l!l
00
MC/DC0%0/1
$scalar ||= 1
$scalar
Truth table0%0/2
A
A= $scalar
Aresult
11
00
707 0 ▶ if ($RANDOM_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if ($YATT::Toplevel::CGI::RANDOM_LIST) { } 0 0 0
708 0 my $val = $RANDOM_LIST->[$RANDOM_INDEX++ % @$RANDOM_LIST];
709 0 $val * $scalar;
710 } else {
711 0 rand $scalar;
712 }
713 }
714  
715 0 ▶sub entity_randomize {
Subroutine entity_randomize: not called CC=3 SCAR=24.8
Pod undocumented
716 0 my ($this) = shift;
717 0 my $sub = $this->can('entity_rand');
718 0 my @result;
719 0 ▶ push @result, splice @_, $sub->($this, scalar @_), 1 while @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ and do { push @result, splice(@_, &$sub($this, scalar @_), 1) } 0 0 0
720 0 ▶ wantarray ? @result : \@result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
721 }
722  
723 0 ▶sub entity_breakpoint {
Subroutine entity_breakpoint: not called CC=1 SCAR=6.9
Pod undocumented
724 0 &YATT::breakpoint();
725 }
726  
727 0 ▶sub entity_concat {
Subroutine entity_concat: not called CC=1 SCAR=6.9
Pod undocumented
728 0 my $this = shift;
729 0 join '', @_;
730 }
731  
732 0 ▶sub entity_join {
Subroutine entity_join: not called CC=2 SCAR=17.9
Pod undocumented
733 0 my ($this, $sep) = splice @_, 0, 2;
734 0 ▶ join $sep, grep {defined $_ && $_ ne ''} @_;
Condition0%0/3
defined $_ && $_ ne ''
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && $_ ne ''
defined $_ $_ ne ''
Truth table0%0/3
A && B
A= defined $_B= $_ ne ''
ABresult
0X0
100
111
735 }
736  
737 0 ▶sub entity_format {
Subroutine entity_format: not called CC=1 SCAR=6.9
Pod undocumented
738 0 my ($this, $format) = (shift, shift);
739 0 sprintf $format, @_;
740 }
741  
742 0 ▶sub entity_is_debug_allowed {
Subroutine entity_is_debug_allowed: not called CC=2 SCAR=17.9
Pod undocumented
743 0 my ($this) = @_;
744 0 ▶ unless (defined $CGI->{'.allow_debug'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $YATT::Toplevel::CGI::CGI->{".allow_debug"}) 0 0 0
745 0 $CGI->{'.allow_debug'} = $this->is_debug_allowed($CGI->remote_addr);
746 }
747 0 $CGI->{'.allow_debug'};
748 }
749  
750 0 ▶sub is_debug_allowed {
Subroutine is_debug_allowed: not called CC=4 SCAR=30.0
Pod undocumented
751 0 my ($this, $ip) = @_;
752 0 my $pat = $$CONFIG{cf_debug_allowed_ip};
753 0 ▶ unless (defined $pat) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $pat) { } 0 0 0
if (do { ref $pat }) { } 0 0 0
elsif ($pat eq '') { } 0 0 0
754 0 $pat = $$CONFIG{cf_debug_allowed_ip} = $this->load_htdebug;
755 } elsif (ref $pat) {
756 0 $pat = $$CONFIG{cf_debug_allowed_ip} = qr{@{[join "|", map {"^$_"} @$pat]}};
757 } elsif ($pat eq '') {
758 0 return 0
759 }
760 0 $ip =~ $pat;
761 }
762  
763 0 ▶sub load_htdebug {
Subroutine load_htdebug: not called CC=5 SCAR=34.0
Pod undocumented
764 0 my ($this) = @_;
765 0 my $dir = untaint_any(dirname($CONFIG->{cf_driver}));
766 0 my $fn = "$dir/.htdebug";
767 0 ▶ return '' unless -r $fn;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $fn 0 0 0
768 0 ▶ open my $fh, '<', $fn or die "Can't open $fn: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $fn or die "Can't open ${fn}: $!" 0 0 0
769 0 local $_;
770 0 my @pat;
771 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
772 0 chomp;
773 0 s/\#.*//;
774 0 ▶ next unless /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 0 0 0
775 0 push @pat, '^'.quotemeta($_);
776 }
777 0 qr{@{[join "|", @pat]}};
778 }
779  
780 0 ▶sub entity_CGI { $CGI }
Subroutine entity_CGI: not called CC=1 SCAR=6.9
Pod undocumented
781  
782 0 ▶sub entity_remote_addr {
Subroutine entity_remote_addr: not called CC=1 SCAR=6.9
Pod undocumented
783 0 $CGI->remote_addr
784 }
785  
786 #========================================
787  
788 0 ▶sub entity_param {
Subroutine entity_param: not called CC=1 SCAR=6.9
Pod undocumented
789 0 my ($this) = shift;
790 0 $CGI->param(@_);
791 }
792  
793 #
794 # For &HTML(); shortcut.
795 # To use this, special_entities should have 'HTML'.
796 #
797 0 ▶sub entity_HTML {
Subroutine entity_HTML: not called CC=1 SCAR=6.9
Pod undocumented
798 0 my $this = shift;
799 0 \ join "", grep {defined $_} @_;
800 }
801  
802 0 ▶sub entity_dump {
Subroutine entity_dump: not called CC=1 SCAR=6.9
Pod undocumented
803 0 shift;
804 0 YATT::Util::terse_dump(@_);
805 }
806  
807 #========================================
808  
809 0 ▶sub canonicalize_html_filename {
Subroutine canonicalize_html_filename: not called CC=2 SCAR=17.9
Pod undocumented
810 0 my $pack = shift;
811 0 ▶ $_[0] .= "index" if $_[0] =~ m{/$};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ m[/$] 0 0 0
812 0 my $copy = shift;
813 0 $copy =~ s{\.(y?html?|yatt?)$}{};
814 0 $copy;
815 }
816  
817 0 ▶sub widget_path_in {
Subroutine widget_path_in: not called CC=4 SCAR=30.0
Pod undocumented
818 0 my ($pack, $rootdir, $file) = @_;
819 0 ▶ unless (index($file, $rootdir) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (index($file, $rootdir) == 0) 0 0 0
820 0 $pack->plain_error
821 (undef, "Requested file $file is not in rootdir $rootdir");
822 }
823  
824 my @elempath
825 0 = split '/', $pack->canonicalize_html_filename
826 (substr($file, length($rootdir)));
827 0 ▶ shift @elempath if defined $elempath[0] and $elempath[0] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $elempath[0] and $elempath[0] eq "" 0 0 0
Condition0%0/3
defined $elempath[0] and $elempath[0] eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $elempath[0] and $elempath[0] eq ""
defined $elempath[0] $elempath[0] eq ""
Truth table0%0/3
A and B
A= defined $elempath[0]B= $elempath[0] eq ""
ABresult
0X0
100
111
828  
829 0 @elempath;
830 }
831  
832 1 ▶sub YATT::Toplevel::CGI::Config::translator_param {
Subroutine translator_param: called CC=3 SCAR=14.2
Pod undocumented
833 1 my Config $config = shift;
834 # print "translator_param: ", terse_dump($config), "\n";
835 map($_ ? (ref $_ eq 'ARRAY' ? @$_ : %$_) : ()
836 , $config->{cf_translator_param})
837 1 ▶}
Branch: 2 branches
BranchTrueFalseTotal
$_ ? : 0 1 1
ref $_ eq 'ARRAY' ? : 0 0 0
838  
839  
840 #========================================
841 2 ▶package YATT::Toplevel::CGI::Batch; use YATT::Inc;
Subroutine BEGIN: called CC=1 SCAR=0.0
842 2 ▶use base qw(YATT::Toplevel::CGI);
Subroutine BEGIN: called CC=1 SCAR=0.0
843 2 ▶use YATT::Util qw(catch);
Subroutine BEGIN: called CC=1 SCAR=0.0
844  
845 0 ▶sub run_files {
Subroutine run_files: not called CC=5 SCAR=34.0
Pod undocumented
846 0 my $pack = shift;
847 0 my ($method, $flag, @opts) = $pack->parse_opts(\@_);
848 0 my $config = $pack->new_config(\@opts);
849 0 $pack->parse_params(\@_, \ my %param);
850  
851 0 foreach my $file (@_) {
852 0 ▶ print "=== $file ===\n" if $ENV{VERBOSE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"VERBOSE"} 0 0 0
853 0 ▶ if (catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&catch(sub { $pack->run_template($pack->rel2abs($file), \%param, $config); } , \my $error)) 0 0 0
854 0 $pack->run_template($pack->rel2abs($file), \%param, $config);
855 } \ my $error) {
856 0 print STDERR $error;
857 }
858 0 ▶ print "\n" if $ENV{VERBOSE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"VERBOSE"} 0 0 0
859 }
860 }
861  
862 0 ▶sub dispatch_action {
Subroutine dispatch_action: not called CC=1 SCAR=6.9
Pod undocumented
863 0 my ($top, $root, $action, $pkg, @param) = @_;
864 0 &YATT::break_handler;
865 0 $action->($pkg, @param);
866 0 $top->bye;
867 }
868  
869 2 1;
« web/cgi-bin/yatt.lib/YATT/Translator/Perl/macro_dbfetch.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/DBSchema.pm »