Fixed cookbook
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / CGI / APR.pm
CommitLineData
e05d67cf 1package Catalyst::Engine::CGI::APR;
2
3use strict;
4use base 'Catalyst::Engine::CGI::Base';
5
6use APR;
7use APR::Pool;
8use APR::Request;
9use APR::Request::CGI;
10use APR::Request::Param;
11
12=head1 NAME
13
14Catalyst::Engine::CGI::APR - The CGI APR Engine
15
16=head1 SYNOPSIS
17
18A script using the Catalyst::Engine::CGI::APR module might look like:
19
20 #!/usr/bin/perl -w
21
22 BEGIN {
23 $ENV{CATALYST_ENGINE} = 'CGI::APR';
24 }
25
26 use strict;
27 use lib '/path/to/MyApp/lib';
28 use MyApp;
29
30 MyApp->run;
31
32=head1 DESCRIPTION
33
34This Catalyst engine uses C<APR::Request> for parsing of message body.
35
36=head1 OVERLOADED METHODS
37
38This class overloads some methods from C<Catalyst::Engine::CGI::Base>.
39
40=over 4
41
42=item $c->prepare_parameters
43
44=cut
45
46sub prepare_parameters {
47 my $c = shift;
48
49 my @params;
50
51 $c->cgi->param->do( sub {
52 my ( $field, $value ) = @_;
53 push( @params, $field, $value );
54 return 1;
55 });
56
57 $c->request->param(@params);
58}
59
60=item $c->prepare_request
61
62=cut
63
64sub prepare_request {
65 my $c = shift;
66 $c->cgi( APR::Request::CGI->new( APR::Pool->new ) );
67}
68
69=item $c->prepare_uploads
70
71=cut
72
73sub prepare_uploads {
74 my $c = shift;
75
76 my @uploads;
77
78 $c->cgi->upload->do( sub {
79 my ( $field, $upload ) = @_;
80
81 my $object = Catalyst::Request::Upload->new(
82 filename => $upload->filename,
83 size => $upload->size,
84 tempname => $upload->tempname,
85 type => $upload->type
86 );
87
88 push( @uploads, $field, $object );
89
90 return 1;
91 });
92
93 $c->request->upload(@uploads);
94}
95
96=back
97
98=head1 SEE ALSO
99
c24122df 100L<Catalyst>, L<Catalyst::Engine>, L<Catalyst::Engine::CGI::Base>,
101sL<APR::Request>.
e05d67cf 102
103=head1 AUTHOR
104
105Sebastian Riedel, C<sri@cpan.org>
106Christian Hansen, C<ch@ngmedia.com>
107
108=head1 COPYRIGHT
109
110This program is free software, you can redistribute it and/or modify it under
111the same terms as Perl itself.
112
113=cut
114
1151;