Fixed MP engines, only load what we need
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / Apache / MP20.pm
1 package Catalyst::Engine::Apache::MP20;
2
3 use strict;
4 use base 'Catalyst::Engine::Apache::Base';
5
6 use Apache2::Connection  ();
7 use Apache2::Const       ();
8 use Apache2::RequestIO   ();
9 use Apache2::RequestRec  ();
10 use Apache2::RequestUtil ();
11 use Apache2::Request     ();
12 use Apache2::Upload      ();
13
14 Apache2::Const->import( -compile => ':common' );
15
16 =head1 NAME
17
18 Catalyst::Engine::Apache::MP20 - Catalyst Apache MP20 Engine
19
20 =head1 SYNOPSIS
21
22 See L<Catalyst>.
23
24 =head1 DESCRIPTION
25
26 This is the Catalyst engine specialized for Apache mod_perl version 2.0.
27
28 =head1 OVERLOADED METHODS
29
30 This class overloads some methods from C<Catalyst::Engine::Apache::Base>.
31
32 =over 4
33
34 =item $c->finalize_headers
35
36 =cut
37
38 sub finalize_headers {
39     my $c = shift;
40
41     for my $name ( $c->response->headers->header_field_names ) {
42         next if $name =~ /Content-Type/i;
43         my @values = $c->response->header($name);
44         $c->apache->headers_out->add( $name => $_ ) for @values;
45     }
46
47     if ( $c->response->header('Set-Cookie') && $c->response->status >= 300 ) {
48         my @values = $c->response->header('Set-Cookie');
49         $c->apache->err_headers_out->add( 'Set-Cookie' => $_ ) for @values;
50     }
51
52     $c->apache->status( $c->response->status );
53     $c->apache->content_type( $c->response->header('Content-Type') );
54
55     return 0;
56 }
57
58 =item $c->handler
59
60 =cut
61
62 sub handler : method {
63     shift->SUPER::handler(@_);
64 }
65
66 =item $c->prepare_request($r)
67
68 =cut
69
70 sub prepare_request {
71     my ( $c, $r ) = @_;
72     $c->apache( Apache2::Request->new($r) );
73 }
74
75 =item $c->prepare_uploads
76
77 =cut
78
79 sub prepare_uploads {
80     my $c = shift;
81
82     my @uploads;
83
84     $c->apache->upload->do( sub {
85         my ( $field, $upload ) = @_;
86
87         my $object = Catalyst::Request::Upload->new(
88             filename => $upload->filename,
89             size     => $upload->size,
90             tempname => $upload->tempname,
91             type     => $upload->type
92         );
93
94         push( @uploads, $field, $object );
95
96         return 1;
97     });
98
99     $c->request->upload(@uploads);
100 }
101
102 =back
103
104 =head1 SEE ALSO
105
106 L<Catalyst>, L<Catalyst::Engine>, L<Catalyst::Engine::Apache::Base>.
107
108 =head1 AUTHOR
109
110 Sebastian Riedel, C<sri@cpan.org>
111 Christian Hansen C<ch@ngmedia.com>
112
113 =head1 COPYRIGHT
114
115 This program is free software, you can redistribute it and/or modify it under
116 the same terms as Perl itself.
117
118 =cut
119
120 1;