Plack::Response(3)
π Plack::Response π
okay bestie, so this is the manual page for Plack::Response β like, the portable HTTP Response object for PSGI response one, from the User Contributed Perl Documentation corner of the world. sit down, grab a strawberry, we're doing this πβ¨
β¨ NAME β¨
Plack::Response β Portable HTTP Response object for PSGI response. that's it, that's the whole vibe. π
π SYNOPSIS π
here's the little glow-up in action, no cap:
use Plack::Response;
sub psgi_handler {
my $env = shift;
my $res = Plack::Response->new(200);
$res->content_type('text/html');
$res->body("Hello World");
return $res->finalize;
}
likeβ¦ look at her. she's serving. π
π¦ DESCRIPTION π¦
so Plack::Response gives you a way to build a PSGI response array ref through a simple API. that's literally the whole deal. no drama, no cryptic nonsense, just vibes and a response ref. β¨
π METHODS π
π« new
$res = Plack::Response->new;
$res = Plack::Response->new($status);
$res = Plack::Response->new($status, $headers);
$res = Plack::Response->new($status, $headers, $body);
Creates a new Plack::Response object. it's giving main character energy, it's giving birth of a response. π«Ά you can hand her nothing, or a status, or a status plus headers, or a status plus headers plus body β she's flexible like that. πΈ
π« status
$res->status(200);
$status = $res->status;
Sets and gets the HTTP status code. code is an alias, so if you're feeling quirky you can call her that instead. iykyk. π
π« headers
$headers = $res->headers;
$res->headers([ 'Content-Type' => 'text/html' ]);
$res->headers({ 'Content-Type' => 'text/html' });
$res->headers( HTTP::Headers::Fast->new );
Sets and gets the HTTP headers of the response. the setter can take either an array ref, a hash ref, or an HTTP::Headers::Fast object containing a list of headers. three options, all iconic, pick your fighter. π§
π« body
$res->body($body_str);
$res->body([ "Hello", "World" ]);
$res->body($io);
Gets and sets the HTTP response body. the setter can take either a string, an array ref, or an IO::Handle-like object. content is an alias, mwah. π
β οΈ okay so this is important, bestie: this method does not automatically setContent-Lengthfor the response. you have to set it manually if you want to, with thecontent_lengthmethod (see below). she's not gonna do it for you, that's a you job. π
π« header
$res->header('X-Foo' => 'bar');
my $val = $res->header('X-Foo');
Shortcut for $res->headers->header. tiny little convenience, and honestly? we're obsessed. β¨
π« content_type, content_length, content_encoding
$res->content_type('text/plain');
$res->content_length(123);
$res->content_encoding('gzip');
Shortcut for the equivalent get/set methods in $res->headers. three lil besties doing the header work so you don't have to type so much. π
π« redirect
$res->redirect($url);
$res->redirect($url, 301);
Sets the redirect URL with an optional status code, which defaults to 302. bye bye, off you go, we're redirecting. π¦
β οΈ note that this method doesn't normalize the given URI string. users of this module have to be responsible about properly encoding URI paths and parameters. so likeβ¦ that's on you, boo. fr fr. π
π« location
Gets and sets the Location header.
β οΈ note that this method doesn't normalize the given URI string in the setter. see above in redirect for details. same energy, same warning. π
π« cookies
$res->cookies->{foo} = 123;
$res->cookies->{foo} = { value => '123' };
Returns a hash reference containing cookies to be set in the response. the keys of the hash are the cookies' names, and their corresponding values are a plain string (for value with everything else defaults) or a hash reference that can contain keys such as value, domain, expires, path, httponly, secure, max-age. π
expires can take a string or an integer (as an epoch time) and does not convert string formats such as "+3M". she said what she said. πΈ
$res->cookies->{foo} = {
value => 'test',
path => "/",
domain => '.example.com',
expires => time + 24 * 60 * 60,
};
look at that cookie being built. gorgeous. β¨
π« finalize
$res->finalize;
Returns the status code, headers, and body of this response as a PSGI response array reference. this is the moment. the finale. the finale finale. ππ
π« to_app
$app = $res->to_app;
A helper shortcut for sub { $res->finalize }. tiny wrapper, big slay. π
π AUTHOR π
Tokuhiro Matsuno
Tatsuhiko Miyagawa
legends, both of them, no notes. π
π SEE ALSO π
Plack::Requestβ the other half of the duo, go say hi π«Ά
and that's the tea, bestie π this was Plack::Response(3), from perl v5.42.3, dated 2026-10-18, served to you fresh in the User Contributed Perl Documentation section. go build a response, you're gonna eat. periodt. πβ¨π¦
π¦ where this page comes from
- fedora 43: perl-Plack 1.0055-1.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- fedora 44: perl-Plack 1.0055-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms