X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FRequest%2FUpload.pm;h=783733b06e7228e315decfa2048dea2549f1a657;hb=cd3bb2484489456f53fc03b568e34bfaf508a3cf;hp=389f81043032c20c2a67b5c64a5ab744e3b23c8d;hpb=47ae6960753acadac1da528c87c5d5009b675281;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Request/Upload.pm b/lib/Catalyst/Request/Upload.pm index 389f810..783733b 100644 --- a/lib/Catalyst/Request/Upload.pm +++ b/lib/Catalyst/Request/Upload.pm @@ -16,11 +16,12 @@ Catalyst::Request::Upload - Catalyst Request Upload Class =head1 SYNOPSIS - $upload->copy + $upload->copy_to $upload->fh $upload->filename; - $upload->link; + $upload->link_to; $upload->size; + $upload->slurp; $upload->tempname; $upload->type; @@ -35,15 +36,21 @@ to the upload data. =over 4 -=item $upload->copy( $target [, $bufferlen ] ) +=item $upload->new + +simple constructor. + +=item $upload->copy_to Copies tempname using C. Returns true for success, false otherwise. + $upload->copy_to('/path/to/target'); + =cut -sub copy { - my ( $self, $target, $buffer ) = @_; - return File::Copy::copy( $self->tempname, $target, $buffer ); +sub copy_to { + my $self = shift; + return File::Copy::copy( $self->tempname, @_ ); } =item $upload->fh @@ -65,16 +72,16 @@ sub fh { Contains client supplied filename. -=item $upload->link +=item $upload->link_to -Creates a new filename linked to the old filename. Returns true for -success, false otherwise. +Creates a hard link to the tempname. Returns true for success, +false otherwise. - $upload->link('/my/path'); + $upload->link_to('/path/to/target'); =cut -sub link { +sub link_to { my ( $self, $target ) = @_; return CORE::link( $self->tempname, $target ); } @@ -83,6 +90,31 @@ sub link { 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.