The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

NetSDS::App::FCGI - FastCGI applications superclass

SYNOPSIS

        # Run application
        MyFCGI->run();

        1;

        # Application package itself
        package MyFCGI;

        use base 'NetSDS::App::FCGI';

        sub process {
                my ($this) = @_;

                $this->data('Hello World');
                $this->mime('text/plain');
                $this->charset('utf-8');

        }

DESCRIPTION

NetSDS::App::FCGI module contains superclass for FastCGI applications. This class is based on NetSDS::App module and inherits all its functionality like logging, configuration processing, etc.

CONSTRUCTOR

new() - constructor

Paramters: class parameters

Returns:

This method provides.....

CLASS AND OBJECT METHODS

cgi() - accessor to CGI.pm request handler
        my $https_header = $this->cgi->https('X-Some-Header');
status([$new_status]) - set response HTTP status

Paramters: new status to set

Returns: response status value

        $this->status('200 OK');
mime() - set response MIME type

Paramters: new MIME type for response

        $this->mime('text/xml'); # output will be XML data
charset() - set response character set if necessary
        $this->mime('text/plain');
        $this->charset('koi8-r'); # ouput as KOI8-R text
data($new_data) - set response data

Paramters: new data "as is"

        $this->mime('text/plain');
        $this->data('Hello world!');
redirect($redirect_url) - send HTTP redirect

Paramters: new URL (relative or absolute)

This method send reponse with 302 status and new location.

        if (havent_data()) {
                $this->redirect('http://www.google.com'); # to google!
        };
cookie() -

Paramters:

Returns:

This method provides.....

headers($headers_hashref) - set/get response HTTP headers

Paramters: new headers as hash reference

        $this->headers({
                'X-Beer' => 'Guiness',
        );
main_loop() - main FastCGI loop

Paramters: none

This method implements common FastCGI (or CGI) loop.

Paramters: hash (name, value, expires)

        $this->set_cookie(name => 'sessid', value => '343q5642653476', expires => '+1h');

Paramters: cookie name

Returns cookie value by it's name

        my $sess = $this->get_cookie('sessid');
param($name) - CGI request parameter

Paramters: CGI parameter name

Returns: CGI parameter value

This method returns CGI parameter value by it's name.

        my $cost = $this->param('cost');
url_param($name) - CGI request parameter

Paramters: URL parameter name

Returns: URL parameter value

This method works similar to param() method, but returns only parameters from the query string.

        my $action = $this->url_param('a');
http($http_field) - request HTTP header

Paramters: request header name

Returns: header value

This method returns HTTP request header value by name.

        my $beer = $this->http('X-Beer');
https($https_field) - request HTTPS header

This method returns HTTPS request header value by name and is almost the same as http() method except of it works with SSL requests.

        my $beer = $this->https('X-Beer');

Just proxying raw_cookie() method from CGI.pm

user_agent() - User-Agent request header
        my $ua_info = $this->user_agent();
request_method() - HTTP request method
        if ($this->request_method eq 'POST') {
                $this->log("info", "Something POST'ed from client");
        }
script_name() - CGI script name

Returns: script name from CGI.pm

path_info() - get PATH_INFO value
        if ($this->path_info eq '/help') {
                $this->data('Help yourself');
        }
remote_host() - remote (client) host name
        warn "Client from: " . $this->remote_host();
remote_addr() - remote (client) IP address

Returns: IP address of client from REMOTE_ADDR environment

        if ($this->remote_addr eq '10.0.0.1') {
                $this->data('Welcome people from our gateway!');
        }
_set_req_cookies() - fetching request cookies (internal method)

Fetching cookies from HTTP request to object req_cookies variable.

EXAMPLES

See samples catalog for more example code.

BUGS

Unknown yet

SEE ALSO

CGI, CGI::Fast, NetSDS::App

TODO

None

AUTHOR

Michael Bochkaryov <misha@rattler.kiev.ua>