NAME

Nginx::Simple - Easy to use interface for "--with-http_perl_module"

SYNOPSIS

  nginx.conf:  
    perl_modules perl;
    perl_require Test.pm;

    server {
       listen       80;
       server_name  localhost;

       location / {
          perl Test::handler;
       }
    }

  Test.pm:
    package Test;
    use Nginx::Simple;

    sub handler { dispatch(shift) }

    sub main
    {
        my $self = shift;
        
        $self->header_set('Content-Type' => 'text/html');
        $self->print('rock on!');
	
        $self->log('I found a rabbit...');
        
        my $something = $self->param("here");
        $self->print("I found $something...");
    }

    # triggered on a server error
    sub error
    {
        my $self = shift;
        my $error = shift;

        $self->status(500);
        $self->print("oh, uh, there is an error! ($error)");
    }
    

METHODS

$self->dispatch

sub header { dispatch(shift) }

Initial dispatcher, to be called by nginx.

$self->server

Returns the nginx server object.

$self->uri

Returns the uri.

$self->filename

Returns the path filename.

$self->request_method

Returns the request_method.

$self->remote_addr

Returns the remote_addr.

$self->header_in

Return value of header_in.

$self->print(...)

Output via http.

$self->header_set('header_type', 'value')

Set output header.

$self->header('content-type')

Set content type.

$self->location('url')

Redirect to a url.

$self->status(...)

Set output status... (200, 404, etc...)

$self->param(...)

Return a parameter passed via CGI--works like CGI::param.

$self->param_hash

Return a friendly hashref of CGI parameters.

$self->cookie

Cookie methods:

$self->cookie->set(-name => 'foo', -value => 'bar');
my %cookies = $self->cookie->read;

Author

Michael J. Flickinger, <mjflick@open-site.org>

Copyright & License

You may distribute under the terms of either the GNU General Public License or the Artistic License.