applied patch to allow a tmpdir setting.
Marcus Ramberg [Thu, 30 Mar 2006 12:29:34 +0000 (12:29 +0000)]
Changes
lib/Catalyst/Engine.pm
lib/Catalyst/Request/Upload.pm

diff --git a/Changes b/Changes
index b388fa8..f5cdebb 100644 (file)
--- a/Changes
+++ b/Changes
@@ -8,6 +8,8 @@ This file documents the revision history for Perl extension Catalyst.
         - Changed default behaviors for $c->model/$c->controller/$c->view
           to more sane settings.
         - added the clear_errors method - an alias for error(0)
+        - Added tmpdir option for uploads (Kei OHSHIRO)
+        - Applied patch from GEOFFR to allow normal filehandles.
 
 5.66    2006-03-10 17:48:00
         - Added Test::WWW::Mechanize::Catalyst support
index ff2e797..0c8929a 100644 (file)
@@ -39,15 +39,16 @@ Finalize body.  Prints the response output.
 
 sub finalize_body {
     my ( $self, $c ) = @_;
-    if ( ref $c->response->body && $c->response->body->can('read') ) {
-        while ( !$c->response->body->eof() ) {
-            $c->response->body->read( my $buffer, $CHUNKSIZE );
+    my $body = $c->response->body;
+    if ( ref $body && ($body->can('read') || ref($body) eq 'GLOB') ) {
+        while ( !eof $body ) {
+            read $body, my $buffer, $CHUNKSIZE;
             last unless $self->write( $c, $buffer );
         }
-        $c->response->body->close();
+        close $body;
     }
     else {
-        $self->write( $c, $c->response->body );
+        $self->write( $c, $body );
     }
 }
 
@@ -315,6 +316,7 @@ sub prepare_body {
 
     unless ( $c->request->{_body} ) {
         $c->request->{_body} = HTTP::Body->new( $type, $self->read_length );
+        $c->request->{_body}->{tmpdir} = $c->config->{uploadtmp} if exists $c->config->{uploadtmp};
     }
 
     if ( $self->read_length > 0 ) {
index 9a5f1c4..a3e6f55 100644 (file)
@@ -27,6 +27,11 @@ Catalyst::Request::Upload - handles file upload requests
     $upload->tempname;
     $upload->type;
 
+To specify where Catalyst should put the temporary files, set the 'uploadtmp'
+option in the Catalyst config. If unset, Catalyst will use the system temp dir.
+
+    __PACKAGE__->config( uploadtmp => '/path/to/tmpdir' );
+
 See also L<Catalyst>.
 
 =head1 DESCRIPTION