minor typos in new Mason.pm
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request / Upload.pm
index 5891332..43a7cff 100644 (file)
@@ -8,6 +8,7 @@ use IO::File   ();
 
 __PACKAGE__->mk_accessors(qw/filename size tempname type/);
 
+sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) }
 
 =head1 NAME
 
@@ -20,6 +21,7 @@ Catalyst::Request::Upload - Catalyst Request Upload Class
     $upload->filename;
     $upload->link_to;
     $upload->size;
+    $upload->slurp;
     $upload->tempname;
     $upload->type;
 
@@ -34,14 +36,6 @@ to the upload data.
 
 =over 4
 
-=item $upload->new
-
-Constructor. Normally only for engine use.
-
-=cut 
-
-sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) }
-
 =item $upload->copy_to
 
 Copies tempname using C<File::Copy>. Returns true for success, false otherwise.
@@ -92,6 +86,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.