Added C::E::CGI::APR and C::E::FastCGI::APR
Christian Hansen [Mon, 25 Apr 2005 21:08:33 +0000 (21:08 +0000)]
lib/Catalyst/Engine/CGI/APR.pm [new file with mode: 0644]
lib/Catalyst/Engine/CGI/Base.pm
lib/Catalyst/Engine/FastCGI/APR.pm [new file with mode: 0644]

diff --git a/lib/Catalyst/Engine/CGI/APR.pm b/lib/Catalyst/Engine/CGI/APR.pm
new file mode 100644 (file)
index 0000000..9162afb
--- /dev/null
@@ -0,0 +1,114 @@
+package Catalyst::Engine::CGI::APR;
+
+use strict;
+use base 'Catalyst::Engine::CGI::Base';
+
+use APR;
+use APR::Pool;
+use APR::Request;
+use APR::Request::CGI;
+use APR::Request::Param;
+
+=head1 NAME
+
+Catalyst::Engine::CGI::APR - The CGI APR Engine
+
+=head1 SYNOPSIS
+
+A script using the Catalyst::Engine::CGI::APR module might look like:
+
+    #!/usr/bin/perl -w
+
+    BEGIN { 
+       $ENV{CATALYST_ENGINE} = 'CGI::APR';
+    }
+
+    use strict;
+    use lib '/path/to/MyApp/lib';
+    use MyApp;
+
+    MyApp->run;
+
+=head1 DESCRIPTION
+
+This Catalyst engine uses C<APR::Request> for parsing of message body.
+
+=head1 OVERLOADED METHODS
+
+This class overloads some methods from C<Catalyst::Engine::CGI::Base>.
+
+=over 4
+
+=item $c->prepare_parameters
+
+=cut
+
+sub prepare_parameters {
+    my $c = shift;
+
+    my @params;
+
+    $c->cgi->param->do( sub {
+        my ( $field, $value ) = @_;
+        push( @params, $field, $value );
+        return 1;    
+    });
+
+    $c->request->param(@params);
+}
+
+=item $c->prepare_request
+
+=cut
+
+sub prepare_request {
+    my $c = shift;
+    $c->cgi( APR::Request::CGI->new( APR::Pool->new ) );
+}
+
+=item $c->prepare_uploads
+
+=cut
+
+sub prepare_uploads {
+    my $c = shift;
+
+    my @uploads;
+
+    $c->cgi->upload->do( sub {
+        my ( $field, $upload ) = @_;
+
+        my $object = Catalyst::Request::Upload->new(
+            filename => $upload->filename,
+            size     => $upload->size,
+            tempname => $upload->tempname,
+            type     => $upload->type
+        );
+
+        push( @uploads, $field, $object );
+
+        return 1;
+    });
+
+    $c->request->upload(@uploads);
+}
+
+=back
+
+=head1 SEE ALSO
+
+L<Catalyst> L<Catalyst::Engine> L<Catalyst::Engine::CGI::Base> L<APR::Request>.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri@cpan.org>
+Christian Hansen, C<ch@ngmedia.com>
+
+=head1 COPYRIGHT
+
+This program is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
+
+1;
index 0f1152b..bc4ef87 100644 (file)
@@ -3,6 +3,7 @@ package Catalyst::Engine::CGI::Base;
 use strict;
 use base 'Catalyst::Engine';
 
+use IO::File ();
 use URI;
 use URI::http;
 
@@ -56,6 +57,23 @@ sub finalize_headers {
     print "\015\012";
 }
 
+=item $c->prepare_body
+
+=cut
+
+sub prepare_body {
+    my $c = shift;
+    
+    my $handle = IO::File->new_from_fd( fileno(STDIN), IO::File::O_RDONLY );
+    my $body   = undef;  
+    
+    while ( $handle->sysread( my $buffer, 8192 ) ) {
+        $body .= $buffer;
+    }
+    
+    $c->request->body($body);
+}
+
 =item $c->prepare_connection
 
 =cut
diff --git a/lib/Catalyst/Engine/FastCGI/APR.pm b/lib/Catalyst/Engine/FastCGI/APR.pm
new file mode 100644 (file)
index 0000000..cb9d95d
--- /dev/null
@@ -0,0 +1,46 @@
+package Catalyst::Engine::FastCGI::APR;
+
+use strict;
+use base qw(Catalyst::Engine::FastCGI::Base Catalyst::Engine::CGI::APR);
+
+=head1 NAME
+
+Catalyst::Engine::FastCGI::APR - Catalyst FastCGI APR Engine
+
+=head1 SYNOPSIS
+
+A script using the Catalyst::Engine::FastCGI::APR module might look like:
+
+    #!/usr/bin/perl -w
+
+    BEGIN { 
+       $ENV{CATALYST_ENGINE} = 'FastCGI::APR';
+    }
+
+    use strict;
+    use lib '/path/to/MyApp/lib';
+    use MyApp;
+
+    MyApp->run;
+
+=head1 DESCRIPTION
+
+This is the Catalyst engine for FastCGI and APR.
+
+=head1 SEE ALSO
+
+L<Catalyst>, L<Catalyst::Engine::CGI::APR>.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri@cpan.org>
+Christian Hansen, C<ch@ngmedia.com>
+
+=head1 COPYRIGHT
+
+This program is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
+
+1;