FCGI-EV

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    Handler class (which name provided in $class parameter to
    FCGI::EV->new()) must implement this interface:

    new( $server, \%env )

      When FCGI::EV object receive initial part of CGI request (environment
      variables) it will call $handler_class->new() to create handler
      object which should process that CGI request.

      Parameter $server is FCGI::EV object itself. It's required to send
      CGI reply. WARNING! Handler may keep only weaken() reference to
      $server!

      After calling new() FCGI::EV object ($server) will continue receiving
      STDIN content from web server and will call $handler->stdin() each
      time it get next part of STDIN.

    stdin( $data, $is_eof )

      The $data is next chunk of STDIN received from web server. Flag
      $is_eof will be true if $data was last part of STDIN.

README  view on Meta::CPAN

    This handler will process CGI requests one-by-one (i.e. in blocking
    mode). On request function main::main() will be executed. That function
    may use standard CGI.pm module to get request parameters and send it
    reply using usual print to STDOUT.

    There no error-handling code in this example, see FCGI::EV::Std for
    more details.

     package FCGI::EV::ExampleHandler;
    
     use Scalar::Util qw( weaken );
     use CGI::Stateless; # needed to re-init CGI.pm state between requests
    
     sub new {
        my ($class, $server, $env) = @_;
        my $self = bless {
            server  => $server,
            env     => $env,
            stdin   => q{},
        }, $class;
        weaken($self->{server});
        return $self;
     }
    
     sub stdin {
        my ($self, $stdin, $is_eof) = @_;
        $self->{stdin} .= $stdin;
        if ($is_eof) {
            local *STDIN;
            open STDIN, '<', \$self->{stdin};
            local %ENV = %{ $self->{env} };

lib/FCGI/EV.pm  view on Meta::CPAN

package FCGI::EV;
use 5.010001;
use warnings;
use strict;
use utf8;
use Carp;

our $VERSION = 'v2.0.1';

use Scalar::Util qw( weaken );
use IO::Stream;


use constant FCGI_HEADER_LEN        => 8;
use constant FCGI_VERSION_1         => 1;
use constant FCGI_BEGIN_REQUEST     => 1;
use constant FCGI_END_REQUEST       => 3;
use constant FCGI_PARAMS            => 4;
use constant FCGI_STDIN             => 5;
use constant FCGI_STDOUT            => 6;

lib/FCGI/EV.pm  view on Meta::CPAN

        handler     => undef,
        handler_class=>$handler_class,
    }, $class;
    $self->{io} = IO::Stream->new({
        fh          => $sock,
        wait_for    => IN|EOF,
        cb          => $self,
        Wait_header => 1,
        Need_in     => FCGI_HEADER_LEN,
    });
    weaken($self->{io});
    # It MAY have sense to add timeout between read() calls and timeout for
    # overall time until EOF on STDIN will be received. First timeout
    # can be about 3 minutes for slow clients, second can be about 4 hours
    # for uploading huge files.
    return;
}

sub DESTROY {
    my ($self) = @_;
    $self->{handler} = undef;   # call handler's DESTROY while $self is alive

lib/FCGI/EV.pm  view on Meta::CPAN


=over

=item new( $server, \%env )

When FCGI::EV object receive initial part of CGI request (environment
variables) it will call $handler_class->new() to create handler object
which should process that CGI request.

Parameter $server is FCGI::EV object itself. It's required to send CGI
reply. WARNING! Handler may keep only weaken() reference to $server!

After calling new() FCGI::EV object ($server) will continue receiving
STDIN content from web server and will call $handler->stdin() each time it
get next part of STDIN.

=item stdin( $data, $is_eof )

The $data is next chunk of STDIN received from web server. Flag $is_eof will
be true if $data was last part of STDIN.

lib/FCGI/EV.pm  view on Meta::CPAN

This handler will process CGI requests one-by-one (i.e. in blocking mode).
On request function main::main() will be executed. That function may use
standard CGI.pm module to get request parameters and send it reply using
usual print to STDOUT.

There no error-handling code in this example, see L<FCGI::EV::Std> for
more details.

 package FCGI::EV::ExampleHandler;

 use Scalar::Util qw( weaken );
 use CGI::Stateless; # needed to re-init CGI.pm state between requests

 sub new {
    my ($class, $server, $env) = @_;
    my $self = bless {
        server  => $server,
        env     => $env,
        stdin   => q{},
    }, $class;
    weaken($self->{server});
    return $self;
 }

 sub stdin {
    my ($self, $stdin, $is_eof) = @_;
    $self->{stdin} .= $stdin;
    if ($is_eof) {
        local *STDIN;
        open STDIN, '<', \$self->{stdin};
        local %ENV = %{ $self->{env} };



( run in 0.693 second using v1.01-cache-2.11-cpan-1f129e94a17 )