1 package PLP::Backend::CGI;
9 # CGI initializer: opens SCRIPT_FILENAME
11 $PLP::print = 'print';
14 if (defined $ENV{PATH_TRANSLATED}) {
15 # SCRIPT_* points to handler script (Apache CGI)
16 # Run backwards through PATH_TRANSLATED to find target filename,
17 # then get file (relative) by stripping PATH_INFO.
18 my ($path, $rel) = (delete $ENV{PATH_TRANSLATED}, delete $ENV{PATH_INFO});
20 while (not -f $path) {
21 if (not $path =~ s/(\/+[^\/]*)$//) {
22 printf STDERR "PLP: Not found: $path$path_info ($ENV{REQUEST_URI})\n";
23 PLP::error(undef, 404);
26 # move last path element onto PATH_INFO
27 $path_info = $1 . $path_info;
29 if (defined $path_info) {
30 $rel =~ s/\Q$path_info\E$//;
31 $ENV{PATH_INFO} = $path_info;
33 $ENV{SCRIPT_FILENAME} = $path;
34 $ENV{SCRIPT_NAME} = $rel;
36 elsif (not -f $ENV{SCRIPT_FILENAME}) {
37 print STDERR "PLP: Not found: $ENV{SCRIPT_FILENAME} ($ENV{REQUEST_URI})\n";
38 PLP::error(undef, 404);
42 $ENV{"PLP_$_"} = $ENV{"SCRIPT_$_"} for qw/NAME FILENAME/;
44 if (not -r $ENV{PLP_FILENAME}) {
45 print STDERR "PLP: Can't read: $ENV{PLP_FILENAME} ($ENV{REQUEST_URI})\n";
46 PLP::error(undef, 403);
51 qw(SCRIPT_NAME SCRIPT_FILENAME),
52 grep /^REDIRECT_/, keys %ENV
55 my ($file, $dir) = File::Basename::fileparse($ENV{PLP_FILENAME});
58 $PLP::code = PLP::source($file, 0, undef, $ENV{PLP_FILENAME});
64 read *STDIN, my ($data), $bytes;
70 $_[0]->init() and PLP::start();
73 # This is run by the CGI script. (#!perl \n use PLP::Backend::CGI;)
75 $PLP::interface = $_[0];
83 PLP::Backend::CGI - CGI interface for PLP
87 For most servers you'll need a script executable.
88 Example F</foo/bar/plp.cgi>:
91 use PLP::Backend::CGI;
93 Or install the C<plp.cgi> included with PLP.
97 Usually in F</etc/lighttpd/lighttpd.conf>:
98 enable I<mod_cgi> (add/outcomment in server.modules), and add:
101 ".plp" => "/foo/bar/plp.cgi",
106 Enable I<mod_actions> and
107 setup F<httpd.conf> (in new installs just create F</etc/apache/conf.d/plp>) with:
109 <IfModule mod_actions.c>
110 ScriptAlias /PLP_COMMON/ /foo/bar/
111 <Directory /foo/bar/>
116 AddHandler plp-document plp
117 Action plp-document /PLP_COMMON/plp.cgi
122 Mischa POSLAWSKY <perl@shiar.org>
126 L<PLP>, L<PLP::Backend::FastCGI>