AnyEvent-FCGI
view release on metacpan or search on metacpan
lib/AnyEvent/FCGI/Request.pm view on Meta::CPAN
package AnyEvent::FCGI::Request;
=head1 NAME
AnyEvent::FCGI::Request - a single FastCGI request handle for L<AnyEvent::FCGI>
=head1 SYNOPSIS
use AnyEvent;
use AnyEvent::FCGI;
use CGI::Stateless;
my $fcgi = new AnyEvent::FCGI(
port => 9000,
on_request => sub {
my $request = shift;
local *STDIN; open STDIN, '<', \$request->read_stdin;
local %ENV = %{$request->params};
local $CGI::Q = new CGI::Stateless;
$request->respond(
'Hello, ' . (CGI::param('name') || 'anonymous'),
'Content-Type' => 'text/html; charset=utf8',
'Set-Cookie' => 'cookie_a=1; path=/',
'Set-Cookie' => 'cookie_b=2; path=/',
);
}
);
AnyEvent->loop;
=head1 DESCRIPTION
This is the request object as generated by L<AnyEvent::FCGI>.
When given to the controlling program, each request will already have its parameters and STDIN data.
The program can then write response data to the STDOUT stream,
messages to the STDERR stream, and eventually finish it.
This module would not be used directly by a program using C<AnyEvent::FCGI>, but
rather, objects in this class are passed into the C<on_request> callback of
the containing C<AnyEvent::FCGI> object.
=cut
use strict;
use warnings;
use Scalar::Util qw/weaken/;
sub new {
my ($class, %params) = @_;
my $self = bless {
id => $params{id},
fcgi => $params{fcgi},
connection => $params{connection},
flags => $params{flags},
stdin => '',
stdin_done => 0,
params => {},
params_string => '',
params_done => 0,
used_stderr => 0,
}, $class;
weaken($self->{fcgi});
weaken($self->{connection});
return $self;
}
sub _ready_check {
my $self = shift;
if ($self->{stdin_done} && $self->{params_done} && $self->{fcgi}) {
$self->{fcgi}->_request_ready($self);
}
}
sub _process_stdin_record {
my ($self, $record) = @_;
if ($record->{length}) {
( run in 0.939 second using v1.01-cache-2.11-cpan-39bf76dae61 )