move detailed setup documentation to interface modules
[perl/plp/.git] / PLP / CGI.pm
index 9b72355c55eafd1050d20a7ae4fab305a2814fbe..698c34b1120d531e7dd1cbeb9e9c45e87a2f7933 100644 (file)
@@ -2,13 +2,14 @@ package PLP::CGI;
 
 use strict;
 
-our $VERSION = '1.01';
+our $VERSION = '1.02';
 
 use PLP;
 
 # CGI initializer: opens SCRIPT_FILENAME
 sub init {
        $PLP::print = 'print';
+       $PLP::read = \&read;
 
        if (defined $ENV{PATH_TRANSLATED}) {
                # SCRIPT_* points to handler script (Apache CGI)
@@ -20,7 +21,7 @@ sub init {
                        if (not $path =~ s/(\/+[^\/]*)$//) {
                                printf STDERR "PLP: Not found: $path$path_info ($ENV{REQUEST_URI})\n";
                                PLP::error(undef, 404);
-                               exit;
+                               return;
                        }
                        # move last path element onto PATH_INFO
                        $path_info = $1 . $path_info;
@@ -43,7 +44,7 @@ sub init {
        if (not -r $ENV{PLP_FILENAME}) {
                print STDERR "PLP: Can't read: $ENV{PLP_FILENAME} ($ENV{REQUEST_URI})\n";
                PLP::error(undef, 403);
-               exit;
+               return;
        }
 
        delete @ENV{
@@ -55,14 +56,71 @@ sub init {
        chdir $dir;
 
        $PLP::code = PLP::source($file, 0, undef, $ENV{PLP_FILENAME});
+       return 1;
+}
+
+sub read ($) {
+       my ($bytes) = @_;
+       read *STDIN, my $data, $bytes;
+       return $data;
 }
 
-# This is run by the CGI script. (#!perl \n use PLP::CGI; PLP::CGI::everything;)
 sub everything {
        PLP::clean();
-       init();
-       PLP::start();
+       $_[0]->init() and PLP::start();
+}
+
+# This is run by the CGI script. (#!perl \n use PLP::CGI;)
+sub import {
+       $_[0]->everything();
 }
 
 1;
 
+=head1 NAME
+
+PLP::CGI - CGI interface for PLP
+
+=head1 SYNOPSIS
+
+For most servers you'll need a script executable.
+Example F</foo/bar/plp.cgi>:
+
+    #!/usr/bin/perl
+    use PLP::CGI;
+
+Or install the C<plp.cgi> included with PLP.
+
+=head2 Lighttpd
+
+Usually in F</etc/lighttpd/lighttpd.conf>:
+enable I<mod_cgi> (add/outcomment in server.modules), and add:
+
+    cgi.assign = (
+        ".plp" => "/foo/bar/plp.cgi",
+    )
+
+=head2 Apache
+
+Enable I<mod_actions> and setup F<httpd.conf>
+(often just create a F</etc/apache2/conf.d/plp>) with:
+
+    <IfModule mod_actions.c>
+        ScriptAlias /PLP_COMMON/ /foo/bar/
+        <Directory /foo/bar/>
+            Options +ExecCGI
+            Order allow,deny
+            Allow from all
+        </Directory>
+        AddHandler plp-document plp
+        Action plp-document /PLP_COMMON/plp.cgi
+    </IfModule>
+
+=head1 AUTHOR
+
+Mischa POSLAWSKY <perl@shiar.org>
+
+=head1 SEE ALSO
+
+L<PLP|PLP>, L<PLP::FastCGI|PLP::FastCGI>
+