Fixed MP20 stuff
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / Apache.pm
CommitLineData
fc7ec1d9 1package Catalyst::Engine::Apache;
2
3use strict;
fc7ec1d9 4use base 'Catalyst::Engine';
e7c0c583 5
fc7ec1d9 6use URI;
bc146cf4 7use URI::http;
fc7ec1d9 8
6dc87a0f 9__PACKAGE__->mk_accessors(qw/apache/);
fc7ec1d9 10
11=head1 NAME
12
13Catalyst::Engine::Apache - Catalyst Apache Engine
14
15=head1 SYNOPSIS
16
17See L<Catalyst>.
18
19=head1 DESCRIPTION
20
23f9d934 21This is the Catalyst engine specialized for Apache (i.e. for mod_perl).
fc7ec1d9 22
23f9d934 23=head1 METHODS
fc7ec1d9 24
23f9d934 25=over 4
26
6dc87a0f 27=item $c->apache
fc7ec1d9 28
29Returns an C<Apache::Request> object.
30
23f9d934 31=back
32
33=head1 OVERLOADED METHODS
fc7ec1d9 34
35This class overloads some methods from C<Catalyst::Engine>.
36
23f9d934 37=over 4
38
23f9d934 39=item $c->finalize_output
fc7ec1d9 40
41=cut
42
43sub finalize_output {
44 my $c = shift;
969647fd 45 $c->apache->print( $c->response->output );
fc7ec1d9 46}
47
0556eb49 48=item $c->prepare_connection
49
50=cut
51
52sub prepare_connection {
53 my $c = shift;
6dc87a0f 54 $c->request->hostname( $c->apache->connection->remote_host );
55 $c->request->address( $c->apache->connection->remote_ip );
fc7ec1d9 56}
57
23f9d934 58=item $c->prepare_headers
fc7ec1d9 59
60=cut
61
62sub prepare_headers {
63 my $c = shift;
6dc87a0f 64 $c->request->method( $c->apache->method );
65 $c->request->header( %{ $c->apache->headers_in } );
fc7ec1d9 66}
67
23f9d934 68=item $c->prepare_parameters
fc7ec1d9 69
70=cut
71
72sub prepare_parameters {
73 my $c = shift;
e7c0c583 74
6dc87a0f 75 foreach my $key ( $c->apache->param ) {
76 my @values = $c->apache->param($key);
e7c0c583 77 $c->req->parameters->{$key} = ( @values == 1 ) ? $values[0] : \@values;
fc7ec1d9 78 }
fc7ec1d9 79}
80
23f9d934 81=item $c->prepare_path
fc7ec1d9 82
83=cut
84
13cafd1a 85# XXX needs fixing, only work with <Location> directive,
6dc87a0f 86# not <Directory> directive
fc7ec1d9 87sub prepare_path {
88 my $c = shift;
6dc87a0f 89 $c->request->path( $c->apache->uri );
90 my $loc = $c->apache->location;
fc7ec1d9 91 no warnings 'uninitialized';
92 $c->req->{path} =~ s/^($loc)?\///;
93 my $base = URI->new;
5ae68c0d 94 $base->scheme( $ENV{HTTPS} ? 'https' : 'http' );
6dc87a0f 95 $base->host( $c->apache->hostname );
96 $base->port( $c->apache->get_server_port );
97 my $path = $c->apache->location;
3803e98f 98 $base->path( $path =~ /\/$/ ? $path : "$path/" );
6dc87a0f 99 $c->request->base( $base->as_string );
fc7ec1d9 100}
101
23f9d934 102=item $c->prepare_request($r)
fc7ec1d9 103
104=cut
105
106sub prepare_request {
107 my ( $c, $r ) = @_;
13cafd1a 108 $c->apache( $ENV{MOD_PERL_API_VERSION} == 2
109 ? Apache2::Request->new($r)
110 : Apache::Request->new($r) );
fc7ec1d9 111}
112
c9afa5fc 113=item $c->run
114
115=cut
116
e646f111 117sub run { }
118
23f9d934 119=back
120
fc7ec1d9 121=head1 SEE ALSO
122
123L<Catalyst>.
124
125=head1 AUTHOR
126
127Sebastian Riedel, C<sri@cpan.org>
128
129=head1 COPYRIGHT
130
131This program is free software, you can redistribute it and/or modify it under
132the same terms as Perl itself.
133
134=cut
135
1361;