Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

perlbal::test(3pm) [debian man page]

Perlbal::Test(3pm)					User Contributed Perl Documentation					Perlbal::Test(3pm)

NAME
Perlbal::Test - Test harness for perlbal server SYNOPSIS
# my $msock = Perlbal::Test::start_server(); DESCRIPTION
Perlbal::Test provides access to a perlbal server running on the local host, for testing purposes. The server can be an already-existing server, a child process, or the current process. Various functions are provided to interact with the server. FUNCTIONS
mgmt_port() Return the current management port number. dump_res($http_response) Return a readable string formatted from an HTTP::Response object. Only the first 80 characters of returned content are returned. tempdir() Return a newly created temporary directory. The directory will be removed automatically upon program exit. new_port() Return the next free port number in the series. Port numbers are assigned starting at 60000. test_port() Return 1 if the port is free to use for listening on $free_port else return 0. filecontent($file>; Return a string containing the contents of the file $file. If $file cannot be opened, then return undef. foreach_aio($callback) Set the server into each AIO mode (none, ioaio) and call the specified callback function with the mode name as argument. manage($cmd, %opts) Send a command $cmd to the server, and return the response line from the server. Optional arguments are: quiet_failure => 1 Output a warning if the response indicated an error, unless $opts{quiet_failure} is true, or the command was 'shutdown' (which doesn't return a response). manage_multi($cmd) Send a command $cmd to the server, and return a multi-line response. Return the number zero if there was an error or no response. start_server($conf) Optionally start a perlbal server and return a socket connected to its management port. The argument $conf is a string specifying initial configuration commands. If the environment variable TEST_PERLBAL_FOREGROUND is set to a true value then a server will be started in the foreground, in which case this function does not return. When the server function finishes, exit() will be called to terminate the process. If the environment variable TEST_PERLBAL_USE_EXISTING is set to a true value then a socket will be returned which is connected to an existing server's management port. Otherwise, a child process is forked and a socket is returned which is connected to the child's management port. The management port is assigned automatically, a new port number each time this function is called. The starting port number is 60000. msock() Return a reference to the socket connected to the server's management port. ua() Return a new instance of LWP::UserAgent. wait_on_child($pid, $port) Return a socket which is connected to a child process. $pid specifies the child process id, and $port is the port number on which the child is listening. Several attempts are made; if the child dies or a connection cannot be made within 5 seconds then this function dies with an error message. resp_from_sock($sock) Read an HTTP response from a socket and return it as an HTTP::Response object In scalar mode, return only the $http_response object. In array mode, return an array of ($http_response, $firstline) where $firstline is the first line read from the socket, for example: "HTTP/1.1 200 OK" perl v5.14.2 2012-02-06 Perlbal::Test(3pm)

Check Out this Related Man Page

Perlbal::Plugin::Cgilike(3pm)				User Contributed Perl Documentation			     Perlbal::Plugin::Cgilike(3pm)

NAME
Perlbal::Plugin::Cgilike - Handle Perlbal requests with a Perl subroutine DESCRIPTION
This module allows responses to be handled with a simple API that's similar in principle to CGI, mod_perl response handlers, etc. It does not, however, come anywhere close to conforming to the CGI "standard". 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. As it currently stands, this is very bare-bones and has only really been used with basic GET requests. It lacks a nice API for handling the body of a POST or PUT request. 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 HTTP service into another application that uses "Danga::Socket". SYNOPSIS
This module provides a Perlbal plugin which can be loaded and used as follows. 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 With this plugin loaded into a particular service, the plugin will then be called for all requests for that service. 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. package MyPackage sub handler { my ($r) = @_; if ($r->uri eq '/') { print "<p>Hello, world</p>"; return Perlbal::Plugin::Cgilike::HANDLED; } else { return 404; } } Return "Perlbal::Plugin::Cgilike::HANDLED" to indicate that the request has been handled, or return some HTTP error code to produce a predefined error message. You may also return "Perlbal::Plugin::Cgilike::DECLINED" 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. If your handler returns any non-success value, it MUST NOT produce any output. If you produce output before returning such a value, the response to the client is likely to be utter nonsense. You may also return "Perlbal::Plugin::Cgilike::POSTPONE_RESPONSE", which is equivalent to returning zero except that the HTTP connection will be left open once you return. It is your responsibility to later call "$r->end_response()" 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 "end_response", you must not call any further methods on $r; it's probably safest to just return immediately afterwards to avoid any mishaps. API DOCUMENTATION
TODO: Write this TODO
Currently there is no API for dealing with the body of a POST or PUT request. Ideally it'd be able to do automatic decoding of application/x-www-form-urlencoded data, too. The POSTPONE_RESPONSE functionality has not been tested extensively and is probably buggy. COPYRIGHT AND LICENSE
Copyright 2007 Martin Atkins <mart@degeneration.co.uk> and Six Apart Ltd. This module is part of the Perlbal distribution, and as such can be distributed under the same licence terms as the rest of Perlbal. perl v5.14.2 2010-12-20 Perlbal::Plugin::Cgilike(3pm)
Man Page