Net-Async-FastCGI
view release on metacpan or search on metacpan
lib/Net/Async/FastCGI.pm view on Meta::CPAN
}
...
use IO::Async::Loop;
my $loop = IO::Async::Loop->new();
my $fastcgi;
$loop->add( $fastcgi = MyFastCGIResponder->new( service => 1234 ) );
$fastcgi->listen(
service => 1234,
on_resolve_error => sub { die "Cannot resolve - $_[-1]\n" },
on_listen_error => sub { die "Cannot listen - $_[-1]\n" },
);
$loop->run;
=head1 DESCRIPTION
This module allows a program to respond asynchronously to FastCGI requests,
as part of a program based on L<IO::Async>. An object in this class represents
a single FastCGI responder that the webserver is configured to communicate
with. It can handle multiple outstanding requests at a time, responding to
each as data is provided by the program. Individual outstanding requests that
have been started but not yet finished, are represented by instances of
L<Net::Async::FastCGI::Request>.
=cut
=head1 EVENTS
The following events are invoked, either using subclass methods or CODE
references in parameters:
=head2 on_request $req
Invoked when a new FastCGI request is received. It will be passed a new
L<Net::Async::FastCGI::Request> object.
=cut
=head1 PARAMETERS
The following named parameters may be passed to C<new> or C<configure>:
=over 8
=item on_request => CODE
CODE references for C<on_request> event handler.
=item default_encoding => STRING
Sets the default encoding used by all new requests. If not supplied then
C<UTF-8> will apply.
=item stream_stdin => BOOL
If true, requests will expect to handling streaming of stdin data. In this
mode, the C<on_request> event handler will be invoked once parameters for a
new request have been received, even if the stdin stream is not yet complete.
=back
=cut
sub _init
{
my $self = shift;
my ( $params ) = @_;
$self->SUPER::_init( $params );
$params->{default_encoding} = "UTF-8";
}
sub configure
{
my $self = shift;
my %params = @_;
foreach (qw( on_request default_encoding stream_stdin )) {
exists $params{$_} and
$self->{$_} = delete $params{$_};
}
$self->SUPER::configure( %params );
}
sub on_stream
{
my $self = shift;
my ( $stream ) = @_;
$self->add_child( Net::Async::FastCGI::ServerProtocol->new(
transport => $stream,
fcgi => $self,
stream_stdin => $self->{stream_stdin},
) );
}
=head1 METHODS
=cut
=head2 listen
$fcgi->listen( %args );
Start listening for connections on a socket, creating it first if necessary.
This method may be called in either of the following ways. To listen on an
existing socket filehandle:
=over 4
=item handle => IO
An IO handle referring to a listen-mode socket. This is now deprecated; use
the C<handle> key to the C<new> or C<configure> methods instead.
( run in 0.598 second using v1.01-cache-2.11-cpan-140bd7fdf52 )