X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FRequest%2FUpload.pm;h=9a5f1c4e6b3969e61f9c4a0c60c33e9d050c87df;hp=ff0b5dee23b67376b517d9eaf5e8658bb93bd44f;hb=b5ecfcf07b8ffe7e9984f0279c8781ce51c6ac6a;hpb=a2f2cde95194a17fe2401ae58c92b5494bac599f diff --git a/lib/Catalyst/Request/Upload.pm b/lib/Catalyst/Request/Upload.pm index ff0b5de..9a5f1c4 100644 --- a/lib/Catalyst/Request/Upload.pm +++ b/lib/Catalyst/Request/Upload.pm @@ -7,19 +7,20 @@ 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] : {@_} ) } =head1 NAME -Catalyst::Request::Upload - Catalyst Request Upload Class +Catalyst::Request::Upload - handles file upload requests =head1 SYNOPSIS - $upload->copy_to - $upload->fh + $upload->copy_to; + $upload->fh; $upload->filename; + $upload->headers; $upload->link_to; $upload->size; $upload->slurp; @@ -30,20 +31,18 @@ See also L. =head1 DESCRIPTION -This is the Catalyst Request Upload class, which provides a set of accessors -to the upload data. +This class provides accessors and methods to handle client upload requests. =head1 METHODS -=over 4 +=head2 $upload->new -=item $upload->new +Simple constructor. -simple constructor. +=head2 $upload->copy_to -=item $upload->copy_to - -Copies tempname using C. Returns true for success, false otherwise. +Copies the temporary file using L. Returns true for success, +false for failure. $upload->copy_to('/path/to/target'); @@ -54,9 +53,9 @@ sub copy_to { return File::Copy::copy( $self->tempname, @_ ); } -=item $upload->fh +=head2 $upload->fh -Opens tempname and returns a C handle. +Opens a temporary file (see tempname below) and returns an L handle. =cut @@ -64,27 +63,30 @@ sub fh { my $self = shift; 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': '$!'/ - ); + message => qq/Can't open '$filename': '$!'/ ); } return $fh; } -=item $upload->filename +=head2 $upload->filename -Contains client supplied filename. +Returns the client-supplied filename. -=item $upload->link_to +=head2 $upload->headers -Creates a hard link to the tempname. Returns true for success, -false otherwise. +Returns an L object for the request. + +=head2 $upload->link_to + +Creates a hard link to the temporary file. Returns true for success, +false for failure. $upload->link_to('/path/to/target'); @@ -95,20 +97,20 @@ sub link_to { return CORE::link( $self->tempname, $target ); } -=item $upload->size +=head2 $upload->size -Contains size of the file in bytes. +Returns the size of the uploaded file in bytes. -=item $upload->slurp +=head2 $upload->slurp -Returns a scalar containing contents of tempname. +Returns a scalar containing the contents of the temporary file. =cut sub slurp { my ( $self, $layer ) = @_; - unless ( $layer ) { + unless ($layer) { $layer = ':raw'; } @@ -124,19 +126,18 @@ sub slurp { return $content; } -=item $upload->tempname +=head2 $upload->tempname -Contains path to the temporary spool file. +Returns the path to the temporary file. -=item $upload->type +=head2 $upload->type -Contains client supplied Content-Type. +Returns the client-supplied Content-Type. -=back - -=head1 AUTHOR +=head1 AUTHORS Sebastian Riedel, C + Christian Hansen, C =head1 COPYRIGHT