1 package Catalyst::Request::Upload;
4 use base 'Class::Accessor::Fast';
6 use Catalyst::Exception;
10 __PACKAGE__->mk_accessors(qw/filename size tempname type/);
12 sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) }
16 Catalyst::Request::Upload - Catalyst Request Upload Class
33 This is the Catalyst Request Upload class, which provides a set of accessors
44 =item $upload->copy_to
46 Copies tempname using C<File::Copy>. Returns true for success, false otherwise.
48 $upload->copy_to('/path/to/target');
54 return File::Copy::copy( $self->tempname, @_ );
59 Opens tempname and returns a C<IO::File> handle.
66 my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY );
68 unless ( defined $fh ) {
70 my $filename = $self->tempname;
72 Catalyst::Exception->throw(
73 message => qq/Can't open '$filename': '$!'/
80 =item $upload->filename
82 Contains client supplied filename.
84 =item $upload->link_to
86 Creates a hard link to the tempname. Returns true for success,
89 $upload->link_to('/path/to/target');
94 my ( $self, $target ) = @_;
95 return CORE::link( $self->tempname, $target );
100 Contains size of the file in bytes.
104 Returns a scalar containing contents of tempname.
109 my ( $self, $layer ) = @_;
116 my $handle = $self->fh;
118 binmode( $handle, $layer );
120 while ( $handle->sysread( my $buffer, 8192 ) ) {
127 =item $upload->tempname
129 Contains path to the temporary spool file.
133 Contains client supplied Content-Type.
139 Sebastian Riedel, C<sri@cpan.org>
140 Christian Hansen, C<ch@ngmedia.com>
144 This program is free software, you can redistribute it and/or modify
145 it under the same terms as Perl itself.