move plp server handlers to respective modules
[perl/plp/.git] / PLP / Apache.pm
1 package PLP::Apache;
2
3 use strict;
4
5 our $VERSION = '1.00';
6
7 use PLP;
8 require Apache::Constants;
9
10 # mod_perl initializer: returns 0 on success, Apache error code on failure
11 sub init {
12         our $r = shift;
13
14         $PLP::print = 'PLP::Apache::print';
15         
16         $ENV{PLP_FILENAME} = my $filename = $r->filename;
17         
18         unless (-f $filename) {
19                 return Apache::Constants::NOT_FOUND();
20         }
21         unless (-r _) {
22                 return Apache::Constants::FORBIDDEN();
23         }
24         
25         $ENV{PLP_NAME} = $r->uri;
26
27         our $use_cache = $r->dir_config('PLPcache') !~ /^off$/i;
28 #S      our $use_safe  = $r->dir_config('PLPsafe')  =~ /^on$/i;
29         my $path = $r->filename();
30         my ($file, $dir) = File::Basename::fileparse($path);
31         chdir $dir;
32
33         $PLP::code = PLP::source($file, 0, undef, $path);
34
35         return 0; # OK
36 }
37
38 # FAST printing under mod_perl
39 sub print {
40         return unless grep length, @_;
41         PLP::sendheaders() unless $PLP::sentheaders;
42         $PLP::Apache::r->print(@_);
43 }
44
45 # This is the mod_perl handler.
46 sub handler {
47         PLP::clean();
48         if (my $ret = init($_[0])) {
49                 return $ret;
50         }
51         #S PLP::start($_[0]);
52         PLP::start();
53         no strict 'subs';
54         return Apache::Constants::OK();
55 }
56
57 1;
58