Skip to content
A SCGI library for Perl 6
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


SCGI for Perl 6

This is a simple SCGI library for Perl 6.

It's main influences are the Perl 5 SCGI library, and the
Perl 6 HTTP::Daemon library.

It offers a bit of candy coating compared to the Perl 5 version.

The environment contains three special keys:

  Request.Body is the request body (usually from an HTTP POST.)
  Request.Object is a reference to the individual request object.
  Request.SCGI is a reference to the SCGI object itself.

Also, you don't need to create your own IO::Socket::INET object.
Just pass an 'addr' and 'port' attribute to the new() declaration and it'll
create the object for you.

Oh yeah, and instead of using the while loop as shown on the Perl 5 SCGI
documentation, there is a convenience method called 'handle' that does
the heavy lifting for you:

  use SCGI;

  my $scgi = :addr<localhost> :port(8080) );

  my $handler = sub (%env) {
    my $name = %env<QUERY_STRING> // 'world';
    my $response = "Content-Type: text/plain\n\n";
    $response ~= "Hello $name\n";
    return $return;

  $scgi.handle: $handler;

The output of the handler will be sent as the SCGI response, 
so make it a valid CGI response.

** Apache configuration with mod_scgi:

Add the following line to your site config, changing the details to match your
SCGI script configuration:

  SCGIMount /scgi/

Then add the following lines either after the above statement, or in an
.htaccess file in your website root:

  RewriteEngine On

  ## Add additional rules before the following!
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ /scgi/$1 [QSA,L,PT]

That's it. Now any path that doesn't match an existing file in your
web root, will be redirected to your SCGI script.

Similar tricks are available for other web servers, but I haven't tested
them, so have not documented them. A quick Google search for SCGI should
turn up a multitude of howto documents.

Author: Timothy Totten (supernovus) <>

Released under the Artisitc License 2.0

Something went wrong with that request. Please try again.