.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Perlbal::Plugin::Cgilike 3pm" .TH Perlbal::Plugin::Cgilike 3pm "2022-06-28" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Perlbal::Plugin::Cgilike \- Handle Perlbal requests with a Perl subroutine .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module allows responses to be handled with a simple \s-1API\s0 that's similar in principle to \&\s-1CGI,\s0 mod_perl response handlers, etc. .PP It does not, however, come anywhere close to conforming to the \s-1CGI\s0 \*(L"standard\*(R". It's actually more like mod_perl in usage, though there are several differences. Most notably, Perlbal is single-process and single-threaded, and handlers run inside the Perlbal process and must therefore return quickly and not do any blocking operations. .PP As it currently stands, this is very bare-bones and has only really been used with basic \s-1GET\s0 requests. It lacks a nice \s-1API\s0 for handling the body of a \s-1POST\s0 or \s-1PUT\s0 request. .PP It is not recommended to use this for extensive applications. Perlbal is first and foremost a load balancer, so if you're doing something at all complicated you're probably better off using something like Apache mod_perl and then putting Perlbal in front if it if necessary. However, this plugin may prove useful for simple handlers or perhaps embedding a simple \&\s-1HTTP\s0 service into another application that uses \f(CW\*(C`Danga::Socket\*(C'\fR. .SH "SYNOPSIS" .IX Header "SYNOPSIS" This module provides a Perlbal plugin which can be loaded and used as follows. .PP .Vb 2 \& LOAD cgilike \& PERLREQUIRE = MyPackage \& \& CREATE SERVICE cgilike \& SET role = web_server \& SET listen = 127.0.0.1:80 \& SET plugins = cgilike \& PERLHANDLER = MyPackage::handler \& ENABLE cgilike .Ve .PP With this plugin loaded into a particular service, the plugin will then be called for all requests for that service. .PP Set cgilike.handler to the name of a subroutine that will handle requests. This subroutine will receive an object which allows interaction with the Perlbal service. .PP .Vb 11 \& package MyPackage \& sub handler { \& my ($r) = @_; \& if ($r\->uri eq \*(Aq/\*(Aq) { \& print "

Hello, world

"; \& return Perlbal::Plugin::Cgilike::HANDLED; \& } \& else { \& return 404; \& } \& } .Ve .PP Return \f(CW\*(C`Perlbal::Plugin::Cgilike::HANDLED\*(C'\fR to indicate that the request has been handled, or return some \s-1HTTP\s0 error code to produce a predefined error message. You may also return \f(CW\*(C`Perlbal::Plugin::Cgilike::DECLINED\*(C'\fR if you do not wish to handle the request, in which case Perlbal will be allowed to handle the request in whatever way it would have done without Cgilike loaded. .PP If your handler returns any non-success value, it \fB\s-1MUST NOT\s0\fR produce any output. If you produce output before returning such a value, the response to the client is likely to be utter nonsense. .PP You may also return \f(CW\*(C`Perlbal::Plugin::Cgilike::POSTPONE_RESPONSE\*(C'\fR, which is equivalent to returning zero except that the \s-1HTTP\s0 connection will be left open once you return. It is your responsibility to later call \f(CW\*(C`$r\->end_response()\*(C'\fR when you have completed the response. This style is necessary when you need to perform some long operation before you can return a response; you'll need to use some appropriate method to set a callback to run when the operation completes and then do your response in the callback. Once you've called \f(CW\*(C`end_response\*(C'\fR, you must not call any further methods on \f(CW$r\fR; it's probably safest to just return immediately afterwards to avoid any mishaps. .SH "API DOCUMENTATION" .IX Header "API DOCUMENTATION" \&\s-1TODO:\s0 Write this .SH "TODO" .IX Header "TODO" Currently there is no \s-1API\s0 for dealing with the body of a \s-1POST\s0 or \s-1PUT\s0 request. Ideally it'd be able to do automatic decoding of application/x\-www\-form\-urlencoded data, too. .PP The \s-1POSTPONE_RESPONSE\s0 functionality has not been tested extensively and is probably buggy. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 2007 Martin Atkins and Six Apart Ltd. .PP This module is part of the Perlbal distribution, and as such can be distributed under the same licence terms as the rest of Perlbal.