seperate modules for backend-specific code
[perl/plp/.git] / PLP / Apache.pm
diff --git a/PLP/Apache.pm b/PLP/Apache.pm
new file mode 100644 (file)
index 0000000..217546f
--- /dev/null
@@ -0,0 +1,43 @@
+package PLP::Apache;
+
+use strict;
+
+our $VERSION = '1.00';
+
+# mod_perl initializer: returns 0 on success, Apache error code on failure
+sub init {
+       our $r = shift;
+
+       $PLP::print = 'PLP::Apache::print';
+       
+       $ENV{PLP_FILENAME} = my $filename = $r->filename;
+       
+       unless (-f $filename) {
+               return Apache::Constants::NOT_FOUND();
+       }
+       unless (-r _) {
+               return Apache::Constants::FORBIDDEN();
+       }
+       
+       $ENV{PLP_NAME} = $r->uri;
+
+       our $use_cache = $r->dir_config('PLPcache') !~ /^off$/i;
+#S     our $use_safe  = $r->dir_config('PLPsafe')  =~ /^on$/i;
+       my $path = $r->filename();
+       my ($file, $dir) = File::Basename::fileparse($path);
+       chdir $dir;
+
+       $PLP::code = PLP::source($file, 0, undef, $path);
+
+       return 0; # OK
+}
+
+# FAST printing under mod_perl
+sub print {
+       return unless grep length, @_;
+       PLP::sendheaders() unless $PLP::sentheaders;
+       $PLP::Apache::r->print(@_);
+}
+
+1;
+