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