Plack::App::CGIBin(3)

πŸ’– Plack::App::CGIBin(3) β€” the cgi-bin glow-up πŸ’–

okay so bestie, this is the perl doc for Plack::App::CGIBin β€” yes, the whole manual page, and yes, we're doing this together. grab a boba. πŸ§‹


✨ NAME ✨

Plack::App::CGIBin β€” it's literally a cgi-bin replacement for Plack servers. she serves the same energy but cuter. πŸŽ€


🌸 SYNOPSIS 🌸

the way you just drop her in:

use Plack::App::CGIBin;
use Plack::Builder;

my $app = Plack::App::CGIBin->new(root => "/path/to/cgi-bin")->to_app;
builder {
    mount "/cgi-bin" => $app;
};

# Or from the command line
plackup -MPlack::App::CGIBin -e 'Plack::App::CGIBin->new(root => "/path/to/cgi-bin")->to_app'

like. it's giving effortless. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so Plack::App::CGIBin lets you load CGI scripts out of a directory and convert them into a PSGI application. iconic behaviour honestly.

and the reason you'd want this? extreme easiness πŸ’… β€” when you have a whole bunch of old CGI scripts that used to be loaded through the cgi-bin of an Apache web server, this is your girl. no cap.


πŸ”₯ HOW IT WORKS πŸ”₯

story time. this application checks whether a given file path is a perl script, and if it is, it uses CGI::Compile to compile that CGI script into a sub (like ModPerl::Registry does) and then runs it as a persistent application using CGI::Emulate::PSGI. queen shit. πŸ‘‘

if the given file is not a perl script, she executes the script just like a normal CGI script with fork & exec. this is like a normal web server mode and no performance benefit is achieved β€” so like, don't expect the glow-up there, bestie. 😭

the default mechanism to figure out if a given file is a Perl script goes like this:

  • Check if the filename ends with .pl. If yes, it is a Perl script.
  • Open the file and see if the shebang (first line of the file) contains the word perl (like #!/usr/bin/perl). If yes, it is a Perl script.

you can customize this behavior by passing the exec_cb callback β€” it takes a file path as its first argument. 🫢

for example, if your perl-based CGI script uses lots of global variables and such and is not ready to run in a persistent environment, you can do:

my $app = Plack::App::CGIBin->new(
    root => "/path/to/cgi-bin",
    exec_cb => sub { 1 },
)->to_app;

to always force the execute option for any files. boom. πŸ“


πŸ‘‘ AUTHOR πŸ‘‘

Tatsuhiko Miyagawa β€” the main character fr fr.


🌈 SEE ALSO 🌈

  • Plack::App::File
  • CGI::Emulate::PSGI
  • CGI::Compile
  • Plack::App::WrapCGI

also see Plack::App::WrapCGI if you compile one CGI script into a PSGI application without serving CGI scripts from a directory β€” that way you can remove overhead of filesystem lookups, etc. iykyk ⭐


lowkey reminder: this page lives in the perl docs, perl v5.42.3, dated 2026-10-18, and it's Plack::App::CGIBin(3). that's the whole vibe. slay, go mount your cgi-bin, periodt. πŸ’–βœ¨πŸ¦‹
πŸ“¦ where this page comes from