217546fbe1abae70c64e711694d7722fc4aa97ce
[perl/plp/.git] / PLP / Apache.pm
1 package PLP::Apache;
2
3 use strict;
4
5 our $VERSION = '1.00';
6
7 # mod_perl initializer: returns 0 on success, Apache error code on failure
8 sub init {
9         our $r = shift;
10
11         $PLP::print = 'PLP::Apache::print';
12         
13         $ENV{PLP_FILENAME} = my $filename = $r->filename;
14         
15         unless (-f $filename) {
16                 return Apache::Constants::NOT_FOUND();
17         }
18         unless (-r _) {
19                 return Apache::Constants::FORBIDDEN();
20         }
21         
22         $ENV{PLP_NAME} = $r->uri;
23
24         our $use_cache = $r->dir_config('PLPcache') !~ /^off$/i;
25 #S      our $use_safe  = $r->dir_config('PLPsafe')  =~ /^on$/i;
26         my $path = $r->filename();
27         my ($file, $dir) = File::Basename::fileparse($path);
28         chdir $dir;
29
30         $PLP::code = PLP::source($file, 0, undef, $path);
31
32         return 0; # OK
33 }
34
35 # FAST printing under mod_perl
36 sub print {
37         return unless grep length, @_;
38         PLP::sendheaders() unless $PLP::sentheaders;
39         $PLP::Apache::r->print(@_);
40 }
41
42 1;
43