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