Plack:...:Agent(3pm)
π Plack::Test::Agent β the manual, but make it cute
okay bestie, welcome to the Plack:...:Agent(3pm) page, aka the docs for Plack::Test::Agent β¨ it's the OO interface for testing low-level Plack/PSGI apps, and yes you're literally about to be obsessed π
β¨ NAME β¨
Plack::Test::Agent β an OO interface for testing low-level Plack/PSGI apps π§
β¨ VERSION β¨
version 1.6 π
β¨ SYNOPSIS β¨
no cap, this is the whole vibe:
use Test::More;
use Plack::Test::Agent;
my $app = sub { ... };
my $local_agent = Plack::Test::Agent->new( app => $app );
my $server_agent = Plack::Test::Agent->new(
app => $app,
server => 'HTTP::Server::Simple' );
my $local_res = $local_agent->get( '/' );
my $server_res = $server_agent->get( '/' );
ok $local_res->is_success, 'local GET / should succeed';
ok $server_res->is_success, 'server GET / should succeed';
like, you got a local one and a server one, and both of them are serving π
β¨ DESCRIPTION β¨
Plack::Test::Agent is an OO interface to test PSGI applications π¦ she can perform GET, POST, PUT and DELETE requests against your PSGI apps β either in process (nice and cozy, no network drama) or over HTTP through a Plack::Handler compatible backend πΈ
it's giving "I test everything, I fear nothing" π
β¨ CONSTRUCTION β¨
new π
The new constructor creates an instance of Plack::Test::Agent. She takes one mandatory named argument and several optional ones, and honestly? iconic. Here's the whole lineup:
appβ this one's the mandatory argument, no exceptions bestie π€ you must provide a PSGI application to test.serverβ optional! when you provide it,Plack::Test::Agentwill attempt to start a PSGI handler and will communicate via HTTP to the application running through that handler π for the deets on picking the right server, go peep Plack::Loader.hostβ optional, it's the name or IP address for the server to use. default islocalhostπportβ optional, the TCP port for the server to use. if you don't provide one, the service will run on a randomly selected available port outside of the IANA reserved range π² (see Test::TCP for how that port number gets picked, iykyk).uaβ optional, and it has to be something that conforms to the LWP::UserAgent interface, meaning it provides arequestmethod that takes an HTTP::Request object and returns an HTTP::Response object π the default is an instance ofLWP::UserAgent.jarβ optional, an HTTP::Cookies instance to be used as the cookie jar for requests πͺ by default a plain one gets created for you. cookies stay warm, periodt.
β¨ METHODS β¨
This class provides several useful methods and honestly each one ate π₯
get π«Ά
This method takes a URI and makes a GET request against the PSGI application with that URI. It returns an HTTP::Response object representing the results of that request π
post π
This method takes a URI and makes a POST request against the PSGI application with that URI. It returns an HTTP::Response object representing the results of that request. As an optional second parameter, pass an array reference of key/value pairs for the form content:
$agent->post( '/edit_user',
[
shoe_size => '10.5',
eye_color => 'blue green',
status => 'twin',
]);
look at those form values, very main character π¦
put β¨
This method takes a URI and makes a PUT request against the PSGI application with that URI. It returns an HTTP::Response object representing the results of that request. As an optional second parameter, pass an array reference of key/value pairs for the form content:
$agent->put( '/edit_user',
[
shoe_size => '10.5',
eye_color => 'blue green',
status => 'twin',
]);
same energy, different HTTP verb, slay π
delete ποΈ
This method takes a URI and makes a DELETE request against the PSGI application with that URI. It returns an HTTP::Response object representing the results of that request. (no build-a-form moment here, just vibes.)
execute_request β‘
This method takes an HTTP::Request, performs it against the bound app, and returns an HTTP::Response π― this is the one where you get to craft your own requests directly, like a lil artisan. obsessed.
get_mech πΉοΈ
Used internally to create a default UserAgent, if none is provided to the constructor. Returns a Test::WWW::Mechanize::Bound object. She's the backup plan and she showed up ready π
normalize_uri π§Ή
Used internally to ensure that all requests use the correct scheme, host and port. The scheme and host default to http and localhost respectively, while the port is determined by Test::TCP. everything gets tidied, no chaos allowed β¨
start_server π
Starts a test server via Test::TCP. If a server arg has been provided to the constructor, it will use this class to load a server. Defaults to letting Plack::Loader decide which server class to use. let the loader choose, she knows what's up π
β¨ CREDITS β¨
Thanks to Zbigniew Εukasiak and Tatsuhiko Miyagawa for suggestions π«Ά absolute legends for that.
β¨ AUTHORS β¨
- chromatic
<chromatic@wgz.org> - Dave Rolsky
<autarch@urth.org> - Ran Eilam
<ran.eilam@gmail.com> - Olaf Alders
<olaf@wundercounter.com>
β¨ CONTRIBUTORS β¨
- Andy Beverley
<andy@andybev.com> - Dave Rolsky
<drolsky@maxmind.com> - Olaf Alders
<oalders@maxmind.com> - Ran Eilam
<reilam@maxmind.com> - Syohei YOSHIDA
<syohex@gmail.com> - Torsten Raudssus
<torsten@raudss.us>
β¨ COPYRIGHT AND LICENSE β¨
This software is copyright (c) 2011 by chromatic. π
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself πΈ (yes bestie, free as in do-what-you-want-within-those-terms, we love a permissive queen.)
ok that's the whole page, no skips, no cuts π everything's in there exactly as written, we just gave it the glow-up it deserved β¨
and for the cute sign-off: this lil rendering came from perl v5.40.1, dated 2025-10-07, and it's the Plack:...:Agent(3pm) manual page β User Contributed Perl Documentation energy all the way π byeeee π π
π¦ where this page comes from
- ubuntu resolute: libplack-test-agent-perl 1.6-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libplack-test-agent-perl 1.6-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms