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; # always enter package::handler
       }
    }

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

    # automatically dispatches here
    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...");
    }

    # (optional) triggered after main is run
    sub cleanup
    {
        my $self = shift;

        # do something?
    }

    # (optional) triggered on a server error (otherwise returns a normal 500 error)
    sub error
    {
        my $self = shift;
        my $error = shift;

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

METHODS

$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->headers

Returns hashref of headers.

$self->location('url')

Redirect to a url.

$self->status(...)

Set output status... (200, 404, etc...) If no argument given, returns status.

$self->param(...)

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

$self->param_hash

Return a friendly hashref of CGI parameters.

$self->request_body & $self->request

Returns request body.

$self->args

Returns args.

$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.