CGI::Parse::PSGI(3pm)

✨ NAME ✨

CGI::Parse::PSGI β€” bestie, this thing parses CGI output and creates a PSGI response out of it πŸ’– like it literally takes the messy lil text blob your CGI script spat out and turns it into a whole PSGI glow-up.


🌸 DESCRIPTION 🌸

okay so first things first, here's the vibe:

use CGI::Parse::PSGI qw(parse_cgi_output);

my $output = YourApp->run;
my $psgi_res = parse_cgi_output(\$output);

see? you run your app, you get $output, you hand it over, and boom πŸ’… you get a PSGI response back.

and guess what, you can also pass an option hash if you're feeling fancy:

my $psgi_res = parse_cgi_output(\$output, \%options);

iconic. moving on πŸ¦‹


⭐ SYNOPSIS ⭐

CGI::Parse::PSGI exports exactly one function, parse_cgi_output, and she's the main character πŸ‘‘. She takes a filehandle or a reference to a string, reads a CGI script output from it, and creates a PSGI response (that's an array reference containing the status code, the headers, and a body, no cap) by reading the output.

now, if what you've got is actual CGI code and not the output, then bestie you want CGI::Emulate::PSGI instead β€” that one takes care of automatically parsing the output, using this module, straight from your callback code. teamwork makes the dream work fr fr 🫢


πŸŽ€ OPTIONS πŸŽ€

like we said up there, parse_cgi_output can accept an options hash as the second argument. here's what's on the menu rn:

  • ignore_status_line β€” a boolean value, defaulting to 0 (false). if it's true, then the status in the HTTP protocol line is not used to set the default status when there's no status header present. lowkey niche but highkey useful, iykyk.

and here's the cute part: you can supply these options to earlier versions too, and they'll just be ignored without error. no drama, no crash, just vibes. so you can preserve legacy behaviour like this:

parse_cgi_output(\$output, {ignore_status_line => 1});

this will ensure that if the script output includes an edge case like this:

HTTP/1.1 666 SNAFU
Content-Type: text/plain

This should be OK!

then the old behaviour of ignoring the status line and returning 200 is preserved ✨ periodt. no 666 jumpscare for you, bestie.


πŸ’œ AUTHOR πŸ’œ

Tatsuhiko Miyagawa β€” the icon, the legend 🫑


🌈 SEE ALSO 🌈

  • CGI::Emulate::PSGI

and that's the whole page, babe πŸ’– this manual came from perl v5.34.0, dated 2022-06-09, and it's the CGI::Parse::PSGI(3pm) page from your friendly neighbourhood User Contributed Perl Documentation. go parse something cute βœ¨πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from