fix decoded uploads
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request / Upload.pm
index 39bc4c0..486653c 100644 (file)
@@ -99,6 +99,14 @@ false for failure.
 
      $upload->copy_to('/path/to/target');
 
+Please note the filename used for the copy target is the 'tempname' that
+is the actual filename on the filesystem, NOT the 'filename' that was
+part of the upload headers.  This might seem counter intuitive but at this
+point this behavior is so established that its not something we can change.
+
+You can always create your own copy routine that munges the target path
+as you wish.
+
 =cut
 
 sub copy_to {
@@ -203,14 +211,20 @@ sub slurp {
         $layer = ':raw';
     }
 
-    my $content = undef;
+    my $content = '';
     my $handle  = $self->fh;
 
     binmode( $handle, $layer );
 
     $handle->seek(0, IO::File::SEEK_SET);
-    while ( $handle->sysread( my $buffer, 8192 ) ) {
-        $content .= $buffer;
+
+    if ($layer eq ':raw') {
+        while ( $handle->sysread( my $buffer, 8192 ) ) {
+            $content .= $buffer;
+        }
+    }
+    else {
+        $content = do { local $/; $handle->getline };
     }
 
     $handle->seek(0, IO::File::SEEK_SET);
@@ -229,11 +243,9 @@ sub decoded_slurp {
     my ( $self, $layer ) = @_;
     my $handle = $self->decoded_fh($layer);
 
-    my $content = undef;
     $handle->seek(0, IO::File::SEEK_SET);
-    while ( $handle->sysread( my $buffer, 8192 ) ) {
-        $content .= $buffer;
-    }
+
+    my $content = do { local $/; $handle->getline };
 
     $handle->seek(0, IO::File::SEEK_SET);
     return $content;