- Added multi-action-from-begin example to cookbook
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request / Upload.pm
index 5df78ee..783733b 100644 (file)
@@ -21,6 +21,7 @@ Catalyst::Request::Upload - Catalyst Request Upload Class
     $upload->filename;
     $upload->link_to;
     $upload->size;
+    $upload->slurp;
     $upload->tempname;
     $upload->type;
 
@@ -35,6 +36,10 @@ to the upload data.
 
 =over 4
 
+=item $upload->new
+
+simple constructor.
+
 =item $upload->copy_to
 
 Copies tempname using C<File::Copy>. Returns true for success, false otherwise.
@@ -85,6 +90,31 @@ sub link_to {
 
 Contains size of the file in bytes.
 
+=item $upload->slurp
+
+Returns a scalar containing contents of tempname.
+
+=cut
+
+sub slurp {
+    my ( $self, $layer ) = @_;
+
+    unless ( $layer ) {
+        $layer = ':raw';
+    }
+
+    my $content = undef;
+    my $handle  = $self->fh;
+
+    binmode( $handle, $layer );
+
+    while ( $handle->sysread( my $buffer, 8192 ) ) {
+        $content .= $buffer;
+    }
+
+    return $content;
+}
+
 =item $upload->tempname
 
 Contains path to the temporary spool file.