- Improved: Params handling with MP engines
[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
329a7e51 21This is a base class 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
06e1b616 39=item $c->finalize_body
fc7ec1d9 40
41=cut
42
06e1b616 43sub finalize_body {
fc7ec1d9 44 my $c = shift;
e060fe05 45 $c->apache->print( $c->response->body );
fc7ec1d9 46}
47
06e1b616 48=item $c->prepare_body
49
50=cut
51
52sub prepare_body {
53 my $c = shift;
54
55 my $length = $c->request->content_length;
56 my ( $buffer, $content );
57
58 while ($length) {
59
60 $c->apache->read( $buffer, ( $length < 8192 ) ? $length : 8192 );
61
62 $length -= length($buffer);
63 $content .= $buffer;
64 }
65
e060fe05 66 $c->request->body($content);
06e1b616 67}
68
0556eb49 69=item $c->prepare_connection
70
71=cut
72
73sub prepare_connection {
74 my $c = shift;
6dc87a0f 75 $c->request->hostname( $c->apache->connection->remote_host );
76 $c->request->address( $c->apache->connection->remote_ip );
fc7ec1d9 77}
78
23f9d934 79=item $c->prepare_headers
fc7ec1d9 80
81=cut
82
83sub prepare_headers {
84 my $c = shift;
6dc87a0f 85 $c->request->method( $c->apache->method );
86 $c->request->header( %{ $c->apache->headers_in } );
fc7ec1d9 87}
88
23f9d934 89=item $c->prepare_parameters
fc7ec1d9 90
91=cut
92
93sub prepare_parameters {
94 my $c = shift;
e7c0c583 95
b9e9fff6 96 my @params;
97
98 $c->apache->param->do( sub {
99 my ( $field, $value ) = @_;
100 push( @params, $field, $value );
101 return 1;
102 });
103
104 $c->req->_assign_values( $c->req->parameters, \@params );
fc7ec1d9 105}
106
23f9d934 107=item $c->prepare_path
fc7ec1d9 108
109=cut
110
13cafd1a 111# XXX needs fixing, only work with <Location> directive,
6dc87a0f 112# not <Directory> directive
fc7ec1d9 113sub prepare_path {
114 my $c = shift;
6dc87a0f 115 $c->request->path( $c->apache->uri );
116 my $loc = $c->apache->location;
fc7ec1d9 117 no warnings 'uninitialized';
118 $c->req->{path} =~ s/^($loc)?\///;
119 my $base = URI->new;
5ae68c0d 120 $base->scheme( $ENV{HTTPS} ? 'https' : 'http' );
6dc87a0f 121 $base->host( $c->apache->hostname );
122 $base->port( $c->apache->get_server_port );
123 my $path = $c->apache->location;
3803e98f 124 $base->path( $path =~ /\/$/ ? $path : "$path/" );
6dc87a0f 125 $c->request->base( $base->as_string );
fc7ec1d9 126}
127
c9afa5fc 128=item $c->run
129
130=cut
131
e646f111 132sub run { }
133
23f9d934 134=back
135
fc7ec1d9 136=head1 SEE ALSO
137
138L<Catalyst>.
139
140=head1 AUTHOR
141
142Sebastian Riedel, C<sri@cpan.org>
329a7e51 143Christian Hansen C<ch@ngmedia.com>
fc7ec1d9 144
145=head1 COPYRIGHT
146
147This program is free software, you can redistribute it and/or modify it under
148the same terms as Perl itself.
149
150=cut
151
1521;