1 package PLP::Backend::CGI;
10 # CGI initializer: opens SCRIPT_FILENAME
12 $PLP::print = 'print';
15 if (defined $ENV{PATH_TRANSLATED}) {
16 # SCRIPT_* points to handler script (Apache CGI)
17 # Run backwards through PATH_TRANSLATED to find target filename,
18 # then get file (relative) by stripping PATH_INFO.
19 my ($path, $rel) = (delete $ENV{PATH_TRANSLATED}, delete $ENV{PATH_INFO});
21 while (not -f $path) {
22 if (not $path =~ s/(\/+[^\/]*)$//) {
23 printf STDERR "PLP: Not found: $path$path_info ($ENV{REQUEST_URI})\n";
24 PLP::error(undef, 404);
27 # move last path element onto PATH_INFO
28 $path_info = $1 . $path_info;
30 if (defined $path_info) {
31 $rel =~ s/\Q$path_info\E$//;
32 $ENV{PATH_INFO} = $path_info;
34 $ENV{SCRIPT_FILENAME} = $path;
35 $ENV{SCRIPT_NAME} = $rel;
37 elsif (not -f $ENV{SCRIPT_FILENAME}) {
38 print STDERR "PLP: Not found: $ENV{SCRIPT_FILENAME} ($ENV{REQUEST_URI})\n";
39 PLP::error(undef, 404);
43 $ENV{"PLP_$_"} = $ENV{"SCRIPT_$_"} for qw/NAME FILENAME/;
45 if (not -r $ENV{PLP_FILENAME}) {
46 print STDERR "PLP: Can't read: $ENV{PLP_FILENAME} ($ENV{REQUEST_URI})\n";
47 PLP::error(undef, 403);
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 Add this to your configuration file (usually F</etc/lighttpd/lighttpd.conf>):
99 server.modules += ("mod_cgi")
100 cgi.assign += (".plp" => "/foo/bar/plp.cgi")
101 server.indexfiles += ("index.plp")
102 static-file.exclude-extensions += (".plp")
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>