X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FRequest%2FUpload.pm;h=25e6d89f58f52183f8c1d44666367a715c72b4c6;hb=74dafab798a163c251e09de7fcc21a267d1678a6;hp=43a7cff191bfded79a5611a98b41a1f4adeb3013;hpb=b549b04945e1756688a2e79d7b065fe201001b6a;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Request/Upload.pm b/lib/Catalyst/Request/Upload.pm index 43a7cff..25e6d89 100644 --- a/lib/Catalyst/Request/Upload.pm +++ b/lib/Catalyst/Request/Upload.pm @@ -3,10 +3,11 @@ package Catalyst::Request::Upload; use strict; use base 'Class::Accessor::Fast'; +use Catalyst::Exception; use File::Copy (); use IO::File (); -__PACKAGE__->mk_accessors(qw/filename size tempname type/); +__PACKAGE__->mk_accessors(qw/filename headers size tempname type/); sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) } @@ -19,6 +20,7 @@ Catalyst::Request::Upload - Catalyst Request Upload Class $upload->copy_to $upload->fh $upload->filename; + $upload->headers; $upload->link_to; $upload->size; $upload->slurp; @@ -36,6 +38,10 @@ to the upload data. =over 4 +=item $upload->new + +simple constructor. + =item $upload->copy_to Copies tempname using C. Returns true for success, false otherwise. @@ -58,8 +64,15 @@ Opens tempname and returns a C handle. sub fh { my $self = shift; - my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY ) - or die( "Can't open ", $self->tempname, ": ", $! ); + my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY ); + + unless ( defined $fh ) { + + my $filename = $self->tempname; + + Catalyst::Exception->throw( + message => qq/Can't open '$filename': '$!'/ ); + } return $fh; } @@ -68,6 +81,10 @@ sub fh { Contains client supplied filename. +=item $upload->headers + +Returns a C object. + =item $upload->link_to Creates a hard link to the tempname. Returns true for success, @@ -95,7 +112,7 @@ Returns a scalar containing contents of tempname. sub slurp { my ( $self, $layer ) = @_; - unless ( $layer ) { + unless ($layer) { $layer = ':raw'; }