package Squatting::On::MP13;
use strict;
use warnings;
use Apache;
use Apache::Log;
use CGI::Cookie;
use Apache::Constants ':common';
use Squatting::H;
# adapt Apache::Log's interface to Squatting::Log's interface
our $log = Squatting::H->new({
_log => undef,
debug => sub {
my ($self, @messages) = @_;
$self->_log->debug(@messages);
},
info => sub {
my ($self, @messages) = @_;
$self->_log->info(@messages);
},
warn => sub {
my ($self, @messages) = @_;
$self->_log->warn(@messages);
},
error => sub {
my ($self, @messages) = @_;
$self->_log->error(@messages);
},
fatal => sub {
my ($self, @messages) = @_;
$self->_log->emerg(@messages);
},
});
# p for private
my %p;
$p{init_cc} = sub {
my ($c, $r) = @_;
my $cc = $c->clone;
$cc->env = { %ENV };
$cc->cookies = $p{c}->($ENV{HTTP_COOKIE});
$cc->input = { $r->args };
$cc->headers = { 'Content-Type' => 'text/html' };
$cc->v = { };
$cc->status = 200;
$cc->log = $log;
$log->_log($r->log);
$cc;
};
# \%cookies = $p{c}->($cookie_header) # Parse Cookie header(s).
$p{c} = sub {
+{ map { ref($_) ? $_->value : $_ } CGI::Cookie->parse($_[0]) };
};
sub mp13($$) {
no strict 'refs';
my ($app, $r) = @_;
my ($c, $p) = &{ $app . "::D" }($r->uri);
my $cc = $p{init_cc}->($c, $r);
my $content = $app->service($cc, @$p);
while (my($header, $value) = each(%{$cc->headers})) {
$r->header_out($header, $value);
}
$r->status($cc->status);
$r->print($content);
OK;
}
sub init {
no strict 'refs';
no warnings 'redefine';
my ($app) = @_;
*{ $app . "::handler" } = sub {
my ($r) = @_;
$app->mp13($r);
};
$app->next::method;
}
1;
__END__
=head1 NAME
Squatting::On::MP13 - a handler for Apache 1.3's mod_perl
=head1 SYNOPSIS
First, load the App + Squatting::On::MP13:
use App 'On::MP13';
App->init;
Then, setup a handler in your Apache config:
SetHandler perl-script
PerlHandler App
Alternatively, if your mod_perl has L
support, you can say:
SetHandler perl-script
PerlHandler App->mp13
VirtualHost configuration using L as an example:
ServerName podserver.mydomain.org
DocumentRoot /www/podserver.mydomain.org
ErrorLog logs/podserver.mydomain.org-error_log
CustomLog logs/podserver.mydomain.org-access_log common
use Pod::Server 'On::MP13';
Pod::Server->init;
SetHandler perl-script
PerlHandler Pod::Server
=head1 DESCRIPTION
The purpose of this module is to add an C method to your app that can be
used as a mod_perl method handler. It also adds a conventional mod_perl handler
so that Squatting apps can be deployed on mod_perl installations that don't
have method handler support built in. To use this module, pass the string
C<'On::MP13'> to the C