Commit | Line | Data |
---|---|---|
fc7ec1d9 | 1 | package Catalyst::Engine::Apache; |
2 | ||
3 | use strict; | |
fc7ec1d9 | 4 | use base 'Catalyst::Engine'; |
e7c0c583 | 5 | |
fc7ec1d9 | 6 | use URI; |
bc146cf4 | 7 | use URI::http; |
fc7ec1d9 | 8 | |
6dc87a0f | 9 | __PACKAGE__->mk_accessors(qw/apache/); |
fc7ec1d9 | 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 | ||
23f9d934 | 21 | This 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 | |
29 | Returns an C<Apache::Request> object. | |
30 | ||
23f9d934 | 31 | =back |
32 | ||
33 | =head1 OVERLOADED METHODS | |
fc7ec1d9 | 34 | |
35 | This 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 | ||
43 | sub 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 | ||
52 | sub 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 | ||
62 | sub 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 | ||
72 | sub 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 | ||
6dc87a0f | 85 | # XXX needs fixing, only work with <Location> directive, |
86 | # not <Directory> directive | |
fc7ec1d9 | 87 | sub 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 | ||
106 | sub prepare_request { | |
107 | my ( $c, $r ) = @_; | |
6dc87a0f | 108 | $c->apache( Apache::Request->new($r) ); |
fc7ec1d9 | 109 | } |
110 | ||
c9afa5fc | 111 | =item $c->run |
112 | ||
113 | =cut | |
114 | ||
e646f111 | 115 | sub run { } |
116 | ||
23f9d934 | 117 | =back |
118 | ||
fc7ec1d9 | 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; |