FCGI-EV-Std
view release on metacpan or search on metacpan
main::main($server), where $server is FCGI::EV object. In this case
main::main() shouldn't do any blocking operations (like using SQL
database) but may setup any events (I/O, timer, etc.) using EV module
and should returns quickly. Other CGI requests will be processed in
parallel while this CGI request wait for events. After CGI will have
some data to send, it should use $server->stdout($data, $is_eof) method
(if $server is still defined - it may become undef if connection to web
server related to this CGI request was already closed). In addition,
FCGI::EV::Std may be configured to call any user function, say,
main::hup($server) if connection to web server will be closed before
CGI sent it reply. WARNING! User shouldn't keep non-weaken() references
to $server in it code!
See also FCGI::EV::Std::Nonblock - it's helper module which make
writing non-blocking CGI ease.
Use these global variables to configure FCGI::EV::Std:
BLOCKING
$FCGI::EV::Std::BLOCKING = 1;
lib/FCGI/EV/Std.pm view on Meta::CPAN
package FCGI::EV::Std;
use 5.010001;
use warnings;
use strict;
use utf8;
use Carp;
our $VERSION = 'v2.0.1';
use Scalar::Util qw( weaken );
use if $INC{'CGI.pm'}, 'CGI::Stateless';
use constant HTTP_417_EXPECTATION_FAILED =>
"Status: 417 Expectation Failed\r\n"
. "Content-Type: text/html\r\n"
. "\r\n"
. '<html><head><title>417 Expectation Failed</title></head>'
. '<body><h1>Expectation Failed</h1>'
lib/FCGI/EV/Std.pm view on Meta::CPAN
sub new {
my ($class, $server, $env) = @_;
my $len = $env->{CONTENT_LENGTH} || 0;
my $self = bless {
server => $server,
env => $env,
stdin => q{},
allow => $len <= $MAX_STDIN,
}, $class;
weaken($self->{server});
return $self;
}
# No protection against reading STDIN larger than CONTENT_LENGTH - because
# FastCGI protocol FORBID this so web server shouldn't send so much data
# ( http://www.fastcgi.com/devkit/doc/fcgi-spec.html#S6.2 ).
#
# If huge files will be uploaded it MAY have sense to save STDIN to
# secure tempfile - but code which parse POST data from STDIN in CGI also
# shouldn't read all STDIN into memory, or this feature will not help.
lib/FCGI/EV/Std.pm view on Meta::CPAN
where $server is FCGI::EV object. In this case main::main() shouldn't
do any blocking operations (like using SQL database) but may setup any
events (I/O, timer, etc.) using EV module and should returns quickly.
Other CGI requests will be processed in parallel while this CGI request
wait for events. After CGI will have some data to send, it should use
$server->stdout($data, $is_eof) method (if $server is still defined - it
may become undef if connection to web server related to this CGI request
was already closed). In addition, FCGI::EV::Std may be configured to call
any user function, say, main::hup($server) if connection to web server will
be closed before CGI sent it reply. WARNING! User shouldn't keep
non-weaken() references to $server in it code!
See also L<FCGI::EV::Std::Nonblock> - it's helper module which make
writing non-blocking CGI ease.
Use these global variables to configure FCGI::EV::Std:
=head2 BLOCKING
$FCGI::EV::Std::BLOCKING = 1;
lib/FCGI/EV/Std/Nonblock.pm view on Meta::CPAN
package FCGI::EV::Std::Nonblock;
use 5.010001;
use warnings;
use strict;
use utf8;
use Carp;
our $VERSION = 'v2.0.1';
use Scalar::Util qw( weaken refaddr );
use FCGI::EV::Std;
$FCGI::EV::Std::BLOCKING= 0;
$FCGI::EV::Std::MAIN = \&new;
$FCGI::EV::Std::HUP = \&HUP;
my $CB_START = \&main::START;
my $CB_PRE = \&main::PRE;
my $CB_POST = \&main::POST;
my $CB_ERROR = \&main::ERROR;
#my $HUP = undef;
my (%Active, %Server);
sub new {
my ($server) = @_;
my $self = bless {}, __PACKAGE__;
$Active{ refaddr($self) } = $server;
$Server{ refaddr($server) } = $self;
weaken( $Active{ refaddr($self) } );
$self->_wrapper($CB_START);
return;
}
sub done {
my ($self) = @_;
if (exists $Active{ refaddr($self) }) {
my $server = delete $Active{ refaddr($self) };
if ($server) {
delete $Server{ refaddr($server) };
lib/FCGI/EV/Std/Nonblock.pm view on Meta::CPAN
my ($self, $buf) = @_;
my $server = $Active{ refaddr($self) };
if ($server) {
$server->stdout($buf, 0);
}
return;
}
sub wrap_cb {
my ($self, $cb, @p) = @_;
weaken(my $this = $self);
return sub { $this && $this->_wrapper($cb, @p, @_) };
}
sub _wrapper {
my ($this, $cb, @p) = @_;
$CB_PRE->($this);
my $err = eval { $cb->($this, @p); 1 } ? undef : $@;
$CB_POST->($this);
( run in 0.247 second using v1.01-cache-2.11-cpan-1f129e94a17 )