Michael J. Flickinger > Nginx-Simple-0.07 > Nginx::Simple



Annotate this POD

View/Report Bugs
Module Version: 0.07   Source  


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


    perl_modules perl;
    perl_require Test.pm;

    server {
       listen       80;
       server_name  localhost;

       location / {
          perl Test::handler; # always enter package::handler

    package Test;
    use Nginx::Simple;

    # (optional) triggered before main is run
    sub init
        my $self = shift;

        $self->{user} = 'stinky_pete';

    # automatically dispatches here
    sub main
        my $self = shift;
        $self->header_set('Content-Type' => 'text/html');
        $self->print('rock on!');
        $self->print("$self->{user} is using the system");
        $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->print("oh, uh, there is an error! ($error)");



Returns the nginx server object.


Returns the uri.


Returns the path filename.


Returns the request_method.


Returns the remote_addr.


Return value of header_in.


Output via http.


Returns true if set, otherwise args 1 sets true and 0 false.


Returns true if we're dispatching actively.

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

Set output header.


Set content type.


Returns hashref of headers.


Redirect to a url.


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


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


Return a friendly hashref of CGI parameters.

$self->request_body & $self->request

Returns request body.


Returns args.


Process the autoheader.


Returns the "error stack" as an array.


Returns error as string.


Unscape HTTP URI encoding.


Cookie methods:

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


Returns elapsed time since initial dispatch.

Author ^

Michael J. Flickinger, <mjflick@gnu.org>

Copyright & License ^

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

syntax highlighting: