Nginx::Simple - Easy to use interface for "--with-http_perl_module"
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; # (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->status(500); $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.
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.
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.
Michael J. Flickinger, <mjflick@gnu.org>
<mjflick@gnu.org>
You may distribute under the terms of either the GNU General Public License or the Artistic License.
To install Nginx::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nginx::Simple
CPAN shell
perl -MCPAN -e shell install Nginx::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.