« blib/lib/Plack/App/CGIBin/Streaming/Request.pm
↑ Summary
blib/lib/Plack/App/CGIBin/Streaming/IO.pm »
| 1 | package Plack::App::CGIBin::Streaming; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 33 | ▶ | use 5.014; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 33 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 33 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 33 | our $VERSION = '0.05'; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | BEGIN { | ||||||||||||||||||||
| 9 | # this works around a bug in perl | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | # In Perl (at least up to 5.18.0) the first assignment to $SIG{CHLD} | ||||||||||||||||||||
| 12 | # or $SIG{CLD} determines which name is later passed to the signal handler | ||||||||||||||||||||
| 13 | # on systems like Linux that support both names. | ||||||||||||||||||||
| 14 | # This hack tries to be the first such assignment in the perl program | ||||||||||||||||||||
| 15 | # and thus pin down that name. | ||||||||||||||||||||
| 16 | # Net::Server based servers like starman rely on "CHLD" to be passed to | ||||||||||||||||||||
| 17 | # the signal handler. | ||||||||||||||||||||
| 18 | 33 | ▶ | local $SIG{CHLD}=$SIG{CHLD}; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 33 | ▶ | use parent qw/Plack::App::File/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 33 | ▶ | use CGI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 33 | ▶ | use CGI::Compile; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 33 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 33 | ▶ | use Plack::App::CGIBin::Streaming::Request; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 33 | ▶ | use Plack::App::CGIBin::Streaming::IO; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 33 | use Plack::Util::Accessor qw/request_class | |||||||||||||||||||
| 29 | request_params | ||||||||||||||||||||
| 30 | 33 | ▶ | preload/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | ▶ | sub allow_path_info { 1 } | ||||||||||||||||||
|
Subroutine
allow_path_info: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | sub prepare_app { | ||||||||||||||||||||
| 35 | 33 | ▶ | my $self=shift; | ||||||||||||||||||
|
Subroutine
prepare_app: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # warn "\n\nprepare_app [@{$self->preload}]\n\n"; | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 33 | $self->SUPER::prepare_app; | |||||||||||||||||||
| 40 | 33 | ▶ | return unless $self->preload; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 4 | for my $pattern (@{$self->preload}) { | |||||||||||||||||||
| 43 | 7 | ▶ | my $pat=($pattern=~m!^/! | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | ? $pattern | ||||||||||||||||||||
| 45 | : $self->root.'/'.$pattern); | ||||||||||||||||||||
| 46 | # warn " pat=$pat\n"; | ||||||||||||||||||||
| 47 | 6 | for my $fn (glob $pat) { | |||||||||||||||||||
| 48 | # warn "preloading $fn\n"; | ||||||||||||||||||||
| 49 | 9 | $self->{_compiled}->{$fn} = do { | |||||||||||||||||||
| 50 | 9 | local $0 = $fn; # keep FindBin happy | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 9 | $self->mkapp(CGI::Compile->compile($fn)); | |||||||||||||||||||
| 53 | }; | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 33 | our $R; | |||||||||||||||||||
| 59 | 13 | ▶ | sub request { return $R } | ||||||||||||||||||
|
Subroutine
request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | sub mkapp { | ||||||||||||||||||||
| 62 | 19 | ▶ | my ($self, $sub) = @_; | ||||||||||||||||||
|
Subroutine
mkapp: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | return sub { | ||||||||||||||||||||
| 65 | 26 | ▶ | my $env = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 66 | return sub { | ||||||||||||||||||||
| 67 | 27 | ▶ | my $responder = shift; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 32 | local $env->{SCRIPT_NAME} = $env->{'plack.file.SCRIPT_NAME'}; | |||||||||||||||||||
| 70 | 32 | local $env->{PATH_INFO} = $env->{'plack.file.PATH_INFO'}; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 32 | my @env_keys = grep !/^(?:plack|psgi.*)\./, keys %$env; | |||||||||||||||||||
| 73 | 32 | local @ENV{@env_keys} = @{$env}{@env_keys}; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 32 | select STDOUT; | |||||||||||||||||||
| 76 | 32 | $|=0; | |||||||||||||||||||
| 77 | 32 | ▶ | binmode STDOUT, 'via(Plack::App::CGIBin::Streaming::IO)'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 32 | ▶ | my $class = ($self->request_class // | ||||||||||||||||||
|
Condition50%1/2
$self->request_class // "Plack::App::CGIBin::Streaming::Request"
MC/DC0%0/1
$self->request_class // "Plack::App::CGIBin::Streaming::Request"
$self->request_class
Truth table50%1/2
A
A= $self->request_class
| |||||||||||||||||||||
| 80 | 'Plack::App::CGIBin::Streaming::Request'); | ||||||||||||||||||||
| 81 | local $R = $class->new | ||||||||||||||||||||
| 82 | ( | ||||||||||||||||||||
| 83 | env => $env, | ||||||||||||||||||||
| 84 | responder => $responder, | ||||||||||||||||||||
| 85 | 32 | ▶ | @{$self->request_params//[]}, | ||||||||||||||||||
|
Condition100%2/2
$self->request_params // []
MC/DC100%1/1
$self->request_params // []
$self->request_params
Truth table100%2/2
A
A= $self->request_params
| |||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 32 | local *STDIN = $env->{'psgi.input'}; | |||||||||||||||||||
| 89 | 32 | binmode STDIN, 'via(Plack::App::CGIBin::Streaming::IO)'; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | # CGI::Compile localizes $0 and %SIG and calls | ||||||||||||||||||||
| 92 | # CGI::initialize_globals. | ||||||||||||||||||||
| 93 | 32 | my $err = eval { | |||||||||||||||||||
| 94 | 32 | local ($/, $\) = ($/, $\); | |||||||||||||||||||
| 95 | 32 | ▶ | $sub->() // ''; | ||||||||||||||||||
|
Condition50%1/2
&$sub() // ""
MC/DC0%0/1
&$sub() // ""
&$sub()
Truth table50%1/2
A
A= &$sub()
| |||||||||||||||||||||
| 96 | }; | ||||||||||||||||||||
| 97 | 32 | my $exc = $@; | |||||||||||||||||||
| 98 | 32 | $R->suppress_flush=1; # turn off normal flush behavior | |||||||||||||||||||
| 99 | 32 | $R->binmode_ok=1; # allow binmode to remove the layer | |||||||||||||||||||
| 100 | { | ||||||||||||||||||||
| 101 | 33 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 102 | 32 | binmode STDOUT; | |||||||||||||||||||
| 103 | 32 | binmode STDIN; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | 32 | $R->finalize; | |||||||||||||||||||
| 106 | 32 | ▶ | unless (defined $err) { # $sub died | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | 6 | warn "$env->{REQUEST_URI}: $exc"; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | 27 | }; | |||||||||||||||||||
| 110 | 19 | }; | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | sub serve_path { | ||||||||||||||||||||
| 114 | 32 | ▶ | my($self, $env, $file) = @_; | ||||||||||||||||||
|
Subroutine
serve_path: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | 32 | ▶ | die "need a server that supports streaming" unless $env->{'psgi.streaming'}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 26 | ▶ | my $app = $self->{_compiled}->{$file} ||= do { | ||||||||||||||||||
|
Condition66%2/3
$self->{"_compiled"}{$file} ||= do {
local $0 = $file;
$self->mkapp("CGI::Compile"->compile($file))
}
MC/DC0%0/2
$self->{"_compiled"}{$file} ||= do {
local $0 = $file;
$self->mkapp("CGI::Compile"->compile($file))
}
$self->{"_compiled"}{$file}
do {
local $0 = $file;
$self->mkapp("CGI::Compile"->compile($file))
}
Truth table66%2/3
A ||= B
A= $self->{"_compiled"}{$file}B= do {
local $0 = $file;
$self->mkapp("CGI::Compile"->compile($file))
}
| |||||||||||||||||||||
| 119 | 16 | local $0 = $file; # keep FindBin happy | |||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 16 | $self->mkapp(CGI::Compile->compile($file)); | |||||||||||||||||||
| 122 | }; | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 32 | $app->($env); | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 38 | 1; | |||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||