[Catalyst] Make slurp() start at the beginning, and restore the file position when done.

Adam Sjøgren adsj at novozymes.com
Tue Feb 15 15:38:15 GMT 2011


---
 lib/Catalyst/Request/Upload.pm |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/lib/Catalyst/Request/Upload.pm b/lib/Catalyst/Request/Upload.pm
index aee3625..bf048b1 100644
--- a/lib/Catalyst/Request/Upload.pm
+++ b/lib/Catalyst/Request/Upload.pm
@@ -5,7 +5,7 @@ with 'MooseX::Emulate::Class::Accessor::Fast';
 
 use Catalyst::Exception;
 use File::Copy ();
-use IO::File   ();
+use IO::File qw(SEEK_SET);
 use File::Spec::Unix;
 
 has filename => (is => 'rw');
@@ -142,10 +142,15 @@ sub slurp {
 
     binmode( $handle, $layer );
 
+    my $prevpos = $handle->getpos;
+
+    $handle->seek(0, SEEK_SET);
     while ( $handle->sysread( my $buffer, 8192 ) ) {
         $content .= $buffer;
     }
 
+    $handle->setpos($prevpos);
+
     return $content;
 }
 
-- 
1.7.2.3



More information about the Catalyst mailing list