Perlbal::Test(3pm)
π Perlbal::Test π
okay bestie, so this is the Perlbal::Test page from the User Contributed Perl Documentation β it's a whole test harness for a perlbal server, and honestly? she's giving "quietly holding the entire test suite together" energy. π«Ά
β¨ NAME β¨
Perlbal::Test β the test harness for the perlbal server, no cap. π
πΈ SYNOPSIS πΈ
# my $msock = Perlbal::Test::start_server();
that's it, that's the whole vibe. one line and you're in. π
π¦ DESCRIPTION π¦
Perlbal::Test gives you access to a perlbal server running on the local host, purely for testing purposes. it's not here to serve your production traffic, she's here to be poked at. π§
the server can be one of three things, and honestly the range:
- an already-existing server
- a child process
- the current process
and then there's a whole lil' friend group of functions provided to interact with the server. let's meet them. π
π FUNCTIONS π
π mgmt_port()
return the current management port number. that's it. that's the function. short queen. β¨
π dump_res($http_response)
return a readable string, formatted from an HTTP::Response object.
heads up tho β only the first 80 characters of returned content are returned. so like, don't expect the whole novel, you're getting the preview. π
π tempdir()
return a newly created temporary directory.
and the best part? the directory gets removed automatically upon program exit. self-cleaning, we love a low-maintenance icon. π§Ήβ¨
π¦ new_port()
return the next free port number in the series.
port numbers are assigned starting at 60000. remember that number, she comes back later. π
β test_port()
return 1 if the port is free to use for listening on $free_port, else return 0.
vibe check for ports, fr fr. π©Ί
π filecontent($file>
return a string containing the contents of the file $file.
if $file cannot be opened, then return undef. no file, no content, no drama. π
πΈ foreach_aio($callback)
set the server into each AIO mode β that's none and ioaio β and call the specified callback function with the mode name as argument.
so your callback gets told which mode it's in. considerate. π
π₯ manage($cmd, %opts)
send a command $cmd to the server, and return the response line from the server.
the 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). yeah, shutdown just ghosts you, it's not gonna reply. π
π 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. zero means bad vibes here, don't @ me. π€
π§ 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.
now here's where it branches, bestie, pay attention:
- if the environment variable
TEST_PERLBAL_FOREGROUNDis 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. so like, you're committing to the bit. π - if the environment variable
TEST_PERLBAL_USE_EXISTINGis set to a true value, then a socket will be returned which is connected to an existing server's management port. reusing, recycling, sustainable queen. β»οΈ - otherwise, a child process is forked and a socket is returned which is connected to the child's management port. the classic route. π£
the management port is assigned automatically, and it's a new port number each time this function is called. the starting port number is 60000. told you she'd come back. π
π«Ά msock()
return a reference to the socket connected to the server's management port. the main character socket, literally. β¨
π ua()
return a new instance of LWP::UserAgent. fresh user agent, fresh start, new me energy. π¦
π wait_on_child($pid, $port)
return a socket which is connected to a child process.
$pidspecifies the child process id$portis the port number on which the child is listening
several attempts are made β so she's patient, she tries again β but if the child dies or a connection cannot be made within 5 seconds, then this function dies with an error message. five seconds, then it's over. β°π
β resp_from_sock($sock)
read an HTTP response from a socket and return it as an HTTP::Response object.
two modes, pick your fighter:
- in scalar mode, return only the
$http_responseobject. - in array mode, return an array of
($http_response, $firstline)where$firstlineis the first line read from the socket, for example:
HTTP/1.1 200 OK
look at her. iconic. π
friendly reminder bestie: this whole thing is for testing purposes β please don't build your empire on it, that's not what she's for. π«Ά
and that's the page!! perl v5.34.0, dated 2022-06-28 β yeah she's been around a minute and she's still slaying. thanks for coming to my ted talk, mwah, bye bestie ππ β¨
π¦ where this page comes from
- debian bookworm: libperlbal-perl 1.80-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libperlbal-perl 1.80-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libperlbal-perl 1.80-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libperlbal-perl 1.80-4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms