| 1 | package YATT::Lite::WebMVC0::SiteApp::CGI; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # -*- coding: utf-8 -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | use YATT::Lite::WebMVC0::SiteApp; # To make lint happy, this is required. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | package YATT::Lite::WebMVC0::SiteApp; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # For debugging only (at least for now). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub _callas_cgi { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_callas_cgi: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | (my MY $self, my $app, my $fh, my Env $init_env, my ($args, %opts)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my Env $env = $self->psgi_cgi_newenv($init_env, $fh); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $res; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if ($self->{noheader}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | require Cwd; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | local $env->{GATEWAY_INTERFACE} = 'CGI/YATT'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | local $env->{REQUEST_METHOD} //= 'GET'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
local $env->{"REQUEST_METHOD"} //= "GET"
MC/DC0%0/1
local $env->{"REQUEST_METHOD"} //= "GET"
local $env->{"REQUEST_METHOD"}
Truth table0%0/2
A
A= local $env->{"REQUEST_METHOD"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | local @{$env}{qw(PATH_TRANSLATED REDIRECT_STATUS)} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | = (Cwd::abs_path(shift @$args), 200) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if (my $err = catch { $res = $app->($env) }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # XXX: Should I do error specific things? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $res = $err; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } elsif ($env->{GATEWAY_INTERFACE}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if (my $err = catch { $res = $app->($env) }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $res = $err; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $res = $app->($env); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | print terse_dump($res); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | print terse_dump($res); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 16 | ▶ | sub _runas_cgi { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_runas_cgi: called CC=11 SCAR=35.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 16 | (my MY $self, my $fh, my Env $env, my ($args, %opts)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 16 | ▶ | if ($self->has_htdebug("env")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $self->printenv($fh, $env); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # This flag is useful to debug "malformed header from script" case. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 16 | ▶ | if ($self->has_htdebug("dumb_header")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | print $fh "\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 16 | $self->init_by_env($env); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 16 | ▶ | if ($self->{noheader}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # コマンド行起動時 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | require Cwd; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | local $env->{GATEWAY_INTERFACE} = 'CGI/YATT'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | local $env->{REQUEST_METHOD} //= 'GET'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
local $env->{"REQUEST_METHOD"} //= "GET"
MC/DC0%0/1
local $env->{"REQUEST_METHOD"} //= "GET"
local $env->{"REQUEST_METHOD"}
Truth table0%0/2
A
A= local $env->{"REQUEST_METHOD"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | local @{$env}{qw(PATH_TRANSLATED REDIRECT_STATUS)} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | = (Cwd::abs_path(shift @$args), 200) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my @params = $self->make_cgi($env, $args, \%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $con = $self->make_connection($fh, @params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $self->cgi_dirhandler($con, @params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } elsif ($env->{GATEWAY_INTERFACE}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # Normal CGI | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 16 | ▶ | if (defined $fh and fileno($fh) >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $fh and fileno $fh >= 0
MC/DC0%0/2
defined $fh and fileno $fh >= 0
defined $fh
fileno $fh >= 0
Truth table33%1/3
A and B
A= defined $fhB= fileno $fh >= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | open STDERR, '>&', $fh or die "can't redirect STDERR: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 16 | my $con; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 16 | ▶ | my $error = catch { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 16 | my @params = $self->make_cgi($env, $args, \%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 16 | $con = $self->make_connection($fh, @params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 16 | $self->cgi_dirhandler($con, @params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 16 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | $self->cgi_process_error($error, $con, $fh, $env); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 16 | ▶ | $con->header_was_sent if $con; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # dispatch without catch. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my @params = $self->make_cgi($env, $args, \%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $con = $self->make_connection($fh, @params, no_auto_flush_headers => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $self->cgi_dirhandler($con, @params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | #======================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 16 | ▶ | sub cgi_dirhandler { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cgi_dirhandler: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 16 | (my MY $self, my ($con, %params)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # dirhandler は必ず load することにする。 *.yatt だけでなくて *.ydo でも。 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # 結局は機能集約モジュールが欲しくなるから。 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # そのために、 dirhandler は死重を減らすよう、部分毎に delayed load する | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 16 | ▶ | my $dh = $self->get_dirhandler(untaint_any($params{dir})) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | or die "Unknown directory: $params{dir}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # XXX: cache のキーは相対パスか、絶対パスか? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 16 | $con->configure(yatt => $dh); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 16 | $self->run_dirhandler($dh, $con, $params{file}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 14 | try_invoke($con, 'flush_headers'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 14 | ▶ | wantarray ? ($dh, $con) : $con; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | #======================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # XXX: $env 渡し中心に変更する. 現状では... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # [1] $fh, $cgi を外から渡すケース... そもそも、これを止めるべき. $env でええやん、と。 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # [2] $fh, $file, []/{} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # [3] $fh, $file, k=v, k=v... のケース | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 16 | ▶ | sub make_cgi { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_cgi: called CC=12 SCAR=39.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 16 | (my MY $self, my Env $env, my ($args, $opts)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 16 | my ($cgi, $root, $loc, $file, $trailer, $is_index, $request_file); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 16 | ▶ | unless ($self->{noheader}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 16 | $cgi = do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 16 | ▶ | if (ref $args and UNIVERSAL::can($args, 'param')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $args and UNIVERSAL::can($args, "param")
MC/DC0%0/2
ref $args and UNIVERSAL::can($args, "param")
ref $args
UNIVERSAL::can($args, "param")
Truth table33%1/3
A and B
A= ref $argsB= UNIVERSAL::can($args, "param")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 16 | $self->new_cgi(@$args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 16 | ($root, $loc, $file, $trailer, $is_index, $request_file) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | = my @pi = $self->split_path_info($env); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 16 | ▶ | unless (@pi) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # XXX: This is too early for fatal to browser. mmm | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->error("Can't parse request. env='%s'", terse_dump($env)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # XXX: /~user_dir の場合は $dir ne $root$loc じゃんか orz... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $path = shift @$args; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | unless (defined $path) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | die "Usage: $0 tmplfile args...\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | unless ($path =~ m{^/}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | unless (-e $path) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | die "No such file: $path\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # XXX: $path が相対パスだったら?この時点で abs 変換よね? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | require Cwd; # でも、これで 10ms 遅くなるのよね。 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | $path = Cwd::abs_path($path) // die "No such file: $path\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
Cwd::abs_path($path) // die("No such file: $path\n")
MC/DC0%0/1
Cwd::abs_path($path) // die("No such file: $path\n")
Cwd::abs_path($path)
Truth table0%0/2
A
A= Cwd::abs_path($path)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # XXX: widget 直接呼び出しは? cgi じゃなしに、直接パラメータ渡しは? => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ($root, $loc, $file, $trailer, $is_index, $request_file) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | = split_path($path, $self->{app_root}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $cgi = $self->new_cgi(@$args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 16 | ▶ | if ($self->has_htdebug("path_info")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $self->raise_psgi_dump([loc => $loc] | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | , [file => $file] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | , [trailer => $trailer] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | , [is_index => $is_index] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 16 | ▶ | $request_file //= $is_index ? '' : trim_ext($file, $self->{ext_public}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$request_file //= $is_index ? "" : trim_ext($file, $self->{"ext_public"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 16 | (env => $env | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | , $self->connection_quad(["$root$loc", $loc, $file, $trailer | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | , $request_file]) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | , cgi => $cgi, root => $root, is_psgi => 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 16 | ▶ | sub init_by_env { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_by_env: called CC=5 SCAR=16.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 16 | (my MY $self, my Env $env) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 16 | ▶ | $self->{noheader} //= 0 if $env->{GATEWAY_INTERFACE}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{"noheader"} //= 0
MC/DC100%1/1
$self->{"noheader"} //= 0
$self->{"noheader"}
Truth table100%2/2
A
A= $self->{"noheader"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 16 | ▶ | $self->{doc_root} //= $env->{DOCUMENT_ROOT} if $env->{DOCUMENT_ROOT}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"doc_root"} //= $env->{"DOCUMENT_ROOT"}
MC/DC0%0/2
$self->{"doc_root"} //= $env->{"DOCUMENT_ROOT"}
$self->{"doc_root"}
$env->{"DOCUMENT_ROOT"}
Truth table33%1/3
A //= B
A= $self->{"doc_root"}B= $env->{"DOCUMENT_ROOT"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 16 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 16 | ▶ | sub new_cgi { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_cgi: called CC=11 SCAR=43.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 16 | my MY $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 16 | my (@params) = do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 16 | ▶ | unless (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | () | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 16 | ▶ | } elsif (@_ == 1 and defined $_[0] and not ref $_[0] and $_[0] =~ /[&;]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
@_ == 1 and defined $_[0] and not ref $_[0] and $_[0] =~ /[&;]/
@_ == 1 and defined $_[0] and not ref $_[0]
@_ == 1 and defined $_[0]
MC/DC0%0/4
@_ == 1 and defined $_[0] and not ref $_[0] and $_[0] =~ /[&;]/
@_ == 1
defined $_[0]
not ref $_[0]
$_[0] =~ /[&;]/
Truth table0%0/5
A and B and not(C) and D
A= @_ == 1B= defined $_[0]C= not ref $_[0]D= $_[0] =~ /[&;]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $_[0]; # Raw query string | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | ▶ | } elsif (@_ > 1 or defined $_[0] and not ref $_[0]) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
@_ > 1 or defined $_[0] and not ref $_[0]
defined $_[0] and not ref $_[0]
MC/DC0%0/3
@_ > 1 or defined $_[0] and not ref $_[0]
@_ > 1
defined $_[0]
not ref $_[0]
Truth table0%0/4
A or B and not(C)
A= @_ > 1B= defined $_[0]C= not ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # k=v list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $self->parse_params(\@_, {}) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } elsif (not defined $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } elsif (ref $_[0] eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my %hash = @{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | \%hash; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 16 | require CGI; CGI->new(@params); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # shift; require CGI::Simple; CGI::Simple->new(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 16 | ▶ | sub cgi_process_error { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cgi_process_error: called CC=9 SCAR=33.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 16 | (my MY $self, my ($error, $con, $fh, $env)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 16 | ▶ | if (not $error or is_done($error)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
not $error or is_done($error)
MC/DC50%1/2
not $error or is_done($error)
not $error
is_done($error)
Truth table66%2/3
not(A) or B
A= not $errorB= is_done($error)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 14 | ▶ | if (not tell($fh) and (my $len = length($con->buffer))) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not tell $fh and my $len = length $con->buffer
MC/DC0%0/2
not tell $fh and my $len = length $con->buffer
not tell $fh
my $len = length $con->buffer
Truth table33%1/3
not(A) and B
A= not tell $fhB= my $len = length $con->buffer
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # We have buffered content but not yet delivered! | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # Possible misuse of Connection API. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $self->cgi_response($fh, $env | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | , 200 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | , ["Content-type", $con->_mk_content_type] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # XXX: We should add API usage suggestion here. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | , [$con->buffer]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Already delivered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } elsif (ref $error eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # Non local exit with PSGI response triplet. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 2 | $self->cgi_response($fh, $env, @{$error}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ▶ | } elsif (defined $con and UNIVERSAL::isa($error, $self->Error)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $con and UNIVERSAL::isa($error, $self->Error)
MC/DC0%0/2
defined $con and UNIVERSAL::isa($error, $self->Error)
defined $con
UNIVERSAL::isa($error, $self->Error)
Truth table0%0/3
A and B
A= defined $conB= UNIVERSAL::isa($error, $self->Error)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # To erase premature output. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $con->rewind; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # Known error. Header (may be) already printed. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | (undef, my $ct, my @rest) = $self->secure_text_plain; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $con->set_content_type($ct); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $con->set_header_list(@rest) if @rest; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $con->flush_headers; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | print $fh $error->message; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # Unknown error. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $self->show_error($fh, $error, $env); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | ▶ | sub cgi_response { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cgi_response: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | (my MY $self, my ($fh, $env, $code, $headers, $body)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | my $header = mk_http_status($code); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | ▶ | while (my ($k, $v) = splice @$headers, 0, 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 2 | $header .= "$k: $v\015\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | $header .= "\015\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | print {*$fh} $header; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | print {*$fh} @$body; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | sub printenv { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
printenv: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | (my MY $self, my ($fh, $env)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $self->dump_pairs($fh, map {$_ => $env->{$_}} sort keys %$env); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | sub dump_pairs { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_pairs: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | (my MY $self, my ($fh)) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $self->show_error($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | while (my ($name, $value) = splice @_, 0, 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | print $fh $name, "\t", terse_dump($value), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | sub show_error { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_error: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | (my MY $self, my ($fh, $error, $env)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (my @kv = $self->secure_text_plain) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | while (my ($k, $v) = splice @kv, 0, 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | print $fh "$k: $v\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | print $fh "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | print $fh "\n". ($error // ""); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$error // ""
MC/DC0%0/1
$error // ""
$error
Truth table0%0/2
A
A= $error
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | sub psgi_cgi_newenv { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
psgi_cgi_newenv: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | (my MY $self, my Env $init_env, my ($stdin, $stderr)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | require Plack::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | require Plack::Request; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my Env $env = +{ %$init_env }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $env->{'psgi.version'} = [1,1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | $env->{'psgi.url_scheme'} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | = ($init_env->{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$init_env->{'HTTPS'} || 'off'
MC/DC0%0/1
$init_env->{'HTTPS'} || 'off'
$init_env->{'HTTPS'}
Truth table0%0/2
A
A= $init_env->{'HTTPS'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | $env->{'psgi.input'} = $stdin || *STDIN; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$stdin || *STDIN
MC/DC0%0/2
$stdin || *STDIN
$stdin
*STDIN
Truth table0%0/3
A || B
A= $stdinB= *STDIN
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | $env->{'psgi.errors'} = $stderr || *STDERR; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$stderr || *STDERR
MC/DC0%0/2
$stderr || *STDERR
$stderr
*STDERR
Truth table0%0/3
A || B
A= $stderrB= *STDERR
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $env->{'psgi.multithread'} = &Plack::Util::FALSE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $env->{'psgi.multiprocess'} = &Plack::Util::FALSE; # XXX: | |||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $env->{'psgi.run_once'} = &Plack::Util::FALSE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $env->{'psgi.streaming'} = &Plack::Util::FALSE; # XXX: Todo. | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $env->{'psgi.nonblocking'} = &Plack::Util::FALSE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # delete $env->{HTTP_CONTENT_TYPE}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # delete $env->{HTTP_CONTENT_LENGTH}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $env; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | &YATT::Lite::Breakpoint::break_load_dispatcher_cgi; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||